From f765702967a7dd2db36f92cb895ba70b3efebad3 Mon Sep 17 00:00:00 2001 From: Mikhail Stolyarov Date: Tue, 17 Sep 2024 14:01:46 +0300 Subject: [PATCH] Fixes vs_config options parsing Fix the parsing logic which wrongly detects '=' in hash values. Closes-Bug: #2080944 Change-Id: I8cd8c8f4640941966ac838580dd45ab56cadb6de (cherry picked from commit 4e4105cf488f2162f27cd81dcd235a2a144488d8) --- lib/puppet/provider/vs_config/ovs.rb | 2 +- spec/acceptance/basic_vswitch_spec.rb | 13 ++++++++++++- spec/unit/provider/vs_config/ovs_spec.rb | 8 +++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/puppet/provider/vs_config/ovs.rb b/lib/puppet/provider/vs_config/ovs.rb index cec87b53..e1f11233 100644 --- a/lib/puppet/provider/vs_config/ovs.rb +++ b/lib/puppet/provider/vs_config/ovs.rb @@ -15,7 +15,7 @@ Puppet::Type.type(:vs_config).provide(:ovs) do type = 'hash' res = {} value[1..-2].gsub('"','').split(', ').map(&:strip).each do |v| - k,val = v.split("=") + k,val = v.split('=', 2) res[k] = val end elsif value[0] == '[' diff --git a/spec/acceptance/basic_vswitch_spec.rb b/spec/acceptance/basic_vswitch_spec.rb index 0e488cc7..7f1df3e3 100644 --- a/spec/acceptance/basic_vswitch_spec.rb +++ b/spec/acceptance/basic_vswitch_spec.rb @@ -53,6 +53,11 @@ describe 'basic vswitch' do value => 'tcp:127.0.0.1:2300', } + vs_config { 'external_ids:ovn-cms-options': + ensure => present, + value => 'enable-chassis-as-gw,availability-zones=nova', + } + vs_config { 'other_config:thisshouldexist': ensure => present, value => 'customvalue', @@ -131,12 +136,18 @@ describe 'basic vswitch' do end end - it 'should get remote addr' do + it 'should get ovn remote addr' do command('ovs-vsctl get Open_vSwitch . external_ids:ovn-remote') do |r| expect(r.stdout).to match(/\"tcp:127.0.0.1:2300\"/) end end + it 'should get ovn cms options' do + command('ovs-vsctl get Open_vSwitch . external_ids:ovn-cms-options') do |r| + expect(r.stdout).to match(/\"enable-chassis-as-gw,availability-zones=nova\"/) + 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}"/) diff --git a/spec/unit/provider/vs_config/ovs_spec.rb b/spec/unit/provider/vs_config/ovs_spec.rb index 8638d7c9..6da27ffd 100644 --- a/spec/unit/provider/vs_config/ovs_spec.rb +++ b/spec/unit/provider/vs_config/ovs_spec.rb @@ -73,11 +73,12 @@ key3 : [1001, 399, 240, 1200]') expect(described_class).to receive(:vsctl).with( "list", "Open_vSwitch", ".").and_return('key1 : {} key2 : {"hash21"="value21"} -key3 : {"hash31"="value31", "hash32"="value32", "hash33"=33}') +key3 : {"hash31"="value31", "hash32"="value32", "hash33"=33} +key4 : {"hash41"="value41,key42=value42"}') end it "should return three resources" do - expect(described_class.instances.size).to eq(4) + expect(described_class.instances.size).to eq(5) end it "should contain valid names and values" do @@ -85,7 +86,8 @@ key3 : {"hash31"="value31", "hash32"="value32", "hash33"=33}') "key2:hash21" => "value21", "key3:hash31" => "value31", "key3:hash32" => "value32", - "key3:hash33" => "33"} + "key3:hash33" => "33", + "key4:hash41" => "value41,key42=value42"} described_class.instances.each do |inst| _inst = inst.instance_variable_get("@property_hash") expect(expected_values.key?(_inst[:name])).to eq true