Project

General

Profile

Download (10.1 KB) Statistics
| Branch: | Tag: | Revision:
e56d7a1e Ewoud Kohl van Wijngaarden
require 'spec_helper'


describe 'foreman::config' do
let :default_facts do
{
b22f96ff Ewoud Kohl van Wijngaarden
:concat_basedir => '/tmp',
:interfaces => '',
e56d7a1e Ewoud Kohl van Wijngaarden
}
end

context 'on redhat' do
let :facts do
default_facts.merge({
b22f96ff Ewoud Kohl van Wijngaarden
:operatingsystem => 'RedHat',
:operatingsystemrelease => '6.4',
:osfamily => 'RedHat',
e56d7a1e Ewoud Kohl van Wijngaarden
})
end

describe 'without parameters' do
let :pre_condition do
"class {'foreman':}"
end

d45718b6 Ewoud Kohl van Wijngaarden
it 'should set up the config' do
de8e0319 Mickaël Canévet
should contain_concat__fragment('foreman_settings+01-header.yaml').
d45718b6 Ewoud Kohl van Wijngaarden
with_content(/^:unattended:\s*true$/).
with_content(/^:login:\s*true$/).
with_content(/^:require_ssl:\s*true$/).
with_content(/^:locations_enabled:\s*false$/).
with_content(/^:organizations_enabled:\s*false$/).
with_content(/^:oauth_active:\s*true$/).
5534df90 Dominic Cleal
with_content(/^:oauth_map_users:\s*false$/).
d45718b6 Ewoud Kohl van Wijngaarden
with_content(/^:oauth_consumer_key:\s*\w+$/).
with_content(/^:oauth_consumer_secret:\s*\w+$/).
6ed59a98 Ewoud Kohl van Wijngaarden
with_content(/^:websockets_encrypt:\s*on$/).
a031f0da Dominic Cleal
with_content(/^:logging:\n\s*:level:\s*info$/).
d45718b6 Ewoud Kohl van Wijngaarden
with({})

de8e0319 Mickaël Canévet
should contain_concat('/etc/foreman/settings.yaml').with({
d45718b6 Ewoud Kohl van Wijngaarden
'owner' => 'root',
'group' => 'foreman',
'mode' => '0640',
})
2fe6c233 Ewoud Kohl van Wijngaarden
end
d45718b6 Ewoud Kohl van Wijngaarden
2fe6c233 Ewoud Kohl van Wijngaarden
it 'should configure the database' do
d45718b6 Ewoud Kohl van Wijngaarden
should contain_file('/etc/foreman/database.yml').with({
'owner' => 'root',
'group' => 'foreman',
'mode' => '0640',
'content' => /adapter: postgresql/,
})
2fe6c233 Ewoud Kohl van Wijngaarden
end
d45718b6 Ewoud Kohl van Wijngaarden
2fe6c233 Ewoud Kohl van Wijngaarden
it 'should set the defaults file' do
d45718b6 Ewoud Kohl van Wijngaarden
should contain_file('/etc/sysconfig/foreman').
with_content(/^FOREMAN_HOME=\/usr\/share\/foreman$/).
with_content(/^FOREMAN_USER=foreman$/).
with_content(/^FOREMAN_ENV=production/).
with_content(/^FOREMAN_USE_PASSENGER=1$/).
d03a4a1e Ewoud Kohl van Wijngaarden
with_ensure('file')
d45718b6 Ewoud Kohl van Wijngaarden
end
e56d7a1e Ewoud Kohl van Wijngaarden
2fe6c233 Ewoud Kohl van Wijngaarden
it { should contain_file('/usr/share/foreman').with_ensure('directory') }
e56d7a1e Ewoud Kohl van Wijngaarden
it { should contain_user('foreman').with({
'ensure' => 'present',
dcb8a702 Mathieu Parent
'shell' => '/bin/false',
e56d7a1e Ewoud Kohl van Wijngaarden
'comment' => 'Foreman',
df3b6ffb Greg Sutcliffe
'gid' => 'foreman',
'groups' => ['puppet'],
e56d7a1e Ewoud Kohl van Wijngaarden
'home' => '/usr/share/foreman',
})}

d45718b6 Ewoud Kohl van Wijngaarden
it 'should remove old crons' do
2fe6c233 Ewoud Kohl van Wijngaarden
should contain_cron('clear_session_table').with_ensure('absent')
should contain_cron('expire_old_reports').with_ensure('absent')
should contain_cron('daily summary').with_ensure('absent')
d45718b6 Ewoud Kohl van Wijngaarden
end
e56d7a1e Ewoud Kohl van Wijngaarden
4b5caab2 Dominic Cleal
it 'should contain foreman::config::passenger' do
should contain_class('foreman::config::passenger').
d03a4a1e Ewoud Kohl van Wijngaarden
with_listen_on_interface(nil).
a64c58e8 Dominic Cleal
with_ruby('/usr/bin/tfm-ruby').
4b5caab2 Dominic Cleal
that_comes_before('Anchor[foreman::config_end]')
end
4cad220c Marek Hulan
it { should contain_apache__vhost('foreman').without_custom_fragment(/Alias/) }
e56d7a1e Ewoud Kohl van Wijngaarden
end

describe 'without passenger' do
let :pre_condition do
"class {'foreman':
passenger => false,
}"
end

it { should_not contain_class('foreman::config::passenger') }
end

describe 'with passenger interface' do
let :pre_condition do
"class {'foreman':
passenger_interface => 'lo',
}"
end

it { should contain_class('foreman::config::passenger').with({
:listen_on_interface => 'lo',
})}
end
d45718b6 Ewoud Kohl van Wijngaarden
describe 'with different template parameters' do
let :pre_condition do
"class {'foreman':
unattended => false,
authentication => false,
ssl => false,
locations_enabled => true,
organizations_enabled => true,
oauth_active => false,
5534df90 Dominic Cleal
oauth_map_users => true,
d45718b6 Ewoud Kohl van Wijngaarden
oauth_consumer_key => 'abc',
oauth_consumer_secret => 'def',
}"
end

it 'should have changed parameters' do
de8e0319 Mickaël Canévet
should contain_concat__fragment('foreman_settings+01-header.yaml').
d45718b6 Ewoud Kohl van Wijngaarden
with_content(/^:unattended:\s*false$/).
with_content(/^:login:\s*false$/).
with_content(/^:require_ssl:\s*false$/).
with_content(/^:locations_enabled:\s*true$/).
with_content(/^:organizations_enabled:\s*true$/).
with_content(/^:oauth_active:\s*false$/).
5534df90 Dominic Cleal
with_content(/^:oauth_map_users:\s*true$/).
d45718b6 Ewoud Kohl van Wijngaarden
with_content(/^:oauth_consumer_key:\s*abc$/).
with_content(/^:oauth_consumer_secret:\s*def$/).
with({})
end
end
4cad220c Marek Hulan
describe 'with url ending with trailing slash' do
let :pre_condition do
"class {'foreman':
foreman_url => 'https://example.com/',
}"
end

it { should contain_apache__vhost('foreman').without_custom_fragment(/Alias/) }
end

describe 'with sub-uri' do
let :pre_condition do
"class {'foreman':
foreman_url => 'https://example.com/foreman',
}"
end

it { should contain_apache__vhost('foreman').with_custom_fragment(/Alias \/foreman/) }
end

describe 'with sub-uri ending with trailing slash' do
let :pre_condition do
"class {'foreman':
foreman_url => 'https://example.com/foreman/',
}"
end

it { should contain_apache__vhost('foreman').with_custom_fragment(/Alias \/foreman/) }
end

describe 'with sub-uri ending with more levels' do
let :pre_condition do
"class {'foreman':
foreman_url => 'https://example.com/apps/foreman/',
}"
end

it { should contain_apache__vhost('foreman').with_custom_fragment(/Alias \/apps\/foreman/) }
end
019adcc7 Trey Dockendorf
describe 'with mysql db_type' do
let :pre_condition do
"class { 'foreman':
db_type => 'mysql',
}"
end

it 'should configure the mysql database' do
should contain_file('/etc/foreman/database.yml').with_content(/adapter: mysql2/)
end
end
a031f0da Dominic Cleal
describe 'with loggers' do
let :pre_condition do
"class { 'foreman':
loggers => {'ldap' => true},
}"
end

it 'should set loggers config' do
should contain_concat__fragment('foreman_settings+01-header.yaml').
with_content(/^:loggers:\n\s+:ldap:\n\s+:enabled:\s*true$/)
end
end
27900688 Erik Geiger
describe 'with email configured for SMTP' do
let :pre_condition do
"class {'foreman':
email_delivery_method => 'smtp',
}"
end

it 'should contain email.yaml with SMTP set' do
should contain_file('/etc/foreman/email.yaml').
with_content(/delivery_method: :smtp/).
with_ensure('file')
end
end

describe 'with email configured and authentication set to login' do
let :pre_condition do
"class {'foreman':
email_delivery_method => 'smtp',
email_smtp_authentication => 'login',
}"
end

it 'should contain email.yaml with login authentication' do
should contain_file('/etc/foreman/email.yaml').
with_content(/authentication: :login/).
with_ensure('file')
end
end

describe 'with email configured for sendmail' do
let :pre_condition do
"class {'foreman':
email_delivery_method => 'sendmail',
}"
end

it 'should contain email.yaml with sendmail' do
should contain_file('/etc/foreman/email.yaml').
with_content(/delivery_method: :sendmail/).
with_ensure('file')
end
end
e56d7a1e Ewoud Kohl van Wijngaarden
end

context 'on debian' do
let :facts do
default_facts.merge({
b22f96ff Ewoud Kohl van Wijngaarden
:operatingsystem => 'Debian',
:operatingsystemrelease => 'wheezy',
:osfamily => 'Debian',
e56d7a1e Ewoud Kohl van Wijngaarden
})
end

describe 'without parameters' do
let :pre_condition do
"class {'foreman':}"
end

2fe6c233 Ewoud Kohl van Wijngaarden
it 'should set up settings.yaml' do
de8e0319 Mickaël Canévet
should contain_concat__fragment('foreman_settings+01-header.yaml').
d45718b6 Ewoud Kohl van Wijngaarden
with_content(/^:unattended:\s*true$/).
with_content(/^:login:\s*true$/).
with_content(/^:require_ssl:\s*true$/).
with_content(/^:locations_enabled:\s*false$/).
with_content(/^:organizations_enabled:\s*false$/).
with_content(/^:oauth_active:\s*true$/).
5534df90 Dominic Cleal
with_content(/^:oauth_map_users:\s*false$/).
d45718b6 Ewoud Kohl van Wijngaarden
with_content(/^:oauth_consumer_key:\s*\w+$/).
with_content(/^:oauth_consumer_secret:\s*\w+$/).
a031f0da Dominic Cleal
with_content(/^:websockets_encrypt:\s*on$/).
with_content(/^:logging:\n\s*:level:\s*info$/).
d45718b6 Ewoud Kohl van Wijngaarden
with({})

de8e0319 Mickaël Canévet
should contain_concat('/etc/foreman/settings.yaml').with({
d45718b6 Ewoud Kohl van Wijngaarden
'owner' => 'root',
'group' => 'foreman',
'mode' => '0640',
})
2fe6c233 Ewoud Kohl van Wijngaarden
end
d45718b6 Ewoud Kohl van Wijngaarden
2fe6c233 Ewoud Kohl van Wijngaarden
it 'should configure the database' do
d45718b6 Ewoud Kohl van Wijngaarden
should contain_file('/etc/foreman/database.yml').with({
'owner' => 'root',
'group' => 'foreman',
'mode' => '0640',
'content' => /adapter: postgresql/,
})
2fe6c233 Ewoud Kohl van Wijngaarden
end
d45718b6 Ewoud Kohl van Wijngaarden
2fe6c233 Ewoud Kohl van Wijngaarden
it 'should set the defaults file' do
d45718b6 Ewoud Kohl van Wijngaarden
should contain_file('/etc/default/foreman').
with_content(/^START=no$/).
with_content(/^FOREMAN_HOME=\/usr\/share\/foreman$/).
with_content(/^FOREMAN_USER=foreman$/).
with_content(/^FOREMAN_ENV=production/).
d03a4a1e Ewoud Kohl van Wijngaarden
with_ensure('file')
d45718b6 Ewoud Kohl van Wijngaarden
end
e56d7a1e Ewoud Kohl van Wijngaarden
2fe6c233 Ewoud Kohl van Wijngaarden
it { should contain_file('/usr/share/foreman').with_ensure('directory') }
e56d7a1e Ewoud Kohl van Wijngaarden
it { should contain_user('foreman').with({
'ensure' => 'present',
dcb8a702 Mathieu Parent
'shell' => '/bin/false',
e56d7a1e Ewoud Kohl van Wijngaarden
'comment' => 'Foreman',
2fe6c233 Ewoud Kohl van Wijngaarden
'gid' => 'foreman',
'groups' => ['puppet'],
e56d7a1e Ewoud Kohl van Wijngaarden
'home' => '/usr/share/foreman',
})}

d45718b6 Ewoud Kohl van Wijngaarden
it 'should remove old crons' do
2fe6c233 Ewoud Kohl van Wijngaarden
should contain_cron('clear_session_table').with_ensure('absent')
should contain_cron('expire_old_reports').with_ensure('absent')
should contain_cron('daily summary').with_ensure('absent')
d45718b6 Ewoud Kohl van Wijngaarden
end
e56d7a1e Ewoud Kohl van Wijngaarden
it { should contain_class('foreman::config::passenger').with({
d03a4a1e Ewoud Kohl van Wijngaarden
:listen_on_interface => nil,
4eaab13b Dominic Cleal
:ruby => nil,
e56d7a1e Ewoud Kohl van Wijngaarden
})}
end
end
end