Skip to content

Commit 9df6e71

Browse files
committed
Refs #37707 - Support purging container_gateway
This implements support to ensure container_gateway is disabled or absent. It does not remove the database, so it's easy to install again and pick up where you left.
1 parent 6a3724a commit 9df6e71

File tree

8 files changed

+98
-3
lines changed

8 files changed

+98
-3
lines changed

manifests/module.pp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Foreman Proxy internally has the concept of modules. Some modules have
44
# providers or even multiple ones. That's not part of this definition.
55
#
6+
# @param ensure
7+
# Whether the module is expected to be present or absent
8+
#
69
# @param enabled
710
# Whether the module is enabled or disabled.
811
#
@@ -20,12 +23,13 @@
2023
# An optional template path
2124
#
2225
define foreman_proxy::module (
26+
Enum['present', 'absent'] $ensure = 'present',
2327
Boolean $enabled = false,
2428
Foreman_proxy::ListenOn $listen_on = 'https',
2529
Optional[String] $template_path = undef,
2630
String $feature = $title.capitalize(),
2731
) {
28-
if $enabled {
32+
if $ensure != 'absent' and $enabled {
2933
$module_enabled = $listen_on ? {
3034
'both' => 'true',
3135
'https' => 'https',
@@ -39,6 +43,7 @@
3943
}
4044

4145
foreman_proxy::settings_file { $name:
46+
ensure => bool2str($ensure == 'present', 'file', 'absent'),
4247
module_enabled => $module_enabled,
4348
template_path => $template_path,
4449
}

manifests/plugin/container_gateway.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
listen_on => $listen_on,
5454
}
5555

56-
if $manage_postgresql and $database_backend == 'postgres' {
56+
if $version != 'absent' and $enabled and $manage_postgresql and $database_backend == 'postgres' {
5757
include postgresql::server
5858
$_postgresql_user = pick($postgresql_user, $foreman_proxy::user)
5959
if $postgresql_password {

manifests/plugin/module.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
package => $package,
3636
}
3737
-> foreman_proxy::module { $name:
38+
ensure => bool2str($version != 'absent', 'present', 'absent'),
3839
enabled => $enabled,
3940
feature => $feature,
4041
listen_on => $listen_on,

spec/acceptance/container_gateway_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,31 @@
77

88
it_behaves_like 'the default foreman proxy application'
99

10+
describe 'is created' do
11+
it { expect(package('rubygem-smart_proxy_container_gateway')).to be_installed }
12+
it { expect(file('/etc/foreman-proxy/settings.d/container_gateway.yml')).to be_file }
13+
end
14+
1015
describe service("postgresql") do
1116
it { is_expected.to be_enabled }
1217
it { is_expected.to be_running }
1318
end
19+
20+
describe 'and purge it' do
21+
it_behaves_like 'an idempotent resource' do
22+
let(:manifest) do
23+
<<~PUPPET
24+
include foreman_proxy
25+
class { 'foreman_proxy::plugin::container_gateway':
26+
version => 'absent',
27+
}
28+
PUPPET
29+
end
30+
31+
describe 'it is purged' do
32+
it { expect(package('rubygem-smart_proxy_container_gateway')).not_to be_installed }
33+
it { expect(file('/etc/foreman-proxy/settings.d/container_gateway.yml')).not_to be_file }
34+
end
35+
end
36+
end
1437
end

spec/classes/foreman_proxy__plugin__container_gateway_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,30 @@
6666
])
6767
end
6868
end
69+
70+
describe 'with enabled => false' do
71+
let(:params) do
72+
{
73+
enabled: false,
74+
}
75+
end
76+
77+
it { is_expected.to compile.with_all_deps }
78+
it { is_expected.to contain_foreman_proxy__plugin__module('container_gateway').with_enabled(false) }
79+
it { is_expected.not_to contain_class('postgresql::server') }
80+
end
81+
82+
describe 'with version => absent' do
83+
let(:params) do
84+
{
85+
version: 'absent',
86+
}
87+
end
88+
89+
it { is_expected.to compile.with_all_deps }
90+
it { is_expected.to contain_foreman_proxy__plugin__module('container_gateway').with_version('absent') }
91+
it { is_expected.not_to contain_class('postgresql::server') }
92+
end
6993
end
7094
end
7195
end

spec/defines/foreman_proxy_module_spec.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
context 'with defaults' do
1111
it { is_expected.to compile.with_all_deps }
12-
it { is_expected.to contain_foreman_proxy__settings_file('test').with_module_enabled('false') }
12+
it { is_expected.to contain_foreman_proxy__settings_file('test').with_ensure('file').with_module_enabled('false') }
1313
it { is_expected.not_to contain_foreman_proxy__feature('Test') }
1414
end
1515

@@ -48,6 +48,24 @@
4848
it { is_expected.to contain_foreman_proxy__feature('TEST') }
4949
end
5050
end
51+
52+
context 'with enabled => false' do
53+
let(:params) { { enabled: false } }
54+
55+
56+
it { is_expected.to compile.with_all_deps }
57+
it { is_expected.not_to contain_foreman_proxy__feature('Test') }
58+
it { is_expected.to contain_foreman_proxy__settings_file('test').with_ensure('file') }
59+
end
60+
61+
context 'with ensure => absent' do
62+
let(:params) { { ensure: 'absent' } }
63+
64+
65+
it { is_expected.to compile.with_all_deps }
66+
it { is_expected.not_to contain_foreman_proxy__feature('Test') }
67+
it { is_expected.to contain_foreman_proxy__settings_file('test').with_ensure('absent') }
68+
end
5169
end
5270
end
5371
end

spec/defines/foreman_proxy_plugin_module_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,24 @@
1111
it { is_expected.to contain_foreman_proxy__plugin('test').with_version('installed').with_package(/[-_]test$/) }
1212
it do
1313
is_expected.to contain_foreman_proxy__module('test')
14+
.with_ensure('present')
1415
.with_enabled(false)
1516
.with_feature('Test')
1617
.with_listen_on('https')
1718
.with_template_path('foreman_proxy/plugin/test.yml.erb')
1819
end
20+
21+
context 'with version absent' do
22+
let(:params) do
23+
{
24+
version: 'absent',
25+
}
26+
end
27+
28+
it { is_expected.to compile.with_all_deps }
29+
it { is_expected.to contain_foreman_proxy__plugin('test').with_version('absent') }
30+
it { is_expected.to contain_foreman_proxy__module('test').with_ensure('absent') }
31+
end
1932
end
2033
end
2134
end

spec/defines/foreman_proxy_settings_file_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@
2525
.with_mode('0640')
2626
.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")
2727
end
28+
29+
context 'with ensure => absent' do
30+
let(:params) do
31+
{
32+
ensure: 'absent',
33+
}
34+
end
35+
36+
it { is_expected.to compile.with_all_deps }
37+
it { is_expected.to contain_file(config_path).with_ensure('absent') }
38+
end
2839
end
2940

3041
context 'with foreman_proxy included' do

0 commit comments

Comments
 (0)