From 5d17f10f93585e7637786c0337b3fcde5a3db9b9 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Mon, 7 Oct 2013 09:55:13 -0400 Subject: [PATCH] Port of a6101dc (mysql::server::monitor fix) to 2.x. --- manifests/server/monitor.pp | 7 +++--- spec/classes/mysql_server_monitor_spec.rb | 21 +++++++++++++--- spec/system/mysql_server_monitor_spec.rb | 30 +++++++++++++++++++++++ 3 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 spec/system/mysql_server_monitor_spec.rb diff --git a/manifests/server/monitor.pp b/manifests/server/monitor.pp index 9254bc6..9e86b92 100644 --- a/manifests/server/monitor.pp +++ b/manifests/server/monitor.pp @@ -7,16 +7,17 @@ class mysql::server::monitor ( Anchor['mysql::server::end'] -> Class['mysql::server::monitor'] - mysql_user{ "${mysql_monitor_username}@${mysql_monitor_hostname}": + mysql_user { "${mysql_monitor_username}@${mysql_monitor_hostname}": ensure => present, password_hash => mysql_password($mysql_monitor_password), + require => Class['mysql::server::service'], } - mysql_grant { "${mysql_monitor_username}@${mysql_monitor_hostname}": + mysql_grant { "${mysql_monitor_username}@${mysql_monitor_hostname}/*.*": ensure => present, user => "${mysql_monitor_username}@${mysql_monitor_hostname}", table => '*.*', - privileges => [ 'PROCESS_PRIV', 'SUPER_PRIV' ], + privileges => [ 'PROCESS', 'SUPER' ], require => Mysql_user["${mysql_monitor_username}@${mysql_monitor_hostname}"], } diff --git a/spec/classes/mysql_server_monitor_spec.rb b/spec/classes/mysql_server_monitor_spec.rb index 78bada2..8df9530 100644 --- a/spec/classes/mysql_server_monitor_spec.rb +++ b/spec/classes/mysql_server_monitor_spec.rb @@ -6,13 +6,26 @@ describe 'mysql::server::monitor' do let :pre_condition do "include 'mysql::server'" end - let :params do + + let :default_params do { - :mysql_monitor_username => 'monitoruser', - :mysql_monitor_password => 'monitorpass', - :mysql_monitor_hostname => 'monitorhost' + :mysql_monitor_username => 'monitoruser', + :mysql_monitor_password => 'monitorpass', + :mysql_monitor_hostname => 'monitorhost', } end + let :params do + default_params + end + it { should contain_mysql_user('monitoruser@monitorhost')} + + it { should contain_mysql_grant('monitoruser@monitorhost/*.*').with( + :ensure => 'present', + :user => 'monitoruser@monitorhost', + :table => '*.*', + :privileges => ["PROCESS", "SUPER"], + :require => 'Mysql_user[monitoruser@monitorhost]' + )} end diff --git a/spec/system/mysql_server_monitor_spec.rb b/spec/system/mysql_server_monitor_spec.rb new file mode 100644 index 0000000..1bbd7c1 --- /dev/null +++ b/spec/system/mysql_server_monitor_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper_system' + +describe 'mysql::server::monitor class' do + context 'should work with no errors' do + pp = <<-EOS + class { 'mysql::server': root_password => 'foo' } + + class { 'mysql::server::monitor': + mysql_monitor_username => 'monitoruser', + mysql_monitor_password => 'monitorpass', + mysql_monitor_hostname => 'localhost', + } + EOS + + context puppet_apply(pp) do + its(:stderr) { should be_empty } + its(:exit_code) { should_not == 1 } + its(:refresh) { should be_nil } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + + context 'should run mysqladmin ping with no errors' do + describe command("mysqladmin -u monitoruser -pmonitorpass -h localhost ping") do + it { should return_stdout /mysqld is alive/ } + it { should return_exit_status 0 } + end + end + end +end