forked from puppetlabs/puppetlabs-puppet_agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_spec.rb
229 lines (200 loc) · 7.61 KB
/
class_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
require 'beaker-puppet'
require 'spec_helper_acceptance'
describe 'puppet_agent class' do
context 'default parameters in apply' do
before(:all) { setup_puppet_on default }
after(:all) { teardown_puppet_on default }
it 'works idempotently with no errors' do
pp = <<-EOS
class { 'puppet_agent': package_version => '5.5.21', collection => 'puppet5' }
EOS
apply_manifest(pp, catch_failures: true)
wait_for_finish_on default
configure_agent_on default
# Run three times to ensure idempotency if upgrading with the package resource (MODULES-10666)
unless %r{solaris-10|aix|osx|windows}i.match?(default['platform'])
apply_manifest(pp, expect_changes: true)
wait_for_finish_on default
end
apply_manifest(pp, catch_changes: true)
end
describe package(package_name(default)) do
it { is_expected.to be_installed }
end
if %r{windows}i.match?(default['platform'])
# MODULES-4244: MCollective not started after upgrade
describe service('mcollective') do
it { is_expected.not_to be_enabled }
it { is_expected.not_to be_running }
end
describe service('puppet') do
# PUPPET_AGENT_STARTUP_MODE=Manual
it { is_expected.not_to be_enabled }
it { is_expected.not_to be_running }
end
else
describe service('mcollective') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end
describe service('puppet') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end
end
describe file(puppet_conf(default)) do
it { is_expected.to exist }
its(:content) do
is_expected.not_to match(%r{stringify_facts[ ]*=[ ]*false})
is_expected.not_to match(%r{parser[ ]*=[ ]*future})
end
end
describe 'manage_repo parameter' do
context 'when true (default)' do
it 'creates repo config' do
pp = "class { 'puppet_agent': }"
apply_manifest(pp, catch_failures: true)
wait_for_finish_on default
case default['platform']
when %r{debian|ubuntu}
pp = "include apt\napt::source { 'pc_repo': ensure => present, location => 'https://apt.puppet.com', repos => 'puppet5'}"
when %r{fedora|el|centos}
pp = "yumrepo { 'pc_repo': ensure => present }"
else
logger.notify("Cannot manage repo on #{default['platform']}, skipping test 'should create repo config'")
next
end
apply_manifest(pp, catch_changes: true)
wait_for_finish_on default
end
end
context 'when false' do
it 'ceases to manage repo config' do
pp = "class { 'puppet_agent': }"
apply_manifest(pp, catch_failures: true)
wait_for_finish_on default
case default['platform']
when %r{debian|ubuntu}
pp = "include apt\napt::source { 'pc_repo': ensure => absent }"
when %r{fedora|el|centos}
pp = "yumrepo { 'pc_repo': ensure => absent }"
else
logger.notify("Cannot manage repo on #{default['platform']}, skipping test 'should cease to manage repo config'")
next
end
apply_manifest(pp, catch_failures: true)
wait_for_finish_on default
pp = "class { 'puppet_agent': manage_repo => false }"
# expect no changes now that repo is unmanaged
apply_manifest(pp, catch_changes: true)
wait_for_finish_on default
end
end
end
end
context 'no services enabled on install' do
before(:all) { setup_puppet_on default }
after(:all) { teardown_puppet_on default }
it 'works idempotently with no errors' do
pp = <<-EOS
class { 'puppet_agent': service_names => [] }
EOS
# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
wait_for_finish_on default
configure_agent_on default
apply_manifest(pp, catch_changes: true)
wait_for_finish_on default
end
describe package(package_name(default)) do
it { is_expected.to be_installed }
end
describe service('puppet') do
it { is_expected.not_to be_running }
end
describe service('mcollective') do
it { is_expected.not_to be_running }
end
end
unless %r{windows}i.match?(default['platform'])
# MODULES-4244: MCollective not started after upgrade
context 'with mcollective configured' do
before(:all) do
setup_puppet_on default, mcollective: true, agent: true
manifest = 'class { "puppet_agent": package_version => "5.5.21", collection => "puppet5", service_names => ["mcollective"] }'
pp = "file { '#{master.puppet['codedir']}/environments/production/manifests/site.pp': ensure => file, content => '#{manifest}' }"
apply_manifest_on(master, pp, catch_failures: true)
end
after(:all) do
pp = "file { '#{master.puppet['codedir']}/environments/production/manifests/site.pp': ensure => absent }"
apply_manifest_on(master, pp, catch_failures: true)
teardown_puppet_on default
end
# rubocop:disable RepeatedExample
it 'mco should be running' do
on default, 'mco ping' do
hostname = default.hostname.split('.', 2).first
assert_match(%r{^#{hostname}[.\w]*\s+time=}, stdout)
end
end
# rubocop:enable RepeatedExample
it 'works idempotently with no errors' do
pp = <<-EOS
class { 'puppet_agent': collection => "puppet5", service_names => ["mcollective"] }
EOS
# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
wait_for_finish_on default
configure_agent_on default
apply_manifest(pp, catch_changes: true)
wait_for_finish_on default
end
describe package(package_name(default)) do
it { is_expected.to be_installed }
end
describe service('mcollective') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end
# rubocop:disable RepeatedExample
it 'has mcollective correctly configured' do
on default, 'mco ping' do
hostname = default.hostname.split('.', 2).first
assert_match(%r{^#{hostname}[.\w]*\s+time=}, stdout)
end
end
# rubocop:enable RepeatedExample
end
unless %r{solaris-10|aix|osx|windows}i.match?(default['platform'])
context 'on platforms managed with the package resource' do
before(:all) { setup_puppet_on default }
after(:all) do
on default, 'rm -f /tmp/a'
teardown_puppet_on default
end
let(:manifest) do
<<-EOS
class { 'puppet_agent': package_version => '5.5.21', collection => 'puppet5', before => File['/tmp/a'] }
file { '/tmp/a': ensure => 'present' }
EOS
end
it 'upgrades the agent on the first run' do
# First run should upgrade the agent
apply_manifest(manifest, expect_changes: true)
configure_agent_on default
expect(package(package_name(default))).to be_installed
expect(file('/tmp/a')).not_to exist
end
it 'evaluates remanining resources on the second run' do
# Second run should apply the file resource
apply_manifest(manifest, expect_changes: true)
expect(file('/tmp/a')).to exist
end
it 'does nothing on future runs' do
# Third run should not do anything
apply_manifest(manifest, catch_changes: true)
end
end
end
end
end