Skip to content

Commit dc4b26f

Browse files
committed
FM-7783 - cleanup mysql
1 parent a6c0d92 commit dc4b26f

17 files changed

+66
-287
lines changed

lib/puppet/functions/mysql_password.rb

-21
This file was deleted.

lib/puppet/functions/mysql_strip_hash.rb

-21
This file was deleted.

lib/puppet/parser/functions/mysql_strip_hash.rb

-19
This file was deleted.

spec/acceptance/locales_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper_acceptance'
22
require 'beaker/i18n_helper'
33

4-
describe 'mysql localization', if: (fact('osfamily') == 'Debian' || fact('osfamily') == 'RedHat') && (Gem::Version.new(puppet_version) >= Gem::Version.new('4.10.5')) do
4+
describe 'mysql localization', if: (fact('osfamily') == 'debian' || fact('osfamily') == 'redhat') && (Gem::Version.new(puppet_version) >= Gem::Version.new('4.10.5')) do
55
before :all do
66
hosts.each do |host|
77
on(host, "sed -i \"96i FastGettext.locale='ja'\" /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet.rb")
@@ -12,7 +12,7 @@
1212
context 'when triggering puppet simple string error' do
1313
# 'service_enabled' being set to false can cause random failures in Debian 9
1414
let(:os_variant) do
15-
if fact('operatingsystem') =~ %r{Debian} && fact('operatingsystemrelease') =~ %r{^9\.}
15+
if os[:family] == 'debian' && os[:release].to_i == 9
1616
'true'
1717
else
1818
'false'

spec/acceptance/mysql_backup_spec.rb

+2-50
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class { 'mysql::server::backup':
2929
}
3030
MANIFEST
3131
it 'when configuring mysql backups' do
32-
execute_manifest(pp, catch_failures: true)
33-
execute_manifest(pp, catch_failures: true)
32+
idempotent_apply(default, pp, {})
3433
end
3534
end
3635

@@ -104,8 +103,7 @@ class { 'mysql::server::backup':
104103
}
105104
MANIFEST
106105
it 'when configuring mysql backups' do
107-
execute_manifest(pp, catch_failures: true)
108-
execute_manifest(pp, catch_failures: true)
106+
idempotent_apply(default, pp, {})
109107
end
110108
end
111109

@@ -153,50 +151,4 @@ class { 'mysql::server::backup':
153151
# rubocop:enable RSpec/MultipleExpectations, RSpec/ExampleLength
154152
end
155153
end
156-
157-
context 'with triggers and routines' do
158-
pre_run
159-
pp = <<-MANIFEST
160-
class { 'mysql::server': root_password => 'password' }
161-
mysql::db { [
162-
'backup1',
163-
'backup2'
164-
]:
165-
user => 'backup',
166-
password => 'secret',
167-
}
168-
package { 'bzip2':
169-
ensure => present,
170-
}
171-
class { 'mysql::server::backup':
172-
backupuser => 'myuser',
173-
backuppassword => 'mypassword',
174-
backupdir => '/tmp/backups',
175-
backupcompress => true,
176-
file_per_database => true,
177-
include_triggers => #{version_is_greater_than('5.1.5')},
178-
include_routines => true,
179-
postscript => [
180-
'rm -rf /var/tmp/mysqlbackups',
181-
'rm -f /var/tmp/mysqlbackups.done',
182-
'cp -r /tmp/backups /var/tmp/mysqlbackups',
183-
'touch /var/tmp/mysqlbackups.done',
184-
],
185-
execpath => '/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin',
186-
require => Package['bzip2'],
187-
}
188-
MANIFEST
189-
it 'when configuring mysql backups with triggers and routines' do
190-
execute_manifest(pp, catch_failures: true)
191-
end
192-
193-
it 'runs mysqlbackup.sh with no errors' do
194-
pre_run
195-
unless version_is_greater_than('5.7.0')
196-
shell('/usr/local/sbin/mysqlbackup.sh') do |r|
197-
expect(r.stderr).to eq('')
198-
end
199-
end
200-
end
201-
end
202154
end

spec/acceptance/mysql_db_spec.rb

-40
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
11
require 'spec_helper_acceptance'
22

33
describe 'mysql::db define' do
4-
describe 'creating a database' do
5-
let(:pp) do
6-
<<-MANIFEST
7-
class { 'mysql::server': root_password => 'password' }
8-
mysql::db { 'spec1':
9-
user => 'root1',
10-
password => 'password',
11-
}
12-
MANIFEST
13-
end
14-
15-
it_behaves_like 'a idempotent resource'
16-
17-
describe command("mysql -e 'show databases;'") do
18-
its(:exit_status) { is_expected.to eq 0 }
19-
its(:stdout) { is_expected.to match %r{^spec1$} }
20-
end
21-
end
22-
234
describe 'creating a database with post-sql' do
245
let(:pp) do
256
<<-MANIFEST
@@ -44,25 +25,4 @@ class { 'mysql::server': override_options => { 'root_password' => 'password' } }
4425
its(:stdout) { is_expected.to match %r{^table1$} }
4526
end
4627
end
47-
48-
describe 'creating a database with dbname parameter' do
49-
let(:check_command) { ' | grep realdb' }
50-
let(:pp) do
51-
<<-MANIFEST
52-
class { 'mysql::server': override_options => { 'root_password' => 'password' } }
53-
mysql::db { 'spec1':
54-
user => 'root1',
55-
password => 'password',
56-
dbname => 'realdb',
57-
}
58-
MANIFEST
59-
end
60-
61-
it_behaves_like 'a idempotent resource'
62-
63-
describe command("mysql -e 'show databases;'") do
64-
its(:exit_status) { is_expected.to eq 0 }
65-
its(:stdout) { is_expected.to match %r{^realdb$} }
66-
end
67-
end
6828
end

spec/acceptance/mysql_server_spec.rb

-48
Original file line numberDiff line numberDiff line change
@@ -46,41 +46,6 @@ class { 'mysql::server':
4646
it_behaves_like 'a idempotent resource'
4747
end
4848

49-
describe 'minimal config' do
50-
before(:all) do
51-
@tmpdir = default.tmpdir('mysql')
52-
end
53-
# 'manage_config_file'/'service_enabled' being set to false can cause random failures in Debian 9
54-
let(:os_variant) do
55-
if fact('operatingsystem') =~ %r{Debian} && fact('operatingsystemrelease') =~ %r{^9\.}
56-
'true'
57-
else
58-
'false'
59-
end
60-
end
61-
let(:pp) do
62-
<<-MANIFEST
63-
class { 'mysql::server':
64-
manage_config_file => '#{os_variant}',
65-
override_options => { 'mysqld' => { 'key_buffer_size' => '32M' }},
66-
package_ensure => 'present',
67-
purge_conf_dir => 'false',
68-
remove_default_accounts => 'false',
69-
restart => 'false',
70-
root_group => 'root',
71-
root_password => 'test',
72-
service_enabled => '#{os_variant}',
73-
service_manage => 'false',
74-
users => {},
75-
grants => {},
76-
databases => {},
77-
}
78-
MANIFEST
79-
end
80-
81-
it_behaves_like 'a idempotent resource'
82-
end
83-
8449
describe 'syslog configuration' do
8550
let(:pp) do
8651
<<-MANIFEST
@@ -92,17 +57,4 @@ class { 'mysql::server':
9257

9358
it_behaves_like 'a idempotent resource'
9459
end
95-
96-
context 'when changing the password' do
97-
let(:password) { 'THE NEW SECRET' }
98-
let(:pp) { "class { 'mysql::server': root_password => '#{password}' }" }
99-
100-
it 'does not display the password' do
101-
result = execute_manifest(pp, catch_failures: true)
102-
# this does not actually prove anything, as show_diff in the puppet config defaults to false.
103-
expect(result.stdout).not_to match %r{#{password}}
104-
end
105-
106-
it_behaves_like 'a idempotent resource'
107-
end
10860
end

spec/acceptance/sql_task_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# run a test task
22
require 'spec_helper_acceptance'
33

4-
describe 'mysql tasks', if: puppet_version =~ %r{(5\.\d\.\d)} && fact('operatingsystem') != 'SLES' do
4+
describe 'mysql tasks', if: puppet_version =~ %r{(5\.\d\.\d)} && os[:release] != 'sles' do
55
describe 'execute some sql' do
66
pp = <<-MANIFEST
77
class { 'mysql::server': root_password => 'password' }

spec/acceptance/types/mysql_plugin_spec.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
# of mysql) have varying levels of support for plugins and have
55
# different plugins available. Choose a plugin that works or don't try
66
# to test plugins if not available.
7-
if fact('osfamily') =~ %r{RedHat}
8-
if fact('operatingsystemrelease') =~ %r{^5\.}
7+
if fact('osfamily') == 'redhat'
8+
if os[:release].to_i == 5
99
plugin = nil # Plugins not supported on mysql on RHEL 5
10-
elsif fact('operatingsystemrelease') =~ %r{^6\.}
10+
elsif os[:release].to_i == 6
1111
plugin = 'example'
1212
plugin_lib = 'ha_example.so'
13-
elsif fact('operatingsystemrelease') =~ %r{^7\.}
13+
elsif os[:release].to_i == 7
1414
plugin = 'pam'
1515
plugin_lib = 'auth_pam.so'
1616
end
17-
elsif fact('osfamily') =~ %r{Debian}
18-
if fact('operatingsystem') =~ %r{Ubuntu}
19-
if fact('operatingsystemrelease') =~ %r{^16\.04|^18\.04}
17+
elsif fact('osfamily') == 'debian'
18+
if os[:family] == 'ubuntu'
19+
if os[:release] =~ %r{^16\.04|^18\.04}
2020
# On Xenial running 5.7.12, the example plugin does not appear to be available.
2121
plugin = 'validate_password'
2222
plugin_lib = 'validate_password.so'
@@ -25,8 +25,8 @@
2525
plugin_lib = 'ha_example.so'
2626
end
2727
end
28-
elsif fact('osfamily') =~ %r{Suse}
29-
plugin = nil # Plugin library path is broken on Suse http://lists.opensuse.org/opensuse-bugs/2013-08/msg01123.html
28+
elsif fact('osfamily') == 'suse'
29+
plugin = nil # Plugin library path is broken on Suse ttp://lists.opensuse.org/opensuse-bugs/2013-08/msg01123.html
3030
end
3131

3232
describe 'mysql_plugin' do

spec/classes/mysql_client_spec.rb

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
describe 'mysql::client' do
44
on_supported_os.each do |os, facts|
5-
next if facts[:osfamily] == 'Archlinux'
65
context "on #{os}" do
76
let(:facts) do
87
facts.merge(root_home: '/root')

spec/defines/mysql_db_spec.rb

+7-11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
it 'subscribes to database if sql script is given' do
2323
params['sql'] = 'test_sql'
24+
is_expected.to contain_mysql_database('test_db')
2425
is_expected.to contain_exec('test_db-import').with_subscribe('Mysql_database[test_db]')
2526
end
2627

@@ -29,21 +30,19 @@
2930
is_expected.to contain_exec('test_db-import').with_refreshonly(true)
3031
end
3132

32-
it 'imports sql script on creation if enforcing #refreshonly' do
33+
it 'imports sql script on creation' do
3334
params.merge!('sql' => 'test_sql', 'enforce_sql' => true)
35+
# ' if enforcing #refreshonly'
3436
is_expected.to contain_exec('test_db-import').with_refreshonly(false)
35-
end
36-
it 'imports sql script on creation if enforcing #command' do
37-
params.merge!('sql' => 'test_sql', 'enforce_sql' => true)
37+
# 'if enforcing #command'
3838
is_expected.to contain_exec('test_db-import').with_command('cat test_sql | mysql test_db')
3939
end
4040

41-
it 'imports sql script with custom command on creation if enforcing #refreshonly' do
41+
it 'imports sql script with custom command on creation ' do
4242
params.merge!('sql' => 'test_sql', 'enforce_sql' => true, 'import_cat_cmd' => 'zcat')
43+
# if enforcing #refreshonly
4344
is_expected.to contain_exec('test_db-import').with_refreshonly(false)
44-
end
45-
it 'imports sql script with custom command on creation if enforcing #command' do
46-
params.merge!('sql' => 'test_sql', 'enforce_sql' => true, 'import_cat_cmd' => 'zcat')
45+
# if enforcing #command
4746
is_expected.to contain_exec('test_db-import').with_command('zcat test_sql | mysql test_db')
4847
end
4948

@@ -55,9 +54,6 @@
5554
it 'does not create database' do
5655
params.merge!('ensure' => 'absent', 'host' => 'localhost')
5756
is_expected.to contain_mysql_database('test_db').with_ensure('absent')
58-
end
59-
it 'does not create database user' do
60-
params.merge!('ensure' => 'absent', 'host' => 'localhost')
6157
is_expected.to contain_mysql_user('testuser@localhost').with_ensure('absent')
6258
end
6359

spec/functions/mysql_password_spec.rb

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
is_expected.to run.with_params('password').and_return('*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19')
1818
end
1919

20+
it 'password should be String' do
21+
is_expected.to run.with_params(123).and_raise_error(ArgumentError)
22+
end
23+
2024
it 'converts an empty password into a empty string' do
2125
is_expected.to run.with_params('').and_return('')
2226
end

0 commit comments

Comments
 (0)