diff --git a/lib/puppet/provider/vs_config/ovs.rb b/lib/puppet/provider/vs_config/ovs.rb index 4ccb5ddc..cec87b53 100644 --- a/lib/puppet/provider/vs_config/ovs.rb +++ b/lib/puppet/provider/vs_config/ovs.rb @@ -85,6 +85,8 @@ Puppet::Type.type(:vs_config).provide(:ovs) do # if skip_if_version matches ovs_version(), then skip the configuration by faking exists if @resource[:skip_if_version].eql? ovs_version() return true + elsif ensure_absent? + @property_hash[:ensure] != :present else @property_hash[:ensure] == :present end @@ -108,7 +110,7 @@ Puppet::Type.type(:vs_config).provide(:ovs) do end def create - if @resource[:value].nil? or @resource[:value].empty? + if ensure_absent? destroy else _set @@ -119,6 +121,8 @@ Puppet::Type.type(:vs_config).provide(:ovs) do # if skip_if_version matches ovs_version(), then skip the configuration by returning the same value if @resource[:skip_if_version].eql? ovs_version() @resource[:value] + elsif ensure_absent? + @resource[:value] else @property_hash[:value] end @@ -129,10 +133,16 @@ Puppet::Type.type(:vs_config).provide(:ovs) do end def value=(value) - if @resource[:value].nil? or @resource[:value].empty? + if ensure_absent? destroy else _set end end + + private + + def ensure_absent? + (@resource[:value].nil? or @resource[:value].empty?) and @resource[:ensure] == :present + end end diff --git a/spec/acceptance/basic_vswitch_spec.rb b/spec/acceptance/basic_vswitch_spec.rb index e7da36d8..3636e665 100644 --- a/spec/acceptance/basic_vswitch_spec.rb +++ b/spec/acceptance/basic_vswitch_spec.rb @@ -44,7 +44,24 @@ describe 'basic vswitch' do vs_config { 'external_ids:ovn-remote': ensure => present, - value => 'tcp:127.0.0.1:2300', + value => 'tcp:127.0.0.1:2300', + } + + vs_config { 'other_config:thisshouldexist': + ensure => present, + value => 'customvalue', + } + vs_config { 'other_config:thisshouldnotexist': + ensure => present, + value => undef, + } + vs_config { 'other_config:thisshouldnotexist2': + ensure => present, + value => '', + } + vs_config { 'other_config:thisshouldnotexist3': + ensure => present, + value => [], } EOS @@ -107,5 +124,11 @@ describe 'basic vswitch' do expect(r.stdout).to match(/\"tcp:127.0.0.1:2300\"/) end end + + it 'should get other config' do + command('sudo ovs-vsctl get Open_Vswitch . other_config') do |r| + expect(r.stdout).to match(/\"{thishshouldexist=customvalue}"/) + end + end end end