From b8a81fca5890ea1953770ae3b1cc5f5aa3860826 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Thu, 4 Oct 2018 23:10:28 +0100 Subject: [PATCH] Various refactoring to improve code readability Hopefully some of the logic in (especially) `init.pp` is less complicated. It should now also be possible to split `init.pp` into the `package -> config ~> service` pattern if someone wants to take on that work. * Replace `if != and !=` with `unless == or ==` * Replace `$snmptrapd_conf_notify` with `subscribes` * Refactor `snmpv3_user` by replacing `require` with `before` * Remove duplication of identical `Service['snmptrapd']` resources * Remove some redundant relationships and reorder resources in init.pp * Refactor client.pp * Don't use absolute class names * Use proper relationship matchers in tests * Replace Exec with File resource for `/etc/init.d/snmptrapd` on Suse --- README.md | 2 +- manifests/client.pp | 10 +- manifests/init.pp | 88 +++++------ manifests/snmpv3_user.pp | 2 +- spec/classes/snmp_client_spec.rb | 13 +- spec/classes/snmp_init_spec.rb | 204 ++++++++++---------------- spec/defines/snmp_snmpv3_user_spec.rb | 54 +++---- 7 files changed, 139 insertions(+), 234 deletions(-) diff --git a/README.md b/README.md index 70208bf9..3d232996 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ class { 'snmp': If you just want to install the SNMP client: ```puppet -include ::snmp::client +include snmp::client ``` To install the SNMP service and the client: diff --git a/manifests/client.pp b/manifests/client.pp index 05dc59f1..f847ec75 100644 --- a/manifests/client.pp +++ b/manifests/client.pp @@ -64,10 +64,11 @@ $file_ensure = 'absent' } - if $::osfamily != 'Suse' { + unless $::osfamily == 'Suse' { package { 'snmp-client': ensure => $package_ensure, name => $package_name, + before => File['snmp.conf'], } } @@ -77,12 +78,6 @@ } } - $req = $::osfamily ? { - 'RedHat' => [Package['snmp-client'], File['/etc/snmp']], - 'Suse' => undef, - default => Package['snmp-client'], - } - file { 'snmp.conf': ensure => $file_ensure, mode => '0644', @@ -90,6 +85,5 @@ group => 'root', path => $snmp::params::client_config, content => template('snmp/snmp.conf.erb'), - require => $req, } } diff --git a/manifests/init.pp b/manifests/init.pp index 11bd5a75..2a849779 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -399,12 +399,6 @@ $trapdrun = 'no' } - if $::osfamily != 'Debian' { - $snmptrapd_conf_notify = Service['snmptrapd'] - } else { - $snmptrapd_conf_notify = Service['snmpd'] - } - if $manage_client { class { 'snmp::client': ensure => $ensure, @@ -413,6 +407,7 @@ } } + # Install package { 'snmpd': ensure => $package_ensure, name => $package_name, @@ -437,6 +432,18 @@ } } + if $::osfamily == 'Suse' { + file { '/etc/init.d/snmptrapd': + source => '/usr/share/doc/packages/net-snmp/rc.snmptrapd', + owner => 'root', + group => 'root', + mode => '0755', + require => Package['snmpd'], + before => Service['snmptrapd'], + } + } + + # Config file { 'snmpd.conf': ensure => $file_ensure, mode => $service_config_perms, @@ -445,10 +452,20 @@ path => $snmp::params::service_config, content => template($template_snmpd_conf), require => Package['snmpd'], - notify => Service['snmpd'], } - if $::osfamily != 'FreeBSD' and $::osfamily != 'OpenBSD' { + file { 'snmptrapd.conf': + ensure => $file_ensure, + mode => $service_config_perms, + owner => 'root', + group => $service_config_dir_group, + path => $snmp::params::trap_service_config, + content => template($template_snmptrapd), + require => Package['snmpd'], + } + + + unless $::osfamily == 'FreeBSD' or $::osfamily == 'OpenBSD' { file { 'snmpd.sysconfig': ensure => $file_ensure, mode => '0644', @@ -461,17 +478,6 @@ } } - file { 'snmptrapd.conf': - ensure => $file_ensure, - mode => $service_config_perms, - owner => 'root', - group => $service_config_dir_group, - path => $snmp::params::trap_service_config, - content => template($template_snmptrapd), - require => Package['snmpd'], - notify => $snmptrapd_conf_notify, - } - if $::osfamily == 'RedHat' { file { 'snmptrapd.sysconfig': ensure => $file_ensure, @@ -483,45 +489,18 @@ require => Package['snmpd'], notify => Service['snmptrapd'], } + } + # Services + unless $::osfamily == 'Debian' { service { 'snmptrapd': ensure => $trap_service_ensure_real, name => $trap_service_name, enable => $trap_service_enable_real, hasstatus => $trap_service_hasstatus, hasrestart => $trap_service_hasrestart, - require => [ Package['snmpd'], File['var-net-snmp'], ], - } - } elsif $::osfamily == 'Suse' { - exec { 'install /etc/init.d/snmptrapd': - command => '/usr/bin/install -o 0 -g 0 -m0755 -p /usr/share/doc/packages/net-snmp/rc.snmptrapd /etc/init.d/snmptrapd', - creates => '/etc/init.d/snmptrapd', - require => Package['snmpd'], - } - - service { 'snmptrapd': - ensure => $trap_service_ensure_real, - name => $trap_service_name, - enable => $trap_service_enable_real, - hasstatus => $trap_service_hasstatus, - hasrestart => $trap_service_hasrestart, - require => [ - Package['snmpd'], - File['var-net-snmp'], - Exec['install /etc/init.d/snmptrapd'], - ], - } - } elsif $::osfamily == 'FreeBSD' or $::osfamily == 'OpenBSD' { - service { 'snmptrapd': - ensure => $trap_service_ensure_real, - name => $trap_service_name, - enable => $trap_service_enable_real, - hasstatus => $trap_service_hasstatus, - hasrestart => $trap_service_hasrestart, - require => [ - Package['snmpd'], - File['var-net-snmp'], - ], + require => File['var-net-snmp'], + subscribe => File['snmptrapd.conf'], } } @@ -531,6 +510,11 @@ enable => $service_enable_real, hasstatus => $service_hasstatus, hasrestart => $service_hasrestart, - require => [ Package['snmpd'], File['var-net-snmp'], ], + require => File['var-net-snmp'], + subscribe => File['snmpd.conf'], + } + + if $::osfamily == 'Debian' { + File['snmptrapd.conf'] ~> Service['snmpd'] } } diff --git a/manifests/snmpv3_user.pp b/manifests/snmpv3_user.pp index 0b2dea63..12333ade 100644 --- a/manifests/snmpv3_user.pp +++ b/manifests/snmpv3_user.pp @@ -61,7 +61,7 @@ Enum['snmpd','snmptrapd'] $daemon = 'snmpd' ) { - include ::snmp + include snmp if ($daemon == 'snmptrapd') and ($::osfamily != 'Debian') { $service_name = 'snmptrapd' diff --git a/spec/classes/snmp_client_spec.rb b/spec/classes/snmp_client_spec.rb index 4750c696..7787a663 100644 --- a/spec/classes/snmp_client_spec.rb +++ b/spec/classes/snmp_client_spec.rb @@ -51,9 +51,8 @@ mode: '0644', owner: 'root', group: 'root', - path: '/etc/snmp/snmp.conf', - require: ['Package[snmp-client]', 'File[/etc/snmp]'] - ) + path: '/etc/snmp/snmp.conf' + ).that_requires(['Package[snmp-client]', 'File[/etc/snmp]']) } end end @@ -83,9 +82,8 @@ mode: '0644', owner: 'root', group: 'root', - path: '/etc/snmp/snmp.conf', - require: 'Package[snmp-client]' - ) + path: '/etc/snmp/snmp.conf' + ).that_requires('Package[snmp-client]') } end end @@ -141,8 +139,7 @@ mode: '0755', owner: 'root', group: 'wheel', - path: '/usr/local/etc/snmp/snmp.conf', - require: nil + path: '/usr/local/etc/snmp/snmp.conf' ) } end diff --git a/spec/classes/snmp_init_spec.rb b/spec/classes/snmp_init_spec.rb index 98b0b16a..8cce8e7b 100644 --- a/spec/classes/snmp_init_spec.rb +++ b/spec/classes/snmp_init_spec.rb @@ -49,9 +49,8 @@ mode: '0700', owner: 'root', group: 'root', - path: '/var/net-snmp', - require: 'Package[snmpd]' - ) + path: '/var/net-snmp' + ).that_requires('Package[snmpd]') } it { @@ -60,10 +59,8 @@ mode: '0644', owner: 'root', group: 'root', - path: '/etc/snmp/snmpd.conf', - require: 'Package[snmpd]', - notify: 'Service[snmpd]' - ) + path: '/etc/snmp/snmpd.conf' + ).that_requires('Package[snmpd]').that_notifies('Service[snmpd]') } # TODO: add more contents for File[snmpd.conf] it 'contains File[snmpd.conf] with expected contents' do @@ -91,10 +88,8 @@ mode: '0644', owner: 'root', group: 'root', - path: '/etc/sysconfig/snmpd.options', - require: 'Package[snmpd]', - notify: 'Service[snmpd]' - ) + path: '/etc/sysconfig/snmpd.options' + ).that_requires('Package[snmpd]').that_notifies('Service[snmpd]') } it 'contains File[snmpd.sysconfig] with contents "OPTIONS="-Lsd -Lf /dev/null -p /var/run/snmpd.pid -a""' do verify_contents(catalogue, 'snmpd.sysconfig', [ @@ -107,9 +102,8 @@ name: 'snmpd', enable: true, hasstatus: true, - hasrestart: true, - require: ['Package[snmpd]', 'File[var-net-snmp]'] - ) + hasrestart: true + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) } it { @@ -118,10 +112,8 @@ mode: '0644', owner: 'root', group: 'root', - path: '/etc/snmp/snmptrapd.conf', - require: 'Package[snmpd]', - notify: 'Service[snmptrapd]' - ) + path: '/etc/snmp/snmptrapd.conf' + ).that_requires('Package[snmpd]').that_notifies('Service[snmptrapd]') } # TODO: add more contents for File[snmptrapd.conf] it 'contains File[snmptrapd.conf] with correct contents' do @@ -137,10 +129,8 @@ mode: '0644', owner: 'root', group: 'root', - path: '/etc/sysconfig/snmptrapd.options', - require: 'Package[snmpd]', - notify: 'Service[snmptrapd]' - ) + path: '/etc/sysconfig/snmptrapd.options' + ).that_requires('Package[snmpd]').that_notifies('Service[snmptrapd]') } it 'contains File[snmptrapd.sysconfig] with contents "OPTIONS="-Lsd -p /var/run/snmptrapd.pid""' do verify_contents(catalogue, 'snmptrapd.sysconfig', [ @@ -153,9 +143,8 @@ name: 'snmptrapd', enable: false, hasstatus: true, - hasrestart: true, - require: ['Package[snmpd]', 'File[var-net-snmp]'] - ) + hasrestart: true + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) } end describe 'for osfamily RedHat, operatingsystem RedHat, operatingsystemrelease 6.4' do @@ -184,9 +173,8 @@ mode: '0755', owner: 'root', group: 'root', - path: '/var/lib/net-snmp', - require: 'Package[snmpd]' - ) + path: '/var/lib/net-snmp' + ).that_requires('Package[snmpd]') } it { @@ -195,10 +183,8 @@ mode: '0600', owner: 'root', group: 'root', - path: '/etc/snmp/snmpd.conf', - require: 'Package[snmpd]', - notify: 'Service[snmpd]' - ) + path: '/etc/snmp/snmpd.conf' + ).that_requires('Package[snmpd]').that_notifies('Service[snmpd]') } # TODO: add more contents for File[snmpd.conf] it 'contains File[snmpd.conf] with expected contents' do @@ -226,10 +212,8 @@ mode: '0644', owner: 'root', group: 'root', - path: '/etc/sysconfig/snmpd', - require: 'Package[snmpd]', - notify: 'Service[snmpd]' - ) + path: '/etc/sysconfig/snmpd' + ).that_requires('Package[snmpd]').that_notifies('Service[snmpd]') } it 'contains File[snmpd.sysconfig] with contents "OPTIONS="-LS0-6d -Lf /dev/null -p /var/run/snmpd.pid""' do verify_contents(catalogue, 'snmpd.sysconfig', [ @@ -242,9 +226,8 @@ name: 'snmpd', enable: true, hasstatus: true, - hasrestart: true, - require: ['Package[snmpd]', 'File[var-net-snmp]'] - ) + hasrestart: true + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) } it { @@ -253,10 +236,8 @@ mode: '0600', owner: 'root', group: 'root', - path: '/etc/snmp/snmptrapd.conf', - require: 'Package[snmpd]', - notify: 'Service[snmptrapd]' - ) + path: '/etc/snmp/snmptrapd.conf' + ).that_requires('Package[snmpd]').that_notifies('Service[snmptrapd]') } # TODO: add more contents for File[snmptrapd.conf] it 'contains File[snmptrapd.conf] with correct contents' do @@ -272,10 +253,8 @@ mode: '0644', owner: 'root', group: 'root', - path: '/etc/sysconfig/snmptrapd', - require: 'Package[snmpd]', - notify: 'Service[snmptrapd]' - ) + path: '/etc/sysconfig/snmptrapd' + ).that_requires('Package[snmpd]').that_notifies('Service[snmptrapd]') } it 'contains File[snmptrapd.sysconfig] with contents "OPTIONS="-Lsd -p /var/run/snmptrapd.pid""' do verify_contents(catalogue, 'snmptrapd.sysconfig', [ @@ -288,9 +267,8 @@ name: 'snmptrapd', enable: false, hasstatus: true, - hasrestart: true, - require: ['Package[snmpd]', 'File[var-net-snmp]'] - ) + hasrestart: true + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) } end @@ -321,9 +299,8 @@ mode: '0755', owner: 'snmp', group: 'snmp', - path: '/var/lib/snmp', - require: 'Package[snmpd]' - ) + path: '/var/lib/snmp' + ).that_requires('Package[snmpd]') } it { @@ -332,10 +309,8 @@ mode: '0600', owner: 'root', group: 'root', - path: '/etc/snmp/snmpd.conf', - require: 'Package[snmpd]', - notify: 'Service[snmpd]' - ) + path: '/etc/snmp/snmpd.conf' + ).that_requires('Package[snmpd]').that_notifies('Service[snmpd]') } # TODO: add more contents for File[snmpd.conf] it 'contains File[snmpd.conf] with expected contents' do @@ -363,10 +338,8 @@ mode: '0644', owner: 'root', group: 'root', - path: '/etc/default/snmpd', - require: 'Package[snmpd]', - notify: 'Service[snmpd]' - ) + path: '/etc/default/snmpd' + ).that_requires('Package[snmpd]').that_notifies('Service[snmpd]') } it 'contains File[snmpd.sysconfig] with contents "SNMPDOPTS=\'-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid\'"' do verify_contents(catalogue, 'snmpd.sysconfig', [ @@ -380,9 +353,8 @@ name: 'snmpd', enable: true, hasstatus: true, - hasrestart: true, - require: ['Package[snmpd]', 'File[var-net-snmp]'] - ) + hasrestart: true + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) } it { @@ -391,10 +363,8 @@ mode: '0600', owner: 'root', group: 'root', - path: '/etc/snmp/snmptrapd.conf', - require: 'Package[snmpd]', - notify: 'Service[snmpd]' - ) + path: '/etc/snmp/snmptrapd.conf' + ).that_requires('Package[snmpd]').that_notifies('Service[snmpd]') } # TODO: add more contents for File[snmptrapd.conf] it 'contains File[snmptrapd.conf] with correct contents' do @@ -442,9 +412,8 @@ mode: '0755', owner: 'root', group: 'root', - path: '/var/lib/net-snmp', - require: 'Package[snmpd]' - ) + path: '/var/lib/net-snmp' + ).that_requires('Package[snmpd]') } it { @@ -453,10 +422,8 @@ mode: '0600', owner: 'root', group: 'root', - path: '/etc/snmp/snmpd.conf', - require: 'Package[snmpd]', - notify: 'Service[snmpd]' - ) + path: '/etc/snmp/snmpd.conf' + ).that_requires('Package[snmpd]').that_notifies('Service[snmpd]') } # TODO: add more contents for File[snmpd.conf] it 'contains File[snmpd.conf] with expected contents' do @@ -484,10 +451,8 @@ mode: '0644', owner: 'root', group: 'root', - path: '/etc/sysconfig/net-snmp', - require: 'Package[snmpd]', - notify: 'Service[snmpd]' - ) + path: '/etc/sysconfig/net-snmp' + ).that_requires('Package[snmpd]').that_notifies('Service[snmpd]') } it 'contains File[snmpd.sysconfig] with contents "SNMPD_LOGLEVEL="d""' do verify_contents(catalogue, 'snmpd.sysconfig', [ @@ -500,9 +465,8 @@ name: 'snmpd', enable: true, hasstatus: true, - hasrestart: true, - require: ['Package[snmpd]', 'File[var-net-snmp]'] - ) + hasrestart: true + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) } it { @@ -511,10 +475,8 @@ mode: '0600', owner: 'root', group: 'root', - path: '/etc/snmp/snmptrapd.conf', - require: 'Package[snmpd]', - notify: 'Service[snmptrapd]' - ) + path: '/etc/snmp/snmptrapd.conf' + ).that_requires('Package[snmpd]').that_notifies('Service[snmptrapd]') } # TODO: add more contents for File[snmptrapd.conf] it 'contains File[snmptrapd.conf] with correct contents' do @@ -526,11 +488,12 @@ end it { is_expected.not_to contain_file('snmptrapd.sysconfig') } it { - is_expected.to contain_exec('install /etc/init.d/snmptrapd').with( - command: '/usr/bin/install -o 0 -g 0 -m0755 -p /usr/share/doc/packages/net-snmp/rc.snmptrapd /etc/init.d/snmptrapd', - creates: '/etc/init.d/snmptrapd', - require: 'Package[snmpd]' - ) + is_expected.to contain_file('/etc/init.d/snmptrapd').with( + source: '/usr/share/doc/packages/net-snmp/rc.snmptrapd', + owner: 'root', + group: 'root', + mode: '0755' + ).that_requires('Package[snmpd]').that_comes_before('Service[snmptrapd]') } it { is_expected.to contain_service('snmptrapd').with( @@ -538,9 +501,8 @@ name: 'snmptrapd', enable: false, hasstatus: true, - hasrestart: true, - require: ['Package[snmpd]', 'File[var-net-snmp]', 'Exec[install /etc/init.d/snmptrapd]'] - ) + hasrestart: true + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]', 'File[/etc/init.d/snmptrapd]']) } end end @@ -571,9 +533,8 @@ mode: '0600', owner: 'root', group: 'wheel', - path: '/var/net-snmp', - require: 'Package[snmpd]' - ) + path: '/var/net-snmp' + ).that_requires('Package[snmpd]') } it { @@ -582,10 +543,8 @@ mode: '0755', owner: 'root', group: 'wheel', - path: '/usr/local/etc/snmp/snmpd.conf', - require: 'Package[snmpd]', - notify: 'Service[snmpd]' - ) + path: '/usr/local/etc/snmp/snmpd.conf' + ).that_requires('Package[snmpd]').that_notifies('Service[snmpd]') } # TODO: add more contents for File[snmpd.conf] it 'contains File[snmpd.conf] with expected contents' do @@ -613,9 +572,8 @@ name: 'snmpd', enable: true, hasstatus: true, - hasrestart: true, - require: ['Package[snmpd]', 'File[var-net-snmp]'] - ) + hasrestart: true + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) } it { @@ -624,10 +582,8 @@ mode: '0755', owner: 'root', group: 'wheel', - path: '/usr/local/etc/snmp/snmptrapd.conf', - require: 'Package[snmpd]', - notify: 'Service[snmptrapd]' - ) + path: '/usr/local/etc/snmp/snmptrapd.conf' + ).that_requires('Package[snmpd]').that_notifies('Service[snmptrapd]') } # TODO: add more contents for File[snmptrapd.conf] it 'contains File[snmptrapd.conf] with correct contents' do @@ -643,9 +599,8 @@ name: 'snmptrapd', enable: false, hasstatus: true, - hasrestart: true, - require: ['Package[snmpd]', 'File[var-net-snmp]'] - ) + hasrestart: true + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) } end end @@ -676,9 +631,8 @@ mode: '0600', owner: '_netsnmp', group: 'wheel', - path: '/var/net-snmp', - require: 'Package[snmpd]' - ) + path: '/var/net-snmp' + ).that_requires('Package[snmpd]') } it { @@ -687,10 +641,8 @@ mode: '0755', owner: 'root', group: 'wheel', - path: '/etc/snmp/snmpd.conf', - require: 'Package[snmpd]', - notify: 'Service[snmpd]' - ) + path: '/etc/snmp/snmpd.conf' + ).that_requires('Package[snmpd]').that_notifies('Service[snmpd]') } # TODO: add more contents for File[snmpd.conf] it 'contains File[snmpd.conf] with expected contents' do @@ -718,9 +670,8 @@ name: 'netsnmpd', enable: true, hasstatus: true, - hasrestart: true, - require: ['Package[snmpd]', 'File[var-net-snmp]'] - ) + hasrestart: true + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) } it { @@ -729,10 +680,8 @@ mode: '0755', owner: 'root', group: 'wheel', - path: '/etc/snmp/snmptrapd.conf', - require: 'Package[snmpd]', - notify: 'Service[snmptrapd]' - ) + path: '/etc/snmp/snmptrapd.conf' + ).that_requires('Package[snmpd]').that_notifies('Service[snmptrapd]') } # TODO: add more contents for File[snmptrapd.conf] it 'contains File[snmptrapd.conf] with correct contents' do @@ -748,9 +697,8 @@ name: 'netsnmptrapd', enable: false, hasstatus: true, - hasrestart: true, - require: ['Package[snmpd]', 'File[var-net-snmp]'] - ) + hasrestart: true + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']) } end end diff --git a/spec/defines/snmp_snmpv3_user_spec.rb b/spec/defines/snmp_snmpv3_user_spec.rb index 807d19e5..b9e948c6 100644 --- a/spec/defines/snmp_snmpv3_user_spec.rb +++ b/spec/defines/snmp_snmpv3_user_spec.rb @@ -87,10 +87,8 @@ it { is_expected.to contain_exec('create-snmpv3-user-myDEFAULTuser').with( command: 'service snmpd stop ; sleep 5 ; echo "createUser myDEFAULTuser SHA \"myauthpass\"" >>/var/lib/net-snmp/snmpd.conf && touch /var/lib/net-snmp/myDEFAULTuser-snmpd', - creates: '/var/lib/net-snmp/myDEFAULTuser-snmpd', - require: ['Package[snmpd]', 'File[var-net-snmp]'], - before: 'Service[snmpd]' - ) + creates: '/var/lib/net-snmp/myDEFAULTuser-snmpd' + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']).that_comes_before('Service[snmpd]') } end @@ -109,10 +107,8 @@ it { is_expected.to contain_exec('create-snmpv3-user-myALLuser').with( command: 'service snmpd stop ; sleep 5 ; echo "createUser myALLuser MD5 \"myauthpass\" DES \"myprivpass\"" >>/var/lib/net-snmp/snmpd.conf && touch /var/lib/net-snmp/myALLuser-snmpd', - creates: '/var/lib/net-snmp/myALLuser-snmpd', - require: ['Package[snmpd]', 'File[var-net-snmp]'], - before: 'Service[snmpd]' - ) + creates: '/var/lib/net-snmp/myALLuser-snmpd' + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']).that_comes_before('Service[snmpd]') } end @@ -129,10 +125,8 @@ it { is_expected.to contain_exec('create-snmpv3-user-myTRAPuser').with( command: 'service snmptrapd stop ; sleep 5 ; echo "createUser myTRAPuser SHA \"myauthpass\"" >>/var/lib/net-snmp/snmptrapd.conf && touch /var/lib/net-snmp/myTRAPuser-snmptrapd', - creates: '/var/lib/net-snmp/myTRAPuser-snmptrapd', - require: ['Package[snmpd]', 'File[var-net-snmp]'], - before: 'Service[snmptrapd]' - ) + creates: '/var/lib/net-snmp/myTRAPuser-snmptrapd' + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']).that_comes_before('Service[snmptrapd]') } end end @@ -160,10 +154,8 @@ it { is_expected.to contain_exec('create-snmpv3-user-myDEFAULTuser').with( command: 'service snmpd stop ; sleep 5 ; echo "createUser myDEFAULTuser SHA \"myauthpass\"" >>/var/lib/snmp/snmpd.conf && touch /var/lib/snmp/myDEFAULTuser-snmpd', - creates: '/var/lib/snmp/myDEFAULTuser-snmpd', - require: ['Package[snmpd]', 'File[var-net-snmp]'], - before: 'Service[snmpd]' - ) + creates: '/var/lib/snmp/myDEFAULTuser-snmpd' + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']).that_comes_before('Service[snmpd]') } end @@ -182,10 +174,8 @@ it { is_expected.to contain_exec('create-snmpv3-user-myALLuser').with( command: 'service snmpd stop ; sleep 5 ; echo "createUser myALLuser MD5 \"myauthpass\" DES \"myprivpass\"" >>/var/lib/snmp/snmpd.conf && touch /var/lib/snmp/myALLuser-snmpd', - creates: '/var/lib/snmp/myALLuser-snmpd', - require: ['Package[snmpd]', 'File[var-net-snmp]'], - before: 'Service[snmpd]' - ) + creates: '/var/lib/snmp/myALLuser-snmpd' + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']).that_comes_before('Service[snmpd]') } end @@ -202,10 +192,8 @@ it { is_expected.to contain_exec('create-snmpv3-user-myTRAPuser').with( command: 'service snmpd stop ; sleep 5 ; echo "createUser myTRAPuser SHA \"myauthpass\"" >>/var/lib/snmp/snmptrapd.conf && touch /var/lib/snmp/myTRAPuser-snmptrapd', - creates: '/var/lib/snmp/myTRAPuser-snmptrapd', - require: ['Package[snmpd]', 'File[var-net-snmp]'], - before: 'Service[snmpd]' - ) + creates: '/var/lib/snmp/myTRAPuser-snmptrapd' + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']).that_comes_before('Service[snmpd]') } end end @@ -233,10 +221,8 @@ it { is_expected.to contain_exec('create-snmpv3-user-myDEFAULTuser').with( command: 'service snmpd stop ; sleep 5 ; echo "createUser myDEFAULTuser SHA \"myauthpass\"" >>/var/lib/net-snmp/snmpd.conf && touch /var/lib/net-snmp/myDEFAULTuser-snmpd', - creates: '/var/lib/net-snmp/myDEFAULTuser-snmpd', - require: ['Package[snmpd]', 'File[var-net-snmp]'], - before: 'Service[snmpd]' - ) + creates: '/var/lib/net-snmp/myDEFAULTuser-snmpd' + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']).that_comes_before('Service[snmpd]') } end @@ -255,10 +241,8 @@ it { is_expected.to contain_exec('create-snmpv3-user-myALLuser').with( command: 'service snmpd stop ; sleep 5 ; echo "createUser myALLuser MD5 \"myauthpass\" DES \"myprivpass\"" >>/var/lib/net-snmp/snmpd.conf && touch /var/lib/net-snmp/myALLuser-snmpd', - creates: '/var/lib/net-snmp/myALLuser-snmpd', - require: ['Package[snmpd]', 'File[var-net-snmp]'], - before: 'Service[snmpd]' - ) + creates: '/var/lib/net-snmp/myALLuser-snmpd' + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']).that_comes_before('Service[snmpd]') } end @@ -275,10 +259,8 @@ it { is_expected.to contain_exec('create-snmpv3-user-myTRAPuser').with( command: 'service snmptrapd stop ; sleep 5 ; echo "createUser myTRAPuser SHA \"myauthpass\"" >>/var/lib/net-snmp/snmptrapd.conf && touch /var/lib/net-snmp/myTRAPuser-snmptrapd', - creates: '/var/lib/net-snmp/myTRAPuser-snmptrapd', - require: ['Package[snmpd]', 'File[var-net-snmp]'], - before: 'Service[snmptrapd]' - ) + creates: '/var/lib/net-snmp/myTRAPuser-snmptrapd' + ).that_requires(['Package[snmpd]', 'File[var-net-snmp]']).that_comes_before('Service[snmptrapd]') } end end