From b9743deaca74a040a7d28b36912fb3a6cea87a6b Mon Sep 17 00:00:00 2001 From: Nitin Mohan Date: Thu, 9 Jan 2014 14:00:03 -0800 Subject: [PATCH] Add shared_server test suite --- .kitchen.yml | 19 +++- .../serverspec/server_spec.rb | 93 +++++++++++++++++++ .../serverspec/spec_helper.rb | 0 .../serverspec/server_spec.rb | 29 ++++++ .../shared_server/serverspec/spec_helper.rb | 5 + 5 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 test/integration/dedicated_server/serverspec/server_spec.rb rename test/integration/{server => dedicated_server}/serverspec/spec_helper.rb (100%) rename test/integration/{server => shared_server}/serverspec/server_spec.rb (64%) create mode 100644 test/integration/shared_server/serverspec/spec_helper.rb diff --git a/.kitchen.yml b/.kitchen.yml index 9bac89b..380165f 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -12,7 +12,7 @@ platforms: box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box customize: cpus: 2 - memory: 1024 + memory: 512 - name: centos-6.4 run_list: - recipe[yum::epel] @@ -21,10 +21,10 @@ platforms: box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box customize: cpus: 2 - memory: 1024 + memory: 512 suites: -- name: server +- name: dedicated_server run_list: - recipe[rs-mysql::server] - recipe[fake::database_mysql] @@ -33,3 +33,16 @@ suites: server_root_password: rootpass server_debian_password: debpass server_repl_password: replpass + rs-mysql: + server_usage: dedicated +- name: shared_server + run_list: + - recipe[rs-mysql::server] + - recipe[fake::database_mysql] + attributes: + mysql: + server_root_password: rootpass + server_debian_password: debpass + server_repl_password: replpass + rs-mysql: + server_usage: shared diff --git a/test/integration/dedicated_server/serverspec/server_spec.rb b/test/integration/dedicated_server/serverspec/server_spec.rb new file mode 100644 index 0000000..63ecc1a --- /dev/null +++ b/test/integration/dedicated_server/serverspec/server_spec.rb @@ -0,0 +1,93 @@ +require 'spec_helper' + +mysql_name = '' +case backend.check_os[:family] +when 'Ubuntu' + mysql_name = 'mysql' + mysql_config_file = '/etc/mysql/my.cnf' + mysql_server_packages = %w{mysql-server apparmor-utils} +when 'RedHat' + mysql_name = 'mysqld' + mysql_config_file = '/etc/my.cnf' + mysql_server_packages = %w{mysql-server} +end + +describe "MySQL server packages are installed" do + mysql_server_packages.each do |pkg| + describe package(pkg) do + it { should be_installed } + end + end +end + +describe service(mysql_name) do + it { should be_enabled } + it { should be_running } +end + +describe port(3306) do + it { should be_listening } +end + +describe file(mysql_config_file) do + it { should be_file } +end + +describe "verify the tuning attributes set in #{mysql_config_file}" do + { + query_cache_size: "4M", + innodb_buffer_pool_size: "392M", + thread_cache_size: 50, + max_connections: 800, + wait_timeout: 28800, + net_read_timeout: 30, + net_write_timeout: 30, + back_log: 128, + max_heap_table_size: "32M", + read_buffer_size: "1M", + read_rnd_buffer_size: "4M", + long_query_time: 5, + key_buffer: "16M", + max_allowed_packet: "20M", + innodb_log_file_size: "4M", + innodb_log_buffer_size: "16M", + table_cache: 256, + sort_buffer_size: "2M", + innodb_additional_mem_pool_size: "50M", + myisam_sort_buffer_size: "64M" + }.each do |attribute, value| + describe command("grep -E \"^#{attribute}\\s+\" #{mysql_config_file}") do + it { should return_stdout /#{value}/ } + end + end +end + +describe file('/var/lib/mysql') do + it { should be_directory } +end + +describe "can run MySQL queries on the server" do + describe "'app_test' database exists" do + describe command( + "echo \"SHOW DATABASES LIKE 'app_test'\" | mysql --user=root --password=rootpass" + ) do + it { should return_stdout /app_test/ } + end + end + + describe "select tables from a database" do + describe command( + "echo \"USE app_test; SELECT * FROM app_test\" | mysql --user=root --password=rootpass" + ) do + it { should return_stdout /I am in the db/ } + end + end + + describe "create database" do + describe command( + "echo \"CREATE DATABASE IF NOT EXISTS blah; SHOW DATABASES LIKE 'blah'\" | mysql --user=root --password=rootpass" + ) do + it { should return_stdout /blah/ } + end + end +end diff --git a/test/integration/server/serverspec/spec_helper.rb b/test/integration/dedicated_server/serverspec/spec_helper.rb similarity index 100% rename from test/integration/server/serverspec/spec_helper.rb rename to test/integration/dedicated_server/serverspec/spec_helper.rb diff --git a/test/integration/server/serverspec/server_spec.rb b/test/integration/shared_server/serverspec/server_spec.rb similarity index 64% rename from test/integration/server/serverspec/server_spec.rb rename to test/integration/shared_server/serverspec/server_spec.rb index 0a0f036..9ad52f5 100644 --- a/test/integration/server/serverspec/server_spec.rb +++ b/test/integration/shared_server/serverspec/server_spec.rb @@ -33,6 +33,35 @@ it { should be_file } end +describe "verify the tuning attributes set in #{mysql_config_file}" do + { + query_cache_size:"2M", + innodb_buffer_pool_size: "196M", + thread_cache_size: 25, + max_connections: 400, + wait_timeout: 14400, + net_read_timeout: 15, + net_write_timeout: 15, + back_log: 64, + max_heap_table_size: "16M", + read_buffer_size: "0M", + read_rnd_buffer_size: "2M", + long_query_time: 5, + key_buffer: "8M", + max_allowed_packet: "10M", + innodb_log_file_size: "2M", + innodb_log_buffer_size: "8M", + table_cache: 128, + sort_buffer_size: "1M", + innodb_additional_mem_pool_size: "25M", + myisam_sort_buffer_size: "32M" + }.each do |attribute, value| + describe command("grep -E \"^#{attribute}\\s+\" #{mysql_config_file}") do + it { should return_stdout /#{value}/ } + end + end +end + describe file('/var/lib/mysql') do it { should be_directory } end diff --git a/test/integration/shared_server/serverspec/spec_helper.rb b/test/integration/shared_server/serverspec/spec_helper.rb new file mode 100644 index 0000000..8e0d0d3 --- /dev/null +++ b/test/integration/shared_server/serverspec/spec_helper.rb @@ -0,0 +1,5 @@ +require 'serverspec' +require 'pathname' + +include Serverspec::Helper::Exec +include Serverspec::Helper::DetectOS