From 7054d9d1745f01fcce832862800b17ebc1be56fa Mon Sep 17 00:00:00 2001 From: Sebastian Reitenbach Date: Mon, 23 May 2016 12:33:27 +0200 Subject: [PATCH] Add OpenBSD to the supported operating systems, similar to FreeBSD support. Add spec tests for OpenBSD and mention it in README and metadata.json --- README.markdown | 1 + manifests/init.pp | 4 +- manifests/params.pp | 22 ++++++++ metadata.json | 4 ++ spec/classes/snmp_client_spec.rb | 25 +++++++++ spec/classes/snmp_init_spec.rb | 91 ++++++++++++++++++++++++++++++++ 6 files changed, 145 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 50e62e0b..ac4af633 100644 --- a/README.markdown +++ b/README.markdown @@ -488,6 +488,7 @@ Net-SNMP module support is available with these operating systems: * SuSE family - tested on SLES 11 SP1 * Debian family - tested on Ubuntu 12.04.2 LTS, Debian 6.0.7, and Debian 7.0 * FreeBSD family - tested on FreeBSD 9.2-RELEASE, FreeBSD 10.0-RELEASE +* OpenBSD family - tested on OpenBSD 5.9 ###Notes: diff --git a/manifests/init.pp b/manifests/init.pp index f62e72e4..467d70e0 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -441,7 +441,7 @@ notify => Service['snmpd'], } - if $::osfamily != 'FreeBSD' { + if $::osfamily != 'FreeBSD' and $::osfamily != 'OpenBSD' { file { 'snmpd.sysconfig': ensure => $file_ensure, mode => '0644', @@ -504,7 +504,7 @@ Exec['install /etc/init.d/snmptrapd'], ], } - } elsif $::osfamily == 'FreeBSD' { + } elsif $::osfamily == 'FreeBSD' or $::osfamily == 'OpenBSD' { service { 'snmptrapd': ensure => $trap_service_ensure_real, name => $trap_service_name, diff --git a/manifests/params.pp b/manifests/params.pp index 73702b5c..86d8fdd5 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -395,6 +395,28 @@ $trap_service_name = 'snmptrapd' $snmptrapd_options = undef } + 'OpenBSD': { + $package_name = 'net-snmp' + $service_config_dir_path = '/etc/snmp' + $service_config_dir_perms = '0755' + $service_config_dir_owner = 'root' + $service_config_dir_group = 'wheel' + $service_config = '/etc/snmp/snmpd.conf' + $service_config_perms = '0755' + $service_name = 'netsnmpd' + $snmpd_options = undef + $var_net_snmp = '/var/net-snmp' + $varnetsnmp_perms = '0600' + $varnetsnmp_owner = '_netsnmp' + $varnetsnmp_group = 'wheel' + + $client_package_name = 'net-snmp' + $client_config = '/etc/snmp/snmp.conf' + + $trap_service_config = '/etc/snmp/snmptrapd.conf' + $trap_service_name = 'netsnmptrapd' + $snmptrapd_options = undef + } default: { fail("Module ${::module} is not supported on ${::operatingsystem}") } diff --git a/metadata.json b/metadata.json index e104d9b8..e5e26b79 100644 --- a/metadata.json +++ b/metadata.json @@ -31,6 +31,10 @@ "operatingsystem": "FreeBSD", "operatingsystemrelease": [ "9.2", "10.0" ] }, + { + "operatingsystem": "OpenBSD", + "operatingsystemrelease": [ "5.9" ] + }, { "operatingsystem": "SLES", "operatingsystemrelease": [ "11 SP1" ] diff --git a/spec/classes/snmp_client_spec.rb b/spec/classes/snmp_client_spec.rb index b62719e0..6cb8eb86 100644 --- a/spec/classes/snmp_client_spec.rb +++ b/spec/classes/snmp_client_spec.rb @@ -24,6 +24,7 @@ #debianish = ['Debian', 'Ubuntu'] suseish = ['Suse'] freebsdish = ['FreeBSD'] + openbsdish = ['OpenBSD'] context 'on a supported osfamily, default parameters' do redhatish.each do |os| @@ -118,6 +119,30 @@ )} end end + + openbsdish.each do |os| + describe "for osfamily OpenBSD, operatingsystem #{os}" do + let(:params) {{}} + let :facts do { + :osfamily => 'OpenBSD', + :operatingsystem => os, + :operatingsystemrelease => '5.9' + } + end + it { should contain_package('snmp-client').with( + :ensure => 'present', + :name => 'net-snmp' + )} + it { should_not contain_file('snmp.conf').with( + :ensure => 'present', + :mode => '0755', + :owner => 'root', + :group => 'wheel', + :path => '/etc/snmp/snmp.conf', + :require => nil + )} + end + end end context 'on a supported osfamily, custom parameters' do diff --git a/spec/classes/snmp_init_spec.rb b/spec/classes/snmp_init_spec.rb index a8c68ffd..8412f769 100644 --- a/spec/classes/snmp_init_spec.rb +++ b/spec/classes/snmp_init_spec.rb @@ -24,6 +24,7 @@ #debianish = ['Debian', 'Ubuntu'] suseish = ['Suse'] freebsdish = ['FreeBSD'] + openbsdish = ['OpenBSD'] context 'on a supported osfamily, default parameters' do describe "for osfamily RedHat, operatingsystem RedHat, operatingsystemrelease 5.9" do @@ -561,6 +562,96 @@ )} end end + + openbsdish.each do |os| + describe "for osfamily OpenBSD, operatingsystem #{os}" do + let(:params) {{}} + let :facts do { + :osfamily => 'OpenBSD', + :operatingsystem => os, + :operatingsystemrelease => '5.9', + :fqdn => 'myhost4.localdomain' + } + end + it { should contain_package('snmpd').with( + :ensure => 'present', + :name => 'net-snmp' + )} + it { should_not contain_class('snmp::client') } + it { should contain_file('var-net-snmp').with( + :ensure => 'directory', + :mode => '0600', + :owner => '_netsnmp', + :group => 'wheel', + :path => '/var/net-snmp', + :require => 'Package[snmpd]' + )} + + it { should contain_file('snmpd.conf').with( + :ensure => 'present', + :mode => '0755', + :owner => 'root', + :group => 'wheel', + :path => '/etc/snmp/snmpd.conf', + :require => 'Package[snmpd]', + :notify => 'Service[snmpd]' + )} + # TODO add more contents for File[snmpd.conf] + it 'should contain File[snmpd.conf] with expected contents' do + verify_contents(catalogue, 'snmpd.conf', [ + 'agentaddress udp:127.0.0.1:161,udp6:[::1]:161', + 'rocommunity public 127.0.0.1', + 'rocommunity6 public ::1', + 'com2sec notConfigUser default public', + 'com2sec6 notConfigUser default public', + 'group notConfigGroup v1 notConfigUser', + 'group notConfigGroup v2c notConfigUser', + 'view systemview included .1.3.6.1.2.1.1', + 'view systemview included .1.3.6.1.2.1.25.1.1', + 'access notConfigGroup "" any noauth exact systemview none none', + 'sysLocation Unknown', + 'sysContact Unknown', + 'sysServices 72', + 'sysName myhost4.localdomain', + 'dontLogTCPWrappersConnects no', + ]) + end + it { should contain_service('snmpd').with( + :ensure => 'running', + :name => 'netsnmpd', + :enable => true, + :hasstatus => true, + :hasrestart => true, + :require => [ 'Package[snmpd]', 'File[var-net-snmp]', ] + )} + + it { should contain_file('snmptrapd.conf').with( + :ensure => 'present', + :mode => '0755', + :owner => 'root', + :group => 'wheel', + :path => '/etc/snmp/snmptrapd.conf', + :require => 'Package[snmpd]', + :notify => 'Service[snmptrapd]' + )} + # TODO add more contents for File[snmptrapd.conf] + it 'should contain File[snmptrapd.conf] with correct contents' do + verify_contents(catalogue, 'snmptrapd.conf', [ + 'doNotLogTraps no', + 'authCommunity log,execute,net public', + 'disableAuthorization no', + ]) + end + it { should contain_service('snmptrapd').with( + :ensure => 'stopped', + :name => 'netsnmptrapd', + :enable => false, + :hasstatus => true, + :hasrestart => true, + :require => [ 'Package[snmpd]', 'File[var-net-snmp]', ] + )} + end + end end context 'on a supported osfamily (RedHat), custom parameters' do