commit 8556da0c4d24d1b0fedfd91b430593b7006eb816 Author: Benedikt Trefzer Date: Wed Sep 23 19:13:46 2020 +0200 add class to configure influxdb storage configuration Change-Id: Ifc51a30f0cb03b1f5b79d70bd1ac396850264828 diff --git a/manifests/storage/influxdb.pp b/manifests/storage/influxdb.pp new file mode 100644 index 0000000..d449bfb --- /dev/null +++ b/manifests/storage/influxdb.pp @@ -0,0 +1,52 @@ +# +# Class to configure influxdb storage +# +# == Parameters +# +# [*username*] +# InfluxDB username (string value) +# [*password*] +# InfluxDB password (string value) +# [*database*] +# InfluxDB database (string value) +# [*retention_policy*] +# Retention policy to use (string value) +# [*host*] +# InfluxDB host (string value) +# [*port*] +# InfluxDB port (integer value) +# [*use_ssl*] +# Set to true to use ssl for influxDB connection. +# (boolean value) +# [*insecure*] +# Set to true to authorize insecure HTTPS connections to influxDB. +# [*cafile*] +# Path of the CA certificate to trust for HTTPS +# connections (string value) +# +class cloudkitty::storage::influxdb( + String $username = $::os_service_default, + String $password = $::os_service_default, + String $database = $::os_service_default, + String $retention_policy = $::os_service_default, + String $host = $::os_service_default, + Variant[String[0],Integer] $port = $::os_service_default, + Variant[String[0],Boolean] $use_ssl = $::os_service_default, + Variant[String[0],Boolean] $insecure = $::os_service_default, + String $cafile = $::os_service_default, +){ + + include cloudkitty::deps + + cloudkitty_config { + 'storage_influxdb/username': value => $username; + 'storage_influxdb/password': value => $password, secret => true; + 'storage_influxdb/database': value => $database; + 'storage_influxdb/retention_policy': value => $retention_policy; + 'storage_influxdb/host': value => $host; + 'storage_influxdb/port': value => $port; + 'storage_influxdb/use_ssl': value => $use_ssl; + 'storage_influxdb/insecure': value => $insecure; + 'storage_influxdb/cafile': value => $cafile; + } +} diff --git a/releasenotes/notes/class_storage_influxdb-262bcc03108b69e1.yaml b/releasenotes/notes/class_storage_influxdb-262bcc03108b69e1.yaml new file mode 100644 index 0000000..2ac58aa --- /dev/null +++ b/releasenotes/notes/class_storage_influxdb-262bcc03108b69e1.yaml @@ -0,0 +1,3 @@ +--- +features: + - add class cloudkitty::storage::influxdb to configure influxdb storage diff --git a/spec/classes/cloudkitty_storage_influxdb_spec.rb b/spec/classes/cloudkitty_storage_influxdb_spec.rb new file mode 100644 index 0000000..2a01e40 --- /dev/null +++ b/spec/classes/cloudkitty_storage_influxdb_spec.rb @@ -0,0 +1,63 @@ +require 'spec_helper' + +describe 'cloudkitty::storage::influxdb' do + + let :params do + { :username => '', + :password => '', + :database => '', + :retention_policy => '', + :host => '', + :port => '', + :use_ssl => '', + :insecure => '', + :cafile => '', + } + end + + + shared_examples_for 'cloudkitty::storage::influxdb' do + it { should contain_class('cloudkitty::deps') } + + it { is_expected.to contain_cloudkitty_config('storage_influxdb/username').with_value( params[:username])} + it { is_expected.to contain_cloudkitty_config('storage_influxdb/password').with( value: params[:password], secret: true)} + it { is_expected.to contain_cloudkitty_config('storage_influxdb/database').with_value( params[:database])} + it { is_expected.to contain_cloudkitty_config('storage_influxdb/retention_policy').with_value( params[:retention_policy])} + it { is_expected.to contain_cloudkitty_config('storage_influxdb/host').with_value( params[:host])} + it { is_expected.to contain_cloudkitty_config('storage_influxdb/port').with_value( params[:port])} + it { is_expected.to contain_cloudkitty_config('storage_influxdb/use_ssl').with_value( params[:use_ssl])} + it { is_expected.to contain_cloudkitty_config('storage_influxdb/insecure').with_value( params[:insecure])} + it { is_expected.to contain_cloudkitty_config('storage_influxdb/cafile').with_value( params[:cafile])} + 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::influxdb' + end + + context 'when overriding parameters' do + before do + params.merge!({ + :username => 'kittycloud', + :password => 'nice', + :database => 'kittycloud', + :retention_policy => 'policy', + :host => 'kitty.heaven.org', + :port => 42, + :use_ssl => 'true', + :insecure => 'true', + :cafile => '/tmp/cafile.crt', + }) + end + it_behaves_like 'cloudkitty::storage::influxdb' + end + end + end +end