Revision b969c150
Added by Mickaël Canévet over 9 years ago
spec/classes/foreman_cli_spec.rb | ||
---|---|---|
require 'spec_helper'
|
||
|
||
describe 'foreman::cli' do
|
||
context 'standalone with parameters' do
|
||
let(:params) do {
|
||
'foreman_url' => 'http://example.com',
|
||
'username' => 'joe',
|
||
'password' => 'secret',
|
||
} end
|
||
|
||
it { should contain_package('foreman-cli').with_ensure('installed') }
|
||
|
||
describe '/etc/hammer/cli.modules.d/foreman.yml' do
|
||
it 'should contain settings' do
|
||
content = subject.resource('file', '/etc/hammer/cli.modules.d/foreman.yml').send(:parameters)[:content]
|
||
content.split("\n").reject { |c| c =~ /(^\s*#|^$)/ }.should == [
|
||
":foreman:",
|
||
" :enable_module: true",
|
||
" :host: 'http://example.com'",
|
||
]
|
||
on_supported_os.each do |os, facts|
|
||
context "on #{os}" do
|
||
let(:facts) do
|
||
facts.merge({
|
||
:concat_basedir => '/tmp',
|
||
})
|
||
end
|
||
end
|
||
|
||
describe '/root/.hammer/cli.modules.d/foreman.yml' do
|
||
it { should contain_file('/root/.hammer/cli.modules.d/foreman.yml').with_replace(false) }
|
||
context 'standalone with parameters' do
|
||
let(:params) do {
|
||
'foreman_url' => 'http://example.com',
|
||
'username' => 'joe',
|
||
'password' => 'secret',
|
||
} end
|
||
|
||
it 'should contain settings' do
|
||
content = subject.resource('file', '/root/.hammer/cli.modules.d/foreman.yml').send(:parameters)[:content]
|
||
content.split("\n").reject { |c| c =~ /(^\s*#|^$)/ }.should == [
|
||
":foreman:",
|
||
" :username: 'joe'",
|
||
" :password: 'secret'",
|
||
" :refresh_cache: false",
|
||
" :request_timeout: 120",
|
||
]
|
||
end
|
||
end
|
||
it { should contain_package('foreman-cli').with_ensure('installed') }
|
||
|
||
describe 'with manage_root_config=false' do
|
||
let(:params) do {
|
||
'foreman_url' => 'http://example.com',
|
||
'username' => 'joe',
|
||
'password' => 'secret',
|
||
'manage_root_config' => false,
|
||
} end
|
||
describe '/etc/hammer/cli.modules.d/foreman.yml' do
|
||
it 'should contain settings' do
|
||
content = subject.resource('file', '/etc/hammer/cli.modules.d/foreman.yml').send(:parameters)[:content]
|
||
content.split("\n").reject { |c| c =~ /(^\s*#|^$)/ }.should == [
|
||
":foreman:",
|
||
" :enable_module: true",
|
||
" :host: 'http://example.com'",
|
||
]
|
||
end
|
||
end
|
||
|
||
it { should_not contain_file('/root/.hammer') }
|
||
it { should_not contain_file('/root/.hammer/cli.modules.d/foreman.yml') }
|
||
end
|
||
end
|
||
describe '/root/.hammer/cli.modules.d/foreman.yml' do
|
||
it { should contain_file('/root/.hammer/cli.modules.d/foreman.yml').with_replace(false) }
|
||
|
||
context 'with foreman' do
|
||
let :facts do {
|
||
:concat_basedir => '/tmp',
|
||
:operatingsystemrelease => '6.4',
|
||
:operatingsystem=> 'RedHat',
|
||
:osfamily => 'RedHat',
|
||
:fqdn => 'foreman.example.com',
|
||
} end
|
||
it 'should contain settings' do
|
||
content = subject.resource('file', '/root/.hammer/cli.modules.d/foreman.yml').send(:parameters)[:content]
|
||
content.split("\n").reject { |c| c =~ /(^\s*#|^$)/ }.should == [
|
||
":foreman:",
|
||
" :username: 'joe'",
|
||
" :password: 'secret'",
|
||
" :refresh_cache: false",
|
||
" :request_timeout: 120",
|
||
]
|
||
end
|
||
end
|
||
|
||
let :pre_condition do
|
||
"class { 'foreman':
|
||
admin_username => 'joe',
|
||
admin_password => 'secret',
|
||
}"
|
||
end
|
||
describe 'with manage_root_config=false' do
|
||
let(:params) do {
|
||
'foreman_url' => 'http://example.com',
|
||
'username' => 'joe',
|
||
'password' => 'secret',
|
||
'manage_root_config' => false,
|
||
} end
|
||
|
||
it { should contain_package('foreman-cli').with_ensure('installed') }
|
||
|
||
describe '/etc/hammer/cli.modules.d/foreman.yml' do
|
||
it 'should contain settings from foreman' do
|
||
content = subject.resource('file', '/etc/hammer/cli.modules.d/foreman.yml').send(:parameters)[:content]
|
||
content.split("\n").reject { |c| c =~ /(^\s*#|^$)/ }.should == [
|
||
":foreman:",
|
||
" :enable_module: true",
|
||
" :host: 'https://#{facts[:fqdn]}'",
|
||
]
|
||
it { should_not contain_file('/root/.hammer') }
|
||
it { should_not contain_file('/root/.hammer/cli.modules.d/foreman.yml') }
|
||
end
|
||
end
|
||
end
|
||
|
||
describe '/root/.hammer/cli.modules.d/foreman.yml' do
|
||
it 'should contain settings from foreman' do
|
||
content = subject.resource('file', '/root/.hammer/cli.modules.d/foreman.yml').send(:parameters)[:content]
|
||
content.split("\n").reject { |c| c =~ /(^\s*#|^$)/ }.should == [
|
||
":foreman:",
|
||
" :username: 'joe'",
|
||
" :password: 'secret'",
|
||
" :refresh_cache: false",
|
||
" :request_timeout: 120",
|
||
]
|
||
context 'with foreman' do
|
||
|
||
let :pre_condition do
|
||
"class { 'foreman':
|
||
admin_username => 'joe',
|
||
admin_password => 'secret',
|
||
}"
|
||
end
|
||
|
||
it { should contain_package('foreman-cli').with_ensure('installed') }
|
||
|
||
describe '/etc/hammer/cli.modules.d/foreman.yml' do
|
||
it 'should contain settings from foreman' do
|
||
content = subject.resource('file', '/etc/hammer/cli.modules.d/foreman.yml').send(:parameters)[:content]
|
||
content.split("\n").reject { |c| c =~ /(^\s*#|^$)/ }.should == [
|
||
":foreman:",
|
||
" :enable_module: true",
|
||
" :host: 'https://#{facts[:fqdn]}'",
|
||
]
|
||
end
|
||
end
|
||
|
||
describe '/root/.hammer/cli.modules.d/foreman.yml' do
|
||
it 'should contain settings from foreman' do
|
||
content = subject.resource('file', '/root/.hammer/cli.modules.d/foreman.yml').send(:parameters)[:content]
|
||
content.split("\n").reject { |c| c =~ /(^\s*#|^$)/ }.should == [
|
||
":foreman:",
|
||
" :username: 'joe'",
|
||
" :password: 'secret'",
|
||
" :refresh_cache: false",
|
||
" :request_timeout: 120",
|
||
]
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
spec/classes/foreman_config_ipa_spec.rb | ||
---|---|---|
require 'spec_helper'
|
||
|
||
|
||
describe 'foreman::config' do
|
||
let :default_facts do
|
||
{
|
||
:concat_basedir => '/tmp',
|
||
:interfaces => '',
|
||
}
|
||
end
|
||
|
||
context 'on redhat' do
|
||
let :operating_system_facts do
|
||
default_facts.merge({
|
||
:operatingsystem => 'RedHat',
|
||
:operatingsystemrelease => '6.4',
|
||
:osfamily => 'RedHat',
|
||
})
|
||
end
|
||
let :facts do
|
||
operating_system_facts
|
||
end
|
||
|
||
describe 'without parameters' do
|
||
let :pre_condition do
|
||
"class {'foreman':}"
|
||
end
|
||
|
||
it('should not integrate ipa') { should_not contain_exec('ipa-getkeytab') }
|
||
end
|
||
|
||
# we don't allow ipa on non-passenger env
|
||
describe 'with freeipa enabled' do
|
||
let :pre_condition do
|
||
"class {'foreman':
|
||
passenger => false,
|
||
ipa_authentication => true,
|
||
}"
|
||
end
|
||
|
||
it "will fail" do
|
||
expect {
|
||
should contain_exec('ipa-getkeytab')
|
||
}.to raise_error(Puppet::Error, /External authentication via IPA can only be enabled when passenger is used/)
|
||
end
|
||
end
|
||
|
||
describe 'with passenger and ipa' do
|
||
let :pre_condition do
|
||
"class {'foreman':
|
||
passenger => true,
|
||
ipa_authentication => true,
|
||
}"
|
||
end
|
||
on_supported_os.each do |os, facts|
|
||
if facts[:osfamily] == 'RedHat'
|
||
context "on #{os}" do
|
||
let(:facts) do
|
||
facts.merge({
|
||
:concat_basedir => '/tmp',
|
||
:interfaces => '',
|
||
})
|
||
end
|
||
|
||
describe 'not IPA-enrolled system' do
|
||
describe 'ipa_server fact missing' do
|
||
let :facts do
|
||
operating_system_facts.merge({:default_ipa_server => ''})
|
||
end
|
||
it "will fail" do
|
||
expect {
|
||
should contain_exec('ipa-getkeytab')
|
||
}.to raise_error(Puppet::Error, /The system does not seem to be IPA-enrolled/)
|
||
describe 'without parameters' do
|
||
let :pre_condition do
|
||
"class {'foreman':}"
|
||
end
|
||
|
||
it('should not integrate ipa') { should_not contain_exec('ipa-getkeytab') }
|
||
end
|
||
|
||
describe 'default_ipa_realm fact missing' do
|
||
let :facts do
|
||
operating_system_facts.merge({:default_ipa_realm => ''})
|
||
# we don't allow ipa on non-passenger env
|
||
describe 'with freeipa enabled' do
|
||
let :pre_condition do
|
||
"class {'foreman':
|
||
passenger => false,
|
||
ipa_authentication => true,
|
||
}"
|
||
end
|
||
|
||
it "will fail" do
|
||
expect {
|
||
should contain_exec('ipa-getkeytab')
|
||
}.to raise_error(Puppet::Error, /The system does not seem to be IPA-enrolled/)
|
||
}.to raise_error(Puppet::Error, /External authentication via IPA can only be enabled when passenger is used/)
|
||
end
|
||
end
|
||
end
|
||
|
||
describe 'enrolled system' do
|
||
let :enrolled_facts do
|
||
operating_system_facts.merge({:default_ipa_server => 'ipa.example.com', :default_ipa_realm => 'REALM'})
|
||
end
|
||
|
||
let :facts do
|
||
enrolled_facts
|
||
end
|
||
|
||
it { should contain_exec('ipa-getkeytab') }
|
||
|
||
describe 'on non-selinux' do
|
||
let :facts do
|
||
enrolled_facts.merge(:selinux => 'false')
|
||
describe 'with passenger and ipa' do
|
||
let :pre_condition do
|
||
"class {'foreman':
|
||
passenger => true,
|
||
ipa_authentication => true,
|
||
}"
|
||
end
|
||
|
||
it { should_not contain_exec('setsebool httpd_dbus_sssd') }
|
||
end
|
||
|
||
describe 'on selinux system but disabled by user' do
|
||
let :facts do
|
||
enrolled_facts.merge(:selinux => 'true')
|
||
describe 'not IPA-enrolled system' do
|
||
describe 'ipa_server fact missing' do
|
||
it "will fail" do
|
||
expect {
|
||
should contain_exec('ipa-getkeytab')
|
||
}.to raise_error(Puppet::Error, /The system does not seem to be IPA-enrolled/)
|
||
end
|
||
end
|
||
|
||
describe 'default_ipa_realm fact missing' do
|
||
it "will fail" do
|
||
expect {
|
||
should contain_exec('ipa-getkeytab')
|
||
}.to raise_error(Puppet::Error, /The system does not seem to be IPA-enrolled/)
|
||
end
|
||
end
|
||
end
|
||
|
||
let :pre_condition do
|
||
"class {'foreman':
|
||
describe 'enrolled system' do
|
||
let :facts do
|
||
facts.merge({
|
||
:concat_basedir => '/tmp',
|
||
:interfaces => '',
|
||
:default_ipa_server => 'ipa.example.com',
|
||
:default_ipa_realm => 'REALM',
|
||
})
|
||
end
|
||
|
||
it { should contain_exec('ipa-getkeytab') }
|
||
|
||
describe 'on non-selinux' do
|
||
let :facts do
|
||
facts.merge({
|
||
:concat_basedir => '/tmp',
|
||
:interfaces => '',
|
||
:default_ipa_server => 'ipa.example.com',
|
||
:default_ipa_realm => 'REALM',
|
||
:selinux => 'false',
|
||
})
|
||
end
|
||
|
||
it { should_not contain_exec('setsebool httpd_dbus_sssd') }
|
||
end
|
||
|
||
describe 'on selinux system but disabled by user' do
|
||
let :facts do
|
||
facts.merge({
|
||
:concat_basedir => '/tmp',
|
||
:interfaces => '',
|
||
:default_ipa_server => 'ipa.example.com',
|
||
:default_ipa_realm => 'REALM',
|
||
:selinux => 'true',
|
||
})
|
||
end
|
||
|
||
let :pre_condition do
|
||
"class {'foreman':
|
||
passenger => true,
|
||
ipa_authentication => true,
|
||
selinux => false,
|
||
}"
|
||
end
|
||
|
||
it { should_not contain_exec('setsebool httpd_dbus_sssd') }
|
||
end
|
||
|
||
describe 'on selinux system with enabled by user' do
|
||
let :facts do
|
||
enrolled_facts.merge(:selinux => 'true')
|
||
end
|
||
|
||
let :pre_condition do
|
||
"class {'foreman':
|
||
end
|
||
|
||
it { should_not contain_exec('setsebool httpd_dbus_sssd') }
|
||
end
|
||
|
||
describe 'on selinux system with enabled by user' do
|
||
let :facts do
|
||
facts.merge({
|
||
:concat_basedir => '/tmp',
|
||
:interfaces => '',
|
||
:default_ipa_server => 'ipa.example.com',
|
||
:default_ipa_realm => 'REALM',
|
||
:selinux => 'true',
|
||
})
|
||
end
|
||
|
||
let :pre_condition do
|
||
"class {'foreman':
|
||
passenger => true,
|
||
ipa_authentication => true,
|
||
selinux => true,
|
||
}"
|
||
end
|
||
|
||
it { should contain_exec('setsebool httpd_dbus_sssd') }
|
||
end
|
||
|
||
describe 'on selinux' do
|
||
let :facts do
|
||
facts.merge({
|
||
:concat_basedir => '/tmp',
|
||
:interfaces => '',
|
||
:default_ipa_server => 'ipa.example.com',
|
||
:default_ipa_realm => 'REALM',
|
||
:selinux => 'true',
|
||
})
|
||
end
|
||
|
||
it { should contain_exec('setsebool httpd_dbus_sssd') }
|
||
end
|
||
end
|
||
|
||
it { should contain_exec('setsebool httpd_dbus_sssd') }
|
||
end
|
||
|
||
describe 'on selinux' do
|
||
let :facts do
|
||
enrolled_facts.merge(:selinux => 'true')
|
||
end
|
||
|
||
it { should contain_exec('setsebool httpd_dbus_sssd') }
|
||
end
|
||
end
|
||
end
|
spec/classes/foreman_database_spec.rb | ||
---|---|---|
require 'spec_helper'
|
||
|
||
describe 'foreman::install' do
|
||
let :default_facts do
|
||
{
|
||
:concat_basedir => '/tmp',
|
||
:interfaces => '',
|
||
}
|
||
end
|
||
|
||
context 'RedHat' do
|
||
let :facts do
|
||
default_facts.merge({
|
||
:operatingsystem => 'RedHat',
|
||
:operatingsystemrelease => '6.4',
|
||
:osfamily => 'RedHat',
|
||
})
|
||
end
|
||
|
||
describe 'without parameters' do
|
||
let :pre_condition do
|
||
"class {'foreman':}"
|
||
on_supported_os.each do |os, facts|
|
||
context "on #{os}" do
|
||
let(:facts) do
|
||
facts.merge({
|
||
:concat_basedir => '/tmp',
|
||
:interfaces => '',
|
||
})
|
||
end
|
||
|
||
it { should contain_class('foreman::database::postgresql') }
|
||
describe 'without parameters' do
|
||
let :pre_condition do
|
||
"class {'foreman':}"
|
||
end
|
||
|
||
it { should contain_foreman_config_entry('db_pending_migration') }
|
||
it { should contain_foreman__rake('db:migrate') }
|
||
it { should contain_foreman_config_entry('db_pending_seed') }
|
||
it { should contain_foreman__rake('db:seed') }
|
||
it { should contain_foreman__rake('apipie:cache') }
|
||
end
|
||
it { should contain_class('foreman::database::postgresql') }
|
||
|
||
describe 'with seed parameters' do
|
||
let :pre_condition do
|
||
"class {'foreman':
|
||
it { should contain_foreman_config_entry('db_pending_migration') }
|
||
it { should contain_foreman__rake('db:migrate') }
|
||
it { should contain_foreman_config_entry('db_pending_seed') }
|
||
it { should contain_foreman__rake('db:seed') }
|
||
it { should contain_foreman__rake('apipie:cache') }
|
||
end
|
||
|
||
describe 'with seed parameters' do
|
||
let :pre_condition do
|
||
"class {'foreman':
|
||
admin_username => 'joe',
|
||
admin_password => 'secret',
|
||
}"
|
||
end
|
||
end
|
||
|
||
it {
|
||
should contain_foreman__rake('db:seed').
|
||
it {
|
||
should contain_foreman__rake('db:seed').
|
||
with_environment({
|
||
'SEED_ADMIN_USER' => 'joe',
|
||
'SEED_ADMIN_PASSWORD' => 'secret',
|
||
})
|
||
}
|
||
end
|
||
end
|
||
|
||
context 'on debian' do
|
||
let :facts do
|
||
default_facts.merge({
|
||
:operatingsystem => 'Debian',
|
||
:operatingsystemrelease => 'wheezy',
|
||
:osfamily => 'Debian',
|
||
})
|
||
end
|
||
|
||
describe 'without parameters' do
|
||
let :pre_condition do
|
||
"class {'foreman':}"
|
||
}
|
||
end
|
||
|
||
it { should contain_class('foreman::database::postgresql') }
|
||
|
||
it { should contain_foreman_config_entry('db_pending_migration') }
|
||
it { should contain_foreman__rake('db:migrate') }
|
||
it { should contain_foreman_config_entry('db_pending_seed') }
|
||
it { should contain_foreman__rake('db:seed') }
|
||
it { should contain_foreman__rake('apipie:cache') }
|
||
end
|
||
end
|
||
end
|
spec/classes/foreman_install_repos_extra_spec.rb | ||
---|---|---|
require 'spec_helper'
|
||
|
||
describe 'foreman::install::repos::extra' do
|
||
describe 'when EL repos are fully enabled' do
|
||
let(:params) do
|
||
{
|
||
:configure_scl_repo => true,
|
||
:configure_epel_repo => true,
|
||
}
|
||
end
|
||
|
||
context 'RHEL 6' do
|
||
let :facts do
|
||
{
|
||
:operatingsystem => 'RedHat',
|
||
:operatingsystemrelease => '6.4',
|
||
:osfamily => 'RedHat',
|
||
}
|
||
on_supported_os.each do |os, facts|
|
||
context "on #{os}" do
|
||
let(:facts) do
|
||
facts.merge({
|
||
:concat_basedir => '/tmp',
|
||
})
|
||
end
|
||
|
||
it { should contain_yumrepo('epel').with({
|
||
:mirrorlist => 'https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch',
|
||
:gpgcheck => 1,
|
||
:gpgkey => 'https://fedoraproject.org/static/0608B895.txt',
|
||
}) }
|
||
it { should contain_package('foreman-release-scl') }
|
||
end
|
||
|
||
context 'RHEL 7' do
|
||
let :facts do
|
||
{
|
||
:operatingsystem => 'RedHat',
|
||
:operatingsystemrelease => '7.0',
|
||
:osfamily => 'RedHat',
|
||
}
|
||
end
|
||
describe 'when repos are fully enabled' do
|
||
case facts[:osfamily]
|
||
when 'Debian'
|
||
if facts[:operatingsystem] == 'Ubuntu'
|
||
let(:params) do
|
||
{
|
||
:configure_brightbox_repo => true,
|
||
}
|
||
end
|
||
|
||
it { should contain_yumrepo('epel').with({
|
||
:mirrorlist => 'https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch',
|
||
:gpgcheck => 1,
|
||
:gpgkey => 'https://fedoraproject.org/static/352C64E5.txt',
|
||
}) }
|
||
it { should contain_package('foreman-release-scl') }
|
||
end
|
||
end
|
||
it { should contain_class('apt') }
|
||
it { should contain_apt__ppa('ppa:brightbox/ruby-ng') }
|
||
it { should contain_alternatives('ruby') }
|
||
it { should contain_alternatives('gem') }
|
||
end
|
||
when 'RedHat'
|
||
if facts[:operatingsystem] != 'Fedora'
|
||
let(:params) do
|
||
{
|
||
:configure_scl_repo => true,
|
||
:configure_epel_repo => true,
|
||
}
|
||
end
|
||
|
||
describe 'when deb repos are fully enabled' do
|
||
let(:params) do
|
||
{
|
||
:configure_brightbox_repo => true,
|
||
}
|
||
end
|
||
let(:gpgkey) do
|
||
case facts[:operatingsystemmajrelease]
|
||
when '6'
|
||
'0608B895'
|
||
when '7'
|
||
'352C64E5'
|
||
end
|
||
end
|
||
|
||
context 'Ubuntu' do
|
||
let :facts do
|
||
{
|
||
:lsbdistid => 'ubuntu',
|
||
:lsbdistcodename => 'precise',
|
||
:operatingsystem => 'Ubuntu',
|
||
:operatingsystemrelease => '12.04',
|
||
:osfamily => 'Debian',
|
||
}
|
||
it { should contain_yumrepo('epel').with({
|
||
:mirrorlist => "https://mirrors.fedoraproject.org/metalink?repo=epel-#{facts[:operatingsystemmajrelease]}&arch=$basearch",
|
||
:gpgcheck => 1,
|
||
:gpgkey => "https://fedoraproject.org/static/#{gpgkey}.txt",
|
||
}) }
|
||
it { should contain_package('foreman-release-scl') }
|
||
end
|
||
end
|
||
end
|
||
|
||
it { should contain_class('apt') }
|
||
it { should contain_apt__ppa('ppa:brightbox/ruby-ng') }
|
||
it { should contain_alternatives('ruby') }
|
||
it { should contain_alternatives('gem') }
|
||
end
|
||
end
|
||
|
||
describe 'when fully disabled' do
|
||
let(:params) do
|
||
{
|
||
:configure_scl_repo => false,
|
||
:configure_epel_repo => false,
|
||
:configure_brightbox_repo => false,
|
||
}
|
||
end
|
||
describe 'when fully disabled' do
|
||
let(:params) do
|
||
{
|
||
:configure_scl_repo => false,
|
||
:configure_epel_repo => false,
|
||
:configure_brightbox_repo => false,
|
||
}
|
||
end
|
||
|
||
context 'RHEL 6' do
|
||
let :facts do
|
||
{
|
||
:operatingsystem => 'RedHat',
|
||
:operatingsystemrelease => '6.4',
|
||
:osfamily => 'RedHat',
|
||
}
|
||
it { should_not contain_yumrepo('epel') }
|
||
it { should_not contain_package('foreman-release-scl') }
|
||
it { should_not contain_class('apt') }
|
||
it { should have_apt__ppa_resource_count(0) }
|
||
end
|
||
|
||
it { should_not contain_yumrepo('epel') }
|
||
it { should_not contain_package('foreman-release-scl') }
|
||
it { should_not contain_class('apt') }
|
||
it { should have_apt__ppa_resource_count(0) }
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
Use rspec-puppet-facts