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
(cherry picked from commit 10202ad22f)
(cherry picked from commit f659ea896e)
This commit is contained in:
Takashi Kajinami
2022-08-24 01:14:17 +09:00
parent f5ee885fff
commit d8d7339ff1
2 changed files with 36 additions and 3 deletions

View File

@@ -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

View File

@@ -17,7 +17,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
@@ -38,5 +55,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