Skip to content

Commit df5fd95

Browse files
ianballouekohl
authored andcommitted
Refs #37325 - add postgresql module as a requirement
1 parent 3c5bc3f commit df5fd95

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

.fixtures.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ fixtures:
1717
systemd: 'https://github.com/camptocamp/puppet-systemd'
1818
tftp: 'https://github.com/theforeman/puppet-tftp'
1919
translate: 'https://github.com/puppetlabs/puppetlabs-translate'
20+
postgresql: 'https://github.com/puppetlabs/puppetlabs-postgresql'
2021
xinetd: 'https://github.com/puppetlabs/puppetlabs-xinetd'
2122
yumrepo_core: "https://github.com/puppetlabs/puppetlabs-yumrepo_core"
2223
sshkeys_core: "https://github.com/puppetlabs/puppetlabs-sshkeys_core"

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ class { 'foreman_proxy::plugin::ansible':
100100
}
101101
```
102102

103-
### Katello Container Gateway Support
104-
105-
If installing a Foreman Proxy with the Container Gateway, ensure that the
106-
postgresql module is available for use on the system.
107-
108103
## Contributing
109104

110105
* Fork the project

manifests/plugin/container_gateway.pp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
Boolean $enabled = true,
3737
Foreman_proxy::ListenOn $listen_on = 'https',
3838
Stdlib::HTTPUrl $pulp_endpoint = "https://${facts['networking']['fqdn']}",
39-
String $database_backend = 'postgres',
39+
Enum['postgres', 'sqlite'] $database_backend = 'postgres',
4040
Stdlib::Absolutepath $sqlite_db_path = '/var/lib/foreman-proxy/smart_proxy_container_gateway.db',
4141
Optional[Integer] $sqlite_timeout = undef,
4242
Boolean $manage_postgresql = true,
43-
Stdlib::Host $postgresql_host = 'localhost',
44-
Stdlib::Port $postgresql_port = 5432,
43+
Optional[Stdlib::Host] $postgresql_host = undef,
44+
Optional[Stdlib::Port] $postgresql_port = undef,
4545
String $postgresql_database = 'container_gateway',
46-
String $postgresql_user = 'foreman-proxy',
46+
String $postgresql_user = pick($foreman_proxy::globals::user, 'foreman-proxy'),
4747
String $postgresql_password = extlib::cache_data('container_gateway_cache_data', 'db_password', extlib::random_password(32))
4848
) {
4949
foreman_proxy::plugin::module { 'container_gateway':
@@ -53,7 +53,8 @@
5353
listen_on => $listen_on,
5454
}
5555

56-
if $foreman_proxy::plugin::container_gateway::manage_postgresql {
56+
if $foreman_proxy::plugin::container_gateway::manage_postgresql and
57+
$foreman_proxy::plugin::container_gateway::database_backend != 'sqlite' {
5758
include postgresql::server
5859
postgresql::server::db { $foreman_proxy::plugin::container_gateway::postgresql_database:
5960
user => $foreman_proxy::plugin::container_gateway::postgresql_user,
@@ -62,8 +63,7 @@
6263
$foreman_proxy::plugin::container_gateway::postgresql_password
6364
),
6465
encoding => 'utf8',
65-
locale => 'en_US.utf8',
66-
require => Package['glibc-langpack-en'],
66+
locale => 'C.utf8',
6767
}
6868
}
6969
}

spec/classes/foreman_proxy__plugin__container_gateway_spec.rb

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,23 @@
77
let(:pre_condition) { 'include foreman_proxy' }
88

99
describe 'with default settings' do
10-
let :postgresql_password do 'changeme' end
1110
it { should contain_foreman_proxy__plugin__module('container_gateway') }
1211
it 'container_gateway.yml should contain the correct configuration' do
13-
verify_exact_contents(catalogue, '/etc/foreman-proxy/settings.d/container_gateway.yml', [
14-
'---',
15-
':enabled: https',
16-
":pulp_endpoint: https://#{facts[:fqdn]}",
17-
':database_backend: postgresql',
18-
':sqlite_db_path: /var/lib/foreman-proxy/smart_proxy_container_gateway.db',
19-
':postgresql_connection_string: postgres://foreman-proxy:changeme@localhost:5432/container_gateway'
20-
])
12+
expect(get_content(catalogue, '/etc/foreman-proxy/settings.d/container_gateway.yml')).to include("---")
13+
expect(get_content(catalogue, '/etc/foreman-proxy/settings.d/container_gateway.yml')).to include(":enabled: https")
14+
expect(get_content(catalogue, '/etc/foreman-proxy/settings.d/container_gateway.yml')).to include(":pulp_endpoint: https://#{facts[:fqdn]}")
15+
expect(get_content(catalogue, '/etc/foreman-proxy/settings.d/container_gateway.yml')).to include(":sqlite_db_path: /var/lib/foreman-proxy/smart_proxy_container_gateway.db")
16+
connection_string = get_content(catalogue, '/etc/foreman-proxy/settings.d/container_gateway.yml').find { |str| str.include?("db_connection_string") }
17+
expect(connection_string.split(/[:@\/]/)[6]).to be_a(String).and have_attributes(length: 32)
2118
end
2219
end
2320

2421
describe 'with overwritten parameters' do
2522
let :params do {
2623
:pulp_endpoint => 'https://test.example.com',
27-
:database_backend => 'postgresql',
2824
:sqlite_db_path => '/dev/null.db',
2925
:sqlite_timeout => 12345,
26+
:database_backend => 'sqlite',
3027
:postgresql_host => 'test.example.com',
3128
:postgresql_port => 5432,
3229
:postgresql_database => 'container_gateway',
@@ -39,10 +36,9 @@
3936
'---',
4037
':enabled: https',
4138
':pulp_endpoint: https://test.example.com',
42-
':database_backend: postgresql',
4339
':sqlite_db_path: /dev/null.db',
4440
':sqlite_timeout: 12345',
45-
':postgresql_connection_string: postgres://foreman-proxy:[email protected]:5432/container_gateway'
41+
':db_connection_string: sqlite:///dev/null.db'
4642
])
4743
end
4844
end

templates/plugin/container_gateway.yml.erb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22
# Container Gateway for Katello
33
:enabled: <%= @module_enabled %>
44
:pulp_endpoint: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::pulp_endpoint") %>
5-
:database_backend: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::database_backend") %>
65
:sqlite_db_path: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::sqlite_db_path") %>
76
<% if scope.lookupvar("foreman_proxy::plugin::container_gateway::sqlite_timeout") -%>
87
:sqlite_timeout: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::sqlite_timeout") %>
98
<% end -%>
10-
:postgresql_connection_string: postgres://<%=
9+
<% if scope.lookupvar("foreman_proxy::plugin::container_gateway::database_backend") == 'postgres' -%>
10+
:db_connection_string: <%=
11+
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::database_backend")}://" \
1112
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_user")}:" \
1213
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_password")}@" \
1314
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_host")}:" \
1415
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_port")}/" \
1516
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_database")}"
16-
%>
17+
%>
18+
<% end -%>
19+
<% if scope.lookupvar("foreman_proxy::plugin::container_gateway::database_backend") == 'sqlite' -%>
20+
:db_connection_string: <%=
21+
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::database_backend")}://" \
22+
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::sqlite_db_path")}"
23+
%>
24+
<% end -%>

0 commit comments

Comments
 (0)