diff --git a/spec/classes/puppet_agent_config_spec.rb b/spec/classes/puppet_agent_config_spec.rb deleted file mode 100644 index 41ac025..0000000 --- a/spec/classes/puppet_agent_config_spec.rb +++ /dev/null @@ -1,93 +0,0 @@ -require 'spec_helper' - -describe 'puppet::agent::config' do - - on_os_under_test.each do |os, facts| - next if facts[:osfamily] == 'windows' # TODO, see https://github.com/fessyfoo/rspec-puppet-windows-issue - context "on #{os}" do - let(:facts) { facts } - - context 'with default parameters' do - let :pre_condition do - 'include ::puppet' - end - - it { should compile.with_all_deps } - it { should contain_concat__fragment( 'puppet.conf_agent' ) } - if facts[:osfamily] == 'Debian' - it { should contain_augeas('puppet::set_start'). - with_context('/files/etc/default/puppet'). - with_changes('set START yes'). - with_incl('/etc/default/puppet'). - with_lens('Shellvars.lns'). - with({}) - } - it { should contain_file('/var/lib/puppet/state/agent_disabled.lock'). - with_ensure(:absent). - with({}) - } - end - - it { should contain_puppet__config__agent('certname').with(facts[:certname]) } - it { should contain_puppet__config__agent('report').with({'value'=>'true'}) } - end - - context 'with runmode => cron', :unless => (facts[:osfamily] == 'Archlinux') do - let :pre_condition do - 'class { "::puppet": runmode => "cron" }' - end - - it { should compile.with_all_deps } - it { should contain_concat__fragment( 'puppet.conf_agent' ) } - if facts[:osfamily] == 'Debian' - it { should contain_augeas('puppet::set_start'). - with_context('/files/etc/default/puppet'). - with_changes('set START no'). - with_incl('/etc/default/puppet'). - with_lens('Shellvars.lns'). - with({}) - } - it { should contain_file('/var/lib/puppet/state/agent_disabled.lock'). - with_ensure(:absent). - with({}) - } - end - end - - context 'with remove_lock => false' do - let :pre_condition do - 'class { "::puppet": remove_lock => false }' - end - - it { should compile.with_all_deps } - it { should contain_concat__fragment( 'puppet.conf_agent' ) } - if facts[:osfamily] == 'Debian' - it { should contain_augeas('puppet::set_start'). - with_context('/files/etc/default/puppet'). - with_changes('set START yes'). - with_incl('/etc/default/puppet'). - with_lens('Shellvars.lns'). - with({}) - } - it { should_not contain_file('/var/lib/puppet/state/agent_disabled.lock') } - end - end - - context 'with client_certname => false' do - let :pre_condition do - 'class { "::puppet": client_certname => false }' - end - - it { should_not contain_puppet__config__agent('certname') } - end - - context 'with report => false' do - let :pre_condition do - 'class { "::puppet": report => false }' - end - - it { should contain_puppet__config__agent('report').with({'value'=>'false'}) } - end - end - end -end diff --git a/spec/classes/puppet_agent_install_spec.rb b/spec/classes/puppet_agent_install_spec.rb deleted file mode 100644 index 33e3ced..0000000 --- a/spec/classes/puppet_agent_install_spec.rb +++ /dev/null @@ -1,103 +0,0 @@ -require 'spec_helper' - -describe 'puppet::agent::install' do - context 'with explicit parameters' do - let :base_params do - { - :manage_packages => true, - :package_name => 'puppet-agent', - :package_version => 'installed', - :package_provider => 'provider', # Can't set this to nil - :package_source => 'source', # Can't set this to nil - } - end - - describe 'base parameters' do - let :params do - base_params - end - - it do - is_expected.to contain_package('puppet-agent'). - with_ensure('installed'). - with_provider('provider'). - with_source('source') - end - end - - describe 'when manage_packages => false' do - let :params do - base_params.merge(:manage_packages => false) - end - - it { is_expected.not_to contain_package('puppet-agent') } - end - - describe "when manage_packages => 'agent'" do - let :params do - base_params.merge(:manage_packages => 'agent') - end - - it { is_expected.to contain_package('puppet-agent') } - end - - describe "when manage_packages => 'server'" do - let :params do - base_params.merge(:manage_packages => 'sever') - end - - it { is_expected.not_to contain_package('puppet-agent') } - end - end - - on_os_under_test.each do |os, facts| - context "on #{os}" do - client_package = if facts[:osfamily] == 'FreeBSD' - if Puppet.version < '5.0' - 'puppet4' - else - 'puppet5' - end - else - 'puppet-agent' - end - - package_provider = if facts[:osfamily] == 'windows' - 'chocolatey' - else - nil - end - - let (:facts) do - facts - end - - describe 'with default parameters' do - let :pre_condition do - 'include ::puppet' - end - - # For windows we specify a package provider which doesn't compile - if facts[:osfamily] != 'windows' - it { is_expected.to compile.with_all_deps } - end - - it do - is_expected.to contain_class('puppet::agent::install'). - with_manage_packages(true). - with_package_name([client_package]). - with_package_version('present'). - with_package_provider(package_provider). - with_package_source(nil) - end - - it do - is_expected.to contain_package(client_package). - with_ensure('present'). - with_provider(package_provider). - with_source(nil) - end - end - end - end -end diff --git a/spec/classes/puppet_agent_service_cron_spec.rb b/spec/classes/puppet_agent_service_cron_spec.rb deleted file mode 100644 index db9e9b5..0000000 --- a/spec/classes/puppet_agent_service_cron_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -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.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_daemon_spec.rb b/spec/classes/puppet_agent_service_daemon_spec.rb deleted file mode 100644 index f5e297b..0000000 --- a/spec/classes/puppet_agent_service_daemon_spec.rb +++ /dev/null @@ -1,68 +0,0 @@ -require 'spec_helper' - -describe 'puppet::agent::service::daemon' do - on_os_under_test.each do |os, facts| - context "on #{os}" do - if facts[:osfamily] == 'FreeBSD' - confdir = '/usr/local/etc/puppet' - else - confdir = '/etc/puppetlabs/puppet' - end - - let :facts do - facts - end - - describe 'when runmode => daemon' do - let :pre_condition do - "class {'puppet': agent => true}" - end - - it do - should contain_service('puppet').with({ - :ensure => 'running', - :name => 'puppet', - :hasstatus => 'true', - :enable => 'true', - }) - end - - describe 'when runmode is not daemon' 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_service('puppet').with({ - :ensure => 'stopped', - :name => 'puppet', - :hasstatus => 'true', - :enable => 'false', - }) - end - end - end - end - - describe 'with custom service_name' do - let :pre_condition do - "class {'puppet': agent => true, service_name => 'pe-puppet'}" - end - - it do - should contain_service('puppet').with({ - :ensure => 'running', - :name => 'pe-puppet', - :hasstatus => 'true', - :enable => 'true', - }) - end - - end - end - end -end diff --git a/spec/classes/puppet_agent_service_spec.rb b/spec/classes/puppet_agent_service_spec.rb deleted file mode 100644 index 80ed9e8..0000000 --- a/spec/classes/puppet_agent_service_spec.rb +++ /dev/null @@ -1,116 +0,0 @@ -require 'spec_helper' - -describe 'puppet::agent::service' do - on_os_under_test.each do |os, facts| - context "on #{os}" do - if facts[:osfamily] == 'FreeBSD' - confdir = '/usr/local/etc/puppet' - else - confdir = '/etc/puppetlabs/puppet' - end - - let :facts do - facts - end - - describe 'with no custom parameters' do - let :pre_condition do - "class {'puppet': agent => true}" - end - - it do - should contain_class('puppet::agent::service::daemon').with(:enabled => true) - should contain_class('puppet::agent::service::cron').with(:enabled => false) - end - case os - when /\Adebian-/, /\A(redhat|centos|scientific)-7/, /\Afedora-/, /\Aubuntu-(16|18)/, /\Aarchlinux-/ - it do - should contain_class('puppet::agent::service::systemd').with(:enabled => false) - should contain_service('puppet-run.timer').with(:ensure => :stopped) - end - else - it do - should contain_class('puppet::agent::service::systemd').with(:enabled => false) - should_not contain_service('puppet-run.timer') - end - end - end - - describe 'when runmode => cron' do - let :pre_condition do - "class {'puppet': agent => true, runmode => 'cron'}" - end - case os - when /\A(windows|archlinux)/ - it do - should raise_error(Puppet::Error, /Runmode of cron not supported on #{facts[:kernel]} operating systems!/) - end - when /\Adebian-/, /\A(redhat|centos|scientific)-7/, /\Afedora-/, /\Aubuntu-(16|18)/ - it do - should contain_class('puppet::agent::service::cron').with(:enabled => true) - should contain_class('puppet::agent::service::daemon').with(:enabled => false) - should contain_class('puppet::agent::service::systemd').with(:enabled => false) - should contain_service('puppet-run.timer').with(:ensure => :stopped) - end - else - it do - should contain_class('puppet::agent::service::cron').with(:enabled => true) - should contain_class('puppet::agent::service::daemon').with(:enabled => false) - should contain_class('puppet::agent::service::systemd').with(:enabled => false) - should_not contain_service('puppet-run.timer') - 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 do - should contain_class('puppet::agent::service::daemon').with(:enabled => false) - should contain_class('puppet::agent::service::cron').with(:enabled => false) - should contain_class('puppet::agent::service::systemd').with(:enabled => true) - should contain_service('puppet-run.timer').with(:ensure => :running) - end - else - it { should raise_error(Puppet::Error, /Runmode of systemd.timer not supported on #{facts[:kernel]} operating systems!/) } - end - end - - describe 'when unavailable_runmodes => ["cron"]' do - let :pre_condition do - "class {'puppet': agent => true, unavailable_runmodes => ['cron']}" - end - - it do - should_not contain_cron('puppet') - end - end - - describe 'when runmode => none' do - let :pre_condition do - "class {'puppet': agent => true, runmode => 'none'}" - end - - it do - should contain_class('puppet::agent::service::daemon').with(:enabled => false) - should contain_class('puppet::agent::service::cron').with(:enabled => false) - end - case os - when /\Adebian-/, /\A(redhat|centos|scientific)-7/, /\Afedora-/, /\Aubuntu-(16|18)/, /\Aarchlinux-/ - it do - should contain_class('puppet::agent::service::systemd').with(:enabled => false) - should contain_service('puppet-run.timer').with(:ensure => :stopped) - end - else - it do - should contain_class('puppet::agent::service::systemd').with(:enabled => false) - should_not contain_service('puppet-run.timer') - 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 deleted file mode 100644 index 6cd008e..0000000 --- a/spec/classes/puppet_agent_service_systemd_spec.rb +++ /dev/null @@ -1,96 +0,0 @@ -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.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/classes/puppet_agent_spec.rb b/spec/classes/puppet_agent_spec.rb index dafa6ed..abd552f 100644 --- a/spec/classes/puppet_agent_spec.rb +++ b/spec/classes/puppet_agent_spec.rb @@ -1,79 +1,347 @@ require 'spec_helper' +require 'deep_merge' -describe 'puppet::agent' do +describe 'puppet' do on_os_under_test.each do |os, facts| context "on #{os}" do case facts[:osfamily] when 'FreeBSD' - if Puppet.version < '5.0' - client_package = 'puppet4' - else - client_package = 'puppet5' - end - confdir = '/usr/local/etc/puppet' + bindir = '/usr/local/bin' + client_package = Puppet.version < '5.0' ? 'puppet4' : 'puppet5' + confdir = '/usr/local/etc/puppet' + package_provider = nil when 'windows' + bindir = 'C:/ProgramData/PuppetLabs/puppet/bin' client_package = 'puppet-agent' - confdir = 'C:/ProgramData/PuppetLabs/puppet/etc' + confdir = 'C:/ProgramData/PuppetLabs/puppet/etc' + package_provider = 'chocolatey' else + bindir = '/opt/puppetlabs/bin' client_package = 'puppet-agent' - confdir = '/etc/puppetlabs/puppet' + confdir = '/etc/puppetlabs/puppet' + package_provider = nil end let :facts do - facts + facts.deep_merge( + # rspec-puppet(-facts) doesn't mock this + clientcert: 'client.example.com', + # Cron/systemd timers are based on the IP - make it consistent + networking: { ip: '192.0.2.100' } + ) + end + + let :params do + { + agent: true + } end describe 'with no custom parameters' do - let :pre_condition do - "class {'puppet': agent => true}" - end - it { should contain_class('puppet::agent::install') } - it { should contain_class('puppet::agent::config') } - it { should contain_class('puppet::agent::service') } - it { should contain_file(confdir).with_ensure('directory') } - it { should contain_concat("#{confdir}/puppet.conf") } - it { should contain_package(client_package).with_ensure('present') } + # For windows we specify a package provider which doesn't compile + if facts[:osfamily] != 'windows' + it { is_expected.to compile.with_all_deps } + end + + # install it do - should contain_concat__fragment('puppet.conf_agent'). - with_content(/^\[agent\]/). - with({}) + is_expected.to contain_class('puppet::agent::install') + .with_manage_packages(true) + .with_package_name([client_package]) + .with_package_version('present') + .with_package_provider(package_provider) + .with_package_source(nil) + .that_notifies(['Class[puppet::agent::config]', 'Class[puppet::agent::service]']) end it do - should_not contain_puppet__config__agent('prerun_command') + is_expected.to contain_package(client_package) + .with_ensure('present') + .with_provider(package_provider) + .with_source(nil) + end + + # config + it { is_expected.to contain_class('puppet::agent::config').that_notifies('Class[puppet::agent::service]') } + it { is_expected.to contain_file(confdir).with_ensure('directory') } + it { is_expected.to contain_concat("#{confdir}/puppet.conf") } + it { is_expected.to contain_concat__fragment('puppet.conf_agent').with_content(/^\[agent\]/) } + it { is_expected.to contain_puppet__config__agent('certname').with_value(facts[:clientcert]) } + it { is_expected.to contain_puppet__config__agent('report').with_value('true') } + it { is_expected.not_to contain_puppet__config__agent('prerun_command') } + it { is_expected.not_to contain_puppet__config__agent('postrun_command') } + + if facts[:osfamily] == 'Debian' + it do + is_expected.to contain_augeas('puppet::set_start') + .with_context('/files/etc/default/puppet') + .with_changes('set START yes') + .with_incl('/etc/default/puppet') + .with_lens('Shellvars.lns') + end + it { is_expected.to contain_file('/var/lib/puppet/state/agent_disabled.lock').with_ensure(:absent) } end + # service + it { is_expected.to contain_class('puppet::agent::service') } + + it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(true) } it do - should_not contain_puppet__config__agent('postrun_command') + is_expected.to contain_service('puppet') + .with_ensure('running') + .with_name('puppet') + .with_hasstatus('true') + .with_enable('true') + end + + it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(false) } + if os =~ /\A(windows|archlinux)/ + it { is_expected.not_to contain_cron('puppet') } + else + it { is_expected.to contain_cron('puppet').with_ensure('absent') } + end + + it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(false) } + case os + when /\Adebian-/, /\A(redhat|centos|scientific)-7/, /\Afedora-/, /\Aubuntu-(16|18)/, /\Aarchlinux-/ + it do + is_expected.to contain_exec('systemctl-daemon-reload-puppet') + .with_refreshonly(true) + .with_command('systemctl daemon-reload') + end + + it do + is_expected.to contain_service('puppet-run.timer') + .with_ensure(:stopped) + .with_provider('systemd') + .with_name('puppet-run.timer') + .with_enable(false) + end + + it { is_expected.to contain_file('/etc/systemd/system/puppet-run.timer').with_ensure(:absent) } + it { is_expected.to contain_file('/etc/systemd/system/puppet-run.service').with_ensure(:absent) } + else + it { is_expected.not_to contain_service('puppet-run.timer') } + it { is_expected.not_to contain_file('/etc/systemd/system/puppet-run.timer') } + it { is_expected.not_to contain_file('/etc/systemd/system/puppet-run.service') } + it { is_expected.not_to contain_exec('systemctl-daemon-reload-puppet') } end end describe 'set prerun_command will be included in config' do - let(:pre_condition) { "class {'puppet': agent => true, prerun_command => '/my/prerun'}" } - it do - should contain_puppet__config__agent('prerun_command').with({'value' => '/my/prerun'}) + let :params do + super().merge(prerun_command: '/my/prerun') end + + it { is_expected.to contain_puppet__config__agent('prerun_command').with_value('/my/prerun') } end describe 'set postrun_command will be included in config' do - let(:pre_condition) { "class {'puppet': agent => true, postrun_command => '/my/postrun'}" } - it do - should contain_puppet__config__agent('postrun_command').with({'value' => '/my/postrun'}) + let :params do + super().merge(postrun_command: '/my/postrun') end + + it { is_expected.to contain_puppet__config__agent('postrun_command').with_value('/my/postrun') } end describe 'with additional settings' do - let :pre_condition do - "class {'puppet': - agent_additional_settings => {ignoreschedules => true}, - }" + let :params do + super().merge(agent_additional_settings: { 'ignoreschedules' => true }) end - it 'should configure puppet.conf' do - should contain_puppet__config__agent('ignoreschedules').with({'value' => 'true'}) + it { is_expected.to contain_puppet__config__agent('ignoreschedules').with_value('true') } + end + + context 'manage_packages' do + describe 'when manage_packages => false' do + let :params do + super().merge(manage_packages: false) + end + + it { is_expected.not_to contain_package('puppet-agent') } + end + + describe "when manage_packages => 'agent'" do + let :params do + super().merge(manage_packages: 'agent') + end + + it { is_expected.to contain_package('puppet-agent') } + end + + describe "when manage_packages => 'server'" do + let :params do + super().merge(manage_packages: 'server') + end + + it { is_expected.not_to contain_package('puppet-agent') } end end + context 'runmode' do + describe 'when runmode => cron' do + let :params do + super().merge(runmode: 'cron') + end + + case os + when /\A(windows|archlinux)/ + it { is_expected.to raise_error(Puppet::Error, /Runmode of cron not supported on #{facts[:kernel]} operating systems!/) } + when /\Adebian-/, /\A(redhat|centos|scientific)-7/, /\Afedora-/, /\Aubuntu-(16|18)/ + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat__fragment('puppet.conf_agent') } + if facts[:osfamily] == 'Debian' + it do + is_expected.to contain_augeas('puppet::set_start') + .with_context('/files/etc/default/puppet') + .with_changes('set START no') + .with_incl('/etc/default/puppet') + .with_lens('Shellvars.lns') + end + it { is_expected.to contain_file('/var/lib/puppet/state/agent_disabled.lock').with_ensure(:absent) } + end + + it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(true) } + it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(false) } + it do + is_expected.to contain_service('puppet') + .with_ensure('stopped') + .with_name('puppet') + .with_hasstatus('true') + .with_enable('false') + end + it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(false) } + it { is_expected.to contain_service('puppet-run.timer').with_ensure(:stopped) } + it do + is_expected.to contain_cron('puppet') + .with_command("#{bindir}/puppet agent --config #{confdir}/puppet.conf --onetime --no-daemonize") + .with_user('root') + .with_minute(%w[10 40]) + .with_hour('*') + end + else + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(true) } + it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(false) } + it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(false) } + it { is_expected.not_to contain_service('puppet-run.timer') } + it do + is_expected.to contain_cron('puppet') + .with_command("#{bindir}/puppet agent --config #{confdir}/puppet.conf --onetime --no-daemonize") + .with_user('root') + .with_minute(%w[10 40]) + .with_hour('*') + end + end + end + + describe 'when runmode => systemd.timer' do + let :params do + super().merge(runmode: 'systemd.timer') + end + + case os + when /\Adebian-/, /\A(redhat|centos|scientific)-7/, /\Afedora-/, /\Aubuntu-(16|18)/, /\Aarchlinux-/ + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(false) } + it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(false) } + it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(true) } + it { is_expected.to contain_service('puppet-run.timer').with_ensure(:running) } + + it do + is_expected.to contain_file('/etc/systemd/system/puppet-run.timer') + .with_content(/.*OnCalendar\=\*-\*-\* \*\:10,40:00.*/) + end + + it do + is_expected.to contain_file('/etc/systemd/system/puppet-run.timer') + .with_content(/^RandomizedDelaySec\=0$/) + end + + it do + is_expected.to contain_file('/etc/systemd/system/puppet-run.service') + .with_content(%r{.*ExecStart=#{bindir}/puppet agent --config #{confdir}/puppet.conf --onetime --no-daemonize.*}) + end + + it do + is_expected.to contain_exec('systemctl-daemon-reload-puppet') + .with_refreshonly(true) + .with_command('systemctl daemon-reload') + end + + it do + is_expected.to contain_service('puppet-run.timer') + .with_provider('systemd') + .with_ensure('running') + .with_name('puppet-run.timer') + .with_enable('true') + end + else + it { is_expected.to raise_error(Puppet::Error, /Runmode of systemd.timer not supported on #{facts[:kernel]} operating systems!/) } + end + end + + describe 'when runmode => none' do + let :params do + super().merge(runmode: 'none') + end + + # For windows we specify a package provider which doesn't compile + if facts[:osfamily] != 'windows' + it { is_expected.to compile.with_all_deps } + end + it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(false) } + it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(false) } + it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(false) } + + case os + when /\Adebian-/, /\A(redhat|centos|scientific)-7/, /\Afedora-/, /\Aubuntu-(16|18)/, /\Aarchlinux-/ + it { is_expected.to contain_service('puppet-run.timer').with_ensure(:stopped) } + else + it { is_expected.not_to contain_service('puppet-run.timer') } + end + end + end + + describe 'when unavailable_runmodes => ["cron"]' do + let :params do + super().merge(unavailable_runmodes: ['cron']) + end + + it { is_expected.not_to contain_cron('puppet') } + end + + describe 'with custom service_name' do + let :params do + super().merge(service_name: 'pe-puppet') + end + + it { is_expected.to contain_service('puppet').with_name('pe-puppet') } + end + + context 'with remove_lock => false' do + let :params do + super().merge(remove_lock: false) + end + + it { should_not contain_file('/var/lib/puppet/state/agent_disabled.lock') } + end + + context 'with client_certname => false' do + let :params do + super().merge(client_certname: false) + end + + it { is_expected.not_to contain_puppet__config__agent('certname') } + end + + context 'with report => false' do + let :params do + super().merge(report: false) + end + + it { is_expected.to contain_puppet__config__agent('report').with_value('false') } + end end end end