From 6e97a5d400ac18a91cd44922c1a8f412bc23acfb Mon Sep 17 00:00:00 2001 From: Gosuke Miyashita Date: Mon, 22 Jun 2015 16:59:10 +0900 Subject: [PATCH] Support checking MySQL configuration --- lib/serverspec/helper/type.rb | 15 ++++++++------- lib/serverspec/type/mysql_config.rb | 10 ++++++++++ spec/type/base/mysql_config_spec.rb | 13 +++++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 lib/serverspec/type/mysql_config.rb create mode 100644 spec/type/base/mysql_config_spec.rb diff --git a/lib/serverspec/helper/type.rb b/lib/serverspec/helper/type.rb index 7c5153ce..0fc87089 100644 --- a/lib/serverspec/helper/type.rb +++ b/lib/serverspec/helper/type.rb @@ -2,13 +2,14 @@ module Serverspec module Helper module Type types = %w( - base bridge bond cgroup command cron default_gateway file fstab group host - iis_website iis_app_pool interface ipfilter ipnat iptables - ip6tables kernel_module linux_kernel_parameter lxc mail_alias - package php_config port ppa process routing_table selinux - selinux_module service user yumrepo windows_feature - windows_hot_fix windows_registry_key windows_scheduled_task zfs - docker_base docker_image docker_container x509_certificate x509_private_key + base bridge bond cgroup command cron default_gateway file fstab + group host iis_website iis_app_pool interface ipfilter ipnat + iptables ip6tables kernel_module linux_kernel_parameter lxc + mail_alias mysql_config package php_config port ppa process + routing_table selinux selinux_module service user yumrepo + windows_feature windows_hot_fix windows_registry_key + windows_scheduled_task zfs docker_base docker_image + docker_container x509_certificate x509_private_key ) types.each {|type| require "serverspec/type/#{type}" } diff --git a/lib/serverspec/type/mysql_config.rb b/lib/serverspec/type/mysql_config.rb new file mode 100644 index 00000000..939b1ac8 --- /dev/null +++ b/lib/serverspec/type/mysql_config.rb @@ -0,0 +1,10 @@ +module Serverspec::Type + class MysqlConfig < Base + def value + ret = @runner.run_command("mysqld --verbose --help 2> /dev/null | grep '^#{@name}'") + val = ret.stdout.match(/#{@name}\s+(.+)$/)[1] + val = val.to_i if val.match(/^\d+$/) + val + end + end +end diff --git a/spec/type/base/mysql_config_spec.rb b/spec/type/base/mysql_config_spec.rb new file mode 100644 index 00000000..0a3d25f6 --- /dev/null +++ b/spec/type/base/mysql_config_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +set :os, :family => 'base' + +describe mysql_config('innodb-buffer-pool-size') do + let(:stdout) { 'innodb-buffer-pool-size 134217728' } + its(:value) { should eq 134217728 } +end + +describe mysql_config('socket') do + let(:stdout) { 'socket /tmp/mysql.sock' } + its(:value) { should eq '/tmp/mysql.sock' } +end