Skip to content

Commit b2b8138

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 7e05634 commit b2b8138

File tree

1 file changed

+200
-155
lines changed

1 file changed

+200
-155
lines changed

spec/classes/snmp_init_spec.rb

Lines changed: 200 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -266,109 +266,218 @@
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 }
278+
it {
279+
is_expected.to contain_package('snmpd').with(
280+
ensure: 'present',
281+
name: 'snmpd'
282+
)
283+
}
284+
it {
285+
is_expected.to contain_package('snmptrapd').with(
286+
ensure: 'present',
287+
name: 'snmptrapd',
288+
)
289+
}
290+
it { is_expected.not_to contain_class('snmp::client') }
291+
292+
it {
293+
is_expected.to contain_file('var-net-snmp').with(
294+
ensure: 'directory',
295+
mode: '0755',
296+
owner: 'Debian-snmp',
297+
group: 'Debian-snmp',
298+
path: '/var/lib/snmp'
299+
).that_requires('Package[snmpd]')
300+
}
292301

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-
])
302+
it {
303+
is_expected.to contain_file('snmpd.conf').with(
304+
ensure: 'present',
305+
mode: '0600',
306+
owner: 'root',
307+
group: 'root',
308+
path: '/etc/snmp/snmpd.conf'
309+
).that_requires('Package[snmpd]').that_notifies('Service[snmpd]')
310+
}
311+
# TODO: add more contents for File[snmpd.conf]
312+
it 'contains File[snmpd.conf] with expected contents' do
313+
verify_contents(catalogue, 'snmpd.conf', [
314+
'agentaddress udp:127.0.0.1:161,udp6:[::1]:161',
315+
'rocommunity public 127.0.0.1',
316+
'rocommunity6 public ::1',
317+
'com2sec notConfigUser default public',
318+
'com2sec6 notConfigUser default public',
319+
'group notConfigGroup v1 notConfigUser',
320+
'group notConfigGroup v2c notConfigUser',
321+
'view systemview included .1.3.6.1.2.1.1',
322+
'view systemview included .1.3.6.1.2.1.25.1.1',
323+
'access notConfigGroup "" any noauth exact systemview none none',
324+
'sysLocation Unknown',
325+
'sysContact Unknown',
326+
'sysServices 72',
327+
'sysName myhost2.localdomain',
328+
'dontLogTCPWrappersConnects no'
329+
])
330+
end
331+
332+
it {
333+
is_expected.to contain_file('snmptrapd.conf').with(
334+
ensure: 'present',
335+
mode: '0600',
336+
owner: 'root',
337+
group: 'root',
338+
path: '/etc/snmp/snmptrapd.conf'
339+
).that_requires('Package[snmptrapd]').that_notifies('Service[snmptrapd]')
340+
}
341+
# TODO: add more contents for File[snmptrapd.conf]
342+
it 'contains File[snmptrapd.conf] with correct contents' do
343+
verify_contents(catalogue, 'snmptrapd.conf', [
344+
'doNotLogTraps no',
345+
'authCommunity log,execute,net public',
346+
'disableAuthorization no'
347+
])
348+
end
321349
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', [
350+
351+
context "for osfamily Debian, operatingsystem #{os} without systemd" do
352+
let(:facts) { debfacts.merge({service_provider: 'debian'}) }
353+
describe 'default params' do
354+
let(:params) { {} }
355+
it {
356+
is_expected.to contain_file('snmpd.sysconfig').with(
357+
ensure: 'present',
358+
mode: '0644',
359+
owner: 'root',
360+
group: 'root',
361+
path: '/etc/default/snmpd'
362+
).that_requires('Package[snmpd]').that_notifies('Service[snmpd]')
363+
}
364+
it 'contains File[snmpd.sysconfig] with contents "SNMPDOPTS=\'-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid\'"' do
365+
verify_contents(catalogue, 'snmpd.sysconfig', [
333366
'SNMPDRUN=yes',
334-
'SNMPDOPTS=\'-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid\''
367+
'SNMPDOPTS=\'-Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux -p /var/run/snmpd.pid\''
335368
])
336-
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-
}
369+
end
370+
it 'contains File[snmptrapd.sysconfig] with contents "TRAPDOPTS=\'-Lsd -p /var/run/snmptrapd.pid\'"' do
371+
verify_contents(catalogue, 'snmptrapd.sysconfig', [
372+
'TRAPDRUN=yes',
373+
'TRAPDOPTS=\'-Lsd -p /var/run/snmptrapd.pid\''
374+
])
375+
end
376+
377+
end
378+
379+
describe 'service_ensure => stopped and trap_service_ensure => running' do
380+
let(:params) do
381+
{
382+
service_ensure: 'stopped',
383+
trap_service_ensure: 'running'
384+
}
385+
end
386+
it { is_expected.to contain_service('snmpd').with_ensure('stopped') }
387+
it { is_expected.to contain_service('snmptrapd').with_ensure('running') }
388+
end
389+
390+
describe 'snmpd_options => blah' do
391+
let(:params) { { snmpd_options: 'blah' } }
392+
it { is_expected.to contain_file('snmpd.sysconfig') }
393+
it 'contains File[snmpd.sysconfig] with contents "SNMPDOPTS=\'blah\'"' do
394+
verify_contents(catalogue, 'snmpd.sysconfig', ['SNMPDOPTS=\'blah\''])
395+
end
396+
end
397+
398+
describe 'snmptrapd_options => bleh' do
399+
let(:params) { { snmptrapd_options: 'bleh' } }
400+
it { is_expected.to contain_file('snmptrapd.sysconfig') }
401+
it 'contains File[snmptrapd.sysconfig] with contents "TRAPDOPTS=\'bleh\'"' do
402+
verify_contents(catalogue, 'snmptrapd.sysconfig', ['TRAPDOPTS=\'bleh\''])
403+
end
404+
end
346405

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-
])
363406
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-
])
407+
408+
context "for osfamily Debian, operatingsystem #{os} with systemd" do
409+
let(:facts) do
410+
debfacts.merge({service_provider: 'systemd', path: '/bin:/sbin:/usr/bin' })
411+
end
412+
413+
it { is_expected.not_to contain_file('snmptrapd.sysconfig') }
414+
it { is_expected.not_to contain_file('snmpd.sysconfig') }
415+
416+
it {
417+
is_expected.to contain_service('snmpd').with(
418+
ensure: 'running',
419+
name: 'snmpd',
420+
enable: true,
421+
hasstatus: true,
422+
hasrestart: true
423+
).that_requires(['Package[snmpd]', 'File[var-net-snmp]'])
424+
}
425+
426+
describe 'default params' do
427+
let(:params) { {} }
428+
it 'contains systemd dropin file for snmpd with execstart' do
429+
is_expected.to contain_file('/etc/systemd/system/snmpd.service.d/local.conf').with(
430+
ensure: 'file',
431+
mode: '0644',
432+
owner: 'root',
433+
group: 'root',
434+
path: '/etc/systemd/system/snmpd.service.d/local.conf'
435+
).that_requires('Package[snmpd]').that_notifies(['Service[snmpd]', 'Exec[systemctl-daemon-reload]'])
436+
437+
expected_lines = [
438+
'[Service]',
439+
'ExecStart=',
440+
'ExecStart=/usr/sbin/snmpd -Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux -p /var/run/snmpd.pid',
441+
'Type=',
442+
'Type=forking',
443+
]
444+
verify_contents(catalogue, '/etc/systemd/system/snmpd.service.d/local.conf', expected_lines)
445+
end
446+
end
447+
describe 'ensure_service => stopped, trap_service_ensure => running' do
448+
let :params do
449+
{
450+
service_ensure: 'stopped',
451+
trap_service_ensure: 'running'
452+
}
453+
end
454+
455+
it { is_expected.to contain_service('snmpd').with_ensure('stopped') }
456+
it { is_expected.to contain_service('snmptrapd').with_ensure('running') }
457+
end
458+
459+
describe 'snmpd_options => blah' do
460+
let(:params) { { snmpd_options: 'blah' } }
461+
462+
it { is_expected.to contain_file('/etc/systemd/system/snmpd.service.d/local.conf') }
463+
it 'contains systemd drop-in file with contents ExecStart' do
464+
verify_contents(catalogue, '/etc/systemd/system/snmpd.service.d/local.conf', [
465+
'ExecStart=/usr/sbin/snmpd blah'
466+
])
467+
end
468+
end
469+
470+
describe 'snmptrapd_options => bleh' do
471+
let(:params) { { snmptrapd_options: 'bleh' } }
472+
473+
it { is_expected.to contain_file('/etc/systemd/system/snmptrapd.service.d/local.conf') }
474+
it 'contains systemd drop-in file with contents ExecStart' do
475+
verify_contents(catalogue, '/etc/systemd/system/snmptrapd.service.d/local.conf', [
476+
'ExecStart=/usr/sbin/snmptrapd bleh'
477+
])
478+
end
479+
end
370480
end
371-
it { is_expected.not_to contain_service('snmptrapd') }
372481
end
373482
end
374483

@@ -1072,70 +1181,6 @@
10721181
end
10731182
end
10741183

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-
11391184
context 'on a supported osfamily (Suse), custom parameters' do
11401185
let :facts do
11411186
{

0 commit comments

Comments
 (0)