Skip to content

Commit

Permalink
Migrate ServerSpec to InSpec (#30)
Browse files Browse the repository at this point in the history
* Initial attempt
* Convert some resources to InSpec exclusive resource
* Put back chef/provisioning
* Remove unneccessary comments
* Convert munin and nagios conf for mysql to ini resource
* Use kernel_parameters resource from InSpec
  • Loading branch information
khashf committed May 22, 2019
1 parent e181d6a commit b770efe
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 164 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -23,3 +23,4 @@ clients/*
cookbooks/*
nodes/*
vms/*
.kitchen.list.yml
2 changes: 2 additions & 0 deletions .kitchen.yml
@@ -1,4 +1,6 @@
---
verifier:
name: inspec
driver:
flavor_ref: 'm1.medium'
provisioner:
Expand Down
6 changes: 6 additions & 0 deletions test/integration/backup/inspec/backup_spec.rb
@@ -0,0 +1,6 @@
describe file('/data/backup') do
it { should be_directory }
its('mode') { should cmp 0700 }
its('owner') { should eq 'root' }
its('group') { should eq 'root' }
end
10 changes: 0 additions & 10 deletions test/integration/backup/serverspec/backup_spec.rb

This file was deleted.

@@ -1,7 +1,3 @@
require 'serverspec'

set :backend, :exec

if os[:family] == 'redhat' && os[:release].to_i == 7
describe package 'mariadb' do
it { should be_installed }
Expand Down
62 changes: 62 additions & 0 deletions test/integration/mon/inspec/mon_spec.rb
@@ -0,0 +1,62 @@
describe file('/etc/nagios/mysql.cnf') do
its('mode') { should cmp 0600 }
its('owner') { should eq 'nrpe' }
its('group') { should eq 'nrpe' }
end

describe ini('/etc/nagios/mysql.cnf') do
its('client.user') { should eq 'monitor' }
its('client.password') { should eq 'ToJzwUyqQmyV4GgMVpz0' }
end

%w(
innodb
pidfile
processlist
replication-delay
).each do |p|
describe file("/etc/nagios/nrpe.d/pmp-check-mysql-#{p}.cfg") do
its('content') do
should match(%r{command\[pmp-check-mysql-#{p}\]=\/usr/lib64/nagios/plugins/pmp-check-mysql-#{p}})
end
end
describe command("/usr/lib64/nagios/plugins/pmp-check-mysql-#{p}") do
its('stdout') { should match(/^OK/) }
its('exit_status') { should eq 0 }
end
end

describe file('/etc/munin/plugin-conf.d/mysql') do
its('mode') { should cmp 0600 }
its('owner') { should eq 'munin' }
its('group') { should eq 'munin' }
its('content') { should match(/env.mysqluser monitor/) }
its('content') { should match(/env.mysqlpassword ToJzwUyqQmyV4GgMVpz0/) }
end

# bin_relay_log
# is excluded from here since it doesn't work
# for a single-node mysql installation
%w(
commands
connections
innodb_bpool
innodb_bpool_act
innodb_semaphores
qcache
qcache_mem
queries
slow
slowqueries
table_locks
threads
tmp_tables
).each do |p|
describe command("/usr/sbin/munin-run mysql_#{p}") do
its('exit_status') { should eq 0 }
end
end

describe command('/usr/local/libexec/mysql-accounting') do
its('exit_status') { should eq 0 }
end
64 changes: 0 additions & 64 deletions test/integration/mon/serverspec/mon_spec.rb

This file was deleted.

95 changes: 95 additions & 0 deletions test/integration/server/inspec/server_spec.rb
@@ -0,0 +1,95 @@
%w(
Percona-Server-server-56
Percona-Server-devel-56
Percona-Server-shared-56
percona-toolkit
percona-xtrabackup
).each do |p|
describe package(p) do
it { should be_installed }
end
end

# Mysql packages should not be installed
%w(
mysql
mysql-libs
mysql55-libs
).each do |p|
describe package(p) do
it { should_not be_installed }
end
end

%w(mysqld_safe mysqld).each do |p|
describe processes(p) do
it { should exist }
end
end

describe port(3306) do
it { should be_listening }
end

describe file('/root/.my.cnf') do
it { should be_file }
end

describe ini('/root/.my.cnf') do
its('client.user') { should eq 'root' }
its('client.password') { should eq '\'jzYY0cQUnPAMcqvIxYaC\'' }
its('mysqladmin.user') { should eq 'root' }
its('mysqladmin.password') { should eq '\'jzYY0cQUnPAMcqvIxYaC\'' }
its('mysqldump.user') { should eq 'root' }
its('mysqldump.password') { should eq '\'jzYY0cQUnPAMcqvIxYaC\'' }
end

describe kernel_parameter('vm.swappiness') do
its('value') { should eq 0 }
end

describe yum.repo('percona-noarch') do
it { should be_enabled }
end

describe crontab do
its('minutes') { should include '0' }
its('hours') { should include '0' }
its('days') { should include '*' }
its('months') { should include '*' }
its('weekdays') { should include '*' }
its('commands') do
should include '/usr/local/libexec/mysql-accounting'
end
end

describe crontab do
its('minutes') { should include '*/30' }
its('hours') { should include '*' }
its('days') { should include '*' }
its('months') { should include '*' }
its('weekdays') { should include '*' }
its('commands') do
should include '/usr/local/libexec/mysql-prometheus'
end
end

describe command('/usr/local/libexec/mysql-accounting') do
its('exit_status') { should eq 0 }
end

describe command('/usr/local/libexec/mysql-prometheus') do
its(:exit_status) { should eq 0 }
end

describe file('/var/lib/node_exporter/mysql_db_size.prom') do
[
/^mysql_db_size_start_time [0-9].+$/,
/^mysql_db_size\{name="information_schema"\} [0-9].+$/,
/^mysql_db_size\{name="mysql"\} [0-9].+$/,
/^mysql_db_size\{name="performance_schema"\} [0-9]+$/,
/^mysql_db_size_completion_time [0-9].+$/,
].each do |line|
its(:content) { should match(line) }
end
end
81 changes: 0 additions & 81 deletions test/integration/server/serverspec/server_spec.rb

This file was deleted.

@@ -1,7 +1,3 @@
require 'serverspec'

set :backend, :exec

describe file('/usr/local/src/xtrabackup-rb') do
it { should be_directory }
end
Expand All @@ -18,6 +14,6 @@
its(:exit_status) { should eq 0 }
end

describe package('percona-xtrabackup.x86_64') do
describe package('percona-xtrabackup') do
it { should be_installed }
end

0 comments on commit b770efe

Please sign in to comment.