Skip to content

Commit

Permalink
Refs #37325 - clean up tests + add postgres acceptance
Browse files Browse the repository at this point in the history
  • Loading branch information
ianballou committed May 16, 2024
1 parent 09489c5 commit c13cb60
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
14 changes: 7 additions & 7 deletions manifests/plugin/container_gateway.pp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
Optional[Stdlib::Host] $postgresql_host = undef,
Optional[Stdlib::Port] $postgresql_port = undef,
String $postgresql_database = 'container_gateway',
String $postgresql_user = pick($foreman_proxy::globals::user, 'foreman-proxy'),
Optional[String[1]] $postgresql_user = undef,
Optional[String] $postgresql_password = undef
) {
foreman_proxy::plugin::module { 'container_gateway':
Expand All @@ -53,14 +53,14 @@
listen_on => $listen_on,
}

if $foreman_proxy::plugin::container_gateway::manage_postgresql and
$foreman_proxy::plugin::container_gateway::database_backend != 'sqlite' {
if $manage_postgresql and $database_backend == 'postgres' {
include postgresql::server
postgresql::server::db { $foreman_proxy::plugin::container_gateway::postgresql_database:
user => $foreman_proxy::plugin::container_gateway::postgresql_user,
$_postgresql_user = pick($postgresql_user, $foreman_proxy::user)
postgresql::server::db { $postgresql_database:
user => $_postgresql_user,
password => postgresql::postgresql_password(
$foreman_proxy::plugin::container_gateway::postgresql_user,
$foreman_proxy::plugin::container_gateway::postgresql_password.lest || {
$_postgresql_user,
$postgresql_password.lest || {
extlib::cache_data('container_gateway_cache_data', 'db_password', extlib::random_password(32))
}
),
Expand Down
5 changes: 5 additions & 0 deletions spec/acceptance/container_gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
include_examples 'the example', 'container_gateway.pp'

it_behaves_like 'the default foreman proxy application'

describe service("postgresql") do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
':enabled: https',
":pulp_endpoint: https://#{facts[:fqdn]}",
':sqlite_db_path: /var/lib/foreman-proxy/smart_proxy_container_gateway.db',
':db_connection_string: postgres://foreman-proxy:@:/container_gateway'
':db_connection_string: postgres://:@:/container_gateway'
])
end
end
Expand All @@ -37,7 +37,6 @@
':enabled: https',
':pulp_endpoint: https://test.example.com',
':sqlite_db_path: /dev/null.db',
':sqlite_timeout: 12345',
':db_connection_string: postgres://foreman-proxy:[email protected]:5432/container_gateway'
])
end
Expand Down
23 changes: 14 additions & 9 deletions templates/plugin/container_gateway.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
<% if scope.lookupvar("foreman_proxy::plugin::container_gateway::sqlite_timeout") -%>
:sqlite_timeout: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::sqlite_timeout") %>
<% end -%>
<% if scope.lookupvar("foreman_proxy::plugin::container_gateway::database_backend") == 'postgres' -%>
:db_connection_string: <%=
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::database_backend")}://" \
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_user")}:" \
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_password")}@" \
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_host")}:" \
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_port")}/" \
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_database")}"
%>
<% if scope.lookupvar('foreman_proxy::plugin::container_gateway::database_backend') == 'postgres' -%>
:db_connection_string: <%= [
scope.lookupvar('foreman_proxy::plugin::container_gateway::database_backend'),
'://',
scope.lookupvar('foreman_proxy::plugin::container_gateway::postgresql_user'),
':',
scope.lookupvar('foreman_proxy::plugin::container_gateway::postgresql_password'),
'@',
scope.lookupvar('foreman_proxy::plugin::container_gateway::postgresql_host'),
':',
scope.lookupvar('foreman_proxy::plugin::container_gateway::postgresql_port'),
'/',
scope.lookupvar('foreman_proxy::plugin::container_gateway::postgresql_database')
].join %>
<% end -%>
<% if scope.lookupvar("foreman_proxy::plugin::container_gateway::database_backend") == 'sqlite' -%>
:db_connection_string: <%=
Expand Down

0 comments on commit c13cb60

Please sign in to comment.