From ccad0d083b26123b27a4f22a6a7ce7e4395cb99c Mon Sep 17 00:00:00 2001 From: Xingchao Yu Date: Thu, 9 Jul 2015 12:46:27 +0800 Subject: [PATCH] Introduce trove:config to manage custom options Class trove::config is aim to use trove config resources to manage custom configurations in trove config files. This will make end user easy to add their own custom options in Hiera data. Change-Id: I5d4b0aae8d5dddede1d56890f6f3e7b970b52bd0 Closes-Bug: #1473316 --- manifests/config.pp | 84 +++++++++++++++++++++++++++++++ spec/classes/trove_config_spec.rb | 63 +++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 manifests/config.pp create mode 100644 spec/classes/trove_config_spec.rb diff --git a/manifests/config.pp b/manifests/config.pp new file mode 100644 index 00000000..93d63136 --- /dev/null +++ b/manifests/config.pp @@ -0,0 +1,84 @@ +# +# Copyright (C) 2015 UnitedStack +# +# Author: Xingchao Yu +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# == Class: trove::config +# +# This class is used to manage arbitrary trove configurations. +# +# === Parameters +# +# [*trove_config*] +# (optional) Allow configuration of arbitrary trove configurations. +# The value is an hash of trove_config resources. +# Defaults to {} +# +# [*trove_taskmanager_config*] +# (optional) Allow configuration of arbitrary trove taskmanager configurations. +# The value is an hash of trove_taskmanager_config resources. +# Defaults to {} +# +# [*trove_conductor_config*] +# (optional) Allow configuration of arbitrary trove conductor configurations. +# The value is an hash of trove_conductor_config resources. +# Defaults to {} +# +# [*trove_guestagent_config*] +# (optional) Allow configuration of arbitrary trove guestagent configurations. +# The value is an hash of trove_guestagent_config resources. +# Defaults to {} +# +# [*trove_api_paste_ini*] +# (optional) Allow configuration of arbitrary trove paste api configurations. +# The value is an hash of trove_paste_api_ini resources. +# Defaults to {} +# +# Example: +# { 'DEFAULT/foo' => { value => 'fooValue'}, +# 'DEFAULT/bar' => { value => 'barValue'} +# } +# +# In yaml format, Example: +# trove_config: +# DEFAULT/foo: +# value: fooValue +# DEFAULT/bar: +# value: barValue +# +# NOTE: The configuration MUST NOT be already handled by this module +# or Puppet catalog compilation will fail with duplicate resources. +# +class trove::config ( + $trove_config = {}, + $trove_taskmanager_config = {}, + $trove_conductor_config = {}, + $trove_guestagent_config = {}, + $trove_api_paste_ini = {}, +) { + + validate_hash($trove_config) + validate_hash($trove_taskmanager_config) + validate_hash($trove_conductor_config) + validate_hash($trove_guestagent_config) + validate_hash($trove_api_paste_ini) + + create_resources('trove_config', $trove_config) + create_resources('trove_taskmanager_config', $trove_taskmanager_config) + create_resources('trove_conductor_config', $trove_conductor_config) + create_resources('trove_guestagent_config', $trove_guestagent_config) + create_resources('trove_api_paste_ini', $trove_api_paste_ini) + +} diff --git a/spec/classes/trove_config_spec.rb b/spec/classes/trove_config_spec.rb new file mode 100644 index 00000000..233945b9 --- /dev/null +++ b/spec/classes/trove_config_spec.rb @@ -0,0 +1,63 @@ +require 'spec_helper' + +describe 'trove::config' do + + let :params do + { :trove_config => { + 'DEFAULT/foo' => { 'value' => 'fooValue' }, + 'DEFAULT/bar' => { 'value' => 'barValue' }, + 'DEFAULT/baz' => { 'ensure' => 'absent' } + }, + :trove_taskmanager_config => { + 'DEFAULT/foo2' => { 'value' => 'fooValue' }, + 'DEFAULT/bar2' => { 'value' => 'barValue' }, + 'DEFAULT/baz2' => { 'ensure' => 'absent' } + }, + :trove_conductor_config => { + 'DEFAULT/foo2' => { 'value' => 'fooValue' }, + 'DEFAULT/bar2' => { 'value' => 'barValue' }, + 'DEFAULT/baz2' => { 'ensure' => 'absent' } + }, + :trove_guestagent_config => { + 'DEFAULT/foo2' => { 'value' => 'fooValue' }, + 'DEFAULT/bar2' => { 'value' => 'barValue' }, + 'DEFAULT/baz2' => { 'ensure' => 'absent' } + }, + :trove_api_paste_ini => { + 'DEFAULT/foo2' => { 'value' => 'fooValue' }, + 'DEFAULT/bar2' => { 'value' => 'barValue' }, + 'DEFAULT/baz2' => { 'ensure' => 'absent' } + } + } + end + + it 'configures arbitrary trove configurations' do + is_expected.to contain_trove_config('DEFAULT/foo').with_value('fooValue') + is_expected.to contain_trove_config('DEFAULT/bar').with_value('barValue') + is_expected.to contain_trove_config('DEFAULT/baz').with_ensure('absent') + end + + it 'configures arbitrary trove taskmanager configurations' do + is_expected.to contain_trove_taskmanager_config('DEFAULT/foo2').with_value('fooValue') + is_expected.to contain_trove_taskmanager_config('DEFAULT/bar2').with_value('barValue') + is_expected.to contain_trove_taskmanager_config('DEFAULT/baz2').with_ensure('absent') + end + + it 'configures arbitrary trove conductor configurations' do + is_expected.to contain_trove_conductor_config('DEFAULT/foo2').with_value('fooValue') + is_expected.to contain_trove_conductor_config('DEFAULT/bar2').with_value('barValue') + is_expected.to contain_trove_conductor_config('DEFAULT/baz2').with_ensure('absent') + end + + it 'configures arbitrary trove guestagent configurations' do + is_expected.to contain_trove_guestagent_config('DEFAULT/foo2').with_value('fooValue') + is_expected.to contain_trove_guestagent_config('DEFAULT/bar2').with_value('barValue') + is_expected.to contain_trove_guestagent_config('DEFAULT/baz2').with_ensure('absent') + end + + it 'configures arbitrary trove api-paste configurations' do + is_expected.to contain_trove_api_paste_ini('DEFAULT/foo2').with_value('fooValue') + is_expected.to contain_trove_api_paste_ini('DEFAULT/bar2').with_value('barValue') + is_expected.to contain_trove_api_paste_ini('DEFAULT/baz2').with_ensure('absent') + end +end