Skip to content

Commit 32213c8

Browse files
committed
Re-order and adjust debian tests
Remove and re-order the old tests for the combined sysconfig file. Add tests for the systemd configuration.
1 parent d46b89e commit 32213c8

File tree

1 file changed

+207
-157
lines changed

1 file changed

+207
-157
lines changed

spec/classes/snmp_init_spec.rb

Lines changed: 207 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -266,109 +266,223 @@
266266
debianish.each do |os|
267267
describe "for osfamily Debian, operatingsystem #{os}" do
268268
let(:params) { {} }
269-
let :facts do
269+
let(:debfacts) do
270270
{
271-
os: { 'release' => { 'full' => '6.0.7', 'major' => '6' }, 'name' => 'Debian', 'family' => 'Debian' },
271+
os: { 'release' => { 'full' => '9.5', 'major' => '9' }, 'name' => 'Debian', 'family' => 'Debian' },
272272
networking: { 'fqdn' => 'myhost2.localdomain' }
273273
}
274274
end
275275

276-
it {
277-
is_expected.to contain_package('snmpd').with(
278-
ensure: 'present',
279-
name: 'snmpd'
280-
)
281-
}
282-
it { is_expected.not_to contain_class('snmp::client') }
283-
it {
284-
is_expected.to contain_file('var-net-snmp').with(
285-
ensure: 'directory',
286-
mode: '0755',
287-
owner: 'snmp',
288-
group: 'snmp',
289-
path: '/var/lib/snmp'
290-
).that_requires('Package[snmpd]')
291-
}
276+
describe 'snmpd / snmptrapd configuration' do
277+
let(:facts) { debfacts }
292278

293-
it {
294-
is_expected.to contain_file('snmpd.conf').with(
295-
ensure: 'present',
296-
mode: '0600',
297-
owner: 'root',
298-
group: 'root',
299-
path: '/etc/snmp/snmpd.conf'
300-
).that_requires('Package[snmpd]').that_notifies('Service[snmpd]')
301-
}
302-
# TODO: add more contents for File[snmpd.conf]
303-
it 'contains File[snmpd.conf] with expected contents' do
304-
verify_contents(catalogue, 'snmpd.conf', [
305-
'agentaddress udp:127.0.0.1:161,udp6:[::1]:161',
306-
'rocommunity public 127.0.0.1',
307-
'rocommunity6 public ::1',
308-
'com2sec notConfigUser default public',
309-
'com2sec6 notConfigUser default public',
310-
'group notConfigGroup v1 notConfigUser',
311-
'group notConfigGroup v2c notConfigUser',
312-
'view systemview included .1.3.6.1.2.1.1',
313-
'view systemview included .1.3.6.1.2.1.25.1.1',
314-
'access notConfigGroup "" any noauth exact systemview none none',
315-
'sysLocation Unknown',
316-
'sysContact Unknown',
317-
'sysServices 72',
318-
'sysName myhost2.localdomain',
319-
'dontLogTCPWrappersConnects no'
320-
])
321-
end
322-
it {
323-
is_expected.to contain_file('snmpd.sysconfig').with(
324-
ensure: 'present',
325-
mode: '0644',
326-
owner: 'root',
327-
group: 'root',
328-
path: '/etc/default/snmpd'
329-
).that_requires('Package[snmpd]').that_notifies('Service[snmpd]')
330-
}
331-
it 'contains File[snmpd.sysconfig] with contents "SNMPDOPTS=\'-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid\'"' do
332-
verify_contents(catalogue, 'snmpd.sysconfig', [
333-
'SNMPDRUN=yes',
334-
'SNMPDOPTS=\'-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid\''
335-
])
279+
it {
280+
is_expected.to contain_package('snmpd').with(
281+
ensure: 'present',
282+
name: 'snmpd'
283+
)
284+
}
285+
it {
286+
is_expected.to contain_package('snmptrapd').with(
287+
ensure: 'present',
288+
name: 'snmptrapd'
289+
)
290+
}
291+
it { is_expected.not_to contain_class('snmp::client') }
292+
293+
it {
294+
is_expected.to contain_file('var-net-snmp').with(
295+
ensure: 'directory',
296+
mode: '0755',
297+
owner: 'Debian-snmp',
298+
group: 'Debian-snmp',
299+
path: '/var/lib/snmp'
300+
).that_requires('Package[snmpd]')
301+
}
302+
303+
it {
304+
is_expected.to contain_file('snmpd.conf').with(
305+
ensure: 'present',
306+
mode: '0600',
307+
owner: 'root',
308+
group: 'root',
309+
path: '/etc/snmp/snmpd.conf'
310+
).that_requires('Package[snmpd]').that_notifies('Service[snmpd]')
311+
}
312+
# TODO: add more contents for File[snmpd.conf]
313+
it 'contains File[snmpd.conf] with expected contents' do
314+
verify_contents(catalogue, 'snmpd.conf', [
315+
'agentaddress udp:127.0.0.1:161,udp6:[::1]:161',
316+
'rocommunity public 127.0.0.1',
317+
'rocommunity6 public ::1',
318+
'com2sec notConfigUser default public',
319+
'com2sec6 notConfigUser default public',
320+
'group notConfigGroup v1 notConfigUser',
321+
'group notConfigGroup v2c notConfigUser',
322+
'view systemview included .1.3.6.1.2.1.1',
323+
'view systemview included .1.3.6.1.2.1.25.1.1',
324+
'access notConfigGroup "" any noauth exact systemview none none',
325+
'sysLocation Unknown',
326+
'sysContact Unknown',
327+
'sysServices 72',
328+
'sysName myhost2.localdomain',
329+
'dontLogTCPWrappersConnects no'
330+
])
331+
end
332+
333+
it {
334+
is_expected.to contain_file('snmptrapd.conf').with(
335+
ensure: 'present',
336+
mode: '0600',
337+
owner: 'root',
338+
group: 'root',
339+
path: '/etc/snmp/snmptrapd.conf'
340+
).that_requires('Package[snmptrapd]').that_notifies('Service[snmptrapd]')
341+
}
342+
# TODO: add more contents for File[snmptrapd.conf]
343+
it 'contains File[snmptrapd.conf] with correct contents' do
344+
verify_contents(catalogue, 'snmptrapd.conf', [
345+
'doNotLogTraps no',
346+
'authCommunity log,execute,net public',
347+
'disableAuthorization no'
348+
])
349+
end
336350
end
337-
it {
338-
is_expected.to contain_service('snmpd').with(
339-
ensure: 'running',
340-
name: 'snmpd',
341-
enable: true,
342-
hasstatus: true,
343-
hasrestart: true
344-
).that_requires(['Package[snmpd]', 'File[var-net-snmp]'])
345-
}
346351

347-
it {
348-
is_expected.to contain_file('snmptrapd.conf').with(
349-
ensure: 'present',
350-
mode: '0600',
351-
owner: 'root',
352-
group: 'root',
353-
path: '/etc/snmp/snmptrapd.conf'
354-
).that_requires('Package[snmpd]').that_notifies('Service[snmpd]')
355-
}
356-
# TODO: add more contents for File[snmptrapd.conf]
357-
it 'contains File[snmptrapd.conf] with correct contents' do
358-
verify_contents(catalogue, 'snmptrapd.conf', [
359-
'doNotLogTraps no',
360-
'authCommunity log,execute,net public',
361-
'disableAuthorization no'
362-
])
352+
context "for osfamily Debian, operatingsystem #{os} without systemd" do
353+
let(:facts) { debfacts.merge(service_provider: 'debian') }
354+
355+
describe 'default params' do
356+
let(:params) { {} }
357+
358+
it {
359+
is_expected.to contain_file('snmpd.sysconfig').with(
360+
ensure: 'present',
361+
mode: '0644',
362+
owner: 'root',
363+
group: 'root',
364+
path: '/etc/default/snmpd'
365+
).that_requires('Package[snmpd]').that_notifies('Service[snmpd]')
366+
}
367+
it 'contains File[snmpd.sysconfig] with contents "SNMPDOPTS=\'-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid\'"' do
368+
verify_contents(catalogue, 'snmpd.sysconfig', [
369+
'SNMPDRUN=yes',
370+
'SNMPDOPTS=\'-Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux -p /var/run/snmpd.pid\''
371+
])
372+
end
373+
it 'contains File[snmptrapd.sysconfig] with contents "TRAPDOPTS=\'-Lsd -p /var/run/snmptrapd.pid\'"' do
374+
verify_contents(catalogue, 'snmptrapd.sysconfig', [
375+
'TRAPDRUN=yes',
376+
'TRAPDOPTS=\'-Lsd -p /var/run/snmptrapd.pid\''
377+
])
378+
end
379+
end
380+
381+
describe 'service_ensure => stopped and trap_service_ensure => running' do
382+
let(:params) do
383+
{
384+
service_ensure: 'stopped',
385+
trap_service_ensure: 'running'
386+
}
387+
end
388+
389+
it { is_expected.to contain_service('snmpd').with_ensure('stopped') }
390+
it { is_expected.to contain_service('snmptrapd').with_ensure('running') }
391+
end
392+
393+
describe 'snmpd_options => blah' do
394+
let(:params) { { snmpd_options: 'blah' } }
395+
396+
it { is_expected.to contain_file('snmpd.sysconfig') }
397+
it 'contains File[snmpd.sysconfig] with contents "SNMPDOPTS=\'blah\'"' do
398+
verify_contents(catalogue, 'snmpd.sysconfig', ['SNMPDOPTS=\'blah\''])
399+
end
400+
end
401+
402+
describe 'snmptrapd_options => bleh' do
403+
let(:params) { { snmptrapd_options: 'bleh' } }
404+
405+
it { is_expected.to contain_file('snmptrapd.sysconfig') }
406+
it 'contains File[snmptrapd.sysconfig] with contents "TRAPDOPTS=\'bleh\'"' do
407+
verify_contents(catalogue, 'snmptrapd.sysconfig', ['TRAPDOPTS=\'bleh\''])
408+
end
409+
end
363410
end
364-
it { is_expected.not_to contain_file('snmptrapd.sysconfig') }
365-
it 'contains File[snmpd.sysconfig] with contents "TRAPDOPTS=\'-Lsd -p /var/run/snmptrapd.pid\'"' do
366-
verify_contents(catalogue, 'snmpd.sysconfig', [
367-
'TRAPDRUN=no',
368-
'TRAPDOPTS=\'-Lsd -p /var/run/snmptrapd.pid\''
369-
])
411+
412+
context "for osfamily Debian, operatingsystem #{os} with systemd" do
413+
let(:facts) do
414+
debfacts.merge(service_provider: 'systemd', path: '/bin:/sbin:/usr/bin')
415+
end
416+
417+
it { is_expected.not_to contain_file('snmptrapd.sysconfig') }
418+
it { is_expected.not_to contain_file('snmpd.sysconfig') }
419+
420+
it {
421+
is_expected.to contain_service('snmpd').with(
422+
ensure: 'running',
423+
name: 'snmpd',
424+
enable: true,
425+
hasstatus: true,
426+
hasrestart: true
427+
).that_requires(['Package[snmpd]', 'File[var-net-snmp]'])
428+
}
429+
430+
describe 'default params' do
431+
let(:params) { {} }
432+
433+
it 'contains systemd dropin file for snmpd with execstart' do
434+
is_expected.to contain_file('/etc/systemd/system/snmpd.service.d/local.conf').with(
435+
ensure: 'file',
436+
mode: '0644',
437+
owner: 'root',
438+
group: 'root',
439+
path: '/etc/systemd/system/snmpd.service.d/local.conf'
440+
).that_requires('Package[snmpd]').that_notifies(['Service[snmpd]', 'Exec[systemctl-daemon-reload]'])
441+
442+
expected_lines = [
443+
'[Service]',
444+
'ExecStart=',
445+
'ExecStart=/usr/sbin/snmpd -Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux -p /var/run/snmpd.pid',
446+
'Type=',
447+
'Type=forking'
448+
]
449+
verify_contents(catalogue, '/etc/systemd/system/snmpd.service.d/local.conf', expected_lines)
450+
end
451+
end
452+
describe 'ensure_service => stopped, trap_service_ensure => running' do
453+
let :params do
454+
{
455+
service_ensure: 'stopped',
456+
trap_service_ensure: 'running'
457+
}
458+
end
459+
460+
it { is_expected.to contain_service('snmpd').with_ensure('stopped') }
461+
it { is_expected.to contain_service('snmptrapd').with_ensure('running') }
462+
end
463+
464+
describe 'snmpd_options => blah' do
465+
let(:params) { { snmpd_options: 'blah' } }
466+
467+
it { is_expected.to contain_file('/etc/systemd/system/snmpd.service.d/local.conf') }
468+
it 'contains systemd drop-in file with contents ExecStart' do
469+
verify_contents(catalogue, '/etc/systemd/system/snmpd.service.d/local.conf', [
470+
'ExecStart=/usr/sbin/snmpd blah'
471+
])
472+
end
473+
end
474+
475+
describe 'snmptrapd_options => bleh' do
476+
let(:params) { { snmptrapd_options: 'bleh' } }
477+
478+
it { is_expected.to contain_file('/etc/systemd/system/snmptrapd.service.d/local.conf') }
479+
it 'contains systemd drop-in file with contents ExecStart' do
480+
verify_contents(catalogue, '/etc/systemd/system/snmptrapd.service.d/local.conf', [
481+
'ExecStart=/usr/sbin/snmptrapd bleh'
482+
])
483+
end
484+
end
370485
end
371-
it { is_expected.not_to contain_service('snmptrapd') }
372486
end
373487
end
374488

@@ -1072,70 +1186,6 @@
10721186
end
10731187
end
10741188

1075-
context 'on a supported osfamily (Debian), custom parameters' do
1076-
let :facts do
1077-
{
1078-
os: { 'release' => { 'full' => '7.0', 'major' => '7' }, 'name' => 'Debian', 'family' => 'Debian' }
1079-
}
1080-
end
1081-
1082-
describe 'service_ensure => stopped and trap_service_ensure => running' do
1083-
let :params do
1084-
{
1085-
service_ensure: 'stopped',
1086-
trap_service_ensure: 'running'
1087-
}
1088-
end
1089-
1090-
it { is_expected.to contain_service('snmpd').with_ensure('running') }
1091-
it { is_expected.not_to contain_service('snmptrapd') }
1092-
it 'contains File[snmpd.sysconfig] with contents "SNMPDRUN=no" and "TRAPDRUN=yes"' do
1093-
verify_contents(catalogue, 'snmpd.sysconfig', [
1094-
'SNMPDRUN=no',
1095-
'TRAPDRUN=yes'
1096-
])
1097-
end
1098-
end
1099-
1100-
describe 'snmpd_options => blah' do
1101-
let(:params) { { snmpd_options: 'blah' } }
1102-
1103-
it { is_expected.to contain_file('snmpd.sysconfig') }
1104-
it 'contains File[snmpd.sysconfig] with contents "SNMPDOPTS=\'blah\'"' do
1105-
verify_contents(catalogue, 'snmpd.sysconfig', [
1106-
'SNMPDOPTS=\'blah\''
1107-
])
1108-
end
1109-
end
1110-
1111-
describe 'snmptrapd_options => bleh' do
1112-
let(:params) { { snmptrapd_options: 'bleh' } }
1113-
1114-
it { is_expected.to contain_file('snmpd.sysconfig') }
1115-
it 'contains File[snmpd.sysconfig] with contents "TRAPDOPTS=\'bleh\'"' do
1116-
verify_contents(catalogue, 'snmpd.sysconfig', [
1117-
'TRAPDOPTS=\'bleh\''
1118-
])
1119-
end
1120-
end
1121-
end
1122-
1123-
context 'on a supported osfamily (Debian Stretch), custom parameters' do
1124-
let :facts do
1125-
{
1126-
os: { 'release' => { 'full' => '9.0', 'major' => '9' }, 'name' => 'Debian', 'family' => 'Debian' }
1127-
}
1128-
end
1129-
1130-
describe 'Debian-snmp as snmp user' do
1131-
it 'contains File[snmpd.sysconfig] with contents "OPTIONS="-Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux -p /var/run/snmpd.pid""' do
1132-
verify_contents(catalogue, 'snmpd.sysconfig', [
1133-
'SNMPDOPTS=\'-Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux -p /var/run/snmpd.pid\''
1134-
])
1135-
end
1136-
end
1137-
end
1138-
11391189
context 'on a supported osfamily (Suse), custom parameters' do
11401190
let :facts do
11411191
{

0 commit comments

Comments
 (0)