From 5ae42bcd48783c9e2be6fd81b99e6123c2c8d793 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 26 Apr 2022 01:05:36 +0900 Subject: [PATCH] Add general basic functionality to the base barbican class This is the prep work to migrate some common parameters from the api class to the base class, and implements basic functionality so that the base class provides consistent functionality in all modules. Change-Id: I0e20b135e8c29f1d27d39d2940d49ea30a1f512c --- manifests/init.pp | 28 ++++++++++- manifests/params.pp | 2 + .../barbican-base-opts-5d7598b51270cc64.yaml | 9 ++++ spec/classes/barbican_init_spec.rb | 49 +++++++++++++++++++ 4 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/barbican-base-opts-5d7598b51270cc64.yaml create mode 100644 spec/classes/barbican_init_spec.rb diff --git a/manifests/init.pp b/manifests/init.pp index de135f1d..bd53c364 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,9 +1,33 @@ # == Class: barbican # -# Full description of class barbican here. +# Barbican base package & configuration # -class barbican { +# === Parameters +# +# [*package_ensure*] +# (Optional) Ensure state for package. +# Defaults to 'present'. +# +# [*purge_config*] +# (optional) Whether to set only the specified config options +# in the cinder config. +# Defaults to false. +# +class barbican( + package_ensure => 'present', + purge_config => false, +) { + include barbican::deps include barbican::params + package { 'barbican': + ensure => package_ensure, + name => $::barbican::params::common_package_name, + tag => ['openstack', 'barbican-packages'], + } + + resources { 'barbican_config': + purge => $purge_config, + } } diff --git a/manifests/params.pp b/manifests/params.pp index 6976c24c..f426e609 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -12,6 +12,7 @@ class barbican::params { case $::osfamily { 'RedHat': { + $common_package_name = 'openstack-barbican-common' $api_package_name = 'openstack-barbican-api' $api_service_name = 'openstack-barbican-api' $worker_package_name = 'openstack-barbican-worker' @@ -22,6 +23,7 @@ class barbican::params { $barbican_wsgi_script_source = '/usr/bin/barbican-wsgi-api' } 'Debian': { + $common_package_name = 'barbican-common' $api_service_name = 'barbican-api' $api_package_name = 'barbican-api' $worker_package_name = 'barbican-worker' diff --git a/releasenotes/notes/barbican-base-opts-5d7598b51270cc64.yaml b/releasenotes/notes/barbican-base-opts-5d7598b51270cc64.yaml new file mode 100644 index 00000000..97482253 --- /dev/null +++ b/releasenotes/notes/barbican-base-opts-5d7598b51270cc64.yaml @@ -0,0 +1,9 @@ +--- +features: + - | + The ``barbican`` class now installs the ``barbican-common`` package. Status + of the package can be customized by the ``barbican::package_ensure`` + parameter. + + - | + The ``barbican::purge_config`` parameter has been added. diff --git a/spec/classes/barbican_init_spec.rb b/spec/classes/barbican_init_spec.rb new file mode 100644 index 00000000..ceccf25b --- /dev/null +++ b/spec/classes/barbican_init_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe 'barbican' do + + shared_examples 'barbican' do + + it { is_expected.to contain_class('barbican::deps') } + + context 'with default parameters' do + let :params do + {} + end + + it 'installs packages' do + is_expected.to contain_package('barbican').with( + :name => platform_params[:barbican_common_package], + :ensure => 'present', + :tag => ['openstack', 'barbican-package'] + ) + end + + it 'passes purge to resource' do + is_expected.to contain_resources('barbican_config').with({ + :purge => false + }) + 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 + + let(:platform_params) do + case facts[:osfamily] + when 'Debian' + { :barbican_common_package => 'barbican-common' } + when 'RedHat' + { :barbican_common_package => 'openstack-barbican-common' } + end + end + it_behaves_like 'barbican' + end + end +end