diff --git a/README.md b/README.md index dcbf4fce..06a33c56 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,11 @@ class { 'foreman_proxy::plugin::ansible': } ``` +### Katello Container Gateway Support + +If installing a Foreman Proxy with the Container Gateway, ensure that the +postgresql module is available for use on the system. + ## Contributing * Fork the project diff --git a/manifests/plugin/container_gateway.pp b/manifests/plugin/container_gateway.pp index 7f419228..c11ce7ae 100644 --- a/manifests/plugin/container_gateway.pp +++ b/manifests/plugin/container_gateway.pp @@ -4,6 +4,18 @@ # # $pulp_endpoint:: Pulp 3 server endpoint # +# $database_backend:: 'sqlite' or 'postgres' +# +# $postgresql_host:: Host of the postgres database. +# +# $postgresql_port:: Port of the postgres database. +# +# $postgresql_database:: Name of the postgres database +# +# $postgresql_user:: User for the postgres database +# +# $postgresql_password:: User password for the postgres database +# # $sqlite_db_path:: Absolute path for the SQLite DB file to exist at # # $sqlite_timeout:: Database busy timeout in milliseconds @@ -22,8 +34,14 @@ Boolean $enabled = true, Foreman_proxy::ListenOn $listen_on = 'https', Stdlib::HTTPUrl $pulp_endpoint = "https://${facts['networking']['fqdn']}", + String $database_backend = 'postgres', Stdlib::Absolutepath $sqlite_db_path = '/var/lib/foreman-proxy/smart_proxy_container_gateway.db', Optional[Integer] $sqlite_timeout = undef, + Stdlib::Host $postgresql_host = 'localhost', + Stdlib::Port $postgresql_port = 5432, + String $postgresql_database = 'container_gateway', + String $postgresql_user = 'foreman-proxy', + String $postgresql_password = extlib::cache_data('container_gateway_cache_data', 'db_password', extlib::random_password(32)) ) { foreman_proxy::plugin::module { 'container_gateway': version => $version, @@ -31,4 +49,15 @@ feature => 'Container_Gateway', listen_on => $listen_on, } + include postgresql::server + postgresql::server::db { $foreman_proxy::plugin::container_gateway::postgresql_database: + user => $foreman_proxy::plugin::container_gateway::postgresql_user, + password => postgresql::postgresql_password( + $foreman_proxy::plugin::container_gateway::postgresql_user, + $foreman_proxy::plugin::container_gateway::postgresql_password + ), + encoding => 'utf8', + locale => 'en_US.utf8', + require => Package['glibc-langpack-en'], + } } diff --git a/spec/classes/foreman_proxy__plugin__container_gateway_spec.rb b/spec/classes/foreman_proxy__plugin__container_gateway_spec.rb index 0363fecd..3b07cfa3 100644 --- a/spec/classes/foreman_proxy__plugin__container_gateway_spec.rb +++ b/spec/classes/foreman_proxy__plugin__container_gateway_spec.rb @@ -7,12 +7,19 @@ let(:pre_condition) { 'include foreman_proxy' } describe 'with default settings' do + let :postgresql_password do 'changeme' end it { should contain_foreman_proxy__plugin__module('container_gateway') } it 'container_gateway.yml should contain the correct configuration' do verify_exact_contents(catalogue, '/etc/foreman-proxy/settings.d/container_gateway.yml', [ '---', ':enabled: https', ":pulp_endpoint: https://#{facts[:fqdn]}", + ':database_backend: postgresql', + ':postgresql_host: localhost', + ':postgresql_port: 5432', + ':postgresql_database: container_gateway', + ':postgresql_user: foreman-proxy', + ':postgresql_password: changeme', ':sqlite_db_path: /var/lib/foreman-proxy/smart_proxy_container_gateway.db' ]) end @@ -21,8 +28,14 @@ describe 'with overwritten parameters' do let :params do { :pulp_endpoint => 'https://test.example.com', + :database_backend => 'postgresql', :sqlite_db_path => '/dev/null.db', :sqlite_timeout => 12345, + :postgresql_host => 'test.example.com', + :postgresql_port => 5432, + :postgresql_database => 'container_gateway', + :postgresql_user => 'foreman-proxy', + :postgresql_password => 'changeme' } end it 'container_gateway.yml should contain the correct configuration' do @@ -30,8 +43,14 @@ '---', ':enabled: https', ':pulp_endpoint: https://test.example.com', + ':database_backend: postgresql', ':sqlite_db_path: /dev/null.db', - ':sqlite_timeout: 12345' + ':sqlite_timeout: 12345', + ':postgresql_host: test.example.com', + ':postgresql_port: 5432', + ':postgresql_database: container_gateway', + ':postgresql_user: foreman-proxy', + ':postgresql_password: changeme' ]) end end diff --git a/templates/plugin/container_gateway.yml.erb b/templates/plugin/container_gateway.yml.erb index c50b9ed4..e13fc0a6 100644 --- a/templates/plugin/container_gateway.yml.erb +++ b/templates/plugin/container_gateway.yml.erb @@ -2,7 +2,19 @@ # Container Gateway for Katello :enabled: <%= @module_enabled %> :pulp_endpoint: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::pulp_endpoint") %> +:database_backend: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::database_backend") %> :sqlite_db_path: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::sqlite_db_path") %> <% if scope.lookupvar("foreman_proxy::plugin::container_gateway::sqlite_timeout") -%> :sqlite_timeout: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::sqlite_timeout") %> <% end -%> +:postgresql_connection_string: postgres://<%= + "#{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")}" + %> +:postgresql_host: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_host") %> +:postgresql_port: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_port") %> +:postgresql_user: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_user") %> +:postgresql_password: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_password") %>