From a032bec7d6a6016126f667361143e6630e159080 Mon Sep 17 00:00:00 2001 From: Tobias Urdin Date: Thu, 17 Dec 2020 09:59:02 +0100 Subject: [PATCH] Improve cinder_type properties regex This changes the regex for properties managed with the cinder_type resource so that it supports the format Cinder needs for multiattach and similar. multiattach= True This patch is needed so that cinder_type resources can set the above. See regex testing here [1]. Needs to be backported to older versions so that cinder_type can be properly used there as well. [1] https://regexr.com/5imqk Change-Id: If08fce9443281e65636aaaa99e3139732435f6f7 --- lib/puppet/type/cinder_type.rb | 2 +- spec/unit/provider/cinder_type/openstack_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/puppet/type/cinder_type.rb b/lib/puppet/type/cinder_type.rb index 326dca36..cd203b79 100644 --- a/lib/puppet/type/cinder_type.rb +++ b/lib/puppet/type/cinder_type.rb @@ -16,7 +16,7 @@ Puppet::Type.newtype(:cinder_type) do is.sort == should.sort end validate do |value| - raise ArgumentError, "Properties doesn't match" unless value.match(/^\s*[^=\s]+=[^=\s]+$/) + raise ArgumentError, "Properties doesn't match" unless value.match(/^\s*[^=\s]+=\S(([^=,])+((?<=\S),(?=\S))?)+([^\s=,])+$/) end end diff --git a/spec/unit/provider/cinder_type/openstack_spec.rb b/spec/unit/provider/cinder_type/openstack_spec.rb index 3f458028..bb7cbc6f 100644 --- a/spec/unit/provider/cinder_type/openstack_spec.rb +++ b/spec/unit/provider/cinder_type/openstack_spec.rb @@ -16,7 +16,7 @@ describe provider_class do { :name => 'Backend_1', :ensure => :present, - :properties => ['key=value', 'new_key=new_value'], + :properties => ['key=value', 'new_key=new_value', 'multiattach=" True"'], :is_public => true, :access_project_ids => [], } @@ -41,10 +41,10 @@ describe provider_class do describe '#create' do it 'creates a type' do provider_class.expects(:openstack) - .with('volume type', 'create', '--format', 'shell', ['--property', 'key=value', '--property', 'new_key=new_value', '--public', 'Backend_1']) + .with('volume type', 'create', '--format', 'shell', ['--property', 'key=value', '--property', 'new_key=new_value', '--property', 'multiattach=" True"', '--public', 'Backend_1']) .returns('id="90e19aff-1b35-4d60-9ee3-383c530275ab" name="Backend_1" -properties="key=\'value\', new_key=\'new_value\'" +properties="key=\'value\', new_key=\'new_value\', multiattach=\' True\'" is_public="True" access_project_ids="" ')