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

Introduce a pulpcore::admin define #43

Merged
merged 1 commit into from
Dec 11, 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
38 changes: 38 additions & 0 deletions manifests/admin.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# @summary Run a django-admin command
#
# @param command
# The command to run
#
# @param refreshonly
# The command should only be run as a refresh mechanism for when a dependent
# object is changed.
#
# @param unless
# A test command that checks the state of the target system and restricts
# when the exec can run.
#
# @param path
# The path to look for commands.
#
# @param pulp_settings
# The pulp settings file to use
#
# @see exec
define pulpcore::admin(
String $command = $title,
Boolean $refreshonly = false,
Optional[String] $unless = undef,
Array[Stdlib::Absolutepath] $path = ['/usr/bin'],
Stdlib::Absolutepath $pulp_settings = $pulpcore::settings_file,
) {
File <| title == $pulp_settings |>
-> exec { "django-admin ${title}":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So once @evgeni has modified the RPM design so that django 3's django-admin does not conflict with django 2, we can update the exec statement in a single place and have it be correct for the whole module.

I really like this approach. LGTM.

path => $path,
environment => [
'DJANGO_SETTINGS_MODULE=pulpcore.app.settings',
"PULP_SETTINGS=${pulp_settings}",
],
refreshonly => $refreshonly,
unless => $unless,
}
}
7 changes: 1 addition & 6 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@
mode => '0755',
}

exec { 'django-admin collectstatic --noinput':
path => ['/usr/local/bin', '/usr/bin'],
environment => [
'DJANGO_SETTINGS_MODULE=pulpcore.app.settings',
"PULP_SETTINGS=${pulpcore::settings_file}",
],
pulpcore::admin { 'collectstatic --noinput':
refreshonly => true,
subscribe => File[$pulpcore::settings_file],
}
Expand Down
10 changes: 3 additions & 7 deletions manifests/database.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@
password => postgresql_password($pulpcore::user, $pulpcore::postgresql_db_password),
}

exec { 'django-admin migrate --noinput':
path => ['/usr/local/bin', '/usr/bin'],
environment => [
'DJANGO_SETTINGS_MODULE=pulpcore.app.settings',
"PULP_SETTINGS=${pulpcore::settings_file}",
],
require => Postgresql::Server::Db[$pulpcore::postgresql_db_name],
pulpcore::admin { 'migrate --noinput':
unless => 'django-admin migrate --plan | grep "No planned migration operations"',
refreshonly => false,
require => Postgresql::Server::Db[$pulpcore::postgresql_db_name],
}

include redis
Expand Down
59 changes: 59 additions & 0 deletions spec/defines/admin_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require 'spec_helper'

describe 'pulpcore::admin' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }
let(:title) { 'help' }

context 'with a fixed pulp_settings' do
let(:params) { { pulp_settings: '/etc/pulpcore/settings.py' } }

context 'default parameters' do
it do
is_expected.to compile.with_all_deps
is_expected.to contain_exec('django-admin help')
.with_environment(['DJANGO_SETTINGS_MODULE=pulpcore.app.settings', 'PULP_SETTINGS=/etc/pulpcore/settings.py'])
.with_refreshonly(false)
.with_unless(nil)
end
end

context 'default parameters' do
let(:params) do
super().merge(
command: 'migrate --noinput',
refreshonly: true,
unless: '/usr/bin/false',
)
end

it do
is_expected.to compile.with_all_deps
is_expected.to contain_exec('django-admin help')
.with_environment(['DJANGO_SETTINGS_MODULE=pulpcore.app.settings', 'PULP_SETTINGS=/etc/pulpcore/settings.py'])
.with_refreshonly(true)
.with_unless('/usr/bin/false')
end
end
end

context 'with inheritance' do
let(:pre_condition) { 'include pulpcore' }

context 'default parameters' do
it do
is_expected.to compile.with_all_deps
is_expected.to contain_pulpcore__admin('help').with_pulp_settings('/etc/pulp/settings.py')
is_expected.to contain_file('/etc/pulp/settings.py')
is_expected.to contain_exec('django-admin help')
.with_environment(['DJANGO_SETTINGS_MODULE=pulpcore.app.settings', 'PULP_SETTINGS=/etc/pulp/settings.py'])
.with_refreshonly(false)
.with_unless(nil)
.that_requires('File[/etc/pulp/settings.py]')
end
end
end
end
end
end