From e56e06b7f34efabaf8adfebcccbb76c08076b8ce Mon Sep 17 00:00:00 2001 From: Marcel Haerry <marcel.haerry@swisscom.com> Date: Sun, 7 Jun 2015 21:45:24 +0200 Subject: [PATCH] make it possible to have multiple type_sets with the same value Add a value option to set value not only by namevar, but rather by a dedicated value variable. Otherwise we might end up with duplicated resources. Change-Id: I64eb8b2efc81821b8f32ca493ba5ba9b3afad1d6 Co-Author: Janosch Rohdewald <janosch.rohdewald@swisscom.com> Backport-Potential: juno --- manifests/type_set.pp | 10 +++++-- spec/defines/cinder_type_set_spec.rb | 42 ++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/manifests/type_set.pp b/manifests/type_set.pp index 5b574537..ddf3373f 100644 --- a/manifests/type_set.pp +++ b/manifests/type_set.pp @@ -13,6 +13,9 @@ # [*key*] # (required) the key name that we are setting the value for. # +# [*value*] +# the value that we are setting. Defaults to content of namevar. +# # [*os_tenant_name*] # (optional) The keystone tenant name. Defaults to 'admin'. # @@ -36,6 +39,7 @@ define cinder::type_set ( $os_username = 'admin', $os_auth_url = 'http://127.0.0.1:5000/v2.0/', $os_region_name = undef, + $value = $name, ) { # TODO: (xarses) This should be moved to a ruby provider so that among other @@ -55,10 +59,10 @@ define cinder::type_set ( $region_env = [] } - exec {"cinder type-key ${type} set ${key}=${name}": + exec {"cinder type-key ${type} set ${key}=${value}": path => ['/usr/bin', '/bin'], - command => "cinder type-key ${type} set ${key}=${name}", - unless => "cinder extra-specs-list | grep -Eq '\\b${type}\\b.*\\b${key}\\b.*\\b${name}\\b'", + command => "cinder type-key ${type} set ${key}=${value}", + unless => "cinder extra-specs-list | grep -Eq '\\b${type}\\b.*\\b${key}\\b.*\\b${value}\\b'", environment => concat($cinder_env, $region_env), require => Package['python-cinderclient'] } diff --git a/spec/defines/cinder_type_set_spec.rb b/spec/defines/cinder_type_set_spec.rb index 97d1180d..9218b3bd 100644 --- a/spec/defines/cinder_type_set_spec.rb +++ b/spec/defines/cinder_type_set_spec.rb @@ -6,7 +6,7 @@ describe 'cinder::type_set' do let(:title) {'hippo'} - let :params do { + let :default_params do { :type => 'sith', :key => 'monchichi', :os_password => 'asdf', @@ -16,15 +16,35 @@ describe 'cinder::type_set' do } end - it 'should have its execs' do - is_expected.to contain_exec('cinder type-key sith set monchichi=hippo').with( - :command => 'cinder type-key sith set monchichi=hippo', - :unless => "cinder extra-specs-list | grep -Eq '\\bsith\\b.*\\bmonchichi\\b.*\\bhippo\\b'", - :environment => [ - 'OS_TENANT_NAME=admin', - 'OS_USERNAME=admin', - 'OS_PASSWORD=asdf', - 'OS_AUTH_URL=http://127.127.127.1:5000/v2.0/'], - :require => 'Package[python-cinderclient]') + describe 'by default' do + let(:params){ default_params } + it 'should have its execs' do + should contain_exec('cinder type-key sith set monchichi=hippo').with( + :command => 'cinder type-key sith set monchichi=hippo', + :unless => "cinder extra-specs-list | grep -Eq '\\bsith\\b.*\\bmonchichi\\b.*\\bhippo\\b'", + :environment => [ + 'OS_TENANT_NAME=admin', + 'OS_USERNAME=admin', + 'OS_PASSWORD=asdf', + 'OS_AUTH_URL=http://127.127.127.1:5000/v2.0/'], + :require => 'Package[python-cinderclient]') + end + end + + describe 'with a different value' do + let(:params){ + default_params.merge({:value => 'hippi'}) + } + it 'should have its execs' do + should contain_exec('cinder type-key sith set monchichi=hippi').with( + :command => 'cinder type-key sith set monchichi=hippi', + :unless => "cinder extra-specs-list | grep -Eq '\\bsith\\b.*\\bmonchichi\\b.*\\bhippi\\b'", + :environment => [ + 'OS_TENANT_NAME=admin', + 'OS_USERNAME=admin', + 'OS_PASSWORD=asdf', + 'OS_AUTH_URL=http://127.127.127.1:5000/v2.0/'], + :require => 'Package[python-cinderclient]') + end end end