From c13cb60e13d3dccbc4d406f3c0e86f2f34cec419 Mon Sep 17 00:00:00 2001 From: Ian Ballou Date: Thu, 16 May 2024 12:25:52 -0400 Subject: [PATCH] Refs #37325 - clean up tests + add postgres acceptance --- manifests/plugin/container_gateway.pp | 14 +++++------ spec/acceptance/container_gateway_spec.rb | 5 ++++ ...n_proxy__plugin__container_gateway_spec.rb | 3 +-- templates/plugin/container_gateway.yml.erb | 23 +++++++++++-------- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/manifests/plugin/container_gateway.pp b/manifests/plugin/container_gateway.pp index a3b16e37..915518af 100644 --- a/manifests/plugin/container_gateway.pp +++ b/manifests/plugin/container_gateway.pp @@ -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': @@ -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)) } ), diff --git a/spec/acceptance/container_gateway_spec.rb b/spec/acceptance/container_gateway_spec.rb index 6f317e51..75f8b748 100644 --- a/spec/acceptance/container_gateway_spec.rb +++ b/spec/acceptance/container_gateway_spec.rb @@ -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 diff --git a/spec/classes/foreman_proxy__plugin__container_gateway_spec.rb b/spec/classes/foreman_proxy__plugin__container_gateway_spec.rb index e96a0357..36a566c0 100644 --- a/spec/classes/foreman_proxy__plugin__container_gateway_spec.rb +++ b/spec/classes/foreman_proxy__plugin__container_gateway_spec.rb @@ -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 @@ -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:changeme@test.example.com:5432/container_gateway' ]) end diff --git a/templates/plugin/container_gateway.yml.erb b/templates/plugin/container_gateway.yml.erb index 4b667c1f..400307b6 100644 --- a/templates/plugin/container_gateway.yml.erb +++ b/templates/plugin/container_gateway.yml.erb @@ -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: <%=