From 093324484434742c8dca5a9dd54b481eb8d176ec Mon Sep 17 00:00:00 2001 From: William Bradford Clark Date: Thu, 1 Jul 2021 12:31:06 -0400 Subject: [PATCH] Refs #32917 - Don't deploy or configure Redis with new tasking system --- manifests/database.pp | 4 ++- manifests/init.pp | 2 ++ spec/acceptance/basic_spec.rb | 21 +++++++++-- spec/classes/pulpcore_spec.rb | 65 ++++++++++++++++++++++++++++++++--- templates/settings.py.erb | 3 ++ 5 files changed, 87 insertions(+), 8 deletions(-) diff --git a/manifests/database.pp b/manifests/database.pp index 3630d88b..c743eac6 100644 --- a/manifests/database.pp +++ b/manifests/database.pp @@ -27,6 +27,8 @@ require => Pulpcore::Admin['migrate --noinput'], } - include redis + if $pulpcore::uses_redis { + include redis + } } diff --git a/manifests/init.pp b/manifests/init.pp index 4460a9a8..698577a4 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -221,6 +221,8 @@ ) { $settings_file = "${config_dir}/settings.py" + $uses_redis = $use_rq_tasking_system or $cache_enabled + contain pulpcore::install contain pulpcore::database contain pulpcore::config diff --git a/spec/acceptance/basic_spec.rb b/spec/acceptance/basic_spec.rb index c5d89c2e..7c28634d 100644 --- a/spec/acceptance/basic_spec.rb +++ b/spec/acceptance/basic_spec.rb @@ -79,10 +79,19 @@ class { 'pulpcore': its(:exit_status) { is_expected.to eq 0 } end + describe service('rh-redis5-redis'), if: %w[centos redhat].include?(os[:family]) && os[:release].to_i == 7 do + it { is_expected.not_to be_running } + it { is_expected.not_to be_enabled } + end + + describe service('redis'), unless: %w[centos redhat].include?(os[:family]) && os[:release].to_i == 7 do + it { is_expected.not_to be_running } + it { is_expected.not_to be_enabled } + end + describe command("DJANGO_SETTINGS_MODULE=pulpcore.app.settings PULP_SETTINGS=/etc/pulp/settings.py rq info -c pulpcore.rqconfig") do - its(:stdout) { is_expected.to match(/^0 workers, /) } - its(:stdout) { is_expected.not_to match(/^resource-manager /) } - its(:exit_status) { is_expected.to eq 0 } + its(:stdout) { is_expected.not_to match(/Connection refused/) } + its(:exit_status) { is_expected.to eq 1 } end end @@ -174,6 +183,12 @@ class { 'pulpcore': it { is_expected.to be_enabled } end + describe command("DJANGO_SETTINGS_MODULE=pulpcore.app.settings PULP_SETTINGS=/etc/pulp/settings.py rq info -c pulpcore.rqconfig") do + its(:stdout) { is_expected.to match(/^0 workers, /) } + its(:stdout) { is_expected.not_to match(/^resource-manager /) } + its(:exit_status) { is_expected.to eq 0 } + end + describe curl_command("https://#{host_inventory['fqdn']}/pulp/api/v3/status/", cacert: "#{certdir}/ca-cert.pem") do its(:response_code) { is_expected.to eq(200) } its(:exit_status) { is_expected.to eq 0 } diff --git a/spec/classes/pulpcore_spec.rb b/spec/classes/pulpcore_spec.rb index c8c74faa..f7992126 100644 --- a/spec/classes/pulpcore_spec.rb +++ b/spec/classes/pulpcore_spec.rb @@ -41,7 +41,7 @@ is_expected.to contain_exec('pulpcore-manager collectstatic --noinput') end - it 'configures the database' do + it 'configures the PostgreSQL database' do is_expected.to contain_class('pulpcore::database') is_expected.to contain_class('postgresql::server') is_expected.to contain_postgresql__server__db('pulpcore') @@ -51,6 +51,29 @@ is_expected.to contain_exec('pulpcore-manager reset-admin-password --random') end + it 'does not install Redis' do + is_expected.not_to contain_class('redis') + end + + it 'does not configure Pulpcore connection to Redis' do + is_expected.to contain_concat__fragment('base') + .without_content(/REDIS_HOST/) + .without_content(/REDIS_POST/) + .without_content(/REDIS_DB/) + end + + it 'does not configure content caching' do + is_expected.to contain_concat__fragment('base') + .without_content(/CACHE_ENABLED = True/) + .without_content(%r{CACHE_SETTINGS = \{\n 'EXPIRES_TTL': 60,\n\}}) + end + + it 'configures pulpcore to use PostgreSQL tasking system' do + is_expected.to contain_concat__fragment('base') + .with_content(/USE_NEW_WORKER_TYPE = True/) + is_expected.to contain_systemd__unit_file('pulpcore-resource-manager.service').with_ensure('absent') + end + it 'configures apache' do is_expected.to contain_class('pulpcore::apache') is_expected.to contain_apache__vhost('pulpcore') @@ -128,7 +151,6 @@ is_expected.to contain_systemd__unit_file('pulpcore-content.socket') is_expected.to contain_systemd__unit_file('pulpcore-content.service') is_expected.to contain_file('/etc/systemd/system/pulpcore-content.socket').that_comes_before('Service[pulpcore-content.service]') - is_expected.to contain_systemd__unit_file('pulpcore-resource-manager.service').with_ensure('absent') is_expected.to contain_systemd__unit_file('pulpcore-worker@.service') is_expected.to contain_service("pulpcore-worker@1.service").with_ensure(true) is_expected.not_to contain_service("pulpcore-worker@2.service") @@ -491,11 +513,46 @@ } end - it do + it 'configures content caching' do is_expected.to contain_concat__fragment('base') - .with_content(%r{CACHE_ENABLED = True}) + .with_content(/CACHE_ENABLED = True/) .with_content(%r{CACHE_SETTINGS = \{\n 'EXPIRES_TTL': 60,\n\}}) end + + it 'installs Redis' do + is_expected.to contain_class('redis') + end + + it 'configures Pulpcore connection to Redis' do + is_expected.to contain_concat__fragment('base') + .with_content(/REDIS_HOST/) + .with_content(/REDIS_PORT/) + .with_content(/REDIS_DB/) + end + end + + context 'can enable RQ tasking system' do + let :params do + { + use_rq_tasking_system: true, + } + end + + it 'configures RQ tasking system' do + is_expected.to contain_concat__fragment('base') + .with_content(/USE_NEW_WORKER_TYPE = False/) + end + + it 'installs Redis' do + is_expected.to contain_class('redis') + end + + it 'configures Pulpcore connection to Redis' do + is_expected.to contain_concat__fragment('base') + .with_content(/REDIS_HOST/) + .with_content(/REDIS_PORT/) + .with_content(/REDIS_DB/) + end end end end diff --git a/templates/settings.py.erb b/templates/settings.py.erb index 7207c1d5..e569f8ec 100644 --- a/templates/settings.py.erb +++ b/templates/settings.py.erb @@ -19,10 +19,13 @@ DATABASES = { <% end -%> }, } + +<% if scope['pulpcore::uses_redis'] -%> REDIS_HOST = "localhost" REDIS_PORT = "<%= scope['redis::port'] %>" REDIS_DB = <%= scope['pulpcore::redis_db'] %> +<% end -%> USE_NEW_WORKER_TYPE = <%= scope['pulpcore::use_rq_tasking_system'] ? "False" : "True" %> MEDIA_ROOT = "<%= scope['pulpcore::media_root'] %>"