Revision dacc457b
Added by Ewoud Kohl van Wijngaarden almost 9 years ago
manifests/rake.pp | ||
---|---|---|
# Run a Foreman rake task when notified
|
||
define foreman::rake($environment = {}, $timeout = undef) {
|
||
define foreman::rake(
|
||
$environment = {},
|
||
$timeout = undef,
|
||
$user = $::foreman::user,
|
||
$app_root = $::foreman::app_root,
|
||
) {
|
||
validate_hash($environment)
|
||
|
||
# https://github.com/rodjek/puppet-lint/issues/327
|
||
# lint:ignore:arrow_alignment
|
||
exec { "foreman-rake-${title}":
|
||
command => "/usr/sbin/foreman-rake ${title}",
|
||
user => $::foreman::user,
|
||
environment => sort(join_keys_to_values(merge({'HOME' => $::foreman::app_root}, $environment), '=')),
|
||
user => $user,
|
||
environment => sort(join_keys_to_values(merge({'HOME' => $app_root}, $environment), '=')),
|
||
logoutput => 'on_failure',
|
||
refreshonly => true,
|
||
timeout => $timeout,
|
manifests/service.pp | ||
---|---|---|
# Configure the foreman service
|
||
class foreman::service {
|
||
case $::foreman::passenger {
|
||
class foreman::service(
|
||
$passenger = $::foreman::passenger,
|
||
$app_root = $::foreman::app_root,
|
||
) {
|
||
case $passenger {
|
||
true: {
|
||
exec {'restart_foreman':
|
||
command => "/bin/touch ${foreman::app_root}/tmp/restart.txt",
|
||
command => "/bin/touch ${app_root}/tmp/restart.txt",
|
||
refreshonly => true,
|
||
cwd => $::foreman::app_root,
|
||
cwd => $app_root,
|
||
path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
|
||
}
|
||
|
spec/classes/foreman_database_spec.rb | ||
---|---|---|
require 'spec_helper'
|
||
|
||
describe 'foreman::install' do
|
||
describe 'foreman::database' do
|
||
|
||
on_supported_os.each do |os, facts|
|
||
context "on #{os}" do
|
spec/classes/foreman_service_spec.rb | ||
---|---|---|
require 'spec_helper'
|
||
|
||
describe 'foreman::install' do
|
||
let :default_facts do
|
||
{
|
||
:concat_basedir => '/tmp',
|
||
:interfaces => '',
|
||
}
|
||
end
|
||
describe 'foreman::service' do
|
||
|
||
context 'RedHat' do
|
||
context 'with inherited parameters' do
|
||
let :facts do
|
||
default_facts.merge({
|
||
:operatingsystem => 'RedHat',
|
||
:operatingsystemrelease => '6.4',
|
||
:osfamily => 'RedHat',
|
||
})
|
||
on_supported_os['redhat-7-x86_64'].merge({:concat_basedir => '/doesnotexist'})
|
||
end
|
||
|
||
describe 'without parameters' do
|
||
let :pre_condition do
|
||
"class {'foreman':}"
|
||
end
|
||
|
||
it 'should restart passenger' do
|
||
should contain_exec('restart_foreman').with({
|
||
:command => '/bin/touch /usr/share/foreman/tmp/restart.txt',
|
||
:refreshonly => true,
|
||
:cwd => '/usr/share/foreman',
|
||
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
|
||
})
|
||
end
|
||
let :pre_condition do
|
||
'include ::foreman'
|
||
end
|
||
|
||
it { should contain_service('foreman').with({
|
||
'ensure' => 'stopped',
|
||
'enable' => false,
|
||
'hasstatus' => true,
|
||
})}
|
||
it 'should restart passenger' do
|
||
should contain_exec('restart_foreman').with({
|
||
:command => '/bin/touch /usr/share/foreman/tmp/restart.txt',
|
||
:refreshonly => true,
|
||
:cwd => '/usr/share/foreman',
|
||
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
|
||
})
|
||
end
|
||
|
||
describe 'with passenger' do
|
||
let :pre_condition do
|
||
"class {'foreman':
|
||
passenger => true,
|
||
}"
|
||
end
|
||
it { should contain_service('foreman').with({
|
||
'ensure' => 'stopped',
|
||
'enable' => false,
|
||
'hasstatus' => true,
|
||
})}
|
||
end
|
||
|
||
it 'should restart passenger' do
|
||
should contain_exec('restart_foreman').with({
|
||
:command => '/bin/touch /usr/share/foreman/tmp/restart.txt',
|
||
:refreshonly => true,
|
||
:cwd => '/usr/share/foreman',
|
||
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
|
||
})
|
||
end
|
||
context 'with passenger' do
|
||
let :params do
|
||
{
|
||
:passenger => true,
|
||
:app_root => '/usr/share/foreman',
|
||
}
|
||
end
|
||
|
||
it { should contain_service('foreman').with({
|
||
'ensure' => 'stopped',
|
||
'enable' => false,
|
||
'hasstatus' => true,
|
||
})}
|
||
it 'should restart passenger' do
|
||
should contain_exec('restart_foreman').with({
|
||
:command => '/bin/touch /usr/share/foreman/tmp/restart.txt',
|
||
:refreshonly => true,
|
||
:cwd => '/usr/share/foreman',
|
||
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
|
||
})
|
||
end
|
||
|
||
describe 'without passenger' do
|
||
let :pre_condition do
|
||
"class {'foreman':
|
||
passenger => false,
|
||
}"
|
||
end
|
||
it { should contain_service('foreman').with({
|
||
'ensure' => 'stopped',
|
||
'enable' => false,
|
||
'hasstatus' => true,
|
||
})}
|
||
end
|
||
|
||
it 'should not restart passenger' do
|
||
should_not contain_exec('restart_foreman')
|
||
end
|
||
context 'without passenger' do
|
||
let :params do
|
||
{
|
||
:passenger => false,
|
||
:app_root => '/usr/share/foreman',
|
||
}
|
||
end
|
||
|
||
it { should contain_service('foreman').with({
|
||
'ensure' => 'running',
|
||
'enable' => true,
|
||
'hasstatus' => true,
|
||
})}
|
||
it 'should not restart passenger' do
|
||
should_not contain_exec('restart_foreman')
|
||
end
|
||
|
||
it { should contain_service('foreman').with({
|
||
'ensure' => 'running',
|
||
'enable' => true,
|
||
'hasstatus' => true,
|
||
})}
|
||
end
|
||
end
|
spec/defines/foreman_config_passenger_fragment_spec.rb | ||
---|---|---|
describe 'foreman::config::passenger::fragment' do
|
||
let(:title) { 'test' }
|
||
|
||
let :pre_condition do
|
||
'include foreman'
|
||
end
|
||
|
||
on_supported_os.each do |os, facts|
|
||
context "on #{os}" do
|
||
let :facts do
|
||
... | ... | |
'/etc/apache2/conf.d'
|
||
end
|
||
|
||
context 'with default parameters' do
|
||
it { should contain_file("#{confd_dir}/05-foreman.d/test.conf").with_ensure(:absent) }
|
||
it { should contain_file("#{confd_dir}/05-foreman-ssl.d/test.conf").with_ensure(:absent) }
|
||
end
|
||
context 'with ssl turned off' do
|
||
let :pre_condition do
|
||
"class { '::foreman::config::passenger':
|
||
app_root => '/usr/share/foreman',
|
||
ssl => false,
|
||
user => 'foreman',
|
||
prestart => true,
|
||
min_instances => '1',
|
||
start_timeout => '600',
|
||
use_vhost => true,
|
||
}"
|
||
end
|
||
|
||
context 'with content parameter' do
|
||
let :params do
|
||
{ :content => '# config' }
|
||
context 'with default parameters' do
|
||
it { should contain_file("#{confd_dir}/05-foreman.d/test.conf").with_ensure(:absent) }
|
||
it { should contain_file("#{confd_dir}/05-foreman-ssl.d/test.conf").with_ensure(:absent) }
|
||
end
|
||
|
||
it { should contain_file("#{confd_dir}/05-foreman.d/test.conf").with_content('# config') }
|
||
it { should contain_file("#{confd_dir}/05-foreman-ssl.d/test.conf").with_ensure(:absent) }
|
||
context 'with content parameter' do
|
||
let :params do
|
||
{ :content => '# config' }
|
||
end
|
||
|
||
it { should contain_file("#{confd_dir}/05-foreman.d/test.conf").with_content('# config') }
|
||
it { should contain_file("#{confd_dir}/05-foreman-ssl.d/test.conf").with_ensure(:absent) }
|
||
end
|
||
|
||
context 'with ssl_content parameter' do
|
||
let :params do
|
||
{ :ssl_content => '# config' }
|
||
end
|
||
|
||
it { should contain_file("#{confd_dir}/05-foreman.d/test.conf").with_ensure(:absent) }
|
||
it { should contain_file("#{confd_dir}/05-foreman-ssl.d/test.conf").with_ensure(:absent) }
|
||
end
|
||
end
|
||
|
||
context 'with ssl_content parameter' do
|
||
let :params do
|
||
{ :ssl_content => '# config' }
|
||
context 'with ssl turned on' do
|
||
let :pre_condition do
|
||
"class { '::foreman::config::passenger':
|
||
app_root => '/usr/share/foreman',
|
||
ssl => true,
|
||
user => 'foreman',
|
||
prestart => true,
|
||
min_instances => '1',
|
||
start_timeout => '600',
|
||
use_vhost => true,
|
||
}"
|
||
end
|
||
|
||
it { should contain_file("#{confd_dir}/05-foreman.d/test.conf").with_ensure(:absent) }
|
||
it { should contain_file("#{confd_dir}/05-foreman-ssl.d/test.conf").with_content('# config') }
|
||
context 'with ssl_content parameter' do
|
||
let :params do
|
||
{ :ssl_content => '# config' }
|
||
end
|
||
|
||
it { should contain_file("#{confd_dir}/05-foreman.d/test.conf").with_ensure(:absent) }
|
||
it { should contain_file("#{confd_dir}/05-foreman-ssl.d/test.conf").with_content('# config') }
|
||
end
|
||
end
|
||
end
|
||
end
|
spec/defines/foreman_rake_spec.rb | ||
---|---|---|
require 'spec_helper'
|
||
|
||
describe 'foreman::rake' do
|
||
let :default_facts do
|
||
{
|
||
:concat_basedir => '/tmp',
|
||
:interfaces => '',
|
||
}
|
||
end
|
||
|
||
let :pre_condition do
|
||
"class { 'foreman':
|
||
db_manage => false,
|
||
}"
|
||
end
|
||
|
||
let(:title) { 'db:migrate' }
|
||
|
||
context 'on RedHat' do
|
||
let :facts do
|
||
default_facts.merge({
|
||
:operatingsystem => 'RedHat',
|
||
:operatingsystemrelease => '6.4',
|
||
:osfamily => 'RedHat',
|
||
})
|
||
on_supported_os['redhat-7-x86_64']
|
||
end
|
||
|
||
it { should contain_exec('foreman-rake-db:migrate').with({
|
||
'command' => '/usr/sbin/foreman-rake db:migrate',
|
||
'user' => 'foreman',
|
||
'environment' => ['HOME=/usr/share/foreman'],
|
||
'logoutput' => 'on_failure',
|
||
'refreshonly' => true,
|
||
})}
|
||
context 'without parameters' do
|
||
# These parameters are inherited normally, but here we cheat for performance
|
||
let :params do
|
||
{
|
||
:user => 'foreman',
|
||
:app_root => '/usr/share/foreman',
|
||
}
|
||
end
|
||
|
||
it { should contain_exec('foreman-rake-db:migrate').with({
|
||
'command' => '/usr/sbin/foreman-rake db:migrate',
|
||
'user' => 'foreman',
|
||
'environment' => ['HOME=/usr/share/foreman'],
|
||
'logoutput' => 'on_failure',
|
||
'refreshonly' => true,
|
||
})}
|
||
end
|
||
|
||
context 'with environment' do
|
||
let(:params) { {'environment' => {'SEED_USER' => 'admin'}} }
|
||
let :params do
|
||
{
|
||
:environment => {'SEED_USER' => 'admin'},
|
||
:user => 'foreman',
|
||
:app_root => '/usr/share/foreman',
|
||
}
|
||
end
|
||
|
||
it { should contain_exec('foreman-rake-db:migrate').with({
|
||
'command' => '/usr/sbin/foreman-rake db:migrate',
|
||
'user' => 'foreman',
|
||
... | ... | |
end
|
||
|
||
context 'with timeout' do
|
||
let(:params) { {'timeout' => 60 }}
|
||
let :params do
|
||
{
|
||
:timeout => 60,
|
||
:user => 'foreman',
|
||
:app_root => '/usr/share/foreman',
|
||
}
|
||
end
|
||
|
||
it { should contain_exec('foreman-rake-db:migrate').with({
|
||
'command' => '/usr/sbin/foreman-rake db:migrate',
|
||
'user' => 'foreman',
|
Also available in: Unified diff
Do not include foreman as a pre condition