Skip to content

Commit ecff1f3

Browse files
committed
Merge pull request #793 from DavidS/fm-4563-workaround-pup-5016
(FM-4563) workaround PUP-5016
2 parents 23672ca + d89062f commit ecff1f3

File tree

4 files changed

+56
-53
lines changed

4 files changed

+56
-53
lines changed

Gemfile

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ def location_for(place, fake_version = nil)
1111
end
1212

1313
group :development, :unit_tests do
14-
# rspec must be v2 for ruby 1.8.7
15-
if RUBY_VERSION >= '1.8.7' and RUBY_VERSION < '1.9'
16-
gem 'rspec', '~> 2.0'
14+
# rspec-core 3.1.7 is the last version to support ruby 1.8
15+
if RUBY_VERSION < '1.9'
16+
gem 'rspec-core', '3.1.7'
1717
else
18-
gem 'rspec-core', '3.1.7', :require => false
18+
# newer version required to avoid BKR-537
19+
gem 'rspec-core', '>= 3.4'
1920
end
2021

2122
gem 'puppetlabs_spec_helper', :require => false

spec/acceptance/mysql_db_spec.rb

+20-26
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,26 @@
22

33
describe 'mysql::db define' do
44
describe 'creating a database' do
5-
# Using puppet_apply as a helper
6-
it 'should work with no errors' do
7-
pp = <<-EOS
5+
let(:pp) do
6+
<<-EOS
87
class { 'mysql::server': root_password => 'password' }
98
mysql::db { 'spec1':
109
user => 'root1',
1110
password => 'password',
1211
}
1312
EOS
13+
end
14+
it_behaves_like "a idempotent resource"
1415

15-
# Run it twice and test for idempotency
16-
apply_manifest(pp, :catch_failures => true)
17-
apply_manifest(pp, :catch_changes => true)
18-
19-
expect(shell("mysql -e 'show databases;'|grep spec1").exit_code).to be_zero
16+
describe command("mysql -e 'show databases;'") do
17+
its(:exit_status) { is_expected.to eq 0 }
18+
its(:stdout) { is_expected.to match /^spec1$/ }
2019
end
2120
end
2221

2322
describe 'creating a database with post-sql' do
24-
# Using puppet_apply as a helper
25-
it 'should work with no errors' do
26-
pp = <<-EOS
23+
let(:pp) do
24+
<<-EOS
2725
class { 'mysql::server': override_options => { 'root_password' => 'password' } }
2826
file { '/tmp/spec.sql':
2927
ensure => file,
@@ -36,36 +34,32 @@ class { 'mysql::server': override_options => { 'root_password' => 'password' } }
3634
sql => '/tmp/spec.sql',
3735
}
3836
EOS
39-
40-
# Run it twice and test for idempotency
41-
apply_manifest(pp, :catch_failures => true)
42-
apply_manifest(pp, :catch_changes => true)
4337
end
38+
it_behaves_like "a idempotent resource"
4439

45-
it 'should have the table' do
46-
expect(shell("mysql -e 'show tables;' spec2|grep table1").exit_code).to be_zero
40+
describe command("mysql -e 'show tables;' spec2") do
41+
its(:exit_status) { is_expected.to eq 0 }
42+
its(:stdout) { is_expected.to match /^table1$/ }
4743
end
4844
end
4945

5046
describe 'creating a database with dbname parameter' do
51-
# Using puppet_apply as a helper
52-
it 'should work with no errors' do
53-
pp = <<-EOS
47+
let(:check_command) { " | grep realdb" }
48+
let(:pp) do
49+
<<-EOS
5450
class { 'mysql::server': override_options => { 'root_password' => 'password' } }
5551
mysql::db { 'spec1':
5652
user => 'root1',
5753
password => 'password',
5854
dbname => 'realdb',
5955
}
6056
EOS
61-
62-
# Run it twice and test for idempotency
63-
apply_manifest(pp, :catch_failures => true)
64-
apply_manifest(pp, :catch_changes => true)
6557
end
58+
it_behaves_like "a idempotent resource"
6659

67-
it 'should have the database named realdb' do
68-
expect(shell("mysql -e 'show databases;'|grep realdb").exit_code).to be_zero
60+
describe command("mysql -e 'show databases;'") do
61+
its(:exit_status) { is_expected.to eq 0 }
62+
its(:stdout) { is_expected.to match /^realdb$/ }
6963
end
7064
end
7165
end

spec/acceptance/mysql_server_spec.rb

+15-23
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
require 'spec_helper_acceptance'
22

33
describe 'mysql class' do
4-
5-
describe 'running puppet code' do
6-
# Using puppet_apply as a helper
7-
it 'should work with no errors' do
8-
tmpdir = default.tmpdir('mysql')
9-
pp = <<-EOS
4+
describe 'advanced config' do
5+
let(:tmpdir) { default.tmpdir('mysql') }
6+
let(:pp) do
7+
<<-EOS
108
class { 'mysql::server':
119
config_file => '#{tmpdir}/my.cnf',
1210
includedir => '#{tmpdir}/include',
@@ -46,39 +44,33 @@ class { 'mysql::server':
4644
}
4745
}
4846
EOS
49-
50-
apply_manifest(pp, :catch_failures => true)
51-
apply_manifest(pp, :catch_changes => true)
5247
end
48+
49+
it_behaves_like "a idempotent resource"
5350
end
5451

55-
describe 'configuration needed for syslog' do
56-
it 'should work with no errors' do
57-
pp = <<-EOS
52+
describe 'syslog configuration' do
53+
let(:pp) do
54+
<<-EOS
5855
class { 'mysql::server':
5956
override_options => { 'mysqld' => { 'log-error' => undef }, 'mysqld_safe' => { 'log-error' => false, 'syslog' => true }},
6057
}
6158
EOS
62-
63-
apply_manifest(pp, :catch_failures => true)
64-
apply_manifest(pp, :catch_changes => true)
6559
end
60+
61+
it_behaves_like "a idempotent resource"
6662
end
6763

68-
describe 'when changing the password' do
64+
context 'when changing the password' do
6965
let(:password) { 'THE NEW SECRET' }
70-
let(:manifest) { "class { 'mysql::server': root_password => '#{password}' }" }
66+
let(:pp) { "class { 'mysql::server': root_password => '#{password}' }" }
7167

7268
it 'should not display the password' do
73-
result = apply_manifest(manifest, :expect_changes => true)
69+
result = apply_manifest(pp, :catch_failures => true)
7470
# this does not actually prove anything, as show_diff in the puppet config defaults to false.
7571
expect(result.stdout).not_to match /#{password}/
7672
end
7773

78-
it 'should be idempotent' do
79-
result = apply_manifest(manifest, :catch_changes => true)
80-
end
81-
74+
it_behaves_like "a idempotent resource"
8275
end
83-
8476
end

spec/spec_helper_acceptance.rb

+16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
# Readable test descriptions
1313
c.formatter = :documentation
1414

15+
# detect the situation where PUP-5016 is triggered and skip the idempotency tests in that case
16+
# also note how fact('puppetversion') is not available because of PUP-4359
17+
if fact('osfamily') == 'Debian' && fact('operatingsystemmajrelease') == '8' && shell('puppet --version').stdout =~ /^4\.2/
18+
c.filter_run_excluding :skip_pup_5016 => true
19+
end
20+
1521
# Configure all nodes in nodeset
1622
c.before :suite do
1723
# Install module and dependencies
@@ -47,3 +53,13 @@
4753
end
4854
end
4955
end
56+
57+
shared_examples "a idempotent resource" do
58+
it 'should apply with no errors' do
59+
apply_manifest(pp, :catch_failures => true)
60+
end
61+
62+
it 'should apply a second time without changes', :skip_pup_5016 do
63+
apply_manifest(pp, :catch_changes => true)
64+
end
65+
end

0 commit comments

Comments
 (0)