|
541 | 541 | end |
542 | 542 | end |
543 | 543 |
|
| 544 | + let(:pid_path) do |
| 545 | + case facts[:os]['name'] |
| 546 | + when 'Ubuntu' |
| 547 | + '/run' |
| 548 | + else |
| 549 | + '/var/run' |
| 550 | + end |
| 551 | + end |
| 552 | + |
544 | 553 | it { |
545 | 554 | is_expected.to contain_package('snmpd').with( |
546 | 555 | ensure: 'present', |
|
630 | 639 | it 'contains File[snmpd.sysconfig] with contents "SNMPDOPTS=\'-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid\'"' do |
631 | 640 | verify_contents(catalogue, 'snmpd.sysconfig', [ |
632 | 641 | 'SNMPDRUN=yes', |
633 | | - "SNMPDOPTS='-Lsd -Lf /dev/null -u #{snmp_user} -g #{snmp_user} -I -smux -p /var/run/snmpd.pid'" |
| 642 | + "SNMPDOPTS='-Lsd -Lf /dev/null -u #{snmp_user} -g #{snmp_user} -I -smux -p #{pid_path}/snmpd.pid'" |
634 | 643 | ]) |
635 | 644 | end |
636 | 645 | it 'contains File[snmptrapd.sysconfig] with contents "TRAPDOPTS=\'-Lsd -p /var/run/snmptrapd.pid\'"' do |
637 | 646 | verify_contents(catalogue, 'snmptrapd.sysconfig', [ |
638 | 647 | 'TRAPDRUN=yes', |
639 | | - 'TRAPDOPTS=\'-Lsd -p /var/run/snmptrapd.pid\'' |
| 648 | + "TRAPDOPTS='-Lsd -p #{pid_path}/snmptrapd.pid'" |
640 | 649 | ]) |
641 | 650 | end |
642 | 651 | end |
|
670 | 679 | end |
671 | 680 | end |
672 | 681 |
|
673 | | - context 'with systemd' do |
674 | | - let(:facts) do |
675 | | - facts.merge(service_provider: 'systemd') |
676 | | - end |
| 682 | + # Deal with the weird part where ubuntu mixes systemd and sysvinit configuration. |
| 683 | + mixed_systemd_sysvinit = (facts[:os]['name'] == 'Ubuntu' && facts[:os]['release']['major'] == '16.04') \ |
| 684 | + || (facts[:os]['name'] == 'Debian' && facts[:os]['release']['major'] == '8') |
677 | 685 |
|
678 | | - it { is_expected.not_to contain_file('snmptrapd.sysconfig') } |
679 | | - it { is_expected.not_to contain_file('snmpd.sysconfig') } |
680 | | - |
681 | | - it { |
682 | | - is_expected.to contain_service('snmpd').with( |
683 | | - ensure: 'running', |
684 | | - name: 'snmpd', |
685 | | - enable: true, |
686 | | - hasstatus: true, |
687 | | - hasrestart: true |
688 | | - ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) |
689 | | - } |
| 686 | + unless mixed_systemd_sysvinit |
| 687 | + context 'with systemd (only!)' do |
| 688 | + let(:facts) do |
| 689 | + facts.merge(service_provider: 'systemd') |
| 690 | + end |
690 | 691 |
|
691 | | - describe 'default params' do |
692 | | - let(:params) { {} } |
| 692 | + it { is_expected.not_to contain_file('snmptrapd.sysconfig') } |
| 693 | + it { is_expected.not_to contain_file('snmpd.sysconfig') } |
693 | 694 |
|
694 | | - it 'contains systemd dropin file for snmpd with execstart' do |
695 | | - is_expected.to contain_systemd__dropin_file('snmpd.conf').with( |
696 | | - unit: 'snmpd.service' |
697 | | - ).that_requires('Package[snmpd]').that_notifies('Service[snmpd]') |
| 695 | + it { |
| 696 | + is_expected.to contain_service('snmpd').with( |
| 697 | + ensure: 'running', |
| 698 | + name: 'snmpd', |
| 699 | + enable: true, |
| 700 | + hasstatus: true, |
| 701 | + hasrestart: true |
| 702 | + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) |
| 703 | + } |
698 | 704 |
|
699 | | - expected_lines = [ |
700 | | - '[Service]', |
701 | | - 'ExecStart=', |
702 | | - "ExecStart=/usr/sbin/snmpd -Lsd -Lf /dev/null -u #{snmp_user} -g #{snmp_user} -I -smux -p /var/run/snmpd.pid -f" |
703 | | - ] |
704 | | - verify_contents(catalogue, '/etc/systemd/system/snmpd.service.d/snmpd.conf', expected_lines) |
| 705 | + describe 'default params' do |
| 706 | + let(:params) { {} } |
| 707 | + |
| 708 | + it 'contains systemd dropin file for snmpd with execstart' do |
| 709 | + is_expected.to contain_systemd__dropin_file('snmpd.conf').with( |
| 710 | + unit: 'snmpd.service' |
| 711 | + ).that_requires('Package[snmpd]').that_notifies('Service[snmpd]') |
| 712 | + |
| 713 | + expected_lines = [ |
| 714 | + '[Service]', |
| 715 | + 'ExecStart=', |
| 716 | + "ExecStart=/usr/sbin/snmpd -Lsd -Lf /dev/null -u #{snmp_user} -g #{snmp_user} -I -smux -p #{pid_path}/snmpd.pid -f" |
| 717 | + ] |
| 718 | + verify_contents(catalogue, '/etc/systemd/system/snmpd.service.d/snmpd.conf', expected_lines) |
| 719 | + end |
705 | 720 | end |
706 | | - end |
707 | | - describe 'ensure_service => stopped, trap_service_ensure => running' do |
708 | | - let :params do |
709 | | - { |
710 | | - service_ensure: 'stopped', |
711 | | - trap_service_ensure: 'running' |
712 | | - } |
| 721 | + describe 'ensure_service => stopped, trap_service_ensure => running' do |
| 722 | + let :params do |
| 723 | + { |
| 724 | + service_ensure: 'stopped', |
| 725 | + trap_service_ensure: 'running' |
| 726 | + } |
| 727 | + end |
| 728 | + |
| 729 | + it { is_expected.to contain_service('snmpd').with_ensure('stopped') } |
| 730 | + it { is_expected.to contain_service('snmptrapd').with_ensure('running') } |
713 | 731 | end |
714 | 732 |
|
715 | | - it { is_expected.to contain_service('snmpd').with_ensure('stopped') } |
716 | | - it { is_expected.to contain_service('snmptrapd').with_ensure('running') } |
717 | | - end |
| 733 | + describe 'snmpd_options => blah' do |
| 734 | + let(:params) { { snmpd_options: 'blah' } } |
718 | 735 |
|
719 | | - describe 'snmpd_options => blah' do |
720 | | - let(:params) { { snmpd_options: 'blah' } } |
721 | | - |
722 | | - it { is_expected.to contain_systemd__dropin_file('snmpd.conf') } |
723 | | - it 'contains systemd drop-in file with contents ExecStart' do |
724 | | - verify_contents(catalogue, '/etc/systemd/system/snmpd.service.d/snmpd.conf', [ |
725 | | - 'ExecStart=/usr/sbin/snmpd blah -f' |
726 | | - ]) |
| 736 | + it { is_expected.to contain_systemd__dropin_file('snmpd.conf') } |
| 737 | + it 'contains systemd drop-in file with contents ExecStart' do |
| 738 | + verify_contents(catalogue, '/etc/systemd/system/snmpd.service.d/snmpd.conf', [ |
| 739 | + 'ExecStart=/usr/sbin/snmpd blah -f' |
| 740 | + ]) |
| 741 | + end |
727 | 742 | end |
728 | | - end |
729 | 743 |
|
730 | | - describe 'snmptrapd_options => bleh' do |
731 | | - let(:params) { { snmptrapd_options: 'bleh' } } |
| 744 | + describe 'snmptrapd_options => bleh' do |
| 745 | + let(:params) { { snmptrapd_options: 'bleh' } } |
732 | 746 |
|
733 | | - it { is_expected.to contain_systemd__dropin_file('snmptrapd.conf') } |
734 | | - it 'contains systemd drop-in file with contents ExecStart' do |
735 | | - verify_contents(catalogue, '/etc/systemd/system/snmptrapd.service.d/snmptrapd.conf', [ |
736 | | - 'ExecStart=/usr/sbin/snmptrapd bleh -f' |
737 | | - ]) |
| 747 | + it { is_expected.to contain_systemd__dropin_file('snmptrapd.conf') } |
| 748 | + it 'contains systemd drop-in file with contents ExecStart' do |
| 749 | + verify_contents(catalogue, '/etc/systemd/system/snmptrapd.service.d/snmptrapd.conf', [ |
| 750 | + 'ExecStart=/usr/sbin/snmptrapd bleh -f' |
| 751 | + ]) |
| 752 | + end |
738 | 753 | end |
739 | 754 | end |
740 | 755 | end |
|
0 commit comments