Browse Source

Merge "vs_config: Accept integer and boolean for value"

changes/76/795476/38
Zuul 4 months ago committed by Gerrit Code Review
parent
commit
001f0ab51f
  1. 16
      lib/puppet/type/vs_config.rb
  2. 17
      manifests/dpdk.pp
  3. 12
      manifests/ovs.pp
  4. 5
      releasenotes/notes/vs_config-allow-integer-and-boolean-20f9aec5951b35f8.yaml
  5. 12
      spec/classes/vswitch_dpdk_spec.rb
  6. 8
      spec/classes/vswitch_ovs_spec.rb
  7. 22
      spec/unit/puppet/lib/type/vs_config_spec.rb

16
lib/puppet/type/vs_config.rb

@ -19,7 +19,7 @@ Puppet::Type.newtype(:vs_config) do
desc 'Skip setting the value when ovs version matches'
validate do |value|
unless value.is_a?(String) and value =~ /^\d+.\d+$/
raise ArgumentError, "Invalid format for #{value}. Requires a String with format \d+.\d+, not a #{value.class}"
raise ArgumentError, "Invalid skip_if_version #{value}. Requires a String with format \d+.\d+, not a #{value.class}"
end
end
end
@ -50,16 +50,20 @@ Puppet::Type.newtype(:vs_config) do
desc 'Configuration value for the parameter'
validate do |value|
if !value.is_a?(String)
raise ArgumentError, "Invalid external_ids #{value}. Requires a String, not a #{value.class}"
if !value.is_a?(String) and !value.is_a?(Integer) and !(value == true) and !(value == false)
raise ArgumentError, "Invalid value #{value}. Requires a String, a Integer or a Boolean, not a #{value.class}"
end
end
munge do |value|
if value[0] == '[' && value[-1] == ']'
"[#{value[1..-2].split(',').map(&:strip).sort.join(",")}]"
if value.is_a?(String)
if value[0] == '[' && value[-1] == ']'
"[#{value[1..-2].split(',').map(&:strip).sort.join(",")}]"
else
super(value)
end
else
super(value)
super(String(value))
end
end
end

17
manifests/dpdk.pp

@ -115,10 +115,9 @@ class vswitch::dpdk (
notify => Vs_config['other_config:dpdk-init'],
}
# lint:ignore:quoted_booleans
if $enable_hw_offload {
vs_config { 'other_config:hw-offload':
value => 'true',
value => true,
restart => true,
wait => true,
}
@ -129,11 +128,10 @@ class vswitch::dpdk (
wait => true,
}
}
# lint:endignore
if $disable_emc {
vs_config { 'other_config:emc-insert-inv-prob':
value => '0',
value => 0,
wait => false,
}
}
@ -144,25 +142,18 @@ class vswitch::dpdk (
ensure => absent,
wait => true,
}
} elsif $vlan_limit == undef {
vs_config { 'other_config:vlan-limit':
ensure => absent,
wait => true,
}
} else {
vs_config { 'other_config:vlan-limit':
value => "${vlan_limit}",
value => $vlan_limit,
wait => true,
}
}
# lint:ignore:quoted_booleans
vs_config { 'other_config:dpdk-init':
value => 'true',
value => true,
require => Service['openvswitch'],
wait => true,
}
# lint:endignore
service { 'openvswitch':
ensure => true,

12
manifests/ovs.pp

@ -87,10 +87,9 @@ class vswitch::ovs(
}
}
# lint:ignore:quoted_booleans
if $enable_hw_offload {
vs_config { 'other_config:hw-offload':
value => 'true',
value => true,
restart => true,
wait => true,
}
@ -105,7 +104,7 @@ class vswitch::ovs(
if $disable_emc {
vs_config { 'other_config:emc-insert-inv-prob':
value => '0',
value => 0,
wait => false,
}
}
@ -116,14 +115,9 @@ class vswitch::ovs(
ensure => absent,
wait => true,
}
} elsif $vlan_limit == undef {
vs_config { 'other_config:vlan-limit':
ensure => absent,
wait => true,
}
} else {
vs_config { 'other_config:vlan-limit':
value => "${vlan_limit}",
value => $vlan_limit,
wait => true,
}
}

5
releasenotes/notes/vs_config-allow-integer-and-boolean-20f9aec5951b35f8.yaml

@ -0,0 +1,5 @@
---
features:
- |
Now the ``value`` property of the ``vs_config`` resource accepts Integer
and Boolean in addition to String.

12
spec/classes/vswitch_dpdk_spec.rb

@ -32,7 +32,7 @@ describe 'vswitch::dpdk' do
end
it 'configures dpdk options' do
is_expected.to contain_vs_config('other_config:dpdk-init').with(
:value => 'true', :wait => true,
:value => true, :wait => true,
)
is_expected.to contain_vs_config('other_config:pmd-cpu-mask').with(
:value => nil, :wait => false,
@ -51,7 +51,7 @@ describe 'vswitch::dpdk' do
)
is_expected.to_not contain_vs_config('other_config:emc-insert-inv-prob')
is_expected.to contain_vs_config('other_config:vlan-limit').with(
:ensure => 'absent', :wait => true,
:value => nil, :wait => true,
)
end
@ -69,7 +69,7 @@ describe 'vswitch::dpdk' do
end
it 'configures dpdk options' do
is_expected.to contain_vs_config('other_config:dpdk-init').with(
:value => 'true', :wait => true,
:value => true, :wait => true,
)
is_expected.to contain_vs_config('other_config:pmd-cpu-mask').with(
:value => '3c0000000003c00000', :wait => false,
@ -84,13 +84,13 @@ describe 'vswitch::dpdk' do
:value => '-n 2', :wait => false,
)
is_expected.to contain_vs_config('other_config:hw-offload').with(
:value => 'true', :restart => true, :wait => true,
:value => true, :restart => true, :wait => true,
)
is_expected.to contain_vs_config('other_config:emc-insert-inv-prob').with(
:value => '0', :wait => false,
:value => 0, :wait => false,
)
is_expected.to contain_vs_config('other_config:vlan-limit').with(
:value => '2', :wait => true,
:value => 2, :wait => true,
)
end
end

8
spec/classes/vswitch_ovs_spec.rb

@ -34,7 +34,7 @@ describe 'vswitch::ovs' do
it 'clears vlan-limit option' do
is_expected.to contain_vs_config('other_config:vlan-limit').with(
:ensure => 'absent', :wait => true,
:value => nil, :wait => true,
)
end
@ -76,17 +76,17 @@ describe 'vswitch::ovs' do
end
it 'configures hw-offload option' do
is_expected.to contain_vs_config('other_config:hw-offload').with(
:value => 'true', :restart => true, :wait => true,
:value => true, :restart => true, :wait => true,
)
end
it 'configures disable_emc option' do
is_expected.to contain_vs_config('other_config:emc-insert-inv-prob').with(
:value => '0', :wait => false,
:value => 0, :wait => false,
)
end
it 'configures vlan-limit option' do
is_expected.to contain_vs_config('other_config:vlan-limit').with(
:value => '2', :wait => true,
:value => 2, :wait => true,
)
end

22
spec/unit/puppet/lib/type/vs_config_spec.rb

@ -47,9 +47,27 @@ describe Puppet::Type.type(:vs_config) do
expect(described_class.attrtype(:value)).to eq(:property)
end
it "should accept only string values" do
it "should accept a string value" do
expect(
described_class.new({:name => "foo", :value => "123", :ensure => :present})[:value]
).to eq "123"
end
it "should accept a integer value" do
expect(
described_class.new({:name => "foo", :value => 123, :ensure => :present})[:value]
).to eq "123"
end
it "should accept a boolean value" do
expect(
described_class.new({:name => "foo", :value => true, :ensure => :present})[:value]
).to eq "true"
end
it "should accept the other values" do
expect do
described_class.new({:name => "foo", :value => 123, :ensure => :present})
described_class.new({:name => "foo", :value => 123.4, :ensure => :present})
end.to raise_error(Puppet::Error)
end

Loading…
Cancel
Save