Skip to content

Commit

Permalink
Refs #32910: Add ability to enable content caching
Browse files Browse the repository at this point in the history
Adds a flag to enable content caching via Redis. This is disabled
by default as its a new optional feature in Pulp 3.14.
  • Loading branch information
ehelms committed Jul 2, 2021
1 parent 08ea4d8 commit 3f9b159
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
8 changes: 8 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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"

Expand Down
51 changes: 51 additions & 0 deletions spec/acceptance/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions spec/classes/pulpcore_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
7 changes: 7 additions & 0 deletions templates/settings.py.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>

0 comments on commit 3f9b159

Please sign in to comment.