From 3f9b1596c8f5c5bc8a03a32cf4c125829a1b2e63 Mon Sep 17 00:00:00 2001 From: "Eric D. Helms" Date: Tue, 29 Jun 2021 11:48:54 -0400 Subject: [PATCH] Refs #32910: Add ability to enable content caching Adds a flag to enable content caching via Redis. This is disabled by default as its a new optional feature in Pulp 3.14. --- manifests/init.pp | 8 ++++++ spec/acceptance/basic_spec.rb | 51 +++++++++++++++++++++++++++++++++++ spec/classes/pulpcore_spec.rb | 16 +++++++++++ templates/settings.py.erb | 7 +++++ 4 files changed, 82 insertions(+) diff --git a/manifests/init.pp b/manifests/init.pp index 6c624297..4eadfaf6 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -155,6 +155,12 @@ # @param api_client_auth_cn_map # Mapping of certificate common name and Pulp user to authenticate to Pulp API. # +# @param cache_enabled +# Enables Redis based content caching within the Pulp content app. +# +# @param cache_expires_ttl +# The number of seconds that content should be cached for. Specify 'None' to never expire the cache. +# # @example Default configuration # include pulpcore # @@ -204,6 +210,8 @@ Integer[0] $content_service_worker_timeout = 90, Integer[0] $api_service_worker_timeout = 90, Hash[String[1], String[1]] $api_client_auth_cn_map = {}, + Boolean $cache_enabled = false, + Optional[Variant[Integer[0], Enum['None']]] $cache_expires_ttl = undef, ) { $settings_file = "${config_dir}/settings.py" diff --git a/spec/acceptance/basic_spec.rb b/spec/acceptance/basic_spec.rb index 277df373..4799d64c 100644 --- a/spec/acceptance/basic_spec.rb +++ b/spec/acceptance/basic_spec.rb @@ -117,3 +117,54 @@ class { 'pulpcore': end end + +describe 'with content cache enabled' do + certdir = '/etc/pulpcore-certs' + + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + class { 'pulpcore': + cache_enabled => true, + } + PUPPET + end + end + + describe service('httpd') do + it { is_expected.to be_enabled } + it { is_expected.to be_running } + end + + describe service('pulpcore-content') do + it { is_expected.to be_enabled } + it { is_expected.to be_running } + end + + describe port(80) do + it { is_expected.to be_listening } + end + + describe port(443) do + it { is_expected.to be_listening } + end + + describe port(6379) do + it { is_expected.to be_listening } + end + + describe service('rh-redis5-redis'), if: %w[centos redhat].include?(os[:family]) && os[:release].to_i == 7 do + it { is_expected.to be_running } + it { is_expected.to be_enabled } + end + + describe service('redis'), if: %w[centos redhat].include?(os[:family]) && os[:release].to_i == 8 do + it { is_expected.to be_running } + it { is_expected.to be_enabled } + 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 } + end +end diff --git a/spec/classes/pulpcore_spec.rb b/spec/classes/pulpcore_spec.rb index fe89e075..8384b36e 100644 --- a/spec/classes/pulpcore_spec.rb +++ b/spec/classes/pulpcore_spec.rb @@ -23,6 +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/) is_expected.to contain_file('/etc/pulp') is_expected.to contain_file('/var/lib/pulp') @@ -481,6 +482,21 @@ ]) end end + + context 'can enable content caching and set an expires' do + let :params do + { + cache_enabled: true, + cache_expires_ttl: 60, + } + end + + it 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 + end end end end diff --git a/templates/settings.py.erb b/templates/settings.py.erb index 54e847fb..01a42451 100644 --- a/templates/settings.py.erb +++ b/templates/settings.py.erb @@ -43,3 +43,10 @@ ALLOWED_CONTENT_CHECKSUMS = <%= scope['pulpcore::allowed_content_checksums'] %> # Derive HTTP/HTTPS via the X-Forwarded-Proto header set by Apache SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') + +CACHE_ENABLED = <%= scope['pulpcore::cache_enabled'] ? 'True' : 'False' %> +<% if scope['pulpcore::cache_expires_ttl'] -%> +CACHE_SETTINGS = { + 'EXPIRES_TTL': <%= scope['pulpcore::cache_expires_ttl'] %>, +} +<% end -%>