From 95ba74b77df202ccb7ab8192637ee04932144bd1 Mon Sep 17 00:00:00 2001 From: Zach Leslie Date: Sat, 21 Jan 2017 13:29:06 -0800 Subject: [PATCH 1/7] Add initial FreeBSD support Without this change, there is no support for FreeBSD. Here we add the basic params data, and update the unit tests for the icinga2 class to ensure that we have the expected results. Also here, we extend the metadata to include FreeBSD so that the unit tests are run. --- manifests/feature.pp | 4 +-- manifests/feature/idomysql.pp | 24 ++++++++------ manifests/feature/idopgsql.pp | 16 ++++++--- manifests/params.pp | 61 ++++++++++++++++++++++++++--------- metadata.json | 7 ++++ spec/classes/init_spec.rb | 19 ++++++++--- 6 files changed, 94 insertions(+), 37 deletions(-) diff --git a/manifests/feature.pp b/manifests/feature.pp index 968caea4d..119dfc846 100644 --- a/manifests/feature.pp +++ b/manifests/feature.pp @@ -26,8 +26,8 @@ 'present' => link, default => absent, }, - owner => 'root', - group => 'root', + owner => $user, + group => $group, target => "../features-available/${feature}.conf", require => Concat["${conf_dir}/features-available/${feature}.conf"], notify => Class['::icinga2::service'], diff --git a/manifests/feature/idomysql.pp b/manifests/feature/idomysql.pp index fd0a97085..728b0dc04 100644 --- a/manifests/feature/idomysql.pp +++ b/manifests/feature/idomysql.pp @@ -150,12 +150,14 @@ ) { require ::icinga2::config + require ::icinga2::params - $owner = $::icinga2::params::user - $group = $::icinga2::params::group - $node_name = $::icinga2::_constants['NodeName'] - $conf_dir = $::icinga2::params::conf_dir - $ssl_dir = "${::icinga2::params::pki_dir}/ido-mysql" + $owner = $::icinga2::params::user + $group = $::icinga2::params::group + $node_name = $::icinga2::_constants['NodeName'] + $conf_dir = $::icinga2::params::conf_dir + $ssl_dir = "${::icinga2::params::pki_dir}/ido-mysql" + $ido_mysql_package = $::icinga2::params::ido_mysql_package File { owner => $owner, @@ -284,8 +286,14 @@ $attrs_ssl = { enable_ssl => $enable_ssl } } - package { 'icinga2-ido-mysql': - ensure => installed, + if $ido_mysql_package { + package { $ido_mysql_package: + ensure => installed, + before => [ + Exec['icinga2-ido-mysql'], + Icinga2::Feature['ido-mysql'] + ] + } } if $import_schema { @@ -294,7 +302,6 @@ path => $::path, command => "mysql -h '${host}' -u '${user}' -p'${password}' '${database}' < '/usr/share/icinga2-ido-mysql/schema/mysql.sql'", unless => "mysql -h '${host}' -u '${user}' -p'${password}' '${database}' -Ns -e 'select version from icinga_dbversion'", - require => Package['icinga2-ido-mysql'], } } @@ -337,6 +344,5 @@ icinga2::feature { 'ido-mysql': ensure => $ensure, - require => Package['icinga2-ido-mysql'] } } diff --git a/manifests/feature/idopgsql.pp b/manifests/feature/idopgsql.pp index ff0d8da0c..8cda6f3b5 100644 --- a/manifests/feature/idopgsql.pp +++ b/manifests/feature/idopgsql.pp @@ -88,8 +88,10 @@ ) { require ::icinga2::config + require ::icinga2::params - $conf_dir = $::icinga2::params::conf_dir + $conf_dir = $::icinga2::params::conf_dir + $ido_pgsql_package = $::icinga2::params::ido_pgsql_package validate_re($ensure, [ '^present$', '^absent$' ], "${ensure} isn't supported. Valid values are 'present' and 'absent'.") @@ -107,8 +109,14 @@ if $categories { validate_array($categories) } validate_bool($import_schema) - package { 'icinga2-ido-pgsql': - ensure => installed, + if $ido_pgsql_package { + package { $ido_pgsql_package: + ensure => installed, + before => [ + Exec['idopgsql_import_schema'], + Icinga2::Feature['ido-pgsql'], + ] + } } if $import_schema { @@ -118,7 +126,6 @@ environment => ["PGPASSWORD=${password}"], command => "psql -h '${host}' -U '${user}' -d '${database}' -w -f /usr/share/icinga2-ido-pgsql/schema/pgsql.sql", unless => "psql -h '${host}' -U '${user}' -d '${database}' -w -c 'select version from icinga_dbversion'", - require => Package['icinga2-ido-pgsql'], } } @@ -159,6 +166,5 @@ icinga2::feature { 'ido-pgsql': ensure => $ensure, - require => Package['icinga2-ido-pgsql'] } } diff --git a/manifests/params.pp b/manifests/params.pp index 3fb3e0e50..b0df41bbe 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -84,13 +84,15 @@ case $::kernel { 'linux': { - $conf_dir = '/etc/icinga2' - $log_dir = '/var/log/icinga2' - $run_dir = '/var/run/icinga2' - $spool_dir = '/var/spool/icinga2' - $cache_dir = '/var/cache/icinga2' - $pki_dir = "${conf_dir}/pki" - $ca_dir = '/var/lib/icinga2/ca' + $conf_dir = '/etc/icinga2' + $log_dir = '/var/log/icinga2' + $run_dir = '/var/run/icinga2' + $spool_dir = '/var/spool/icinga2' + $cache_dir = '/var/cache/icinga2' + $pki_dir = "${conf_dir}/pki" + $ca_dir = '/var/lib/icinga2/ca' + $ido_pgsql_package = 'icinga2-ido-pgsql' + $ido_mysql_package = 'icinga2-ido-mysql' case $::osfamily { 'redhat': { @@ -133,15 +135,18 @@ } # Linux 'windows': { - $user = 'SYSTEM' - $group = undef - $conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - $log_dir = 'C:/ProgramData/icinga2/var/log/icinga2' - $run_dir = 'C:/ProgramData/icinga2/var/run/icinga2' - $spool_dir = 'C:/ProgramData/icinga2/var/spool/icinga2' - $cache_dir = 'C:/ProgramData/icinga2/var/cache/icinga2' - $pki_dir = "${conf_dir}/pki" - $ca_dir = 'C:/ProgramData/icinga2/var/lib/icinga2/ca' + $user = 'SYSTEM' + $group = undef + $conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' + $log_dir = 'C:/ProgramData/icinga2/var/log/icinga2' + $run_dir = 'C:/ProgramData/icinga2/var/run/icinga2' + $spool_dir = 'C:/ProgramData/icinga2/var/spool/icinga2' + $cache_dir = 'C:/ProgramData/icinga2/var/cache/icinga2' + $pki_dir = "${conf_dir}/pki" + $ca_dir = 'C:/ProgramData/icinga2/var/lib/icinga2/ca' + $ido_pgsql_package = undef + $ido_mysql_package = undef + $constants = { 'PluginDir' => 'C:/Program Files/ICINGA2/sbin', 'PluginContribDir' => 'C:/Program Files/ICINGA2/sbin', @@ -152,6 +157,30 @@ } } # Windows + 'FreeBSD': { + $conf_dir = '/usr/local/etc/icinga2' + $log_dir = '/var/log/icinga2' + $run_dir = '/var/run/icinga2' + $spool_dir = '/var/spool/icinga2' + $cache_dir = '/var/cache/icinga2' + $pki_dir = "${conf_dir}/pki" + $ca_dir = '/var/icinga2/ca' + $user = 'icinga' + $group = 'icinga' + $lib_dir = '/usr/local/lib/icinga2' + $ido_pgsql_package = undef + $ido_mysql_package = undef + + $constants = { + 'PluginDir' => '/usr/local/libexec/nagios', + 'PluginContribDir' => '/usr/local/share/icinga2/include/plugins-contrib.d', + 'ManubulonPluginDir' => '/usr/local/libexec/nagios', + 'ZoneName' => $::fqdn, + 'NodeName' => $::fqdn, + 'TicketSalt' => '', + } + } # FreeBSD + default: { fail("Your plattform ${::osfamily} is not supported, yet.") } diff --git a/metadata.json b/metadata.json index 0ced05c19..c8ba7c5c1 100644 --- a/metadata.json +++ b/metadata.json @@ -59,6 +59,13 @@ "operatingsystemrelease": [ "12" ] + }, + { + "operatingsystem": "FreeBSD", + "operatingsystemrelease": [ + "11", + "10" + ] } ] } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index eeb5c71b8..24ad1be32 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,10 +1,6 @@ require 'spec_helper' describe('icinga2', :type => :class) do - before(:all) do - @icinga2_conf = '/etc/icinga2/icinga2.conf' - @constants_conf = '/etc/icinga2/constants.conf' - end on_supported_os.each do |os, facts| context "on #{os}" do @@ -12,6 +8,19 @@ facts end + case facts[:kernel] + when 'Linux' + before(:all) do + @icinga2_conf = '/etc/icinga2/icinga2.conf' + @constants_conf = '/etc/icinga2/constants.conf' + end + when 'FreeBSD' + before(:all) do + @icinga2_conf = '/usr/local/etc/icinga2/icinga2.conf' + @constants_conf = '/usr/local/etc/icinga2/constants.conf' + end + end + context 'with all default parameters' do it { is_expected.to contain_package('icinga2').with({ 'ensure' => 'installed' }) } @@ -192,4 +201,4 @@ context 'on unsupported plattform' do it { is_expected.to raise_error(Puppet::Error, /bar is not supported/) } end -end \ No newline at end of file +end From 0006f29b232bf4e39cbea62cf52d0a7a80a86849 Mon Sep 17 00:00:00 2001 From: Zach Leslie Date: Mon, 30 Jan 2017 13:07:22 -0800 Subject: [PATCH 2/7] Begin serverspec --- serverspec/Vagrantfile | 5 +++++ serverspec/scripts/i2freebsd10puppet4.sh | 4 ++++ .../i2freebsd10puppet4/plattform_independent_spec.rb | 10 ++++++++++ 3 files changed, 19 insertions(+) create mode 100644 serverspec/scripts/i2freebsd10puppet4.sh create mode 100644 serverspec/spec/i2freebsd10puppet4/plattform_independent_spec.rb diff --git a/serverspec/Vagrantfile b/serverspec/Vagrantfile index 3943fe90b..29b387f8a 100644 --- a/serverspec/Vagrantfile +++ b/serverspec/Vagrantfile @@ -42,6 +42,11 @@ nodes = { :url => 'http://boxes.icinga.com/vagrant/private/w2k12r2.box', :md5 => '8d2f63885253289bfcad47256146ea02' }, + 'i2freebsd10puppet4' => { + :box => 'freebsd-10.3-x64-virtualbox', + :url => 'http://boxes.icinga.com/vagrant/freebsd/freebsd-10.3-amd64-virtualbox.box', + :md5 => '68c708200667c6fd075d24a3f8e29061' + }, } # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! diff --git a/serverspec/scripts/i2freebsd10puppet4.sh b/serverspec/scripts/i2freebsd10puppet4.sh new file mode 100644 index 000000000..49ac337f8 --- /dev/null +++ b/serverspec/scripts/i2freebsd10puppet4.sh @@ -0,0 +1,4 @@ +export ASSUME_ALWAYS_YES=YES +pkg bootstrap +pkg update -f +pkg install -y puppet4 diff --git a/serverspec/spec/i2freebsd10puppet4/plattform_independent_spec.rb b/serverspec/spec/i2freebsd10puppet4/plattform_independent_spec.rb new file mode 100644 index 000000000..caa382dc1 --- /dev/null +++ b/serverspec/spec/i2freebsd10puppet4/plattform_independent_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe package('icinga2') do + it { should be_installed } +end + +describe service('icinga2') do + it { should be_enabled } + it { should be_running } +end From 5c5c7e3b176ed16c34d79aefb694f4acd42e722d Mon Sep 17 00:00:00 2001 From: Blerim Sheqa Date: Tue, 31 Jan 2017 09:46:11 +0100 Subject: [PATCH 3/7] Set 'rsync' type for FreeBSD machines Vagrant does not support mounting directories via VBox Guest Additions. This commits provides a workaround to use RSync instead. --- serverspec/Vagrantfile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/serverspec/Vagrantfile b/serverspec/Vagrantfile index 29b387f8a..a2f2e32fb 100644 --- a/serverspec/Vagrantfile +++ b/serverspec/Vagrantfile @@ -43,9 +43,10 @@ nodes = { :md5 => '8d2f63885253289bfcad47256146ea02' }, 'i2freebsd10puppet4' => { - :box => 'freebsd-10.3-x64-virtualbox', - :url => 'http://boxes.icinga.com/vagrant/freebsd/freebsd-10.3-amd64-virtualbox.box', - :md5 => '68c708200667c6fd075d24a3f8e29061' + :box => 'freebsd-10.3-x64-virtualbox', + :url => 'http://boxes.icinga.com/vagrant/freebsd/freebsd-10.3-amd64-virtualbox.box', + :md5 => '68c708200667c6fd075d24a3f8e29061', + :kernel => 'bsd' }, } @@ -63,6 +64,10 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| node_config.vm.box_download_checksum_type = 'md5' node_config.vm.network :private_network, :adapter => 2, ip: options[:ip] if options[:ip] + if options[:kernel] == "bsd" + node_config.vm.synced_folder "./environments", "/tmp/vagrant-puppet/environments", type: "rsync" + end + if options[:forwarded] options[:forwarded].each_pair do |guest, local| node_config.vm.network "forwarded_port", guest: guest, host: local From 85c82f91c188c5ebeca24d48965b9f4e817b4d92 Mon Sep 17 00:00:00 2001 From: Blerim Sheqa Date: Wed, 1 Feb 2017 10:46:04 +0100 Subject: [PATCH 4/7] serverspec: disable repo management for FreeBSD --- serverspec/environments/production/manifests/default.pp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/serverspec/environments/production/manifests/default.pp b/serverspec/environments/production/manifests/default.pp index 507f6c519..a4d05c1ad 100644 --- a/serverspec/environments/production/manifests/default.pp +++ b/serverspec/environments/production/manifests/default.pp @@ -1,5 +1,9 @@ -node default { +node /(debian|rhel|ubuntu|sles)/ { class { 'icinga2': manage_repo => true, } } + +node /freebsd/ { + class { 'icinga2': } +} From 16e65a4fe74d21df2953eddc62a89674943fe1e3 Mon Sep 17 00:00:00 2001 From: Blerim Sheqa Date: Wed, 1 Feb 2017 12:26:55 +0100 Subject: [PATCH 5/7] Add FreeBSD 11 to serverspec testing --- serverspec/Vagrantfile | 8 +++++++- serverspec/scripts/i2freebsd11puppet4.sh | 4 ++++ .../i2freebsd11puppet4/plattform_independent_spec.rb | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 serverspec/scripts/i2freebsd11puppet4.sh create mode 100644 serverspec/spec/i2freebsd11puppet4/plattform_independent_spec.rb diff --git a/serverspec/Vagrantfile b/serverspec/Vagrantfile index a2f2e32fb..be115e6b3 100644 --- a/serverspec/Vagrantfile +++ b/serverspec/Vagrantfile @@ -43,11 +43,17 @@ nodes = { :md5 => '8d2f63885253289bfcad47256146ea02' }, 'i2freebsd10puppet4' => { - :box => 'freebsd-10.3-x64-virtualbox', + :box => 'freebsd-10.3-amd64-virtualbox', :url => 'http://boxes.icinga.com/vagrant/freebsd/freebsd-10.3-amd64-virtualbox.box', :md5 => '68c708200667c6fd075d24a3f8e29061', :kernel => 'bsd' }, + 'i2freebsd11puppet4' => { + :box => 'freebsd-10.3-amd64-virtualbox', + :url => 'http://boxes.icinga.com/vagrant/freebsd/freebsd-11.0-amd64-virtualbox.box', + :md5 => '3ee3583815214a7443e9a0d288241cc4', + :kernel => 'bsd' + }, } # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! diff --git a/serverspec/scripts/i2freebsd11puppet4.sh b/serverspec/scripts/i2freebsd11puppet4.sh new file mode 100644 index 000000000..49ac337f8 --- /dev/null +++ b/serverspec/scripts/i2freebsd11puppet4.sh @@ -0,0 +1,4 @@ +export ASSUME_ALWAYS_YES=YES +pkg bootstrap +pkg update -f +pkg install -y puppet4 diff --git a/serverspec/spec/i2freebsd11puppet4/plattform_independent_spec.rb b/serverspec/spec/i2freebsd11puppet4/plattform_independent_spec.rb new file mode 100644 index 000000000..caa382dc1 --- /dev/null +++ b/serverspec/spec/i2freebsd11puppet4/plattform_independent_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe package('icinga2') do + it { should be_installed } +end + +describe service('icinga2') do + it { should be_enabled } + it { should be_running } +end From 6b21cc79d51a0c2ac8228a4055666da3d9ef78d7 Mon Sep 17 00:00:00 2001 From: Blerim Sheqa Date: Wed, 1 Feb 2017 13:16:02 +0100 Subject: [PATCH 6/7] Fix dependency in idomysql feature --- manifests/feature/idomysql.pp | 4 ++-- manifests/feature/idopgsql.pp | 4 ++-- .../environments/production/manifests/default.pp | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/manifests/feature/idomysql.pp b/manifests/feature/idomysql.pp index 728b0dc04..ab458159f 100644 --- a/manifests/feature/idomysql.pp +++ b/manifests/feature/idomysql.pp @@ -290,14 +290,14 @@ package { $ido_mysql_package: ensure => installed, before => [ - Exec['icinga2-ido-mysql'], + Exec['idomysql-import-schema'], Icinga2::Feature['ido-mysql'] ] } } if $import_schema { - exec { 'idomysql_import_schema': + exec { 'idomysql-import-schema': user => 'root', path => $::path, command => "mysql -h '${host}' -u '${user}' -p'${password}' '${database}' < '/usr/share/icinga2-ido-mysql/schema/mysql.sql'", diff --git a/manifests/feature/idopgsql.pp b/manifests/feature/idopgsql.pp index 8cda6f3b5..b2dc3da7a 100644 --- a/manifests/feature/idopgsql.pp +++ b/manifests/feature/idopgsql.pp @@ -113,14 +113,14 @@ package { $ido_pgsql_package: ensure => installed, before => [ - Exec['idopgsql_import_schema'], + Exec['idopgsql-import-schema'], Icinga2::Feature['ido-pgsql'], ] } } if $import_schema { - exec { 'idopgsql_import_schema': + exec { 'idopgsql-import-schema': user => 'root', path => $::path, environment => ["PGPASSWORD=${password}"], diff --git a/serverspec/environments/production/manifests/default.pp b/serverspec/environments/production/manifests/default.pp index a4d05c1ad..6645e4c12 100644 --- a/serverspec/environments/production/manifests/default.pp +++ b/serverspec/environments/production/manifests/default.pp @@ -1,7 +1,17 @@ node /(debian|rhel|ubuntu|sles)/ { - class { 'icinga2': - manage_repo => true, + class { '::icinga2': + constants => { + 'TicketSalt' => '5a3d695b8aef8f18452fc494593056a4', + } } + + class{ '::icinga2::feature::idomysql': + user => 'icinga2', + password => 'icinga2', + database => 'icinga2', + import_schema => true, + } + } node /freebsd/ { From 2575ba05f43c2ef8c3cfd400da4862005f346a45 Mon Sep 17 00:00:00 2001 From: Blerim Sheqa Date: Wed, 1 Feb 2017 13:22:41 +0100 Subject: [PATCH 7/7] Update specs for idomysql and idopgsql --- spec/classes/idomysql_spec.rb | 8 ++++---- spec/classes/idopgsql_spec.rb | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/classes/idomysql_spec.rb b/spec/classes/idomysql_spec.rb index a36540c2a..82d6ba53c 100644 --- a/spec/classes/idomysql_spec.rb +++ b/spec/classes/idomysql_spec.rb @@ -316,14 +316,14 @@ context "#{os} with import_schema => true" do let(:params) { {:import_schema => true} } - it { is_expected.to contain_exec('idomysql_import_schema') } + it { is_expected.to contain_exec('idomysql-import-schema') } end context "#{os} with import_schema => false" do let(:params) { {:import_schema => false} } - it { should_not contain_exec('idomysql_import_schema') } + it { should_not contain_exec('idomysql-import-schema') } end @@ -655,14 +655,14 @@ context "Windows 2012 R2 with import_schema => true" do let(:params) { {:import_schema => true} } - it { is_expected.to contain_exec('idomysql_import_schema') } + it { is_expected.to contain_exec('idomysql-import-schema') } end context "Windows 2012 R2 with import_schema => false" do let(:params) { {:import_schema => false} } - it { should_not contain_exec('idomysql_import_schema') } + it { should_not contain_exec('idomysql-import-schema') } end diff --git a/spec/classes/idopgsql_spec.rb b/spec/classes/idopgsql_spec.rb index f881fe5a1..e6c11411b 100644 --- a/spec/classes/idopgsql_spec.rb +++ b/spec/classes/idopgsql_spec.rb @@ -177,14 +177,14 @@ context "#{os} with import_schema => true" do let(:params) { {:import_schema => true} } - it { is_expected.to contain_exec('idopgsql_import_schema') } + it { is_expected.to contain_exec('idopgsql-import-schema') } end context "#{os} with import_schema => false" do let(:params) { {:import_schema => false} } - it { should_not contain_exec('idopgsql_import_schema') } + it { should_not contain_exec('idopgsql-import-schema') } end @@ -379,14 +379,14 @@ context "Windows 2012 R2 with import_schema => true" do let(:params) { {:import_schema => true} } - it { is_expected.to contain_exec('idopgsql_import_schema') } + it { is_expected.to contain_exec('idopgsql-import-schema') } end context "Windows 2012 R2 with import_schema => false" do let(:params) { {:import_schema => false} } - it { should_not contain_exec('idopgsql_import_schema') } + it { should_not contain_exec('idopgsql-import-schema') } end