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

Run migrations if there are pending migrations #778

Merged
merged 1 commit into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
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
8 changes: 3 additions & 5 deletions manifests/database.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
contain $db_class

if $::foreman::db_manage_rake {
Class[$db_class] ~> Foreman_config_entry['db_pending_migration']
ehelms marked this conversation as resolved.
Show resolved Hide resolved
Class[$db_class] ~> Foreman::Rake['db:migrate']
}
}

Expand All @@ -21,11 +21,9 @@
'SEED_LOCATION' => $::foreman::initial_location,
}

foreman_config_entry { 'db_pending_migration':
value => false,
dry => true,
foreman::rake { 'db:migrate':
unless => '/usr/sbin/foreman-rake db:abort_if_pending_migrations',
}
~> foreman::rake { 'db:migrate': }
~> foreman_config_entry { 'db_pending_seed':
value => false,
dry => true,
Expand Down
4 changes: 3 additions & 1 deletion manifests/rake.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
$timeout = undef,
$user = $::foreman::user,
$app_root = $::foreman::app_root,
$unless = undef,
) {
# https://github.com/rodjek/puppet-lint/issues/327
# lint:ignore:arrow_alignment
Expand All @@ -12,8 +13,9 @@
user => $user,
environment => sort(join_keys_to_values(merge({'HOME' => $app_root}, $environment), '=')),
logoutput => 'on_failure',
refreshonly => true,
refreshonly => $unless =~ Undef,
timeout => $timeout,
unless => $unless,
}
# lint:endignore
}
2 changes: 0 additions & 2 deletions spec/classes/foreman_database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

it { should_not 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') }
Expand All @@ -24,7 +23,6 @@
it { should compile.with_all_deps }
it { should contain_class('foreman::database::postgresql') }

it { should_not contain_foreman_config_entry('db_pending_migration') }
it { should_not contain_foreman__rake('db:migrate') }
it { should_not contain_foreman_config_entry('db_pending_seed') }
it { should_not contain_foreman__rake('db:seed') }
Expand Down
3 changes: 1 addition & 2 deletions spec/classes/foreman_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,9 @@
it { should_not contain_class('foreman::database::mysql') }
it {
should contain_class('foreman::database::postgresql')
.that_notifies('Foreman_config_entry[db_pending_migration]')
.that_notifies('Foreman::Rake[db:migrate]')
}

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') }
Expand Down
61 changes: 32 additions & 29 deletions spec/defines/foreman_rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,66 @@
on_supported_os['redhat-7-x86_64']
end

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
# These parameters are inherited normally, but here we cheat for performance
let :params do
{
user: 'foreman',
app_root: '/usr/share/foreman'
}
end

it {
context 'without parameters' do
it do
should contain_exec('foreman-rake-db:migrate')
.with_command('/usr/sbin/foreman-rake db:migrate')
.with_user('foreman')
.with_environment(['HOME=/usr/share/foreman'])
.with_logoutput('on_failure')
.with_refreshonly(true)
}
.with_timeout(nil)
.with_unless(nil)
end
end

context 'with environment' do
let :params do
{
environment: { 'SEED_USER' => 'admin' },
user: 'foreman',
app_root: '/usr/share/foreman'
}
end
let(:params) { super().merge(environment: { 'SEED_USER' => 'admin' }) }

it {
it do
should contain_exec('foreman-rake-db:migrate')
.with_command('/usr/sbin/foreman-rake db:migrate')
.with_user('foreman')
.with_environment(['HOME=/usr/share/foreman', 'SEED_USER=admin'])
.with_logoutput('on_failure')
.with_refreshonly(true)
.with_timeout(nil)
}
end
end

context 'with timeout' do
let :params do
{
timeout: 60,
user: 'foreman',
app_root: '/usr/share/foreman'
}
end
let(:params) { super().merge(timeout: 60) }

it {
it do
should contain_exec('foreman-rake-db:migrate')
.with_command('/usr/sbin/foreman-rake db:migrate')
.with_user('foreman')
.with_environment(['HOME=/usr/share/foreman'])
.with_timeout(60)
.with_logoutput('on_failure')
.with_refreshonly(true)
}
end
end

context 'with unless' do
let(:params) { super().merge(unless: '/usr/bin/true') }

it do
should contain_exec('foreman-rake-db:migrate')
.with_command('/usr/sbin/foreman-rake db:migrate')
.with_user('foreman')
.with_environment(['HOME=/usr/share/foreman'])
.with_logoutput('on_failure')
.with_refreshonly(false)
.with_unless('/usr/bin/true')
end
end
end
end