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

Refs #37707 - Support purging container_gateway #843

Merged
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
7 changes: 6 additions & 1 deletion manifests/module.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Foreman Proxy internally has the concept of modules. Some modules have
# providers or even multiple ones. That's not part of this definition.
#
# @param ensure
# Whether the module is expected to be present or absent
#
# @param enabled
# Whether the module is enabled or disabled.
#
Expand All @@ -20,12 +23,13 @@
# An optional template path
#
define foreman_proxy::module (
Enum['present', 'absent'] $ensure = 'present',
Boolean $enabled = false,
Foreman_proxy::ListenOn $listen_on = 'https',
Optional[String] $template_path = undef,
String $feature = $title.capitalize(),
) {
if $enabled {
if $ensure != 'absent' and $enabled {
$module_enabled = $listen_on ? {
'both' => 'true',
'https' => 'https',
Expand All @@ -39,6 +43,7 @@
}

foreman_proxy::settings_file { $name:
ensure => bool2str($ensure == 'present', 'file', 'absent'),
module_enabled => $module_enabled,
template_path => $template_path,
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/plugin/container_gateway.pp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
listen_on => $listen_on,
}

if $manage_postgresql and $database_backend == 'postgres' {
if $version != 'absent' and $enabled and $manage_postgresql and $database_backend == 'postgres' {
include postgresql::server
$_postgresql_user = pick($postgresql_user, $foreman_proxy::user)
if $postgresql_password {
Expand Down
1 change: 1 addition & 0 deletions manifests/plugin/module.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
package => $package,
}
-> foreman_proxy::module { $name:
ensure => bool2str($version != 'absent', 'present', 'absent'),
enabled => $enabled,
feature => $feature,
listen_on => $listen_on,
Expand Down
23 changes: 23 additions & 0 deletions spec/acceptance/container_gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,31 @@

it_behaves_like 'the default foreman proxy application'

describe 'is created' do
it { expect(package('rubygem-smart_proxy_container_gateway')).to be_installed }
it { expect(file('/etc/foreman-proxy/settings.d/container_gateway.yml')).to be_file }
end

describe service("postgresql") do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe 'and purge it' do
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<~PUPPET
include foreman_proxy
class { 'foreman_proxy::plugin::container_gateway':
version => 'absent',
}
PUPPET
end

describe 'it is purged' do
it { expect(package('rubygem-smart_proxy_container_gateway')).not_to be_installed }
it { expect(file('/etc/foreman-proxy/settings.d/container_gateway.yml')).not_to be_file }
end
end
end
end
24 changes: 24 additions & 0 deletions spec/classes/foreman_proxy__plugin__container_gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@
])
end
end

describe 'with enabled => false' do
let(:params) do
{
enabled: false,
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_foreman_proxy__plugin__module('container_gateway').with_enabled(false) }
it { is_expected.not_to contain_class('postgresql::server') }
end

describe 'with version => absent' do
let(:params) do
{
version: 'absent',
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_foreman_proxy__plugin__module('container_gateway').with_version('absent') }
it { is_expected.not_to contain_class('postgresql::server') }
end
end
end
end
20 changes: 19 additions & 1 deletion spec/defines/foreman_proxy_module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

context 'with defaults' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_foreman_proxy__settings_file('test').with_module_enabled('false') }
it { is_expected.to contain_foreman_proxy__settings_file('test').with_ensure('file').with_module_enabled('false') }
it { is_expected.not_to contain_foreman_proxy__feature('Test') }
end

Expand Down Expand Up @@ -48,6 +48,24 @@
it { is_expected.to contain_foreman_proxy__feature('TEST') }
end
end

context 'with enabled => false' do
let(:params) { { enabled: false } }


it { is_expected.to compile.with_all_deps }
it { is_expected.not_to contain_foreman_proxy__feature('Test') }
it { is_expected.to contain_foreman_proxy__settings_file('test').with_ensure('file') }
end

context 'with ensure => absent' do
let(:params) { { ensure: 'absent' } }


it { is_expected.to compile.with_all_deps }
it { is_expected.not_to contain_foreman_proxy__feature('Test') }
it { is_expected.to contain_foreman_proxy__settings_file('test').with_ensure('absent') }
end
end
end
end
13 changes: 13 additions & 0 deletions spec/defines/foreman_proxy_plugin_module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,24 @@
it { is_expected.to contain_foreman_proxy__plugin('test').with_version('installed').with_package(/[-_]test$/) }
it do
is_expected.to contain_foreman_proxy__module('test')
.with_ensure('present')
.with_enabled(false)
.with_feature('Test')
.with_listen_on('https')
.with_template_path('foreman_proxy/plugin/test.yml.erb')
end

context 'with version absent' do
let(:params) do
{
version: 'absent',
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_foreman_proxy__plugin('test').with_version('absent') }
it { is_expected.to contain_foreman_proxy__module('test').with_ensure('absent') }
end
end
end
end
11 changes: 11 additions & 0 deletions spec/defines/foreman_proxy_settings_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
.with_mode('0640')
.with_content("---\n# Test file only\n# Can be true, false, or http/https to enable just one of the protocols\n:enabled: false\n")
end

context 'with ensure => absent' do
let(:params) do
{
ensure: 'absent',
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_file(config_path).with_ensure('absent') }
end
end

context 'with foreman_proxy included' do
Expand Down
Loading