Merge "vs_config: Accept integer and boolean for value"
This commit is contained in:
commit
001f0ab51f
|
@ -19,7 +19,7 @@ Puppet::Type.newtype(:vs_config) do
|
||||||
desc 'Skip setting the value when ovs version matches'
|
desc 'Skip setting the value when ovs version matches'
|
||||||
validate do |value|
|
validate do |value|
|
||||||
unless value.is_a?(String) and value =~ /^\d+.\d+$/
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -50,16 +50,20 @@ Puppet::Type.newtype(:vs_config) do
|
||||||
desc 'Configuration value for the parameter'
|
desc 'Configuration value for the parameter'
|
||||||
|
|
||||||
validate do |value|
|
validate do |value|
|
||||||
if !value.is_a?(String)
|
if !value.is_a?(String) and !value.is_a?(Integer) and !(value == true) and !(value == false)
|
||||||
raise ArgumentError, "Invalid external_ids #{value}. Requires a String, not a #{value.class}"
|
raise ArgumentError, "Invalid value #{value}. Requires a String, a Integer or a Boolean, not a #{value.class}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
munge do |value|
|
munge do |value|
|
||||||
if value[0] == '[' && value[-1] == ']'
|
if value.is_a?(String)
|
||||||
"[#{value[1..-2].split(',').map(&:strip).sort.join(",")}]"
|
if value[0] == '[' && value[-1] == ']'
|
||||||
|
"[#{value[1..-2].split(',').map(&:strip).sort.join(",")}]"
|
||||||
|
else
|
||||||
|
super(value)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
super(value)
|
super(String(value))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -115,10 +115,9 @@ class vswitch::dpdk (
|
||||||
notify => Vs_config['other_config:dpdk-init'],
|
notify => Vs_config['other_config:dpdk-init'],
|
||||||
}
|
}
|
||||||
|
|
||||||
# lint:ignore:quoted_booleans
|
|
||||||
if $enable_hw_offload {
|
if $enable_hw_offload {
|
||||||
vs_config { 'other_config:hw-offload':
|
vs_config { 'other_config:hw-offload':
|
||||||
value => 'true',
|
value => true,
|
||||||
restart => true,
|
restart => true,
|
||||||
wait => true,
|
wait => true,
|
||||||
}
|
}
|
||||||
|
@ -129,11 +128,10 @@ class vswitch::dpdk (
|
||||||
wait => true,
|
wait => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# lint:endignore
|
|
||||||
|
|
||||||
if $disable_emc {
|
if $disable_emc {
|
||||||
vs_config { 'other_config:emc-insert-inv-prob':
|
vs_config { 'other_config:emc-insert-inv-prob':
|
||||||
value => '0',
|
value => 0,
|
||||||
wait => false,
|
wait => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,25 +142,18 @@ class vswitch::dpdk (
|
||||||
ensure => absent,
|
ensure => absent,
|
||||||
wait => true,
|
wait => true,
|
||||||
}
|
}
|
||||||
} elsif $vlan_limit == undef {
|
|
||||||
vs_config { 'other_config:vlan-limit':
|
|
||||||
ensure => absent,
|
|
||||||
wait => true,
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
vs_config { 'other_config:vlan-limit':
|
vs_config { 'other_config:vlan-limit':
|
||||||
value => "${vlan_limit}",
|
value => $vlan_limit,
|
||||||
wait => true,
|
wait => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# lint:ignore:quoted_booleans
|
|
||||||
vs_config { 'other_config:dpdk-init':
|
vs_config { 'other_config:dpdk-init':
|
||||||
value => 'true',
|
value => true,
|
||||||
require => Service['openvswitch'],
|
require => Service['openvswitch'],
|
||||||
wait => true,
|
wait => true,
|
||||||
}
|
}
|
||||||
# lint:endignore
|
|
||||||
|
|
||||||
service { 'openvswitch':
|
service { 'openvswitch':
|
||||||
ensure => true,
|
ensure => true,
|
||||||
|
|
|
@ -87,10 +87,9 @@ class vswitch::ovs(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# lint:ignore:quoted_booleans
|
|
||||||
if $enable_hw_offload {
|
if $enable_hw_offload {
|
||||||
vs_config { 'other_config:hw-offload':
|
vs_config { 'other_config:hw-offload':
|
||||||
value => 'true',
|
value => true,
|
||||||
restart => true,
|
restart => true,
|
||||||
wait => true,
|
wait => true,
|
||||||
}
|
}
|
||||||
|
@ -105,7 +104,7 @@ class vswitch::ovs(
|
||||||
|
|
||||||
if $disable_emc {
|
if $disable_emc {
|
||||||
vs_config { 'other_config:emc-insert-inv-prob':
|
vs_config { 'other_config:emc-insert-inv-prob':
|
||||||
value => '0',
|
value => 0,
|
||||||
wait => false,
|
wait => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,14 +115,9 @@ class vswitch::ovs(
|
||||||
ensure => absent,
|
ensure => absent,
|
||||||
wait => true,
|
wait => true,
|
||||||
}
|
}
|
||||||
} elsif $vlan_limit == undef {
|
|
||||||
vs_config { 'other_config:vlan-limit':
|
|
||||||
ensure => absent,
|
|
||||||
wait => true,
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
vs_config { 'other_config:vlan-limit':
|
vs_config { 'other_config:vlan-limit':
|
||||||
value => "${vlan_limit}",
|
value => $vlan_limit,
|
||||||
wait => true,
|
wait => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Now the ``value`` property of the ``vs_config`` resource accepts Integer
|
||||||
|
and Boolean in addition to String.
|
|
@ -32,7 +32,7 @@ describe 'vswitch::dpdk' do
|
||||||
end
|
end
|
||||||
it 'configures dpdk options' do
|
it 'configures dpdk options' do
|
||||||
is_expected.to contain_vs_config('other_config:dpdk-init').with(
|
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(
|
is_expected.to contain_vs_config('other_config:pmd-cpu-mask').with(
|
||||||
:value => nil, :wait => false,
|
: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_not contain_vs_config('other_config:emc-insert-inv-prob')
|
||||||
is_expected.to contain_vs_config('other_config:vlan-limit').with(
|
is_expected.to contain_vs_config('other_config:vlan-limit').with(
|
||||||
:ensure => 'absent', :wait => true,
|
:value => nil, :wait => true,
|
||||||
)
|
)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -69,7 +69,7 @@ describe 'vswitch::dpdk' do
|
||||||
end
|
end
|
||||||
it 'configures dpdk options' do
|
it 'configures dpdk options' do
|
||||||
is_expected.to contain_vs_config('other_config:dpdk-init').with(
|
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(
|
is_expected.to contain_vs_config('other_config:pmd-cpu-mask').with(
|
||||||
:value => '3c0000000003c00000', :wait => false,
|
:value => '3c0000000003c00000', :wait => false,
|
||||||
|
@ -84,13 +84,13 @@ describe 'vswitch::dpdk' do
|
||||||
:value => '-n 2', :wait => false,
|
:value => '-n 2', :wait => false,
|
||||||
)
|
)
|
||||||
is_expected.to contain_vs_config('other_config:hw-offload').with(
|
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(
|
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(
|
is_expected.to contain_vs_config('other_config:vlan-limit').with(
|
||||||
:value => '2', :wait => true,
|
:value => 2, :wait => true,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,7 +34,7 @@ describe 'vswitch::ovs' do
|
||||||
|
|
||||||
it 'clears vlan-limit option' do
|
it 'clears vlan-limit option' do
|
||||||
is_expected.to contain_vs_config('other_config:vlan-limit').with(
|
is_expected.to contain_vs_config('other_config:vlan-limit').with(
|
||||||
:ensure => 'absent', :wait => true,
|
:value => nil, :wait => true,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -76,17 +76,17 @@ describe 'vswitch::ovs' do
|
||||||
end
|
end
|
||||||
it 'configures hw-offload option' do
|
it 'configures hw-offload option' do
|
||||||
is_expected.to contain_vs_config('other_config:hw-offload').with(
|
is_expected.to contain_vs_config('other_config:hw-offload').with(
|
||||||
:value => 'true', :restart => true, :wait => true,
|
:value => true, :restart => true, :wait => true,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
it 'configures disable_emc option' do
|
it 'configures disable_emc option' do
|
||||||
is_expected.to contain_vs_config('other_config:emc-insert-inv-prob').with(
|
is_expected.to contain_vs_config('other_config:emc-insert-inv-prob').with(
|
||||||
:value => '0', :wait => false,
|
:value => 0, :wait => false,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
it 'configures vlan-limit option' do
|
it 'configures vlan-limit option' do
|
||||||
is_expected.to contain_vs_config('other_config:vlan-limit').with(
|
is_expected.to contain_vs_config('other_config:vlan-limit').with(
|
||||||
:value => '2', :wait => true,
|
:value => 2, :wait => true,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -47,9 +47,27 @@ describe Puppet::Type.type(:vs_config) do
|
||||||
expect(described_class.attrtype(:value)).to eq(:property)
|
expect(described_class.attrtype(:value)).to eq(:property)
|
||||||
end
|
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
|
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.to raise_error(Puppet::Error)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue