diff --git a/spec/classes/puppet_agent_service_cron_spec.rb b/spec/classes/puppet_agent_service_cron_spec.rb index a2c7e38..db9e9b5 100644 --- a/spec/classes/puppet_agent_service_cron_spec.rb +++ b/spec/classes/puppet_agent_service_cron_spec.rb @@ -1,51 +1,52 @@ require 'spec_helper' +require 'deep_merge' describe 'puppet::agent::service::cron' do on_os_under_test.each do |os, facts| context "on #{os}" do if facts[:osfamily] == 'FreeBSD' bindir = '/usr/local/bin' confdir = '/usr/local/etc/puppet' else confdir = '/etc/puppetlabs/puppet' bindir = '/opt/puppetlabs/bin' end let :facts do - facts.merge(ipaddress: '192.0.2.100') + facts.deep_merge(networking: { ip: '192.0.2.100' }) end describe 'when runmode is not cron' do let :pre_condition do "class {'puppet': agent => true}" end if os =~ /\A(windows|archlinux)/ it { should_not contain_cron('puppet') } else it { should contain_cron('puppet').with_ensure('absent') } end end describe 'when runmode => cron' do let :pre_condition do "class {'puppet': agent => true, runmode => 'cron'}" end it do case os when /\A(windows|archlinux)/ should raise_error(Puppet::Error, /Runmode of cron not supported on #{facts[:kernel]} operating systems!/) else should contain_cron('puppet').with({ :command => "#{bindir}/puppet agent --config #{confdir}/puppet.conf --onetime --no-daemonize", :user => 'root', :minute => ['10','40'], :hour => '*', }) end end end end end end diff --git a/spec/classes/puppet_agent_service_systemd_spec.rb b/spec/classes/puppet_agent_service_systemd_spec.rb index c2e2817..6cd008e 100644 --- a/spec/classes/puppet_agent_service_systemd_spec.rb +++ b/spec/classes/puppet_agent_service_systemd_spec.rb @@ -1,95 +1,96 @@ require 'spec_helper' +require 'deep_merge' describe 'puppet::agent::service::systemd' do on_os_under_test.each do |os, facts| context "on #{os}" do if facts[:osfamily] == 'FreeBSD' bindir = '/usr/local/bin' confdir = '/usr/local/etc/puppet' elsif facts[:osfamily] == 'Archlinux' bindir = '/usr/bin' confdir = '/etc/puppetlabs/puppet' else bindir = '/opt/puppetlabs/bin' confdir = '/etc/puppetlabs/puppet' end let :facts do - facts.merge(ipaddress: '192.0.2.100') + facts.deep_merge(networking: { ip: '192.0.2.100' }) end describe 'when runmode is not systemd' do let :pre_condition do "class {'puppet': agent => true}" end case os when /\Adebian-/, /\A(redhat|centos|scientific)-7/, /\Afedora-/, /\Aubuntu-(16|18)/, /\Aarchlinux-/ it 'should disable systemd timer' do should contain_class('puppet::agent::service::systemd').with({ 'enabled' => false, }) should contain_service('puppet-run.timer').with({ :provider => 'systemd', :ensure => 'stopped', :name => 'puppet-run.timer', :enable => 'false', }) should contain_file('/etc/systemd/system/puppet-run.timer').with_ensure(:absent) should contain_file('/etc/systemd/system/puppet-run.service').with_ensure(:absent) should contain_exec('systemctl-daemon-reload-puppet').with({ :refreshonly => true, :command => 'systemctl daemon-reload', }) end else it 'should not have a systemd timer service' do should_not contain_service('puppet-run.timer') should_not contain_file('/etc/systemd/system/puppet-run.timer') should_not contain_file('/etc/systemd/system/puppet-run.service') should_not contain_exec('systemctl-daemon-reload-puppet') end end end describe 'when runmode => systemd.timer' do let :pre_condition do "class {'puppet': agent => true, runmode => 'systemd.timer'}" end case os when /\Adebian-/, /\A(redhat|centos|scientific)-7/, /\Afedora-/, /\Aubuntu-(16|18)/, /\Aarchlinux-/ it 'should enable systemd timer' do should contain_class('puppet::agent::service::systemd').with_enabled(true) should contain_file('/etc/systemd/system/puppet-run.timer'). with_content(/.*OnCalendar\=\*-\*-\* \*\:10,40:00.*/) should contain_file('/etc/systemd/system/puppet-run.timer'). with_content(/^RandomizedDelaySec\=0$/) should contain_file('/etc/systemd/system/puppet-run.service'). with_content(/.*ExecStart=#{bindir}\/puppet agent --config #{confdir}\/puppet.conf --onetime --no-daemonize.*/) should contain_exec('systemctl-daemon-reload-puppet').with({ :refreshonly => true, :command => 'systemctl daemon-reload', }) should contain_service('puppet-run.timer').with({ :provider => 'systemd', :ensure => 'running', :name => 'puppet-run.timer', :enable => 'true', }) end else it { should raise_error(Puppet::Error, /Runmode of systemd.timer not supported on #{facts[:kernel]} operating systems!/) } end end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b8153cf..7b41016 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,74 +1,74 @@ # This file is managed centrally by modulesync # https://github.com/theforeman/foreman-installer-modulesync require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' include RspecPuppetFacts # Original fact sources: add_custom_fact :puppet_environmentpath, '/etc/puppetlabs/code/environments' # puppetlabs-stdlib add_custom_fact :root_home, '/root' # puppetlabs-stdlib # Workaround for no method in rspec-puppet to pass undef through :params class Undef def inspect; 'undef'; end end # Running tests with the ONLY_OS environment variable set # limits the tested platforms to the specified values. # Example: ONLY_OS=centos-7-x86_64,ubuntu-14-x86_64 def only_test_os if ENV.key?('ONLY_OS') ENV['ONLY_OS'].split(',') end end # Running tests with the EXCLUDE_OS environment variable set # limits the tested platforms to all but the specified values. # Example: EXCLUDE_OS=centos-7-x86_64,ubuntu-14-x86_64 def exclude_test_os if ENV.key?('EXCLUDE_OS') ENV['EXCLUDE_OS'].split(',') end end # Use the above environment variables to limit the platforms under test def on_os_under_test - on_supported_os.reject do |os, facts| + on_supported_os(facterversion: '3.0.0').reject do |os, facts| (only_test_os() && !only_test_os.include?(os)) || (exclude_test_os() && exclude_test_os.include?(os)) end end def get_content(subject, title) is_expected.to contain_file(title) content = subject.resource('file', title).send(:parameters)[:content] content.split(/\n/).reject { |line| line =~ /(^#|^$|^\s+#)/ } end def verify_exact_contents(subject, title, expected_lines) expect(get_content(subject, title)).to match_array(expected_lines) end def verify_concat_fragment_contents(subject, title, expected_lines) is_expected.to contain_concat__fragment(title) content = subject.resource('concat::fragment', title).send(:parameters)[:content] expect(content.split("\n") & expected_lines).to match_array(expected_lines) end def verify_concat_fragment_exact_contents(subject, title, expected_lines) is_expected.to contain_concat__fragment(title) content = subject.resource('concat::fragment', title).send(:parameters)[:content] expect(content.split(/\n/).reject { |line| line =~ /(^#|^$|^\s+#)/ }).to match_array(expected_lines) end aio = on_os_under_test.reject do |os, facts| ['FreeBSD', 'DragonFly', 'Windows'].include?(facts[:operatingsystem]) end.keys add_custom_fact :rubysitedir, '/opt/puppetlabs/puppet/lib/ruby/site_ruby/2.1.0', :confine => aio def unsupported_puppetmaster_osfamily(osfamily) ['Archlinux', 'windows', 'Suse'].include?(osfamily) end