From e5e5d0ef9fd70c0ac752576fff3ae568d4b73f79 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sat, 20 Aug 2016 23:03:38 +0200 Subject: [PATCH 01/12] modulesync 0.12.2 --- .msync.yml | 2 +- .travis.yml | 2 +- Gemfile | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.msync.yml b/.msync.yml index 3e71eb6a7..617efbb5f 100644 --- a/.msync.yml +++ b/.msync.yml @@ -1 +1 @@ -modulesync_config_version: '0.12.1' +modulesync_config_version: '0.12.2' diff --git a/.travis.yml b/.travis.yml index ffd4b8464..387c5a32b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ notifications: email: false deploy: provider: puppetforge - edge: + deploy: branch: ha-bug-puppet-forge user: puppet password: diff --git a/Gemfile b/Gemfile index ddbd23d50..5aebd2a83 100644 --- a/Gemfile +++ b/Gemfile @@ -22,6 +22,7 @@ group :test do gem 'puppet-lint-classes_and_types_beginning_with_digits-check', :require => false gem 'puppet-lint-unquoted_string-check', :require => false gem 'puppet-lint-variable_contains_upcase', :require => false + gem 'puppet-lint', '2.0.0', :require => false gem 'metadata-json-lint', :require => false gem 'puppet-blacksmith', :require => false gem 'voxpupuli-release', :require => false, :git => 'https://github.com/voxpupuli/voxpupuli-release-gem.git' From e29c792cd72a59eaa426e5936a001462b52ba9fb Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sat, 20 Aug 2016 23:13:31 +0200 Subject: [PATCH 02/12] migrate agent tests to rspec-puppet-facts --- spec/classes/agent_spec.rb | 277 ++++++++++++++++++------------------- 1 file changed, 133 insertions(+), 144 deletions(-) diff --git a/spec/classes/agent_spec.rb b/spec/classes/agent_spec.rb index c3536414d..42363e04d 100644 --- a/spec/classes/agent_spec.rb +++ b/spec/classes/agent_spec.rb @@ -12,153 +12,142 @@ } end - context 'On RedHat 7.1' do - let :facts do - { - osfamily: 'RedHat', - operatingsystem: 'RedHat', - operatingsystemrelease: '7.1', - operatingsystemmajrelease: '7', - architecture: 'x86_64', - lsbdistid: 'RedHat', - concat_basedir: '/tmp', - is_pe: false, - puppetversion: Puppet.version, - facterversion: Facter.version, - ipaddress: '192.168.1.10', - lsbdistcodename: '', - id: 'root', - kernel: 'Linux', - path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin', - systemd: true - } - end - - # Make sure package will be installed, service running and ensure of directory. - it { should contain_package('zabbix-agent').with_ensure('present') } - it { should contain_package('zabbix-agent').with_name('zabbix-agent') } - - it { should contain_service('zabbix-agent').with_ensure('running') } - it { should contain_service('zabbix-agent').with_name('zabbix-agent') } - - it { should contain_file('/etc/zabbix/zabbix_agentd.d').with_ensure('directory') } - - context 'when declaring manage_repo is true' do - let :params do - { - manage_repo: true - } - end - - it { should contain_class('zabbix::repo').with_zabbix_version('3.0') } - it { should contain_package('zabbix-agent').with_require('Class[Zabbix::Repo]') } - end - - context 'when declaring manage_resources is true' do - let :params do - { - manage_resources: true - } - end - - it { should contain_class('zabbix::resources::agent') } - end - - context 'configuration file with hostnameitem' do - let :params do - { - hostnameitem: 'system.hostname' - } - end - - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^HostnameItem=system.hostname$} } - end - - context 'when declaring manage_firewall is true' do - let :params do - { - manage_firewall: true - } - end - - it { should contain_firewall('150 zabbix-agent') } - end - - context 'when declaring manage_firewall is false' do - let :params do - { - manage_firewall: false - } + on_supported_os.each do |os, facts| + context "on #{os} " do + let :facts do + facts.merge( + mocked_facts + ) end - it { should_not contain_firewall('150 zabbix-agent') } - end - - context 'configuration file with full options' do - let :params do - { - allowroot: '0', - agent_configfile_path: '/etc/zabbix/zabbix_agentd.conf', - buffersend: '5', - buffersize: '100', - debuglevel: '4', - enableremotecommands: '1', - hostname: '10050', - include_dir: '/etc/zabbix/zabbix_agentd.d', - listenport: '10050', - loadmodulepath: '${libdir}/modules', - logfilesize: '4', - logfile: '/var/log/zabbix/zabbix_agentd.log', - logremotecommands: '0', - pidfile: '/var/run/zabbix/zabbix_agentd.pid', - refreshactivechecks: '120', - server: '192.168.1.1', - serveractive: '192.168.1.1', - startagents: '3', - timeout: '30', - unsafeuserparameters: '0', - tlsconnect: 'cert', - tlsaccept: 'cert', - tlscafile: '/etc/zabbix/keys/file.ca', - tlscrlfile: '/etc/zabbix/keys/file.crl', - tlsservercertissuer: 'Zabbix.Com', - tlsservercertsubject: 'MySubJect', - tlscertfile: '/etc/zabbix/keys/tls.crt', - tlskeyfile: '/etc/zabbix/keys/tls.key', - tlspskidentity: '/etc/zabbix/keys/tlspskidentity.id', - tlspskfile: '/etc/zabbix/keys/tlspskfile.key' - } + context 'with all defaults' do + # Make sure package will be installed, service running and ensure of directory. + it { should contain_package('zabbix-agent').with_ensure('present') } + it { should contain_package('zabbix-agent').with_name('zabbix-agent') } + + it { should contain_service('zabbix-agent').with_ensure('running') } + it { should contain_service('zabbix-agent').with_name('zabbix-agent') } + + it { should contain_file('/etc/zabbix/zabbix_agentd.d').with_ensure('directory') } + + context 'when declaring manage_repo is true' do + let :params do + { + manage_repo: true + } + end + + it { should contain_class('zabbix::repo').with_zabbix_version('3.0') } + it { should contain_package('zabbix-agent').with_require('Class[Zabbix::Repo]') } + end + + context 'when declaring manage_resources is true' do + let :params do + { + manage_resources: true + } + end + + it { should contain_class('zabbix::resources::agent') } + end + + context 'configuration file with hostnameitem' do + let :params do + { + hostnameitem: 'system.hostname' + } + end + + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^HostnameItem=system.hostname$} } + end + + context 'when declaring manage_firewall is true' do + let :params do + { + manage_firewall: true + } + end + + it { should contain_firewall('150 zabbix-agent') } + end + + context 'when declaring manage_firewall is false' do + let :params do + { + manage_firewall: false + } + end + + it { should_not contain_firewall('150 zabbix-agent') } + end + + context 'configuration file with full options' do + let :params do + { + allowroot: '0', + agent_configfile_path: '/etc/zabbix/zabbix_agentd.conf', + buffersend: '5', + buffersize: '100', + debuglevel: '4', + enableremotecommands: '1', + hostname: '10050', + include_dir: '/etc/zabbix/zabbix_agentd.d', + listenport: '10050', + loadmodulepath: '${libdir}/modules', + logfilesize: '4', + logfile: '/var/log/zabbix/zabbix_agentd.log', + logremotecommands: '0', + pidfile: '/var/run/zabbix/zabbix_agentd.pid', + refreshactivechecks: '120', + server: '192.168.1.1', + serveractive: '192.168.1.1', + startagents: '3', + timeout: '30', + unsafeuserparameters: '0', + tlsconnect: 'cert', + tlsaccept: 'cert', + tlscafile: '/etc/zabbix/keys/file.ca', + tlscrlfile: '/etc/zabbix/keys/file.crl', + tlsservercertissuer: 'Zabbix.Com', + tlsservercertsubject: 'MySubJect', + tlscertfile: '/etc/zabbix/keys/tls.crt', + tlskeyfile: '/etc/zabbix/keys/tls.key', + tlspskidentity: '/etc/zabbix/keys/tlspskidentity.id', + tlspskfile: '/etc/zabbix/keys/tlspskfile.key' + } + end + + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^AllowRoot=0$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^BufferSend=5$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^BufferSize=100$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^DebugLevel=4$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^EnableRemoteCommands=1$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Hostname=10050$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Include=/etc/zabbix/zabbix_agentd.d$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^ListenPort=10050$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LoadModulePath=\$\{libdir\}/modules$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogFileSize=4$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogFile=/var/log/zabbix/zabbix_agentd.log$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogRemoteCommands=0$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^PidFile=/var/run/zabbix/zabbix_agentd.pid$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^RefreshActiveChecks=120$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Server=192.168.1.1$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^ServerActive=192.168.1.1$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^StartAgents=3$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Timeout=30$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^UnsafeUserParameters=0$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSConnect=cert$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSAccept=cert$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCAFile=/etc/zabbix/keys/file.ca$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCRLFile=/etc/zabbix/keys/file.crl$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSServerCertIssuer=Zabbix.Com$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSServerCertSubject=MySubJect$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCertFile=/etc/zabbix/keys/tls.crt$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSKeyFile=/etc/zabbix/keys/tls.key$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSPSKIdentity=/etc/zabbix/keys/tlspskidentity.id$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSPSKFile=/etc/zabbix/keys/tlspskfile.key$} } + end end - - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^AllowRoot=0$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^BufferSend=5$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^BufferSize=100$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^DebugLevel=4$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^EnableRemoteCommands=1$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Hostname=10050$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Include=/etc/zabbix/zabbix_agentd.d$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^ListenPort=10050$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LoadModulePath=\$\{libdir\}/modules$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogFileSize=4$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogFile=/var/log/zabbix/zabbix_agentd.log$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogRemoteCommands=0$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^PidFile=/var/run/zabbix/zabbix_agentd.pid$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^RefreshActiveChecks=120$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Server=192.168.1.1$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^ServerActive=192.168.1.1$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^StartAgents=3$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Timeout=30$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^UnsafeUserParameters=0$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSConnect=cert$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSAccept=cert$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCAFile=/etc/zabbix/keys/file.ca$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCRLFile=/etc/zabbix/keys/file.crl$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSServerCertIssuer=Zabbix.Com$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSServerCertSubject=MySubJect$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCertFile=/etc/zabbix/keys/tls.crt$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSKeyFile=/etc/zabbix/keys/tls.key$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSPSKIdentity=/etc/zabbix/keys/tlspskidentity.id$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSPSKFile=/etc/zabbix/keys/tlspskfile.key$} } end end end From 5a287346aafd3fe51ad1aaf821a846bc279baced Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sat, 20 Aug 2016 23:31:14 +0200 Subject: [PATCH 03/12] fix indentation --- manifests/params.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/params.pp b/manifests/params.pp index 5cd1c19bb..d16da88cf 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -26,7 +26,7 @@ $server_fping6location = '/usr/bin/fping6' $proxy_fpinglocation = '/usr/bin/fping' $proxy_fping6location = '/usr/bin/fping6' - $manage_repo = false + $manage_repo = false $zabbix_package_agent = 'zabbix3-agent' } From a0122ee5757c1d80d4b41cae1ccba8c4a5a68a69 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sat, 20 Aug 2016 23:40:05 +0200 Subject: [PATCH 04/12] fix error message --- manifests/repo.pp | 2 +- spec/classes/sender_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/repo.pp b/manifests/repo.pp index 208e7075e..9aff4d337 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -108,7 +108,7 @@ Class['Apt::Update'] -> Package<|tag == 'zabbix'|> } default : { - fail('Unrecognized operating system for webserver') + fail("Managing a repo on ${::osfamily} is currently not implemented") } } } # end if ($manage_repo) diff --git a/spec/classes/sender_spec.rb b/spec/classes/sender_spec.rb index 4ab472b36..60eb53830 100644 --- a/spec/classes/sender_spec.rb +++ b/spec/classes/sender_spec.rb @@ -26,7 +26,7 @@ end if facts[:osfamily] == 'Archlinux' it 'fails' do - should raise_error(Puppet::Error, %r{Unrecognized operating system for webserver}) + should raise_error(Puppet::Error, %r{Managing a repo on Archlinux is currently not implemented}) end else it { should contain_class('zabbix::repo').with_zabbix_version('3.0') } From 465e2f94b2e5ea4af1b5eb7aacf4ee1138c0de1b Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sat, 20 Aug 2016 23:40:49 +0200 Subject: [PATCH 05/12] clean up spec tests for zabbix::agent --- spec/classes/agent_spec.rb | 231 ++++++++++++++++++++----------------- 1 file changed, 127 insertions(+), 104 deletions(-) diff --git a/spec/classes/agent_spec.rb b/spec/classes/agent_spec.rb index 42363e04d..4246fc544 100644 --- a/spec/classes/agent_spec.rb +++ b/spec/classes/agent_spec.rb @@ -21,132 +21,155 @@ end context 'with all defaults' do + package = case facts[:osfamily] + when 'Archlinux' + 'zabbix3-agent' + else + 'zabbix-agent' + end # Make sure package will be installed, service running and ensure of directory. - it { should contain_package('zabbix-agent').with_ensure('present') } - it { should contain_package('zabbix-agent').with_name('zabbix-agent') } + it do + should contain_package(package).with( + ensure: 'present', + require: 'Class[Zabbix::Repo]', + tag: 'zabbix' + ) + end - it { should contain_service('zabbix-agent').with_ensure('running') } - it { should contain_service('zabbix-agent').with_name('zabbix-agent') } + it do + should contain_service('zabbix-agent').with( + ensure: 'running', + enable: true, + hasstatus: true, + hasrestart: true, + require: "Package[#{package}]" + ) + end it { should contain_file('/etc/zabbix/zabbix_agentd.d').with_ensure('directory') } + end - context 'when declaring manage_repo is true' do - let :params do - { - manage_repo: true - } - end + context 'when declaring manage_repo is true' do + let :params do + { + manage_repo: true + } + end + case facts[:osfamily] + when 'Archlinux' + it { should raise_error(Puppet::Error, %r{Managing a repo on Archlinux is currently not implemented}) } + else it { should contain_class('zabbix::repo').with_zabbix_version('3.0') } it { should contain_package('zabbix-agent').with_require('Class[Zabbix::Repo]') } end + end - context 'when declaring manage_resources is true' do - let :params do - { - manage_resources: true - } - end - - it { should contain_class('zabbix::resources::agent') } + context 'when declaring manage_resources is true' do + let :params do + { + manage_resources: true + } end - context 'configuration file with hostnameitem' do - let :params do - { - hostnameitem: 'system.hostname' - } - end + it { should contain_class('zabbix::resources::agent') } + end - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^HostnameItem=system.hostname$} } + context 'configuration file with hostnameitem' do + let :params do + { + hostnameitem: 'system.hostname' + } end - context 'when declaring manage_firewall is true' do - let :params do - { - manage_firewall: true - } - end + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^HostnameItem=system.hostname$} } + end - it { should contain_firewall('150 zabbix-agent') } + context 'when declaring manage_firewall is true' do + let :params do + { + manage_firewall: true + } end - context 'when declaring manage_firewall is false' do - let :params do - { - manage_firewall: false - } - end + it { should contain_firewall('150 zabbix-agent') } + end - it { should_not contain_firewall('150 zabbix-agent') } + context 'when declaring manage_firewall is false' do + let :params do + { + manage_firewall: false + } end - context 'configuration file with full options' do - let :params do - { - allowroot: '0', - agent_configfile_path: '/etc/zabbix/zabbix_agentd.conf', - buffersend: '5', - buffersize: '100', - debuglevel: '4', - enableremotecommands: '1', - hostname: '10050', - include_dir: '/etc/zabbix/zabbix_agentd.d', - listenport: '10050', - loadmodulepath: '${libdir}/modules', - logfilesize: '4', - logfile: '/var/log/zabbix/zabbix_agentd.log', - logremotecommands: '0', - pidfile: '/var/run/zabbix/zabbix_agentd.pid', - refreshactivechecks: '120', - server: '192.168.1.1', - serveractive: '192.168.1.1', - startagents: '3', - timeout: '30', - unsafeuserparameters: '0', - tlsconnect: 'cert', - tlsaccept: 'cert', - tlscafile: '/etc/zabbix/keys/file.ca', - tlscrlfile: '/etc/zabbix/keys/file.crl', - tlsservercertissuer: 'Zabbix.Com', - tlsservercertsubject: 'MySubJect', - tlscertfile: '/etc/zabbix/keys/tls.crt', - tlskeyfile: '/etc/zabbix/keys/tls.key', - tlspskidentity: '/etc/zabbix/keys/tlspskidentity.id', - tlspskfile: '/etc/zabbix/keys/tlspskfile.key' - } - end - - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^AllowRoot=0$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^BufferSend=5$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^BufferSize=100$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^DebugLevel=4$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^EnableRemoteCommands=1$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Hostname=10050$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Include=/etc/zabbix/zabbix_agentd.d$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^ListenPort=10050$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LoadModulePath=\$\{libdir\}/modules$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogFileSize=4$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogFile=/var/log/zabbix/zabbix_agentd.log$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogRemoteCommands=0$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^PidFile=/var/run/zabbix/zabbix_agentd.pid$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^RefreshActiveChecks=120$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Server=192.168.1.1$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^ServerActive=192.168.1.1$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^StartAgents=3$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Timeout=30$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^UnsafeUserParameters=0$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSConnect=cert$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSAccept=cert$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCAFile=/etc/zabbix/keys/file.ca$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCRLFile=/etc/zabbix/keys/file.crl$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSServerCertIssuer=Zabbix.Com$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSServerCertSubject=MySubJect$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCertFile=/etc/zabbix/keys/tls.crt$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSKeyFile=/etc/zabbix/keys/tls.key$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSPSKIdentity=/etc/zabbix/keys/tlspskidentity.id$} } - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSPSKFile=/etc/zabbix/keys/tlspskfile.key$} } + it { should_not contain_firewall('150 zabbix-agent') } + end + + context 'configuration file with full options' do + let :params do + { + allowroot: '0', + agent_configfile_path: '/etc/zabbix/zabbix_agentd.conf', + buffersend: '5', + buffersize: '100', + debuglevel: '4', + enableremotecommands: '1', + hostname: '10050', + include_dir: '/etc/zabbix/zabbix_agentd.d', + listenport: '10050', + loadmodulepath: '${libdir}/modules', + logfilesize: '4', + logfile: '/var/log/zabbix/zabbix_agentd.log', + logremotecommands: '0', + pidfile: '/var/run/zabbix/zabbix_agentd.pid', + refreshactivechecks: '120', + server: '192.168.1.1', + serveractive: '192.168.1.1', + startagents: '3', + timeout: '30', + unsafeuserparameters: '0', + tlsconnect: 'cert', + tlsaccept: 'cert', + tlscafile: '/etc/zabbix/keys/file.ca', + tlscrlfile: '/etc/zabbix/keys/file.crl', + tlsservercertissuer: 'Zabbix.Com', + tlsservercertsubject: 'MySubJect', + tlscertfile: '/etc/zabbix/keys/tls.crt', + tlskeyfile: '/etc/zabbix/keys/tls.key', + tlspskidentity: '/etc/zabbix/keys/tlspskidentity.id', + tlspskfile: '/etc/zabbix/keys/tlspskfile.key' + } end + + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^AllowRoot=0$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^BufferSend=5$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^BufferSize=100$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^DebugLevel=4$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^EnableRemoteCommands=1$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Hostname=10050$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Include=/etc/zabbix/zabbix_agentd.d$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^ListenPort=10050$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LoadModulePath=\$\{libdir\}/modules$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogFileSize=4$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogFile=/var/log/zabbix/zabbix_agentd.log$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogRemoteCommands=0$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^PidFile=/var/run/zabbix/zabbix_agentd.pid$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^RefreshActiveChecks=120$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Server=192.168.1.1$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^ServerActive=192.168.1.1$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^StartAgents=3$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Timeout=30$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^UnsafeUserParameters=0$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSConnect=cert$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSAccept=cert$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCAFile=/etc/zabbix/keys/file.ca$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCRLFile=/etc/zabbix/keys/file.crl$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSServerCertIssuer=Zabbix.Com$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSServerCertSubject=MySubJect$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCertFile=/etc/zabbix/keys/tls.crt$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSKeyFile=/etc/zabbix/keys/tls.key$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSPSKIdentity=/etc/zabbix/keys/tlspskidentity.id$} } + it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSPSKFile=/etc/zabbix/keys/tlspskfile.key$} } end end end From c472a24c4eb3775c543a5d9940d85cc447667840 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sun, 21 Aug 2016 00:02:38 +0200 Subject: [PATCH 06/12] add test for presence of zabbix::startup --- spec/classes/agent_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/classes/agent_spec.rb b/spec/classes/agent_spec.rb index 4246fc544..569833a8f 100644 --- a/spec/classes/agent_spec.rb +++ b/spec/classes/agent_spec.rb @@ -47,6 +47,8 @@ end it { should contain_file('/etc/zabbix/zabbix_agentd.d').with_ensure('directory') } + + it { should contain_zabbix__startup('zabbix-agent').that_requires("Package[#{package}]") } end context 'when declaring manage_repo is true' do From 273ecd2234888755b576ac9e54bb670e12a4f344 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sun, 21 Aug 2016 00:04:23 +0200 Subject: [PATCH 07/12] cleanup zabbix::startup tests --- spec/defines/startup_spec.rb | 50 +++++++++++++++++------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/spec/defines/startup_spec.rb b/spec/defines/startup_spec.rb index ffa5d13e1..7a5f8885e 100644 --- a/spec/defines/startup_spec.rb +++ b/spec/defines/startup_spec.rb @@ -3,37 +3,33 @@ describe 'zabbix::startup', type: :define do let(:title) { 'zabbix-agent' } - context 'with systemd' do - %w(RedHat Debian).each do |osfamily| - context "on #{osfamily}" do - context 'no systemd' do - ['false', false].each do |systemd| - let :facts do - { - osfamily: osfamily, - systemd: systemd, - path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin' - } - end - it { should_not contain_class('systemd') } - it { should_not contain_file('/etc/systemd/system/zabbix-agent.service') } - it { should contain_file('/etc/init.d/zabbix-agent').with_ensure('file') } + %w(RedHat Debian).each do |osfamily| + context "on #{osfamily}" do + context 'no systemd' do + ['false', false].each do |systemd_fact_state| + let :facts do + { + osfamily: osfamily, + systemd: systemd_fact_state, + } end + it { should_not contain_class('systemd') } + it { should_not contain_file('/etc/systemd/system/zabbix-agent.service') } + it { should contain_file('/etc/init.d/zabbix-agent').with_ensure('file') } end + end - context 'has systemd' do - ['true', true].each do |systemd| - let :facts do - { - osfamily: osfamily, - systemd: systemd, - path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin' - } - end - it { should contain_class('systemd') } - it { should contain_file('/etc/systemd/system/zabbix-agent.service') } - it { should contain_file('/etc/init.d/zabbix-agent').with_ensure('absent') } + context 'has systemd' do + ['true', true].each do |systemd_fact_state| + let :facts do + { + osfamily: osfamily, + systemd: systemd_fact_state, + } end + it { should contain_class('systemd') } + it { should contain_file('/etc/systemd/system/zabbix-agent.service') } + it { should contain_file('/etc/init.d/zabbix-agent').with_ensure('absent') } end end end From 21a0321e09fbed2e4a0442cd108d5303e455f33c Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sun, 21 Aug 2016 00:07:38 +0200 Subject: [PATCH 08/12] remove wrong copryright notice this file was introduced after Werner moved the module to Vox Pupuli. Proof: https://github.com/voxpupuli/puppet-zabbix/commit/a41669a16a3c44ef68f6dd7b2a5cc027691262de --- manifests/startup.pp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/manifests/startup.pp b/manifests/startup.pp index a19d1935a..338c2a596 100644 --- a/manifests/startup.pp +++ b/manifests/startup.pp @@ -11,14 +11,6 @@ # zabbix::startup { 'agent': # } # -# === Authors -# -# Author Name: ikben@werner-dijkerman.nl -# -# === Copyright -# -# Copyright 2014 Werner Dijkerman -# define zabbix::startup { if str2bool($::systemd) { contain ::systemd @@ -40,4 +32,4 @@ content => template("zabbix/${name}-${osfamily_downcase}.init.erb"), } } -} \ No newline at end of file +} From 069455855387e398d42a39f5640c0fb39b09a3b2 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sun, 21 Aug 2016 01:49:57 +0200 Subject: [PATCH 09/12] Implement zabbix::startup with proper params this is an approch to fix the issues from: https://github.com/voxpupuli/puppet-zabbix/issues/267 https://github.com/voxpupuli/puppet-zabbix/issues/266 we workaround the wrong scoping by adding suitable params. We validate each of them in the defined resource. --- manifests/agent.pp | 4 +++- manifests/server.pp | 5 ++++- manifests/startup.pp | 30 +++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/manifests/agent.pp b/manifests/agent.pp index e5c81ccee..1752b9c6c 100644 --- a/manifests/agent.pp +++ b/manifests/agent.pp @@ -315,7 +315,9 @@ # Ensure that the correct config file is used. zabbix::startup {'zabbix-agent': - require => Package[$zabbix_package_agent], + pidfile => $pidfile, + agent_configfile_path => $agent_configfile_path, + require => Package[$zabbix_package_agent], } if $agent_configfile_path != '/etc/zabbix/zabbix_agentd.conf' { diff --git a/manifests/server.pp b/manifests/server.pp index 38ece38bb..0113e8be4 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -436,7 +436,10 @@ # Ensure that the correct config file is used. zabbix::startup {'zabbix-server': - require => Package["zabbix-server-${db}"], + pidfile => $pidfile, + database_type => $database_type, + server_configfile_path => $server_configfile_path, + require => Package["zabbix-server-${db}"], } if $server_configfile_path != '/etc/zabbix/zabbix_server.conf' { diff --git a/manifests/startup.pp b/manifests/startup.pp index 338c2a596..d614a6472 100644 --- a/manifests/startup.pp +++ b/manifests/startup.pp @@ -11,8 +11,34 @@ # zabbix::startup { 'agent': # } # -define zabbix::startup { +define zabbix::startup ( + $pidfile = undef, + $agent_configfile_path = undef, + $server_configfile_path = undef, + $database_type = undef, + ) { + case $title { + /agent/: { + unless $agent_configfile_path { + fail('you have to provide a agent_configfile_path param') + } + } + /server/: { + unless $server_configfile_path { + fail('you have to provide a server_configfile_path param') + } + unless $database_type { + fail('you have to provide a database_type param') + } + } + default: { + fail('we currently only spport a title that contains agent or server') + } + } if str2bool($::systemd) { + unless $pidfile { + fail('you have to provide a pidfile param') + } contain ::systemd file { "/etc/systemd/system/${name}.service": ensure => file, @@ -31,5 +57,7 @@ mode => '0755', content => template("zabbix/${name}-${osfamily_downcase}.init.erb"), } + } else { + fail('We currently only support Debian and RedHat osfamily as non-systemd') } } From e0d5fb198b03fea37dabd6b7aa2e64a42e430172 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sun, 21 Aug 2016 01:59:14 +0200 Subject: [PATCH 10/12] manage selinux on every OS --- manifests/server.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/server.pp b/manifests/server.pp index 0113e8be4..dc8ceb5a9 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -535,7 +535,7 @@ } # check if selinux is active and allow zabbix - if $::osfamily == 'RedHat' and $::selinux_config_mode == 'enforcing' { + if $::selinux_config_mode == 'enforcing' { selboolean{'zabbix_can_network': persistent => true, value => 'on', From 757c2dc3b260005356e7fc6e837c3838e401f40b Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sun, 21 Aug 2016 02:01:27 +0200 Subject: [PATCH 11/12] implement rspec-puppet-facts for zabbix::server --- spec/classes/server_spec.rb | 568 ++++++++++++++++++------------------ 1 file changed, 281 insertions(+), 287 deletions(-) diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index 7fce4d0de..2ac3f243f 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -11,316 +11,310 @@ 'rspec.puppet.com' end - context 'On RedHat 7.1' do - let :facts do - { - osfamily: 'RedHat', - operatingsystem: 'RedHat', - operatingsystemrelease: '7.1', - operatingsystemmajrelease: '7', - architecture: 'x86_64', - lsbdistid: 'RedHat', - concat_basedir: '/tmp', - is_pe: false, - puppetversion: Puppet.version, - facterversion: Facter.version, - ipaddress: '192.168.1.10', - lsbdistcodename: '', - id: 'root', - kernel: 'Linux', - path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin', - selinux_config_mode: '', - systemd: true - } - end - - describe 'with default settings' do - it { should contain_class('zabbix::repo') } - it { should contain_service('zabbix-server').with_ensure('running') } - it { should_not contain_selboolean('zabbix_can_network') } - end - - describe 'with enabled selinux' do + on_supported_os.each do |os, facts| + context "on #{os} " do + systemd_fact = case facts[:osfamily] + when 'Archlinux' + { systemd: true } + else + { systemd: false } + end let :facts do - super().merge(selinux_config_mode: 'enforcing') + facts.merge( + mocked_facts + ).merge( + systemd_fact + ) end - it { should contain_selboolean('zabbix_can_network').with('value' => 'on', 'persistent' => true) } - end - describe 'with database_type as postgresql' do - let :params do - { - database_type: 'postgresql', - server_configfile_path: '/etc/zabbix/zabbix_server.conf', - include_dir: '/etc/zabbix/zabbix_server.conf.d' - } - end + describe 'with default settings' do + it { should contain_class('zabbix::repo') } + it { should contain_service('zabbix-server').with_ensure('running') } + it { should_not contain_selboolean('zabbix_can_network') } + end - it { should contain_package('zabbix-server-pgsql').with_ensure('present') } - it { should contain_package('zabbix-server-pgsql').with_name('zabbix-server-pgsql') } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_require('Package[zabbix-server-pgsql]') } - end + describe 'with enabled selinux' do + let :facts do + super().merge(selinux_config_mode: 'enforcing') + end + it { should contain_selboolean('zabbix_can_network').with('value' => 'on', 'persistent' => true) } + end - describe 'with database_type as mysql' do - let :params do - { - database_type: 'mysql' - } - end + describe 'with database_type as postgresql' do + let :params do + { + database_type: 'postgresql', + server_configfile_path: '/etc/zabbix/zabbix_server.conf', + include_dir: '/etc/zabbix/zabbix_server.conf.d' + } + end - it { should contain_package('zabbix-server-mysql').with_ensure('present') } - it { should contain_package('zabbix-server-mysql').with_name('zabbix-server-mysql') } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_require('Package[zabbix-server-mysql]') } - end + it { should contain_package('zabbix-server-pgsql').with_ensure('present') } + it { should contain_package('zabbix-server-pgsql').with_name('zabbix-server-pgsql') } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_require('Package[zabbix-server-pgsql]') } + end - # Include directory should be available. - it { should contain_file('/etc/zabbix/zabbix_server.conf.d').with_ensure('directory') } - it { should contain_file('/etc/zabbix/zabbix_server.conf.d').with_require('File[/etc/zabbix/zabbix_server.conf]') } + describe 'with database_type as mysql' do + let :params do + { + database_type: 'mysql' + } + end - context 'with zabbix::database::postgresql class' do - let :params do - { - database_type: 'postgresql', - database_user: 'zabbix-server', - database_password: 'zabbix-server', - database_host: 'localhost', - database_name: 'zabbix-server' - } - end + it { should contain_package('zabbix-server-mysql').with_ensure('present') } + it { should contain_package('zabbix-server-mysql').with_name('zabbix-server-mysql') } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_require('Package[zabbix-server-mysql]') } + end - it { should contain_class('zabbix::database::postgresql').with_zabbix_type('server') } - it { should contain_class('zabbix::database::postgresql').with_zabbix_version('3.0') } - it { should contain_class('zabbix::database::postgresql').with_database_name('zabbix-server') } - it { should contain_class('zabbix::database::postgresql').with_database_user('zabbix-server') } - it { should contain_class('zabbix::database::postgresql').with_database_password('zabbix-server') } - it { should contain_class('zabbix::database::postgresql').with_database_host('localhost') } - end + # Include directory should be available. + it { should contain_file('/etc/zabbix/zabbix_server.conf.d').with_ensure('directory') } + it { should contain_file('/etc/zabbix/zabbix_server.conf.d').with_require('File[/etc/zabbix/zabbix_server.conf]') } - context 'with zabbix::database::mysql class' do - let :params do - { - database_type: 'mysql', - database_user: 'zabbix-server', - database_password: 'zabbix-server', - database_host: 'localhost', - database_name: 'zabbix-server' - } - end + context 'with zabbix::database::postgresql class' do + let :params do + { + database_type: 'postgresql', + database_user: 'zabbix-server', + database_password: 'zabbix-server', + database_host: 'localhost', + database_name: 'zabbix-server' + } + end - it { should contain_class('zabbix::database::mysql').with_zabbix_type('server') } - it { should contain_class('zabbix::database::mysql').with_zabbix_version('3.0') } - it { should contain_class('zabbix::database::mysql').with_database_name('zabbix-server') } - it { should contain_class('zabbix::database::mysql').with_database_user('zabbix-server') } - it { should contain_class('zabbix::database::mysql').with_database_password('zabbix-server') } - it { should contain_class('zabbix::database::mysql').with_database_host('localhost') } - end + it { should contain_class('zabbix::database::postgresql').with_zabbix_type('server') } + it { should contain_class('zabbix::database::postgresql').with_zabbix_version('3.0') } + it { should contain_class('zabbix::database::postgresql').with_database_name('zabbix-server') } + it { should contain_class('zabbix::database::postgresql').with_database_user('zabbix-server') } + it { should contain_class('zabbix::database::postgresql').with_database_password('zabbix-server') } + it { should contain_class('zabbix::database::postgresql').with_database_host('localhost') } + end - # So if manage_firewall is set to true, it should install - # the firewall rule. - context 'when declaring manage_firewall is true' do - let :params do - { - manage_firewall: true - } - end + context 'with zabbix::database::mysql class' do + let :params do + { + database_type: 'mysql', + database_user: 'zabbix-server', + database_password: 'zabbix-server', + database_host: 'localhost', + database_name: 'zabbix-server' + } + end - it { should contain_firewall('151 zabbix-server') } - end + it { should contain_class('zabbix::database::mysql').with_zabbix_type('server') } + it { should contain_class('zabbix::database::mysql').with_zabbix_version('3.0') } + it { should contain_class('zabbix::database::mysql').with_database_name('zabbix-server') } + it { should contain_class('zabbix::database::mysql').with_database_user('zabbix-server') } + it { should contain_class('zabbix::database::mysql').with_database_password('zabbix-server') } + it { should contain_class('zabbix::database::mysql').with_database_host('localhost') } + end - context 'when declaring manage_firewall is false' do - let :params do - { - manage_firewall: false - } - end + # So if manage_firewall is set to true, it should install + # the firewall rule. + context 'when declaring manage_firewall is true' do + let :params do + { + manage_firewall: true + } + end - it { should_not contain_firewall('151 zabbix-server') } - end + it { should contain_firewall('151 zabbix-server') } + end - # If manage_service is true (default), it should create a service - # and ensure that it is running. - context 'when declaring manage_service is true' do - let :params do - { - manage_service: true - } - end + context 'when declaring manage_firewall is false' do + let :params do + { + manage_firewall: false + } + end - it { should contain_service('zabbix-server').with_ensure('running') } - end + it { should_not contain_firewall('151 zabbix-server') } + end - # When the manage_service is false, it may not make the service. - context 'when declaring manage_service is false' do - let :params do - { - manage_service: false - } - end + # If manage_service is true (default), it should create a service + # and ensure that it is running. + context 'when declaring manage_service is true' do + let :params do + { + manage_service: true + } + end - it { should_not contain_service('zabbix-server') } - end + it { should contain_service('zabbix-server').with_ensure('running') } + end - context 'with all zabbix_server.conf-related parameters' do - let :params do - { - alertscriptspath: '${datadir}/zabbix/alertscripts', - allowroot: '1', - cachesize: '8M', - cacheupdatefrequency: '30', - database_host: 'localhost', - database_name: 'zabbix-server', - database_password: 'zabbix-server', - database_port: '3306', - database_schema: 'zabbix-server', - database_socket: '/tmp/socket.db', - database_user: 'zabbix-server', - debuglevel: '3', - externalscripts: '/usr/lib/zabbix/externalscripts0', - fping6location: '/usr/sbin/fping6', - fpinglocation: '/usr/sbin/fping', - historycachesize: '4M', - historytextcachesize: '4M', - housekeepingfrequency: '1', - include_dir: '/etc/zabbix/zabbix_server.conf.d', - javagateway: '192.168.2.2', - javagatewayport: '10052', - listenip: '192.168.1.1', - listenport: '10051', - loadmodulepath: '${libdir}/modules', - loadmodule: 'pizza', - logfilesize: '10', - logfile: '/var/log/zabbix/zabbix_server.log', - logslowqueries: '0', - maxhousekeeperdelete: '500', - nodeid: '0', - nodenoevents: '0', - nodenohistory: '0', - pidfile: '/var/run/zabbix/zabbix_server.pid', - proxyconfigfrequency: '3600', - proxydatafrequency: '1', - senderfrequency: '30', - snmptrapperfile: '/tmp/zabbix_traps.tmp', - sourceip: '192.168.1.1', - sshkeylocation: '/home/zabbix', - startdbsyncers: '4', - startdiscoverers: '1', - starthttppollers: '1', - startipmipollers: '12', - startpingers: '1', - startpollers: '12', - startpollersunreachable: '1', - startproxypollers: '1', - startsnmptrapper: '1', - starttimers: '1', - starttrappers: '5', - startvmwarecollectors: '5', - timeout: '3', - tmpdir: '/tmp', - trappertimeout: '30', - trendcachesize: '4M', - unavailabledelay: '30', - unreachabledelay: '30', - unreachableperiod: '30', - valuecachesize: '4M', - vmwarecachesize: '8M', - vmwarefrequency: '60', - zabbix_version: '2.2' - } - end + # When the manage_service is false, it may not make the service. + context 'when declaring manage_service is false' do + let :params do + { + manage_service: false + } + end - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^AlertScriptsPath=\$\{datadir\}/zabbix/alertscripts} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^AllowRoot=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^CacheSize=8M} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^CacheUpdateFrequency=30} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBHost=localhost} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBName=zabbix-server} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBPassword=zabbix-server} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBPort=3306} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBSchema=zabbix-server} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBSocket=/tmp/socket.db} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBUser=zabbix-server} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DebugLevel=3} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ExternalScripts=/usr/lib/zabbix/externalscripts} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^Fping6Location=/usr/sbin/fping6} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^FpingLocation=/usr/sbin/fping} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^HistoryCacheSize=4M} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^HistoryTextCacheSize=4M} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^HousekeepingFrequency=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^Include=/etc/zabbix/zabbix_server.conf.d} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^JavaGateway=192.168.2.2} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^JavaGatewayPort=10052} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ListenIP=192.168.1.1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ListenPort=10051$} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LoadModulePath=\$\{libdir\}/modules} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LoadModule = pizza} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LogFileSize=10} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LogFile=/var/log/zabbix/zabbix_server.log} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LogSlowQueries=0} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^MaxHousekeeperDelete=500} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeID=0$} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeNoEvents=0} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeNoHistory=0} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^PidFile=/var/run/zabbix/zabbix_server.pid} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ProxyConfigFrequency=3600} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ProxyDataFrequency=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SenderFrequency=30} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SNMPTrapperFile=/tmp/zabbix_traps.tmp} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SourceIP=192.168.1.1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SSHKeyLocation=/home/zabbix} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartDBSyncers=4} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartDiscoverers=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartHTTPPollers=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartIPMIPollers=12} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartPingers=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartPollers=12} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartPollersUnreachable=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartProxyPollers=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartSNMPTrapper=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartTimers=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartTrappers=5} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartVMwareCollectors=5} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^Timeout=3} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TmpDir=/tmp} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TrapperTimeout=30} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TrendCacheSize=4M} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^UnavailableDelay=30} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^UnreachableDelay=30} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^UnreachablePeriod=30} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ValueCacheSize=4M} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^VMwareCacheSize=8M} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^VMwareFrequency=60} } - end + it { should_not contain_service('zabbix-server') } + end - context 'with zabbix_server.conf and version 2.4' do - let :params do - { - nodeid: '0', - nodenohistory: '0', - nodenoevents: '0', - zabbix_version: '2.4' - } - end + context 'with all zabbix_server.conf-related parameters' do + let :params do + { + alertscriptspath: '${datadir}/zabbix/alertscripts', + allowroot: '1', + cachesize: '8M', + cacheupdatefrequency: '30', + database_host: 'localhost', + database_name: 'zabbix-server', + database_password: 'zabbix-server', + database_port: '3306', + database_schema: 'zabbix-server', + database_socket: '/tmp/socket.db', + database_user: 'zabbix-server', + debuglevel: '3', + externalscripts: '/usr/lib/zabbix/externalscripts0', + fping6location: '/usr/sbin/fping6', + fpinglocation: '/usr/sbin/fping', + historycachesize: '4M', + historytextcachesize: '4M', + housekeepingfrequency: '1', + include_dir: '/etc/zabbix/zabbix_server.conf.d', + javagateway: '192.168.2.2', + javagatewayport: '10052', + listenip: '192.168.1.1', + listenport: '10051', + loadmodulepath: '${libdir}/modules', + loadmodule: 'pizza', + logfilesize: '10', + logfile: '/var/log/zabbix/zabbix_server.log', + logslowqueries: '0', + maxhousekeeperdelete: '500', + nodeid: '0', + nodenoevents: '0', + nodenohistory: '0', + pidfile: '/var/run/zabbix/zabbix_server.pid', + proxyconfigfrequency: '3600', + proxydatafrequency: '1', + senderfrequency: '30', + snmptrapperfile: '/tmp/zabbix_traps.tmp', + sourceip: '192.168.1.1', + sshkeylocation: '/home/zabbix', + startdbsyncers: '4', + startdiscoverers: '1', + starthttppollers: '1', + startipmipollers: '12', + startpingers: '1', + startpollers: '12', + startpollersunreachable: '1', + startproxypollers: '1', + startsnmptrapper: '1', + starttimers: '1', + starttrappers: '5', + startvmwarecollectors: '5', + timeout: '3', + tmpdir: '/tmp', + trappertimeout: '30', + trendcachesize: '4M', + unavailabledelay: '30', + unreachabledelay: '30', + unreachableperiod: '30', + valuecachesize: '4M', + vmwarecachesize: '8M', + vmwarefrequency: '60', + zabbix_version: '2.2' + } + end - it { should_not contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeID=0$} } - it { should_not contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeNoEvents=0} } - it { should_not contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeNoHistory=0} } - end + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^AlertScriptsPath=\$\{datadir\}/zabbix/alertscripts} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^AllowRoot=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^CacheSize=8M} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^CacheUpdateFrequency=30} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBHost=localhost} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBName=zabbix-server} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBPassword=zabbix-server} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBPort=3306} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBSchema=zabbix-server} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBSocket=/tmp/socket.db} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBUser=zabbix-server} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DebugLevel=3} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ExternalScripts=/usr/lib/zabbix/externalscripts} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^Fping6Location=/usr/sbin/fping6} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^FpingLocation=/usr/sbin/fping} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^HistoryCacheSize=4M} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^HistoryTextCacheSize=4M} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^HousekeepingFrequency=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^Include=/etc/zabbix/zabbix_server.conf.d} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^JavaGateway=192.168.2.2} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^JavaGatewayPort=10052} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ListenIP=192.168.1.1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ListenPort=10051$} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LoadModulePath=\$\{libdir\}/modules} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LoadModule = pizza} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LogFileSize=10} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LogFile=/var/log/zabbix/zabbix_server.log} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LogSlowQueries=0} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^MaxHousekeeperDelete=500} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeID=0$} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeNoEvents=0} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeNoHistory=0} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^PidFile=/var/run/zabbix/zabbix_server.pid} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ProxyConfigFrequency=3600} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ProxyDataFrequency=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SenderFrequency=30} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SNMPTrapperFile=/tmp/zabbix_traps.tmp} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SourceIP=192.168.1.1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SSHKeyLocation=/home/zabbix} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartDBSyncers=4} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartDiscoverers=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartHTTPPollers=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartIPMIPollers=12} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartPingers=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartPollers=12} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartPollersUnreachable=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartProxyPollers=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartSNMPTrapper=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartTimers=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartTrappers=5} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartVMwareCollectors=5} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^Timeout=3} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TmpDir=/tmp} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TrapperTimeout=30} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TrendCacheSize=4M} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^UnavailableDelay=30} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^UnreachableDelay=30} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^UnreachablePeriod=30} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ValueCacheSize=4M} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^VMwareCacheSize=8M} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^VMwareFrequency=60} } + end - context 'with zabbix_server.conf and version 3.0' do - let :params do - { - tlscafile: '/etc/zabbix/keys/zabbix-server.ca', - tlscrlfile: '/etc/zabbix/keys/zabbix-server.crl', - tlscertfile: '/etc/zabbix/keys/zabbix-server.crt', - tlskeyfile: '/etc/zabbix/keys/zabbix-server.key', - zabbix_version: '3.0' - } - end + context 'with zabbix_server.conf and version 2.4' do + let :params do + { + nodeid: '0', + nodenohistory: '0', + nodenoevents: '0', + zabbix_version: '2.4' + } + end - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSCAFile=/etc/zabbix/keys/zabbix-server.ca$} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSCRLFile=/etc/zabbix/keys/zabbix-server.crl$} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSCertFile=/etc/zabbix/keys/zabbix-server.crt$} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSKeyFile=/etc/zabbix/keys/zabbix-server.key$} } - end - end + it { should_not contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeID=0$} } + it { should_not contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeNoEvents=0} } + it { should_not contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeNoHistory=0} } + end + + context 'with zabbix_server.conf and version 3.0' do + let :params do + { + tlscafile: '/etc/zabbix/keys/zabbix-server.ca', + tlscrlfile: '/etc/zabbix/keys/zabbix-server.crl', + tlscertfile: '/etc/zabbix/keys/zabbix-server.crt', + tlskeyfile: '/etc/zabbix/keys/zabbix-server.key', + zabbix_version: '3.0' + } + end + + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSCAFile=/etc/zabbix/keys/zabbix-server.ca$} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSCRLFile=/etc/zabbix/keys/zabbix-server.crl$} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSCertFile=/etc/zabbix/keys/zabbix-server.crt$} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSKeyFile=/etc/zabbix/keys/zabbix-server.key$} } + end + end + end end From 112fc0d47b30b7554324bdf0d6ad681a9b2dcb4a Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sun, 21 Aug 2016 02:04:07 +0200 Subject: [PATCH 12/12] spec test new zabbix::startup --- spec/classes/agent_spec.rb | 9 +- spec/classes/server_spec.rb | 533 ++++++++++++++++++----------------- spec/defines/startup_spec.rb | 185 +++++++++++- 3 files changed, 448 insertions(+), 279 deletions(-) diff --git a/spec/classes/agent_spec.rb b/spec/classes/agent_spec.rb index 569833a8f..275e3275f 100644 --- a/spec/classes/agent_spec.rb +++ b/spec/classes/agent_spec.rb @@ -14,9 +14,17 @@ on_supported_os.each do |os, facts| context "on #{os} " do + systemd_fact = case facts[:osfamily] + when 'Archlinux' + { systemd: true } + else + { systemd: false } + end let :facts do facts.merge( mocked_facts + ).merge( + systemd_fact ) end @@ -47,7 +55,6 @@ end it { should contain_file('/etc/zabbix/zabbix_agentd.d').with_ensure('directory') } - it { should contain_zabbix__startup('zabbix-agent').that_requires("Package[#{package}]") } end diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index 2ac3f243f..f6c973cfc 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -27,294 +27,295 @@ ) end - describe 'with default settings' do - it { should contain_class('zabbix::repo') } - it { should contain_service('zabbix-server').with_ensure('running') } - it { should_not contain_selboolean('zabbix_can_network') } - end + describe 'with default settings' do + it { should contain_class('zabbix::repo') } + it { should contain_service('zabbix-server').with_ensure('running') } + it { should_not contain_selboolean('zabbix_can_network') } + it { should contain_zabbix__startup('zabbix-server') } + end - describe 'with enabled selinux' do - let :facts do - super().merge(selinux_config_mode: 'enforcing') - end - it { should contain_selboolean('zabbix_can_network').with('value' => 'on', 'persistent' => true) } - end + describe 'with enabled selinux' do + let :facts do + super().merge(selinux_config_mode: 'enforcing') + end + it { should contain_selboolean('zabbix_can_network').with('value' => 'on', 'persistent' => true) } + end - describe 'with database_type as postgresql' do - let :params do - { - database_type: 'postgresql', - server_configfile_path: '/etc/zabbix/zabbix_server.conf', - include_dir: '/etc/zabbix/zabbix_server.conf.d' - } - end + describe 'with database_type as postgresql' do + let :params do + { + database_type: 'postgresql', + server_configfile_path: '/etc/zabbix/zabbix_server.conf', + include_dir: '/etc/zabbix/zabbix_server.conf.d' + } + end - it { should contain_package('zabbix-server-pgsql').with_ensure('present') } - it { should contain_package('zabbix-server-pgsql').with_name('zabbix-server-pgsql') } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_require('Package[zabbix-server-pgsql]') } - end + it { should contain_package('zabbix-server-pgsql').with_ensure('present') } + it { should contain_package('zabbix-server-pgsql').with_name('zabbix-server-pgsql') } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_require('Package[zabbix-server-pgsql]') } + end - describe 'with database_type as mysql' do - let :params do - { - database_type: 'mysql' - } - end + describe 'with database_type as mysql' do + let :params do + { + database_type: 'mysql' + } + end - it { should contain_package('zabbix-server-mysql').with_ensure('present') } - it { should contain_package('zabbix-server-mysql').with_name('zabbix-server-mysql') } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_require('Package[zabbix-server-mysql]') } - end + it { should contain_package('zabbix-server-mysql').with_ensure('present') } + it { should contain_package('zabbix-server-mysql').with_name('zabbix-server-mysql') } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_require('Package[zabbix-server-mysql]') } + end - # Include directory should be available. - it { should contain_file('/etc/zabbix/zabbix_server.conf.d').with_ensure('directory') } - it { should contain_file('/etc/zabbix/zabbix_server.conf.d').with_require('File[/etc/zabbix/zabbix_server.conf]') } + # Include directory should be available. + it { should contain_file('/etc/zabbix/zabbix_server.conf.d').with_ensure('directory') } + it { should contain_file('/etc/zabbix/zabbix_server.conf.d').with_require('File[/etc/zabbix/zabbix_server.conf]') } - context 'with zabbix::database::postgresql class' do - let :params do - { - database_type: 'postgresql', - database_user: 'zabbix-server', - database_password: 'zabbix-server', - database_host: 'localhost', - database_name: 'zabbix-server' - } - end + context 'with zabbix::database::postgresql class' do + let :params do + { + database_type: 'postgresql', + database_user: 'zabbix-server', + database_password: 'zabbix-server', + database_host: 'localhost', + database_name: 'zabbix-server' + } + end - it { should contain_class('zabbix::database::postgresql').with_zabbix_type('server') } - it { should contain_class('zabbix::database::postgresql').with_zabbix_version('3.0') } - it { should contain_class('zabbix::database::postgresql').with_database_name('zabbix-server') } - it { should contain_class('zabbix::database::postgresql').with_database_user('zabbix-server') } - it { should contain_class('zabbix::database::postgresql').with_database_password('zabbix-server') } - it { should contain_class('zabbix::database::postgresql').with_database_host('localhost') } - end + it { should contain_class('zabbix::database::postgresql').with_zabbix_type('server') } + it { should contain_class('zabbix::database::postgresql').with_zabbix_version('3.0') } + it { should contain_class('zabbix::database::postgresql').with_database_name('zabbix-server') } + it { should contain_class('zabbix::database::postgresql').with_database_user('zabbix-server') } + it { should contain_class('zabbix::database::postgresql').with_database_password('zabbix-server') } + it { should contain_class('zabbix::database::postgresql').with_database_host('localhost') } + end - context 'with zabbix::database::mysql class' do - let :params do - { - database_type: 'mysql', - database_user: 'zabbix-server', - database_password: 'zabbix-server', - database_host: 'localhost', - database_name: 'zabbix-server' - } - end + context 'with zabbix::database::mysql class' do + let :params do + { + database_type: 'mysql', + database_user: 'zabbix-server', + database_password: 'zabbix-server', + database_host: 'localhost', + database_name: 'zabbix-server' + } + end - it { should contain_class('zabbix::database::mysql').with_zabbix_type('server') } - it { should contain_class('zabbix::database::mysql').with_zabbix_version('3.0') } - it { should contain_class('zabbix::database::mysql').with_database_name('zabbix-server') } - it { should contain_class('zabbix::database::mysql').with_database_user('zabbix-server') } - it { should contain_class('zabbix::database::mysql').with_database_password('zabbix-server') } - it { should contain_class('zabbix::database::mysql').with_database_host('localhost') } - end + it { should contain_class('zabbix::database::mysql').with_zabbix_type('server') } + it { should contain_class('zabbix::database::mysql').with_zabbix_version('3.0') } + it { should contain_class('zabbix::database::mysql').with_database_name('zabbix-server') } + it { should contain_class('zabbix::database::mysql').with_database_user('zabbix-server') } + it { should contain_class('zabbix::database::mysql').with_database_password('zabbix-server') } + it { should contain_class('zabbix::database::mysql').with_database_host('localhost') } + end - # So if manage_firewall is set to true, it should install - # the firewall rule. - context 'when declaring manage_firewall is true' do - let :params do - { - manage_firewall: true - } - end + # So if manage_firewall is set to true, it should install + # the firewall rule. + context 'when declaring manage_firewall is true' do + let :params do + { + manage_firewall: true + } + end - it { should contain_firewall('151 zabbix-server') } - end + it { should contain_firewall('151 zabbix-server') } + end - context 'when declaring manage_firewall is false' do - let :params do - { - manage_firewall: false - } - end + context 'when declaring manage_firewall is false' do + let :params do + { + manage_firewall: false + } + end - it { should_not contain_firewall('151 zabbix-server') } - end + it { should_not contain_firewall('151 zabbix-server') } + end - # If manage_service is true (default), it should create a service - # and ensure that it is running. - context 'when declaring manage_service is true' do - let :params do - { - manage_service: true - } - end + # If manage_service is true (default), it should create a service + # and ensure that it is running. + context 'when declaring manage_service is true' do + let :params do + { + manage_service: true + } + end - it { should contain_service('zabbix-server').with_ensure('running') } - end + it { should contain_service('zabbix-server').with_ensure('running') } + end - # When the manage_service is false, it may not make the service. - context 'when declaring manage_service is false' do - let :params do - { - manage_service: false - } - end + # When the manage_service is false, it may not make the service. + context 'when declaring manage_service is false' do + let :params do + { + manage_service: false + } + end - it { should_not contain_service('zabbix-server') } - end + it { should_not contain_service('zabbix-server') } + end - context 'with all zabbix_server.conf-related parameters' do - let :params do - { - alertscriptspath: '${datadir}/zabbix/alertscripts', - allowroot: '1', - cachesize: '8M', - cacheupdatefrequency: '30', - database_host: 'localhost', - database_name: 'zabbix-server', - database_password: 'zabbix-server', - database_port: '3306', - database_schema: 'zabbix-server', - database_socket: '/tmp/socket.db', - database_user: 'zabbix-server', - debuglevel: '3', - externalscripts: '/usr/lib/zabbix/externalscripts0', - fping6location: '/usr/sbin/fping6', - fpinglocation: '/usr/sbin/fping', - historycachesize: '4M', - historytextcachesize: '4M', - housekeepingfrequency: '1', - include_dir: '/etc/zabbix/zabbix_server.conf.d', - javagateway: '192.168.2.2', - javagatewayport: '10052', - listenip: '192.168.1.1', - listenport: '10051', - loadmodulepath: '${libdir}/modules', - loadmodule: 'pizza', - logfilesize: '10', - logfile: '/var/log/zabbix/zabbix_server.log', - logslowqueries: '0', - maxhousekeeperdelete: '500', - nodeid: '0', - nodenoevents: '0', - nodenohistory: '0', - pidfile: '/var/run/zabbix/zabbix_server.pid', - proxyconfigfrequency: '3600', - proxydatafrequency: '1', - senderfrequency: '30', - snmptrapperfile: '/tmp/zabbix_traps.tmp', - sourceip: '192.168.1.1', - sshkeylocation: '/home/zabbix', - startdbsyncers: '4', - startdiscoverers: '1', - starthttppollers: '1', - startipmipollers: '12', - startpingers: '1', - startpollers: '12', - startpollersunreachable: '1', - startproxypollers: '1', - startsnmptrapper: '1', - starttimers: '1', - starttrappers: '5', - startvmwarecollectors: '5', - timeout: '3', - tmpdir: '/tmp', - trappertimeout: '30', - trendcachesize: '4M', - unavailabledelay: '30', - unreachabledelay: '30', - unreachableperiod: '30', - valuecachesize: '4M', - vmwarecachesize: '8M', - vmwarefrequency: '60', - zabbix_version: '2.2' - } - end + context 'with all zabbix_server.conf-related parameters' do + let :params do + { + alertscriptspath: '${datadir}/zabbix/alertscripts', + allowroot: '1', + cachesize: '8M', + cacheupdatefrequency: '30', + database_host: 'localhost', + database_name: 'zabbix-server', + database_password: 'zabbix-server', + database_port: '3306', + database_schema: 'zabbix-server', + database_socket: '/tmp/socket.db', + database_user: 'zabbix-server', + debuglevel: '3', + externalscripts: '/usr/lib/zabbix/externalscripts0', + fping6location: '/usr/sbin/fping6', + fpinglocation: '/usr/sbin/fping', + historycachesize: '4M', + historytextcachesize: '4M', + housekeepingfrequency: '1', + include_dir: '/etc/zabbix/zabbix_server.conf.d', + javagateway: '192.168.2.2', + javagatewayport: '10052', + listenip: '192.168.1.1', + listenport: '10051', + loadmodulepath: '${libdir}/modules', + loadmodule: 'pizza', + logfilesize: '10', + logfile: '/var/log/zabbix/zabbix_server.log', + logslowqueries: '0', + maxhousekeeperdelete: '500', + nodeid: '0', + nodenoevents: '0', + nodenohistory: '0', + pidfile: '/var/run/zabbix/zabbix_server.pid', + proxyconfigfrequency: '3600', + proxydatafrequency: '1', + senderfrequency: '30', + snmptrapperfile: '/tmp/zabbix_traps.tmp', + sourceip: '192.168.1.1', + sshkeylocation: '/home/zabbix', + startdbsyncers: '4', + startdiscoverers: '1', + starthttppollers: '1', + startipmipollers: '12', + startpingers: '1', + startpollers: '12', + startpollersunreachable: '1', + startproxypollers: '1', + startsnmptrapper: '1', + starttimers: '1', + starttrappers: '5', + startvmwarecollectors: '5', + timeout: '3', + tmpdir: '/tmp', + trappertimeout: '30', + trendcachesize: '4M', + unavailabledelay: '30', + unreachabledelay: '30', + unreachableperiod: '30', + valuecachesize: '4M', + vmwarecachesize: '8M', + vmwarefrequency: '60', + zabbix_version: '2.2' + } + end - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^AlertScriptsPath=\$\{datadir\}/zabbix/alertscripts} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^AllowRoot=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^CacheSize=8M} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^CacheUpdateFrequency=30} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBHost=localhost} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBName=zabbix-server} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBPassword=zabbix-server} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBPort=3306} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBSchema=zabbix-server} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBSocket=/tmp/socket.db} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBUser=zabbix-server} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DebugLevel=3} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ExternalScripts=/usr/lib/zabbix/externalscripts} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^Fping6Location=/usr/sbin/fping6} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^FpingLocation=/usr/sbin/fping} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^HistoryCacheSize=4M} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^HistoryTextCacheSize=4M} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^HousekeepingFrequency=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^Include=/etc/zabbix/zabbix_server.conf.d} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^JavaGateway=192.168.2.2} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^JavaGatewayPort=10052} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ListenIP=192.168.1.1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ListenPort=10051$} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LoadModulePath=\$\{libdir\}/modules} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LoadModule = pizza} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LogFileSize=10} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LogFile=/var/log/zabbix/zabbix_server.log} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LogSlowQueries=0} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^MaxHousekeeperDelete=500} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeID=0$} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeNoEvents=0} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeNoHistory=0} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^PidFile=/var/run/zabbix/zabbix_server.pid} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ProxyConfigFrequency=3600} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ProxyDataFrequency=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SenderFrequency=30} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SNMPTrapperFile=/tmp/zabbix_traps.tmp} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SourceIP=192.168.1.1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SSHKeyLocation=/home/zabbix} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartDBSyncers=4} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartDiscoverers=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartHTTPPollers=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartIPMIPollers=12} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartPingers=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartPollers=12} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartPollersUnreachable=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartProxyPollers=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartSNMPTrapper=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartTimers=1} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartTrappers=5} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartVMwareCollectors=5} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^Timeout=3} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TmpDir=/tmp} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TrapperTimeout=30} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TrendCacheSize=4M} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^UnavailableDelay=30} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^UnreachableDelay=30} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^UnreachablePeriod=30} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ValueCacheSize=4M} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^VMwareCacheSize=8M} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^VMwareFrequency=60} } - end + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^AlertScriptsPath=\$\{datadir\}/zabbix/alertscripts} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^AllowRoot=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^CacheSize=8M} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^CacheUpdateFrequency=30} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBHost=localhost} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBName=zabbix-server} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBPassword=zabbix-server} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBPort=3306} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBSchema=zabbix-server} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBSocket=/tmp/socket.db} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DBUser=zabbix-server} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^DebugLevel=3} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ExternalScripts=/usr/lib/zabbix/externalscripts} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^Fping6Location=/usr/sbin/fping6} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^FpingLocation=/usr/sbin/fping} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^HistoryCacheSize=4M} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^HistoryTextCacheSize=4M} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^HousekeepingFrequency=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^Include=/etc/zabbix/zabbix_server.conf.d} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^JavaGateway=192.168.2.2} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^JavaGatewayPort=10052} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ListenIP=192.168.1.1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ListenPort=10051$} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LoadModulePath=\$\{libdir\}/modules} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LoadModule = pizza} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LogFileSize=10} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LogFile=/var/log/zabbix/zabbix_server.log} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^LogSlowQueries=0} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^MaxHousekeeperDelete=500} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeID=0$} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeNoEvents=0} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeNoHistory=0} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^PidFile=/var/run/zabbix/zabbix_server.pid} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ProxyConfigFrequency=3600} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ProxyDataFrequency=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SenderFrequency=30} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SNMPTrapperFile=/tmp/zabbix_traps.tmp} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SourceIP=192.168.1.1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^SSHKeyLocation=/home/zabbix} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartDBSyncers=4} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartDiscoverers=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartHTTPPollers=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartIPMIPollers=12} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartPingers=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartPollers=12} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartPollersUnreachable=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartProxyPollers=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartSNMPTrapper=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartTimers=1} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartTrappers=5} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^StartVMwareCollectors=5} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^Timeout=3} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TmpDir=/tmp} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TrapperTimeout=30} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TrendCacheSize=4M} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^UnavailableDelay=30} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^UnreachableDelay=30} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^UnreachablePeriod=30} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^ValueCacheSize=4M} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^VMwareCacheSize=8M} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^VMwareFrequency=60} } + end - context 'with zabbix_server.conf and version 2.4' do - let :params do - { - nodeid: '0', - nodenohistory: '0', - nodenoevents: '0', - zabbix_version: '2.4' - } - end + context 'with zabbix_server.conf and version 2.4' do + let :params do + { + nodeid: '0', + nodenohistory: '0', + nodenoevents: '0', + zabbix_version: '2.4' + } + end - it { should_not contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeID=0$} } - it { should_not contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeNoEvents=0} } - it { should_not contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeNoHistory=0} } - end + it { should_not contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeID=0$} } + it { should_not contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeNoEvents=0} } + it { should_not contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^NodeNoHistory=0} } + end - context 'with zabbix_server.conf and version 3.0' do - let :params do - { - tlscafile: '/etc/zabbix/keys/zabbix-server.ca', - tlscrlfile: '/etc/zabbix/keys/zabbix-server.crl', - tlscertfile: '/etc/zabbix/keys/zabbix-server.crt', - tlskeyfile: '/etc/zabbix/keys/zabbix-server.key', - zabbix_version: '3.0' - } - end + context 'with zabbix_server.conf and version 3.0' do + let :params do + { + tlscafile: '/etc/zabbix/keys/zabbix-server.ca', + tlscrlfile: '/etc/zabbix/keys/zabbix-server.crl', + tlscertfile: '/etc/zabbix/keys/zabbix-server.crt', + tlskeyfile: '/etc/zabbix/keys/zabbix-server.key', + zabbix_version: '3.0' + } + end - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSCAFile=/etc/zabbix/keys/zabbix-server.ca$} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSCRLFile=/etc/zabbix/keys/zabbix-server.crl$} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSCertFile=/etc/zabbix/keys/zabbix-server.crt$} } - it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSKeyFile=/etc/zabbix/keys/zabbix-server.key$} } - end - end - end + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSCAFile=/etc/zabbix/keys/zabbix-server.ca$} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSCRLFile=/etc/zabbix/keys/zabbix-server.crl$} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSCertFile=/etc/zabbix/keys/zabbix-server.crt$} } + it { should contain_file('/etc/zabbix/zabbix_server.conf').with_content %r{^TLSKeyFile=/etc/zabbix/keys/zabbix-server.key$} } + end + end + end end diff --git a/spec/defines/startup_spec.rb b/spec/defines/startup_spec.rb index 7a5f8885e..27a9c3ff8 100644 --- a/spec/defines/startup_spec.rb +++ b/spec/defines/startup_spec.rb @@ -1,35 +1,196 @@ require 'spec_helper' -describe 'zabbix::startup', type: :define do +describe 'zabbix::startup', type: :define do # rubocop:disable RSpec/MultipleDescribes let(:title) { 'zabbix-agent' } - %w(RedHat Debian).each do |osfamily| + %w(RedHat Debian Gentoo).each do |osfamily| context "on #{osfamily}" do - context 'no systemd' do + context 'on legacy init systems' do ['false', false].each do |systemd_fact_state| let :facts do { + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin', osfamily: osfamily, - systemd: systemd_fact_state, + systemd: systemd_fact_state } end - it { should_not contain_class('systemd') } - it { should_not contain_file('/etc/systemd/system/zabbix-agent.service') } - it { should contain_file('/etc/init.d/zabbix-agent').with_ensure('file') } + context 'it works' do + let :params do + { + agent_configfile_path: '/something' + } + end + if osfamily == 'Debian' + it do + should contain_file('/etc/init.d/zabbix-agent').with( + ensure: 'file', + content: %r{DAEMON_OPTS="-c /something"} + ) + end + elsif osfamily == 'RedHat' + it do + should contain_file('/etc/init.d/zabbix-agent').with( + ensure: 'file', + content: %r{OPTS="-c /something"} + ) + end + else + it { should raise_error(Puppet::Error, %r{We currently only support Debian and RedHat osfamily as non-systemd}) } + next + end + it { should_not contain_class('systemd') } + it { should_not contain_file('/etc/systemd/system/zabbix-agent.service') } + end + + context 'it fails when agent_configfile_path param is missing' do + let :params do + {} + end + it { should raise_error(Puppet::Error, %r{you have to provide a agent_configfile_path param}) } + end end end + end + context 'on systemd' do + ['true', true].each do |systemd_fact_state| + let :facts do + { + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin', + osfamily: osfamily, + systemd: systemd_fact_state + } + end + context 'it works' do + let :params do + { + agent_configfile_path: '/something', + pidfile: '/somethingelse' + } + end + it { should contain_class('systemd') } + it { should contain_file('/etc/init.d/zabbix-agent').with_ensure('absent') } + it do + should contain_file('/etc/systemd/system/zabbix-agent.service').with( + ensure: 'file', + mode: '0664' + ).that_notifies('Exec[systemctl-daemon-reload]') + end + it { should contain_file('/etc/systemd/system/zabbix-agent.service').with_content(%r{ExecStart=/usr/sbin/zabbix_agentd -c /something}) } + it { should contain_file('/etc/systemd/system/zabbix-agent.service').with_content(%r{PIDFile=/somethingelse}) } + end - context 'has systemd' do - ['true', true].each do |systemd_fact_state| + context 'it fails when pidfile param is missing' do + let :params do + { + agent_configfile_path: '/something' + } + end + it { should raise_error(Puppet::Error, %r{you have to provide a pidfile param}) } + end + end + end + end +end +describe 'zabbix::startup', type: :define do + let(:title) { 'zabbix-server' } + %w(RedHat Debian Gentoo).each do |osfamily| + context "on #{osfamily}" do + context 'on legacy init systems' do + ['false', false].each do |systemd_fact_state| let :facts do { + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin', osfamily: osfamily, - systemd: systemd_fact_state, + systemd: systemd_fact_state + } + end + context 'it works' do + let :params do + { + server_configfile_path: '/something', + database_type: 'mysql' + } + end + if osfamily == 'Debian' + it do + should contain_file('/etc/init.d/zabbix-server').with( + ensure: 'file', + content: %r{DAEMON_OPTS="-c /something"} + ) + end + elsif osfamily == 'RedHat' + it do + should contain_file('/etc/init.d/zabbix-server').with( + ensure: 'file', + content: %r{OPTS="-c /something"} + ) + end + else + it { should raise_error(Puppet::Error, %r{We currently only support Debian and RedHat osfamily as non-systemd}) } + next + end + it { should_not contain_class('systemd') } + it { should_not contain_file('/etc/systemd/system/zabbix-server.service') } + end + + context 'it fails when server_configfile_path param is missing' do + let :params do + {} + end + it { should raise_error(Puppet::Error, %r{you have to provide a server_configfile_path param}) } + end + end + end + end + context 'on systemd' do + ['true', true].each do |systemd_fact_state| + let :facts do + { + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin', + osfamily: osfamily, + systemd: systemd_fact_state + } + end + context 'it works on mysql' do + let :params do + { + server_configfile_path: '/something', + pidfile: '/somethingelse', + database_type: 'mysql' } end it { should contain_class('systemd') } - it { should contain_file('/etc/systemd/system/zabbix-agent.service') } - it { should contain_file('/etc/init.d/zabbix-agent').with_ensure('absent') } + it { should contain_file('/etc/init.d/zabbix-server').with_ensure('absent') } + it do + should contain_file('/etc/systemd/system/zabbix-server.service').with( + ensure: 'file', + mode: '0664' + ).that_notifies('Exec[systemctl-daemon-reload]') + end + it { should contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{ExecStart=/usr/sbin/zabbix_server -c /something}) } + it { should contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{PIDFile=/somethingelse}) } + it { should contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{After=syslog.target network.target mysqld.service}) } + + context 'and works on postgres' do + let :params do + { + server_configfile_path: '/something', + pidfile: '/somethingelse', + database_type: 'postgres' + } + end + it { should contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{After=syslog.target network.target postgresql.service}) } + end + end + + context 'it fails when database_type param is missing' do + let :params do + { + server_configfile_path: '/something', + pidfile: '/somethingelse' + } + end + it { should raise_error(Puppet::Error, %r{you have to provide a database_type param}) } end end end