From fe039b7a046c6579049149f725e6899bf230077c Mon Sep 17 00:00:00 2001 From: Simeon Gourlin Date: Tue, 16 Mar 2021 17:18:55 +0100 Subject: [PATCH] This add the cname_lookup middleware for swift proxy. This commit add the manifest to install and use the cname_lookup middleware for swift proxy pipeline. It includes the cname_lookup middleware parameters available in swift-proxy configuration file. It also install the required dependency python-dnspython. Change-Id: If68511fb97bae688e0201fb32928acc9cf68cafc --- manifests/params.pp | 5 +- manifests/proxy/cname_lookup.pp | 80 +++++++++++++++++++ .../notes/cname_lookup-a545519cb21e37cd.yaml | 4 + spec/classes/swift_proxy_cname_lookup_spec.rb | 74 +++++++++++++++++ 4 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 manifests/proxy/cname_lookup.pp create mode 100644 releasenotes/notes/cname_lookup-a545519cb21e37cd.yaml create mode 100644 spec/classes/swift_proxy_cname_lookup_spec.rb diff --git a/manifests/params.pp b/manifests/params.pp index fecca602..22715044 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -6,8 +6,9 @@ class swift::params { include openstacklib::defaults $pyvers = $::openstacklib::defaults::pyvers - $client_package = "python${pyvers}-swiftclient" - $service_provider = undef + $client_package = "python${pyvers}-swiftclient" + $dnspython_pakage_name = "python${pyvers}-dnspython" + $service_provider = undef case $::osfamily { 'Debian': { diff --git a/manifests/proxy/cname_lookup.pp b/manifests/proxy/cname_lookup.pp new file mode 100644 index 00000000..b41c0ebd --- /dev/null +++ b/manifests/proxy/cname_lookup.pp @@ -0,0 +1,80 @@ +# == Class: swift::proxy::cname_lookup +# +# Configure CNAME Lookup middleware for swift +# +# === Parameters +# +# [*log_name*] +# The log name of cname_lookup. +# Default to $::os_service_default +# +# [*log_facility*] +# The log facility of cname_lookup. +# Default to $::os_service_default +# +# [*log_level*] +# The log level of cname_lookup. +# Default to $::os_service_default +# +# [*log_headers*] +# The log headers of cname_lookup. +# Default to $::os_service_default +# +# [*log_address*] +# The log address of cname_lookup. +# Default to $::os_service_default +# +# [*storage_domain*] +# Specify the storage_domain that match your cloud, multiple domains +# can be specified separated by a comma. +# Default to $::os_service_default +# +# [*lookup_depth*] +# Because CNAMES can be recursive, specifies the number of levels +# through which to search. +# Default to $::os_service_default +# +# [*nameservers*] +# Specify the nameservers to use to do the CNAME resolution. If unset, the +# system configuration is used. Multiple nameservers can be specified +# separated by a comma. Default port 53 can be overridden. IPv6 is accepted. +# Example: 127.0.0.1, 127.0.0.2, 127.0.0.3:5353, [::1], [::1]:5353 +# Default to $::os_service_default +# +# +class swift::proxy::cname_lookup( + $log_name = $::os_service_default, + $log_facility = $::os_service_default, + $log_level = $::os_service_default, + $log_headers = $::os_service_default, + $log_address = $::os_service_default, + $storage_domain = $::os_service_default, + $lookup_depth = $::os_service_default, + $nameservers = $::os_service_default, +) { + + include swift::deps + include swift::params + + if defined(Service['swift-proxy-server']) { + Package['python3-dnspython'] -> Service['swift-proxy-server'] + } + + swift_proxy_config { + 'filter:cname_lookup/use': value => 'egg:swift#cname_lookup'; + 'filter:cname_lookup/set log_name': value => $log_name; + 'filter:cname_lookup/set log_facility': value => $log_facility; + 'filter:cname_lookup/set log_level': value => $log_level; + 'filter:cname_lookup/set log_headers': value => $log_headers; + 'filter:cname_lookup/set log_address': value => $log_address; + 'filter:cname_lookup/storage_domain' : value => $storage_domain; + 'filter:cname_lookup/lookup_depth' : value => $lookup_depth; + 'filter:cname_lookup/nameservers' : value => $nameservers; + } + + package { 'python-dnspython': + ensure => 'present', + name => $::swift::params::dnspython_pakage_name, + tag => ['openstack', 'swift-support-package'], + } +} diff --git a/releasenotes/notes/cname_lookup-a545519cb21e37cd.yaml b/releasenotes/notes/cname_lookup-a545519cb21e37cd.yaml new file mode 100644 index 00000000..8d0c69b1 --- /dev/null +++ b/releasenotes/notes/cname_lookup-a545519cb21e37cd.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Support for the cname_lookup middlehware has been added. diff --git a/spec/classes/swift_proxy_cname_lookup_spec.rb b/spec/classes/swift_proxy_cname_lookup_spec.rb new file mode 100644 index 00000000..98b555db --- /dev/null +++ b/spec/classes/swift_proxy_cname_lookup_spec.rb @@ -0,0 +1,74 @@ +require 'spec_helper' + +describe 'swift::proxy::cname_lookup' do + shared_examples 'swift::proxy::cname_lookup' do + describe "when using default parameters" do + it { is_expected.to contain_swift_proxy_config('filter:cname_lookup/set log_name').with_value('') } + it { is_expected.to contain_swift_proxy_config('filter:cname_lookup/set log_facility').with_value('') } + it { is_expected.to contain_swift_proxy_config('filter:cname_lookup/set log_level').with_value('') } + it { is_expected.to contain_swift_proxy_config('filter:cname_lookup/set log_headers').with_value('') } + it { is_expected.to contain_swift_proxy_config('filter:cname_lookup/set log_address').with_value('') } + it { is_expected.to contain_swift_proxy_config('filter:cname_lookup/storage_domain').with_value('') } + it { is_expected.to contain_swift_proxy_config('filter:cname_lookup/lookup_depth').with_value('') } + it { is_expected.to contain_swift_proxy_config('filter:cname_lookup/nameservers').with_value('') } + it { is_expected.to contain_package('python-dnspython').with( + :name => platform_params[:dnspython_package_name], + :ensure => 'present', + :tag => ['openstack','swift-support-package'], + ) } + end + + describe "when overriding default parameters" do + let :params do + { + :log_name => 'newcname_lookup', + :log_facility => 'LOG_LOCAL3', + :log_level => 'WARN', + :log_headers => 'True', + :log_address => '/var/log', + :storage_domain => 'example.com', + :lookup_depth => '2', + :nameservers => '8.8.8.8', + } + end + + it { is_expected.to contain_swift_proxy_config('filter:cname_lookup/set log_name').with_value('newcname_lookup') } + it { is_expected.to contain_swift_proxy_config('filter:cname_lookup/set log_facility').with_value('LOG_LOCAL3') } + it { is_expected.to contain_swift_proxy_config('filter:cname_lookup/set log_level').with_value('WARN') } + it { is_expected.to contain_swift_proxy_config('filter:cname_lookup/set log_headers').with_value('True') } + it { is_expected.to contain_swift_proxy_config('filter:cname_lookup/set log_address').with_value('/var/log') } + it { is_expected.to contain_swift_proxy_config('filter:cname_lookup/storage_domain').with_value('example.com') } + it { is_expected.to contain_swift_proxy_config('filter:cname_lookup/lookup_depth').with_value('2') } + it { is_expected.to contain_swift_proxy_config('filter:cname_lookup/nameservers').with_value('8.8.8.8') } + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge(OSDefaults.get_facts()) + end + + let(:platform_params) do + case facts[:osfamily] + when 'Debian' + { :dnspython_package_name => 'python3-dnspython' } + when 'RedHat' + if facts[:operatingsystem] == 'Fedora' + { :dnspython_package_name => 'python3-dnspython' } + else + if facts[:operatingsystemmajrelease] > '7' + { :dnspython_package_name => 'python3-dnspython' } + else + { :dnspython_package_name => 'python-dnspython' } + end + end + end + end + + it_configures 'swift::proxy::cname_lookup' + end + end +end