Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(MODULES-6686) Fix puppet_agent_spec tests for Windows #275

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 37 additions & 14 deletions spec/classes/puppet_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ def global_facts(facts, os)
{
:is_pe => true,
}
elsif os =~ /windows/
{
:puppet_agent_appdata => 'C:\\ProgramData',
:puppet_confdir => 'C:\\ProgramData\\Puppetlabs\\puppet\\etc',
:mco_confdir => 'C:\\ProgramData\\Puppetlabs\\mcollective\\etc',
:env_temp_variable => 'C:/tmp',
:puppet_agent_pid => 42,
:puppet_config => Puppet.version < "4.0.0" ? "file:///C:\\\\puppet.conf" : "C:\\puppet.conf",
}
else
{}
end).merge({:servername => 'master.example.vm'})
Expand Down Expand Up @@ -72,7 +81,14 @@ def global_facts(facts, os)
end

context 'supported operating systems' do
on_supported_os.each do |os, facts|
# Due to https://github.com/mcanevet/rspec-puppet-facts/issues/68
# Need to ensure that Windows tests are set last, otherwise puppet tries
# to load windows providers on non-windows platforms in error.
os_list = on_supported_os.select { |os, _x| !(os =~ /windows/) }
windows_list = on_supported_os.select{ |os, _x| os =~ /windows/ }
os_list.merge!(windows_list)

os_list.each do |os, facts|
context "on #{os}" do
let(:facts) do
global_facts(facts, os)
Expand Down Expand Up @@ -118,9 +134,9 @@ def global_facts(facts, os)
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('puppet_agent::install').with_install_options(['OPTION1=value1','OPTION2=value2']) }

# Note this should fail on Windows, but it doesn't get tested due to https://github.com/mcanevet/rspec-puppet-facts/issues/42
# Windows is not seen as a supported OS when `on_supported_os` is used :-(
it { is_expected.to contain_package('puppet-agent').with_install_options(['OPTION1=value1','OPTION2=value2']) }
unless facts[:osfamily] == 'windows'
it { is_expected.to contain_package('puppet-agent').with_install_options(['OPTION1=value1','OPTION2=value2']) }
end
end
end

Expand Down Expand Up @@ -150,22 +166,29 @@ def global_facts(facts, os)
it { is_expected.to contain_package('puppet-agent').with_ensure(deb_package_version) }
elsif facts[:osfamily] == 'Solaris' && (facts[:operatingsystemmajrelease] == '10' || Puppet.version < '4.0.0')
it { is_expected.to contain_package('puppet-agent').with_ensure('present') }
elsif facts[:osfamily] == 'windows'
# Windows does not contain any Package resources
else
it { is_expected.to contain_package('puppet-agent').with_ensure(package_version) }
end

if Puppet.version < "4.0.0" || (os !~ /sles/ && os !~ /solaris/)
it { is_expected.to contain_class('puppet_agent::service').that_requires('Class[puppet_agent::install]') }
unless os =~ /windows/
if Puppet.version < "4.0.0" || (os !~ /sles/ && os !~ /solaris/)
it { is_expected.to contain_class('puppet_agent::service').that_requires('Class[puppet_agent::install]') }
end
end

if params[:service_names].nil? &&
!(facts[:osfamily] == 'Solaris' && facts[:operatingsystemmajrelease] == '11') &&
(Puppet.version < "4.0.0" || os !~ /sles/)
it { is_expected.to contain_service('puppet') }
it { is_expected.to contain_service('mcollective') }
else
it { is_expected.to_not contain_service('puppet') }
it { is_expected.to_not contain_service('mcollective') }
# Windows platform does not use Service resources
unless facts[:osfamily] == 'windows'
if params[:service_names].nil? &&
!(facts[:osfamily] == 'Solaris' && facts[:operatingsystemmajrelease] == '11') &&
(Puppet.version < "4.0.0" || os !~ /sles/)
it { is_expected.to contain_service('puppet') }
it { is_expected.to contain_service('mcollective') }
else
it { is_expected.to_not contain_service('puppet') }
it { is_expected.to_not contain_service('mcollective') }
end
end
end
end
Expand Down