From 1b5eceeb3651bce0e129f5a5837812a7d6c8eb59 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sun, 18 Feb 2024 14:08:44 +0900 Subject: [PATCH] Add support for read_only middleware Change-Id: I82726ab76587a134f9267521821b48e8a1a05936 --- manifests/proxy/read_only.pp | 27 ++++++++++++++ .../notes/read_only-f0e5b52bfcbbe99d.yaml | 4 +++ spec/classes/swift_proxy_read_only_spec.rb | 36 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 manifests/proxy/read_only.pp create mode 100644 releasenotes/notes/read_only-f0e5b52bfcbbe99d.yaml create mode 100644 spec/classes/swift_proxy_read_only_spec.rb diff --git a/manifests/proxy/read_only.pp b/manifests/proxy/read_only.pp new file mode 100644 index 00000000..74646fad --- /dev/null +++ b/manifests/proxy/read_only.pp @@ -0,0 +1,27 @@ +# == Class: swift::proxy::read_only +# +# Configure read_only middleware +# +# === Parameters +# +# [*read_only*] +# (optional) Turn on global read only. +# Defauls to $facts['os_service_default'] +# +# [*allow_deletes*] +# (optional) Allow deletes. +# Defauls to $facts['os_service_default'] +# +class swift::proxy::read_only( + $read_only = $facts['os_service_default'], + $allow_deletes = $facts['os_service_default'] +) { + + include swift::deps + + swift_proxy_config { + 'filter:read_only/use': value => 'egg:swift#read_only'; + 'filter:read_only/read_only': value => $read_only; + 'filter:read_only/allow_deletes': value => $allow_deletes; + } +} diff --git a/releasenotes/notes/read_only-f0e5b52bfcbbe99d.yaml b/releasenotes/notes/read_only-f0e5b52bfcbbe99d.yaml new file mode 100644 index 00000000..80639809 --- /dev/null +++ b/releasenotes/notes/read_only-f0e5b52bfcbbe99d.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + The new ``swift::proxy::read_only`` class has been added. diff --git a/spec/classes/swift_proxy_read_only_spec.rb b/spec/classes/swift_proxy_read_only_spec.rb new file mode 100644 index 00000000..338ce131 --- /dev/null +++ b/spec/classes/swift_proxy_read_only_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe 'swift::proxy::read_only' do + shared_examples 'swift::proxy::read_only' do + context 'when using default parameters' do + it { is_expected.to contain_swift_proxy_config('filter:read_only/use').with_value('egg:swift#read_only') } + it { is_expected.to contain_swift_proxy_config('filter:read_only/read_only').with_value('') } + it { is_expected.to contain_swift_proxy_config('filter:read_only/allow_deletes').with_value('') } + end + + context 'when overriding default parameters' do + let :params do + { + :read_only => true, + :allow_deletes => false, + } + end + + it { is_expected.to contain_swift_proxy_config('filter:read_only/use').with_value('egg:swift#read_only') } + it { is_expected.to contain_swift_proxy_config('filter:read_only/read_only').with_value(true) } + it { is_expected.to contain_swift_proxy_config('filter:read_only/allow_deletes').with_value(false) } + 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 + + it_behaves_like 'swift::proxy::read_only' + end + end +end