Skip to content

Commit

Permalink
Introduce a pulpcore::admin define
Browse files Browse the repository at this point in the history
This is essentially a wrapper around django-admin with the right
settings.
  • Loading branch information
ekohl authored and ehelms committed Dec 11, 2019
1 parent fc9d5d0 commit e018c1d
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 13 deletions.
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}":
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

0 comments on commit e018c1d

Please sign in to comment.