From 2072b01aac999554582756ac95cafa63cf4633ae Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Wed, 17 Aug 2022 13:57:27 +0900 Subject: [PATCH] Add support for Elasticsearch storage backend Change-Id: I9b3b74f3c32a43ae982f0c429c95819dc387bf80 --- manifests/storage/elasticsearch.pp | 35 +++++++++++++ .../notes/elasticsearch-87e4adec7946e2ab.yaml | 5 ++ .../cloudkitty_storage_elasticsearch_spec.rb | 52 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 manifests/storage/elasticsearch.pp create mode 100644 releasenotes/notes/elasticsearch-87e4adec7946e2ab.yaml create mode 100644 spec/classes/cloudkitty_storage_elasticsearch_spec.rb diff --git a/manifests/storage/elasticsearch.pp b/manifests/storage/elasticsearch.pp new file mode 100644 index 0000000..10e13e5 --- /dev/null +++ b/manifests/storage/elasticsearch.pp @@ -0,0 +1,35 @@ +# +# Class to configure elasticsearch storage +# +# == Parameters +# +# [*host*] +# Elasticsearch host, along with port and protocol. (string value) +# [*index_name*] +# Elasticsearch index to use. (string value) +# [*insecure*] +# Set to true to authorize insecure HTTPS connections to elasticsearch. +# [*cafile*] +# Path of the CA certificate to trust for HTTPS connections (string value). +# [*scroll_duration*] +# Duration (in seconds) for which the ES scroll contexts should be kept +# alive. (interer value) +# +class cloudkitty::storage::elasticsearch( + String $host = $::os_service_default, + String $index_name = $::os_service_default, + Variant[String[0],Boolean] $insecure = $::os_service_default, + String $cafile = $::os_service_default, + Variant[String[0],Integer] $scroll_duration = $::os_service_default, +){ + + include cloudkitty::deps + + cloudkitty_config { + 'storage_elasticsearch/host': value => $host; + 'storage_elasticsearch/index_name': value => $index_name; + 'storage_elasticsearch/insecure': value => $insecure; + 'storage_elasticsearch/cafile': value => $cafile; + 'storage_elasticsearch/scroll_duration': value => $scroll_duration; + } +} diff --git a/releasenotes/notes/elasticsearch-87e4adec7946e2ab.yaml b/releasenotes/notes/elasticsearch-87e4adec7946e2ab.yaml new file mode 100644 index 0000000..0de08e0 --- /dev/null +++ b/releasenotes/notes/elasticsearch-87e4adec7946e2ab.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + The new ``cloudkitty::storage::elasticsearch`` class has been added. This + class can be used to set up the Elasticsearch storage backend. diff --git a/spec/classes/cloudkitty_storage_elasticsearch_spec.rb b/spec/classes/cloudkitty_storage_elasticsearch_spec.rb new file mode 100644 index 0000000..54999de --- /dev/null +++ b/spec/classes/cloudkitty_storage_elasticsearch_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +describe 'cloudkitty::storage::elasticsearch' do + + let :params do + { + :host => '', + :index_name => '', + :insecure => '', + :cafile => '', + :scroll_duration => '', + } + end + + + shared_examples_for 'cloudkitty::storage::elasticsearch' do + it { should contain_class('cloudkitty::deps') } + + it { is_expected.to contain_cloudkitty_config('storage_elasticsearch/host').with_value( params[:host])} + it { is_expected.to contain_cloudkitty_config('storage_elasticsearch/index_name').with_value( params[:index_name])} + it { is_expected.to contain_cloudkitty_config('storage_elasticsearch/insecure').with_value( params[:insecure])} + it { is_expected.to contain_cloudkitty_config('storage_elasticsearch/cafile').with_value( params[:cafile])} + it { is_expected.to contain_cloudkitty_config('storage_elasticsearch/scroll_duration').with_value( params[:scroll_duration])} + 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 + + context 'with default parameters' do + it_behaves_like 'cloudkitty::storage::elasticsearch' + end + + context 'when overriding parameters' do + before do + params.merge!({ + :host => 'http://localhost:9200', + :index_name => 'cloudkitty', + :insecure => true, + :cafile => '/tmp/cafile.crt', + :scroll_duration => 30, + }) + end + it_behaves_like 'cloudkitty::storage::elasticsearch' + end + end + end +end