vs_config: Fix broken idempotency with nil/empty value
If the value is nil or empty then the option should NOT exist. This change fixes the logic to determine whether the option already exists which is causing broken idempotency. Closes-Bug: #1987419 Change-Id: I56f85ca35f8e9ee4e5e8d07c714b65f655b1e9ae
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user