Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refs #32917 - Don't deploy or configure Redis with new tasking system #207

Merged
merged 1 commit into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion manifests/database.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
require => Pulpcore::Admin['migrate --noinput'],
}

include redis
if $pulpcore::uses_redis {
include redis
}

}
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions spec/acceptance/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 }
Expand Down
67 changes: 62 additions & 5 deletions spec/classes/pulpcore_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
.with_content(%r{ALLOWED_EXPORT_PATHS = \[\]})
.with_content(%r{ALLOWED_IMPORT_PATHS = \["/var/lib/pulp/sync_imports"\]})
.with_content(%r{ALLOWED_CONTENT_CHECKSUMS = \["sha224", "sha256", "sha384", "sha512"\]})
.with_content(%r{CACHE_ENABLED = False})
.without_content(/sslmode/)
.without_content(%r{sslmode})
is_expected.to contain_file('/etc/pulp')
is_expected.to contain_file('/var/lib/pulp')
is_expected.to contain_file('/var/lib/pulp/sync_imports')
Expand All @@ -41,7 +40,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')
Expand All @@ -51,6 +50,30 @@
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(%r{REDIS_HOST})
.without_content(%r{REDIS_POST})
.without_content(%r{REDIS_DB})
end

it 'does not configure content caching' do
is_expected.to contain_concat__fragment('base')
.with_content(/CACHE_ENABLED = False/)
.without_content(%r{CACHE_SETTINGS})
.without_content(%r{'EXPIRES_TTL':})
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thank you.


it 'configures pulpcore to use PostgreSQL tasking system' do
is_expected.to contain_concat__fragment('base')
.with_content(%r{USE_NEW_WORKER_TYPE = True})
is_expected.to contain_systemd__unit_file('pulpcore-resource-manager.service').with_ensure('absent')
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This are OK here, but they feel better up here https://github.com/theforeman/puppet-pulpcore/pull/207/files#diff-257fe3136ecfdbfcb123b6445ff2de6c21d1fe08b0d6af54c08dde40637d2594R19 for me as it connects all of the configuration file together.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started to think that it makes sense to structure the tests around the real world use case rather than the specific object being tested..

So instead of having all tests for the configuration file in the same place, have a test for 'content caching is disabled', 'postgresql tasking system is used', and so on.

I see two primary benefits: 1. This feels more maintainable in the longer term (when we make modifications to a specific feature, the tests for that feature are all located in that block, rather than spread out across different components the feature touches). 2. This should lead to more readable test output, and particularly failures. So instead of getting a failure like default parameters - it configures pulpcore - it is expected to contain a file with (lots of stuff, including all kinds of things that aren't relevant to the specific thing you broke) you would instead see something more like default parameters - it uses new tasking system - it is expected to contain a configuration file with specific things that are relevant to the tasking system

I want to pursue this idea more consistently in my planned refactoring. For this PR I thought, it makes sense to write the net-new tests using this style, to minimize the amount of re-writing I have to do later.


it 'configures apache' do
is_expected.to contain_class('pulpcore::apache')
is_expected.to contain_apache__vhost('pulpcore')
Expand Down Expand Up @@ -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('[email protected]')
is_expected.to contain_service("[email protected]").with_ensure(true)
is_expected.not_to contain_service("[email protected]")
Expand Down Expand Up @@ -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(%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(%r{REDIS_HOST})
.with_content(%r{REDIS_PORT})
.with_content(%r{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(%r{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(%r{REDIS_HOST})
.with_content(%r{REDIS_PORT})
.with_content(%r{REDIS_DB})
end
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions templates/settings.py.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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'] %>"
Expand Down