From 06b384e84df36f942ca7686481d0d40fb5618f0f Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Wed, 28 Feb 2024 11:12:11 +0900 Subject: [PATCH] Support healthcheck middleware options Trove introduced the healthcheck middleware during this cycle. This introduces the new class to support the middleware options. Depends-on: https://review.opendev.org/c/openstack/trove/+/910117 Change-Id: I5baf1e07078cb904d0c1ca17874c2639620e5e4f --- manifests/healthcheck.pp | 54 ++++++++++++++++ .../notes/healthcheck-39c7baba411cc930.yaml | 4 ++ spec/classes/trove_healthcheck_spec.rb | 61 +++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 manifests/healthcheck.pp create mode 100644 releasenotes/notes/healthcheck-39c7baba411cc930.yaml create mode 100644 spec/classes/trove_healthcheck_spec.rb diff --git a/manifests/healthcheck.pp b/manifests/healthcheck.pp new file mode 100644 index 00000000..ae2cbe10 --- /dev/null +++ b/manifests/healthcheck.pp @@ -0,0 +1,54 @@ +# == Class: trove::healthcheck +# +# Configure oslo_middleware options in healthcheck section +# +# == Params +# +# [*detailed*] +# (Optional) Show more detailed information as part of the response. +# Defaults to $facts['os_service_default'] +# +# [*backends*] +# (Optional) Additional backends that can perform health checks and report +# that information back as part of a request. +# Defaults to $facts['os_service_default'] +# +# [*allowed_source_ranges*] +# (Optional) A list of network addresses to limit source ip allowed to access +# healthcheck information. +# Defaults to $facts['os_service_default'] +# +# [*ignore_proxied_requests*] +# (Optional) Ignore requests with proxy headers +# Defaults to $facts['os_service_default'] +# +# [*disable_by_file_path*] +# (Optional) Check the presence of a file to determine if an application +# is running on a port. +# Defaults to $facts['os_service_default'] +# +# [*disable_by_file_paths*] +# (Optional) Check the presence of a file to determine if an application +# is running on a port. Expects a "port:path" list of strings. +# Defaults to $facts['os_service_default'] +# +class trove::healthcheck ( + $detailed = $facts['os_service_default'], + $backends = $facts['os_service_default'], + $allowed_source_ranges = $facts['os_service_default'], + $ignore_proxied_requests = $facts['os_service_default'], + $disable_by_file_path = $facts['os_service_default'], + $disable_by_file_paths = $facts['os_service_default'], +) { + + include trove::deps + + oslo::healthcheck { 'trove_config': + detailed => $detailed, + backends => $backends, + allowed_source_ranges => $allowed_source_ranges, + ignore_proxied_requests => $ignore_proxied_requests, + disable_by_file_path => $disable_by_file_path, + disable_by_file_paths => $disable_by_file_paths, + } +} diff --git a/releasenotes/notes/healthcheck-39c7baba411cc930.yaml b/releasenotes/notes/healthcheck-39c7baba411cc930.yaml new file mode 100644 index 00000000..071d73a8 --- /dev/null +++ b/releasenotes/notes/healthcheck-39c7baba411cc930.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + The new ``trove::healthcheck`` class has been added. diff --git a/spec/classes/trove_healthcheck_spec.rb b/spec/classes/trove_healthcheck_spec.rb new file mode 100644 index 00000000..e3db8b85 --- /dev/null +++ b/spec/classes/trove_healthcheck_spec.rb @@ -0,0 +1,61 @@ +require 'spec_helper' + +describe 'trove::healthcheck' do + + shared_examples_for 'trove::healthcheck' do + + context 'with default parameters' do + let :params do + {} + end + + it 'configures default values' do + is_expected.to contain_oslo__healthcheck('trove_config').with( + :detailed => '', + :backends => '', + :allowed_source_ranges => '', + :ignore_proxied_requests => '', + :disable_by_file_path => '', + :disable_by_file_paths => '', + ) + end + end + + context 'with specific parameters' do + let :params do + { + :detailed => true, + :backends => ['disable_by_file'], + :allowed_source_ranges => ['10.0.0.0/24', '10.0.1.0/24'], + :ignore_proxied_requests => false, + :disable_by_file_path => '/etc/trove/healthcheck/disabled', + :disable_by_file_paths => ['8779:/etc/trove/healthcheck/disabled'], + } + end + + it 'configures specified values' do + is_expected.to contain_oslo__healthcheck('trove_config').with( + :detailed => true, + :backends => ['disable_by_file'], + :allowed_source_ranges => ['10.0.0.0/24', '10.0.1.0/24'], + :ignore_proxied_requests => false, + :disable_by_file_path => '/etc/trove/healthcheck/disabled', + :disable_by_file_paths => ['8779:/etc/trove/healthcheck/disabled'], + ) + end + 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_configures 'trove::healthcheck' + end + end + +end