Puppet4 support: l23network spec updates

* Fixes in the l23 module's ruby liraries

Change-Id: Ib08c1c81255bdbdf557bfdf48f2ad409bbd8957a
Related-Bug: 1586480
This commit is contained in:
Dmitry Ilyin 2016-06-23 23:13:11 +03:00
parent 7a312e222e
commit 29ab657707
25 changed files with 605 additions and 674 deletions

View File

@ -3,10 +3,11 @@ source 'https://rubygems.org'
group :development, :test do
gem 'rake', :require => false
gem 'pry', :require => false
gem 'rspec', '~>3.3', :require => false
gem 'rspec-puppet', '~>2.2.0', :require => false
gem 'rspec', :require => false
gem 'rspec-puppet', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'puppet-lint', '~> 1.1'
gem 'rspec-puppet-facts'
end
if puppetversion = ENV['PUPPET_GEM_VERSION']
@ -14,5 +15,3 @@ if puppetversion = ENV['PUPPET_GEM_VERSION']
else
gem 'puppet', :require => false
end
# vim:ft=ruby

View File

@ -39,16 +39,16 @@ end
:l3_fqdn_hostname => 'stupid_hostname',
:netrings => {
'eth1' => {
'maximums' => {'RX'=>'4096', 'TX'=>'4096'},
'current' => {'RX'=>'256', 'TX'=>'256'}
'maximums' => {'rx'=>'4096', 'tx'=>'4096'},
'current' => {'rx'=>'256', 'tx'=>'256'}
},
'eth2' => {
'maximums' => {'RX'=>'4096', 'TX'=>'4096'},
'current' => {'RX'=>'256', 'TX'=>'256'}
'maximums' => {'rx'=>'4096', 'tx'=>'4096'},
'current' => {'rx'=>'256', 'tx'=>'256'}
},
'eth3' => {
'maximums' => {'RX'=>'4096', 'TX'=>'4096'},
'current' => {'RX'=>'2048', 'TX'=>'2048'}
'maximums' => {'rx'=>'4096', 'tx'=>'4096'},
'current' => {'rx'=>'2048', 'tx'=>'2048'}
}
}
}

View File

@ -68,16 +68,16 @@ end
:l3_fqdn_hostname => 'stupid_hostname',
:netrings => {
'eth1' => {
'maximums' => {'RX'=>'4096', 'TX'=>'4096'},
'current' => {'RX'=>'256', 'TX'=>'256'}
'maximums' => {'rx'=>'4096', 'tx'=>'4096'},
'current' => {'rx'=>'256', 'tx'=>'256'}
},
'eth2' => {
'maximums' => {'RX'=>'4096', 'TX'=>'4096'},
'current' => {'RX'=>'256', 'TX'=>'256'}
'maximums' => {'rx'=>'4096', 'tx'=>'4096'},
'current' => {'rx'=>'256', 'tx'=>'256'}
},
'eth3' => {
'maximums' => {'RX'=>'4096', 'TX'=>'4096'},
'current' => {'RX'=>'2048', 'TX'=>'2048'}
'maximums' => {'rx'=>'4096', 'tx'=>'4096'},
'current' => {'rx'=>'2048', 'tx'=>'2048'}
}
}
}
@ -90,8 +90,8 @@ end
let(:rings) do
{
'rings' => {
'RX' => '4096',
'TX' => '4096'
'rx' => '4096',
'tx' => '4096'
}
}
end

View File

@ -10,8 +10,8 @@ describe 'l23network::l3::ifconfig', :type => :define do
:kernel => 'Linux',
:netrings => {
'eth4' => {
'maximums' => {'RX'=>'4096', 'TX'=>'4096'},
'current' => {'RX'=>'256', 'TX'=>'256'}
'maximums' => {'rx'=>'4096', 'tx'=>'4096'},
'current' => {'rx'=>'256', 'tx'=>'256'}
},
}
} }

View File

@ -10,8 +10,8 @@ describe 'l23network::l3::ifconfig', :type => :define do
:kernel => 'Linux',
:netrings => {
'eth4' => {
'maximums' => {'RX'=>'4096', 'TX'=>'4096'},
'current' => {'RX'=>'256', 'TX'=>'256'}
'maximums' => {'rx'=>'4096', 'tx'=>'4096'},
'current' => {'rx'=>'256', 'tx'=>'256'}
},
}
} }

View File

@ -1,7 +1,5 @@
include ::l23network::params
#include ::l23network::params
# this is a workaround for run spec tests not only on Linux platform
if $::l23network::params::network_manager_name != undef {
Package<| title == $::l23network::params::network_manager_name |> { provider => apt }
}
###
Package <||> { provider => 'apt' }
###

View File

@ -1,32 +1,21 @@
require 'spec_helper'
describe 'array_or_string_to_array' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it 'should exist' do
expect(Puppet::Parser::Functions.function('array_or_string_to_array')).to eq('function_array_or_string_to_array')
end
it 'should throw an error on invalid types' do
expect {
scope.function_array_or_string_to_array([{:foo => :bar}])
}.to(raise_error(Puppet::ParseError))
is_expected.to run.with_params({:foo => :bar}).and_raise_error(Puppet::ParseError)
end
it 'should throw an error on invalid arguments number' do
expect {
scope.function_array_or_string_to_array([])
}.to(raise_error(Puppet::ParseError))
expect {
scope.function_array_or_string_to_array([[1,2],[3,4]])
}.to(raise_error(Puppet::ParseError))
is_expected.to run.with_params().and_raise_error(Puppet::ParseError)
is_expected.to run.with_params([1,2],[3,4]).and_raise_error(Puppet::ParseError)
end
it 'should return array if given array' do
expect(scope.function_array_or_string_to_array([[1,2,3,4,5,6,7,8,9]])).to eq([1,2,3,4,5,6,7,8,9])
is_expected.to run.with_params([1,2,3,4,5,6,7,8,9]).and_return([1,2,3,4,5,6,7,8,9])
end
it 'should return array of strings if given string with separators' do
expect(scope.function_array_or_string_to_array(['1,2,3,4,5:6,7 8,9'])).to eq(['1','2','3','4','5','6','7','8','9'])
is_expected.to run.with_params('1,2,3,4,5:6,7 8,9').and_return(%w(1 2 3 4 5 6 7 8 9))
end
end
end

View File

@ -1,62 +1,51 @@
require 'spec_helper'
describe 'array_part' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it 'should exist' do
expect(Puppet::Parser::Functions.function('array_part')).to eq 'function_array_part'
is_expected.not_to be_nil
end
it 'should throw an error on invalid types' do
expect do
scope.function_array_part([{:foo => :bar}])
end.to raise_error(Puppet::ParseError)
is_expected.to run.with_params({:foo => :bar}).and_raise_error(Puppet::ParseError)
end
it 'should throw an error on invalid arguments number' do
expect do
scope.function_array_part([[1,2,3,4,5,6,7,8],2])
end.to raise_error(Puppet::ParseError)
expect do
scope.function_array_part([[1,2,3],1,2,3])
end.to raise_error(Puppet::ParseError)
expect do
scope.function_array_part([])
end.to raise_error(Puppet::ParseError)
is_expected.to run.with_params([1,2,3,4,5,6,7,8],2).and_raise_error(Puppet::ParseError)
is_expected.to run.with_params([[1,2,3],1,2,3]).and_raise_error(Puppet::ParseError)
is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError)
end
it 'should throw an error if 3d argument less of 2nd' do
expect do
scope.function_array_part([[1,2,3,4,5],3,1])
end.to raise_error(Puppet::ParseError)
is_expected.to run.with_params([1,2,3,4,5],3,1).and_raise_error(Puppet::ParseError)
end
it 'should return NIL if empty array given' do
expect(scope.function_array_part([[],1,2])).to eq nil
is_expected.to run.with_params([],1,2).and_return(nil)
end
it 'should return NIL if 2nd parameter less than zero' do
expect(scope.function_array_part([[1,2,3,4,5],-1,2])).to eq nil
is_expected.to run.with_params([1,2,3,4,5],-1,2).and_return(nil)
end
it 'should return NIL if 2nd parameter more than array len' do
expect(scope.function_array_part([[1,2,3,4,5],100,2])).to eq nil
is_expected.to run.with_params([1,2,3,4,5],100,2).and_return(nil)
end
it 'should return array of single element if 2nd and 3d parameter are equal' do
expect(scope.function_array_part([[0,0,1,0,0],2,2])).to eq([1])
is_expected.to run.with_params([0,0,1,0,0],2,2).and_return([1])
end
it 'should work properly' do
expect(scope.function_array_part([[0,1,2,3,4,5,6,7,8,9],2,5])).to eq([2,3,4,5])
is_expected.to run.with_params([0,1,2,3,4,5,6,7,8,9],2,5).and_return([2,3,4,5])
end
it 'should return from given index to end' do
expect(scope.function_array_part([[0,1,2,3,4,5,6,7,8,9],2,0])).to eq([2,3,4,5,6,7,8,9])
is_expected.to run.with_params([0,1,2,3,4,5,6,7,8,9],2,0).and_return([2,3,4,5,6,7,8,9])
end
it 'should return undef if requested range out of given array' do
expect(scope.function_array_part([[0,1],2,0])).to eq nil
is_expected.to run.with_params([0,1],2,0).and_return(nil)
end
end

View File

@ -1,29 +1,18 @@
require 'spec_helper'
describe 'check_cidrs' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it 'should exist' do
expect(Puppet::Parser::Functions.function('check_cidrs')).to eq 'function_check_cidrs'
end
it 'should throw an error on invalid arguments number' do
expect do
scope.function_check_cidrs(['a','b'])
end.to raise_error(Puppet::ParseError)
is_expected.to run.with_params('a','b').and_raise_error(Puppet::ParseError)
end
it 'should throw an error on invalid types' do
expect do
scope.function_check_cidrs([{:foo => :bar}])
end.to raise_error(Puppet::ParseError)
is_expected.to run.with_params({:foo => :bar}).and_raise_error(Puppet::ParseError)
end
it 'should throw an error on invalid CIDRs' do
invalid_cidrs = ['192.168.33.66', '192.256.33.66/23', '192.168.33.66/33', '192.168.33.66/333', 'jhgjhgghggh']
expect do
scope.function_check_cidrs([invalid_cidrs])
end.to raise_error(Puppet::ParseError)
is_expected.to run.with_params(invalid_cidrs).and_raise_error(Puppet::ParseError)
end
end

View File

@ -1,37 +1,30 @@
require 'spec_helper'
describe 'cidr_to_ipaddr' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it 'should exist' do
expect(Puppet::Parser::Functions.function('cidr_to_ipaddr')).to eq 'function_cidr_to_ipaddr'
is_expected.not_to be_nil
end
it 'should throw an error on invalid types' do
expect do
scope.function_cidr_to_ipaddr([{:foo => :bar}])
end.to raise_error(Puppet::ParseError)
is_expected.to run.with_params({:foo => :bar}).and_raise_error(Puppet::ParseError)
end
it 'should throw an error on invalid CIDR' do
invalid_cidrs = ['192.168.33.66', '192.256.33.66/23', 'jhgjhgghggh']
for cidr in invalid_cidrs
expect do
scope.function_cidr_to_ipaddr([cidr])
end.to raise_error(Puppet::ParseError)
is_expected.to run.with_params(cidr).and_raise_error(Puppet::ParseError)
end
end
it 'should throw an error on invalid CIDR masklen' do
cidr = '192.168.33.66/33'
expect do
scope.function_cidr_to_ipaddr([cidr])
end.to raise_error(Puppet::ParseError)
is_expected.to run.with_params(cidr).and_raise_error(Puppet::ParseError)
end
it 'should return IP address from CIDR' do
cidr = '192.168.33.66/25'
ipaddr = '192.168.33.66'
expect(scope.function_cidr_to_ipaddr([cidr])).to eq ipaddr
is_expected.to run.with_params(cidr).and_return(ipaddr)
end
end

View File

@ -1,37 +1,30 @@
require 'spec_helper'
describe 'cidr_to_netmask' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it 'should exist' do
expect(Puppet::Parser::Functions.function('cidr_to_netmask')).to eq 'function_cidr_to_netmask'
is_expected.not_to be_nil
end
it 'should throw an error on invalid types' do
expect do
scope.function_cidr_to_netmask([{:foo => :bar}])
end.to raise_error(Puppet::ParseError)
is_expected.to run.with_params({:foo => :bar}).and_raise_error(Puppet::ParseError)
end
it 'should throw an error on invalid CIDR' do
invalid_cidrs = ['192.168.33.66', '192.256.33.66/23', 'jhgjhgghggh']
for cidr in invalid_cidrs
expect do
scope.function_cidr_to_netmask([cidr])
end.to raise_error(Puppet::ParseError)
is_expected.to run.with_params(cidr).and_raise_error(Puppet::ParseError)
end
end
it 'should throw an error on invalid CIDR masklen' do
cidr = '192.168.33.66/33'
expect do
scope.function_cidr_to_netmask([cidr])
end.to raise_error(Puppet::ParseError)
is_expected.to run.with_params(cidr).and_raise_error(Puppet::ParseError)
end
it 'should return netmask from CIDR' do
cidr = '192.168.33.66/25'
netmask = '255.255.255.128'
expect(scope.function_cidr_to_netmask([cidr])).to eq netmask
is_expected.to run.with_params(cidr).and_return(netmask)
end
end

View File

@ -1,14 +1,18 @@
require 'spec_helper'
describe 'default_provider_for' do
let(:facts) {{
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:kernel => 'Linux',
:l23_os => 'ubuntu',
:l3_fqdn_hostname => 'stupid_hostname',
}}
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params('file').and_return('posix') }
end
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end
it { is_expected.not_to be_nil }
it { is_expected.to run.with_params('file').and_return('posix') }
end
end
end

View File

@ -2,9 +2,10 @@ require 'spec_helper'
require 'yaml'
require_relative '../../lib/puppetx/l23_hash_tools'
describe Puppet::Parser::Functions.function(:get_default_gateways) do
let(:network_scheme) do
<<eof
describe 'get_default_gateways' do
let(:network_scheme) do
<<-eof
---
version: 1.1
provider: lnx
@ -40,15 +41,10 @@ let(:network_scheme) do
br-floating:
IP: none
eof
end
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
subject do
function_name = Puppet::Parser::Functions.function(:get_default_gateways)
scope.method(function_name)
it 'should exist' do
is_expected.not_to be_nil
end
context ":get_default_gateways() usage" do
@ -60,12 +56,8 @@ end
)
end
it 'should exist' do
subject == Puppet::Parser::Functions.function(:get_default_gateways)
end
it do
should run.with_params().and_return(['10.1.3.1', '10.1.2.1', '10.1.1.1'])
is_expected.to run.with_params().and_return(['10.1.3.1', '10.1.2.1', '10.1.1.1'])
end
end

View File

@ -2,9 +2,10 @@ require 'spec_helper'
require 'yaml'
require_relative '../../lib/puppetx/l23_hash_tools'
describe Puppet::Parser::Functions.function(:get_dpdk_interfaces) do
let(:network_scheme) do
<<eof
describe 'get_dpdk_interfaces' do
let(:network_scheme) do
<<-eof
---
version: 1.1
provider: lnx
@ -27,31 +28,28 @@ let(:network_scheme) do
vendor_specific:
driver: tg3
bus_info: "0000:02:00.1"
eof
end
eof
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
subject do
function_name = Puppet::Parser::Functions.function(:get_dpdk_interfaces)
scope.method(function_name)
it 'should exist' do
is_expected.not_to be_nil
end
context "get_dpdk_interfaces() usage" do
before(:each) do
scope.stubs(:lookupvar).with('l3_fqdn_hostname').returns('node1.tld')
L23network::Scheme.set_config(
scope.lookupvar('l3_fqdn_hostname'),
L23network.sanitize_keys_in_hash(YAML.load(network_scheme))
scope.lookupvar('l3_fqdn_hostname'),
L23network.sanitize_keys_in_hash(YAML.load(network_scheme))
)
end
it 'should exist' do
subject == Puppet::Parser::Functions.function(:get_transformation_property)
end
it 'should return dpdk driver list' do
should run.with_params().and_return([["0000:01:00.0", "igb_uio"], ["0000:01:00.1", "igb_uio"]])
is_expected.to run.with_params().and_return(
[
["0000:01:00.0", "igb_uio"], ["0000:01:00.1", "igb_uio"]
]
)
end
end
end

View File

@ -2,9 +2,10 @@ require 'spec_helper'
require 'yaml'
require_relative '../../lib/puppetx/l23_hash_tools'
describe Puppet::Parser::Functions.function(:get_network_role_property) do
let(:network_scheme) do
<<eof
describe 'get_network_role_property' do
let(:network_scheme) do
<<-eof
---
version: 1.1
provider: lnx
@ -114,74 +115,64 @@ let(:network_scheme) do
custom: br-aux
zzz: br44
bond_103: bond0.103
eof
end
eof
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
subject do
function_name = Puppet::Parser::Functions.function(:get_network_role_property)
scope.method(function_name)
it 'should exist' do
is_expected.not_to be_nil
end
context "get_network_role_property('**something_role**', 'phys_dev') usage" do
before(:each) do
scope.stubs(:lookupvar).with('l3_fqdn_hostname').returns('node1.tld')
L23network::Scheme.set_config(
scope.lookupvar('l3_fqdn_hostname'),
L23network.sanitize_keys_in_hash(YAML.load(network_scheme))
scope.lookupvar('l3_fqdn_hostname'),
L23network.sanitize_keys_in_hash(YAML.load(network_scheme))
)
end
it 'should exist' do
subject == Puppet::Parser::Functions.function(:get_network_role_property)
end
it 'should return physical device name for "management" network role (just subinterface)' do
should run.with_params('management', 'phys_dev').and_return(["eth1"])
is_expected.to run.with_params('management', 'phys_dev').and_return(["eth1"])
end
it 'should return physical device name for "ex" network role (subinterface of bond)' do
should run.with_params('ex', 'phys_dev').and_return(["bond0", "eth2", "eth3"])
is_expected.to run.with_params('ex', 'phys_dev').and_return(["bond0", "eth2", "eth3"])
end
it 'should return physical device name for "floating" network role (OVS-bridge, connected by patch to LNX bridge)' do
should run.with_params('neutron/floating', 'phys_dev').and_return(["bond0", "eth2", "eth3"])
is_expected.to run.with_params('neutron/floating', 'phys_dev').and_return(["bond0", "eth2", "eth3"])
end
it 'should return physical device name for "private" network role' do
should run.with_params('neutron/private', 'phys_dev').and_return(["bond0", "eth2", "eth3"])
is_expected.to run.with_params('neutron/private', 'phys_dev').and_return(["bond0", "eth2", "eth3"])
end
it 'should return physical device name for "storage" network role (bond, without tag)' do
should run.with_params('storage', 'phys_dev').and_return(["bond0", "eth2", "eth3"])
is_expected.to run.with_params('storage', 'phys_dev').and_return(["bond0", "eth2", "eth3"])
end
it 'should return physical device name for "admin" network role (just interface has IP address)' do
should run.with_params('admin', 'phys_dev').and_return(['eth0'])
is_expected.to run.with_params('admin', 'phys_dev').and_return(['eth0'])
end
it 'should return physical device name for untagged interface with simple transformation' do
should run.with_params('xxx', 'phys_dev').and_return(['eth4'])
is_expected.to run.with_params('xxx', 'phys_dev').and_return(['eth4'])
end
it 'should return physical device name for subinterface of bond' do
should run.with_params('bond_103', 'phys_dev').and_return(["bond0", "eth2", "eth3"])
is_expected.to run.with_params('bond_103', 'phys_dev').and_return(["bond0", "eth2", "eth3"])
end
it 'should return physical devices names for "custom" network role (two interfaces)' do
should run.with_params('custom', 'phys_dev').and_return(["eth5", "bond0"])
is_expected.to run.with_params('custom', 'phys_dev').and_return(["eth5", "bond0"])
end
it 'should return physical device name for endpoint with interface with long name, contains shot name of another interface' do
should run.with_params('zzz', 'phys_dev').and_return(['eth44'])
is_expected.to run.with_params('zzz', 'phys_dev').and_return(['eth44'])
end
it 'should return NIL for "non-existent" network role' do
should run.with_params('non-existent', 'phys_dev').and_return(nil)
is_expected.to run.with_params('non-existent', 'phys_dev').and_return(nil)
end
end

View File

@ -1,11 +1,9 @@
require 'spec_helper'
describe Puppet::Parser::Functions.function(:get_network_role_property) do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
describe 'get_network_role_property' do
subject do
function_name = Puppet::Parser::Functions.function(:get_network_role_property)
scope.method(function_name)
it 'should exist' do
is_expected.not_to be_nil
end
context "mtk" do
@ -13,85 +11,83 @@ describe Puppet::Parser::Functions.function(:get_network_role_property) do
#Puppet::Parser::Scope.any_instance.stubs(:lookupvar).with('l3_fqdn_hostname').returns('node1.tld')
scope.stubs(:lookupvar).with('l3_fqdn_hostname').returns('node1.tld')
L23network::Scheme.set_config(scope.lookupvar('l3_fqdn_hostname'), {
:transformations => [ {
:bridge => 'br-ex',
:name => 'bond0',
:mtu => 1450,
:interfaces => ["eth1", "eth2"],
}, ],
:interfaces => {
:eth0 => {},
},
:endpoints => {
:eth0 => {:IP => 'dhcp'},
:"br-ex" => {
:gateway => '10.1.3.1',
:IP => ['10.1.3.11/24'],
:transformations => [
{
:bridge => 'br-ex',
:name => 'bond0',
:mtu => 1450,
:interfaces => ["eth1", "eth2"],
},
],
:interfaces => {
:eth0 => {},
},
:endpoints => {
:eth0 => {:IP => 'dhcp'},
:"br-ex" => {
:gateway => '10.1.3.1',
:IP => ['10.1.3.11/24'],
},
:"br-mgmt" => {:IP => ['10.20.1.11/25']},
:"br-storage" => {:IP => ['192.168.1.2/24']},
:"br-prv" => {:IP => 'none'},
},
:roles => {
:management => 'br-mgmt',
:private => 'br-prv',
:ex => 'br-ex',
:storage => 'br-storage',
:admin => 'eth0',
},
:"br-mgmt" => { :IP => ['10.20.1.11/25'] },
:"br-storage" => { :IP => ['192.168.1.2/24'] },
:"br-prv" => { :IP => 'none' },
},
:roles => {
:management => 'br-mgmt',
:private => 'br-prv',
:ex => 'br-ex',
:storage => 'br-storage',
:admin => 'eth0',
},
})
end
it 'should exist' do
subject == Puppet::Parser::Functions.function(:get_network_role_property)
end
it 'should return interface name for "private" network role' do
should run.with_params('private', 'interface').and_return('br-prv')
is_expected.to run.with_params('private', 'interface').and_return('br-prv')
end
it 'should raise for non-existing role name' do
expect(subject.call(['not_exist', 'interface'])).to be_nil
is_expected.to run.with_params('not_exist', 'interface').and_return(nil)
end
it 'should return ip address for "management" network role' do
should run.with_params('management', 'ipaddr').and_return('10.20.1.11')
is_expected.to run.with_params('management', 'ipaddr').and_return('10.20.1.11')
end
it 'should return cidr-notated ip address for "management" network role' do
should run.with_params('management', 'cidr').and_return('10.20.1.11/25')
is_expected.to run.with_params('management', 'cidr').and_return('10.20.1.11/25')
end
it 'should return cidr-notated network address for "management" network role' do
should run.with_params('management', 'network').and_return('10.20.1.0/25')
is_expected.to run.with_params('management', 'network').and_return('10.20.1.0/25')
end
it 'should return netmask for "management" network role' do
should run.with_params('management', 'netmask').and_return('255.255.255.128')
is_expected.to run.with_params('management', 'netmask').and_return('255.255.255.128')
end
it 'should return ip address and netmask for "management" network role' do
should run.with_params('management', 'ipaddr_netmask_pair').and_return(['10.20.1.11','255.255.255.128'])
is_expected.to run.with_params('management', 'ipaddr_netmask_pair').and_return(['10.20.1.11', '255.255.255.128'])
end
it 'should return physical device name for "ex" network role' do
should run.with_params('ex', 'phys_dev').and_return(["bond0", "eth1", "eth2"])
is_expected.to run.with_params('ex', 'phys_dev').and_return(["bond0", "eth1", "eth2"])
end
it 'should return NIL for "admin" network role' do
should run.with_params('admin', 'netmask').and_return(nil)
is_expected.to run.with_params('admin', 'netmask').and_return(nil)
end
it 'should return NIL for "admin" network role' do
should run.with_params('admin', 'ipaddr').and_return(nil)
is_expected.to run.with_params('admin', 'ipaddr').and_return(nil)
end
it 'should return NIL for "admin" network role' do
should run.with_params('admin', 'cidr').and_return(nil)
is_expected.to run.with_params('admin', 'cidr').and_return(nil)
end
it 'should return NIL for "admin" network role' do
should run.with_params('admin', 'ipaddr_netmask_pair').and_return(nil)
is_expected.to run.with_params('admin', 'ipaddr_netmask_pair').and_return(nil)
end
it 'should return eth0 for "admin" network role phys_dev' do
should run.with_params('admin', 'phys_dev').and_return(["eth0"])
is_expected.to run.with_params('admin', 'phys_dev').and_return(["eth0"])
end
end

View File

@ -2,9 +2,10 @@ require 'spec_helper'
require 'yaml'
require_relative '../../lib/puppetx/l23_hash_tools'
describe Puppet::Parser::Functions.function(:get_nic_passthrough_whitelist) do
let(:network_scheme) do
<<eof
describe 'get_nic_passthrough_whitelist' do
let(:network_scheme) do
<<-eof
---
version: 1.1
provider: lnx
@ -33,41 +34,34 @@ let(:network_scheme) do
sriov_numvfs: 4
endpoints:
roles:
eof
end
eof
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
subject do
function_name = Puppet::Parser::Functions.function(:get_nic_passthrough_whitelist)
scope.method(function_name)
it 'should exist' do
is_expected.not_to be_nil
end
context "get_nic_passthrough_whitelist() usage" do
before(:each) do
scope.stubs(:lookupvar).with('l3_fqdn_hostname').returns('node1.tld')
L23network::Scheme.set_config(
scope.lookupvar('l3_fqdn_hostname'),
L23network.sanitize_keys_in_hash(YAML.load(network_scheme))
scope.lookupvar('l3_fqdn_hostname'),
L23network.sanitize_keys_in_hash(YAML.load(network_scheme))
)
end
it 'should exist' do
subject == Puppet::Parser::Functions.function(:get_pci_passthrough_whitelist)
end
it 'should return sriov mappings from transformations' do
should run.with_params('sriov').and_return([
{"devname" => "enp1s0f0", "physical_network" => "physnet1"},
{"devname" => "enp1s0f1", "physical_network" => "physnet2"}
])
is_expected.to run.with_params('sriov').and_return(
[
{"devname" => "enp1s0f0", "physical_network" => "physnet1"},
{"devname" => "enp1s0f1", "physical_network" => "physnet2"}
]
)
end
it 'should return empty mapping from transformations' do
should run.with_params('dumb').and_return(nil)
is_expected.to run.with_params('dumb').and_return(nil)
end
end
end
end

View File

@ -6,38 +6,32 @@ require 'spec_helper'
# names, that connected by patchcord.
describe 'get_pair_of_jack_names' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
subject do
function_name = Puppet::Parser::Functions.function(:get_pair_of_jack_names)
scope.method(function_name)
it 'should exist' do
is_expected.not_to be_nil
end
context "t1" do
it 'should exist' do
subject == Puppet::Parser::Functions.function(:get_pair_of_jack_names)
end
it 'should throw an error on invalid types' do
should run.with_params({:foo => :bar}).and_raise_error(Puppet::ParseError)
is_expected.to run.with_params({:foo => :bar}).and_raise_error(Puppet::ParseError)
end
it 'should throw an error on invalid arguments number' do
should run.with_params().and_raise_error(Puppet::ParseError)
should run.with_params([1,2],[3,4]).and_raise_error(Puppet::ParseError)
is_expected.to run.with_params().and_raise_error(Puppet::ParseError)
is_expected.to run.with_params([1, 2], [3, 4]).and_raise_error(Puppet::ParseError)
end
it 'should return numbered interface names for pair of bridges' do
should run.with_params(['br1', 'br2']).and_return(["p_39a440c1-0", "p_39a440c1-1"])
is_expected.to run.with_params(['br1', 'br2']).and_return(["p_39a440c1-0", "p_39a440c1-1"])
end
it 'should return numbered interface names for pair of bridges in reverse order' do
should run.with_params(['br2', 'br1']).and_return(["p_39a440c1-0", "p_39a440c1-1"])
is_expected.to run.with_params(['br2', 'br1']).and_return(["p_39a440c1-0", "p_39a440c1-1"])
end
it 'should return numbered interface names for pair of bridges with long name' do
should run.with_params(['br-mmmmmmmmmmmmmmmmmmmmmmmmgmt', 'br-ex']).and_return(["p_0c7224e9-0", "p_0c7224e9-1"])
is_expected.to run.with_params(['br-mmmmmmmmmmmmmmmmmmmmmmmmgmt', 'br-ex']).and_return(["p_0c7224e9-0", "p_0c7224e9-1"])
end
end

View File

@ -1,35 +1,29 @@
require 'spec_helper'
describe 'get_patch_name' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
subject do
function_name = Puppet::Parser::Functions.function(:get_patch_name)
scope.method(function_name)
it 'should exist' do
is_expected.not_to be_nil
end
context "t1" do
it 'should exist' do
subject == Puppet::Parser::Functions.function(:get_patch_name)
end
it 'should throw an error on invalid types' do
should run.with_params({:foo => :bar}).and_raise_error(Puppet::ParseError)
is_expected.to run.with_params({:foo => :bar}).and_raise_error(Puppet::ParseError)
end
it 'should throw an error on invalid arguments number' do
should run.with_params().and_raise_error(Puppet::ParseError)
should run.with_params([1,2],[3,4]).and_raise_error(Puppet::ParseError)
is_expected.to run.with_params().and_raise_error(Puppet::ParseError)
is_expected.to run.with_params([1,2],[3,4]).and_raise_error(Puppet::ParseError)
end
it 'should return numbered interface names' do
should run.with_params(['br-mgmt', 'br-ex']).and_return("patch__br-ex--br-mgmt")
is_expected.to run.with_params(['br-mgmt', 'br-ex']).and_return("patch__br-ex--br-mgmt")
end
#todo(sv): should be refactoded reo returns more shot name
# it 'should cut interface names for long interfaces' do
# should run.with_params(['br-mmmmmmmmmmmmmmmmmmmmmmmmgmt', 'br-ex']).and_return(["p_br-mmmmmmmm-0", "p_br-ex-1"])
# is_expected.to run.with_params(['br-mmmmmmmmmmmmmmmmmmmmmmmmgmt', 'br-ex']).and_return(["p_br-mmmmmmmm-0", "p_br-ex-1"])
# end
end

View File

@ -1,38 +1,29 @@
require 'spec_helper'
describe 'get_route_resource_name' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
subject do
function_name = Puppet::Parser::Functions.function(:get_route_resource_name)
scope.method(function_name)
it 'should exist' do
is_expected.not_to be_nil
end
context "get_route_resource_name" do
it 'should exist' do
subject == Puppet::Parser::Functions.function(:get_route_resource_name)
end
it 'should throw an error if called without args' do
should run.with_params().and_raise_error(Puppet::ParseError)
end
it 'should throw an error if called with more two args' do
should run.with_params('192.168.2.0/24', 10, 20).and_raise_error(Puppet::ParseError)
end
it do
should run.with_params('192.168.2.0/24').and_return('192.168.2.0/24')
end
it do
should run.with_params('192.168.2.0/24', 10).and_return('192.168.2.0/24,metric:10')
end
it do
should run.with_params('192.168.2.0/24', 'xxx').and_return('192.168.2.0/24')
end
it 'should throw an error if called without args' do
is_expected.to run.with_params().and_raise_error(Puppet::ParseError)
end
it 'should throw an error if called with more two args' do
is_expected.to run.with_params('192.168.2.0/24', 10, 20).and_raise_error(Puppet::ParseError)
end
it do
is_expected.to run.with_params('192.168.2.0/24').and_return('192.168.2.0/24')
end
it do
is_expected.to run.with_params('192.168.2.0/24', 10).and_return('192.168.2.0/24,metric:10')
end
it do
is_expected.to run.with_params('192.168.2.0/24', 'xxx').and_return('192.168.2.0/24')
end
end

View File

@ -1,135 +1,129 @@
require 'spec_helper'
require 'yaml'
require_relative '../../lib/puppetx/l23_hash_tools'
require_relative '../../lib/puppetx/l23_network_scheme'
describe Puppet::Parser::Functions.function(:get_transformation_property) do
let(:network_scheme) do
<<eof
describe 'get_transformation_property' do
let(:network_scheme) do
<<-eof
---
version: 1.1
provider: lnx
interfaces:
eth0:
mtu: 2048
eth1:
mtu: 999
eth2:
mtu: 1024
eth3: {}
transformations:
- action: add-br
name: br-storage
- action: add-br
name: br-ex
- action: add-br
name: br-mgmt
- action: add-port
name: eth1.101
bridge: br-mgmt
- action: add-bond
name: bond0
bridge: br-storage
interfaces:
- eth2
- eth3
mtu: 4000
bond_properties:
mode: balance-rr
interface_properties:
mtu: 9000
vendor_specific:
disable_offloading: true
- action: add-port
name: bond0.102
bridge: br-ex
- action: add-br
name: br-floating
provider: ovs
- action: add-patch
bridges:
- br-floating
- br-ex
provider: ovs
- action: add-br
name: br-prv
provider: ovs
- action: add-patch
bridges:
- br-prv
- br-storage
provider: ovs
endpoints:
eth0:
IP:
- '10.1.0.11/24'
br-ex:
gateway: 10.1.3.1
IP:
- '10.1.3.11/24'
br-storage:
IP:
- '10.1.2.11/24'
br-mgmt:
IP:
- '10.1.1.11/24'
br-floating:
IP: none
br-prv:
IP: none
roles:
admin: eth0
ex: br-ex
management: br-mgmt
storage: br-storage
neutron/floating: br-floating
neutron/private: br-prv
eof
end
version: 1.1
provider: lnx
interfaces:
eth0:
mtu: 2048
eth1:
mtu: 999
eth2:
mtu: 1024
eth3: {}
transformations:
- action: add-br
name: br-storage
- action: add-br
name: br-ex
- action: add-br
name: br-mgmt
- action: add-port
name: eth1.101
bridge: br-mgmt
- action: add-bond
name: bond0
bridge: br-storage
interfaces:
- eth2
- eth3
mtu: 4000
bond_properties:
mode: balance-rr
interface_properties:
mtu: 9000
vendor_specific:
disable_offloading: true
- action: add-port
name: bond0.102
bridge: br-ex
- action: add-br
name: br-floating
provider: ovs
- action: add-patch
bridges:
- br-floating
- br-ex
provider: ovs
- action: add-br
name: br-prv
provider: ovs
- action: add-patch
bridges:
- br-prv
- br-storage
provider: ovs
endpoints:
eth0:
IP:
- '10.1.0.11/24'
br-ex:
gateway: 10.1.3.1
IP:
- '10.1.3.11/24'
br-storage:
IP:
- '10.1.2.11/24'
br-mgmt:
IP:
- '10.1.1.11/24'
br-floating:
IP: none
br-prv:
IP: none
roles:
admin: eth0
ex: br-ex
management: br-mgmt
storage: br-storage
neutron/floating: br-floating
neutron/private: br-prv
eof
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
subject do
function_name = Puppet::Parser::Functions.function(:get_transformation_property)
scope.method(function_name)
it 'should exist' do
is_expected.not_to be_nil
end
context "get_transformation_property('some_property', 'transformation') usage" do
before(:each) do
scope.stubs(:lookupvar).with('l3_fqdn_hostname').returns('node1.tld')
L23network::Scheme.set_config(
scope.lookupvar('l3_fqdn_hostname'),
L23network.sanitize_keys_in_hash(YAML.load(network_scheme))
scope.lookupvar('l3_fqdn_hostname'),
L23network.sanitize_keys_in_hash(YAML.load(network_scheme))
)
end
it 'should exist' do
subject == Puppet::Parser::Functions.function(:get_transformation_property)
end
it 'should return mtu value for "bond0" transformation' do
should run.with_params('mtu', 'bond0').and_return(4000)
is_expected.to run.with_params('mtu', 'bond0').and_return(4000)
end
it 'should return mtu value for "eth0" transformation' do
should run.with_params('mtu', 'eth0').and_return(2048)
is_expected.to run.with_params('mtu', 'eth0').and_return(2048)
end
it 'should return 1024 for "eth2" transformation' do
should run.with_params('mtu', 'eth2').and_return(1024)
is_expected.to run.with_params('mtu', 'eth2').and_return(1024)
end
it 'should return NIL for "eth3" transformation' do
should run.with_params('mtu', 'eth3').and_return(nil)
is_expected.to run.with_params('mtu', 'eth3').and_return(nil)
end
it 'should return ovs for "br-floating" transformation' do
should run.with_params('provider', 'br-floating').and_return('ovs')
is_expected.to run.with_params('provider', 'br-floating').and_return('ovs')
end
it 'should return NIL for "br-storage" transformation' do
should run.with_params('provider', 'br-storage').and_return(nil)
is_expected.to run.with_params('provider', 'br-storage').and_return(nil)
end
end

View File

@ -2,126 +2,140 @@ require 'spec_helper'
require 'yaml'
describe 'override_transformations' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
before :each do
#setup_scope
puppet_debug_override
end
it 'should exist' do
expect(Puppet::Parser::Functions.function('override_transformations')).to eq 'function_override_transformations'
is_expected.not_to be_nil
end
it 'should has ability to override existing fields and add new' do
expect(scope.function_override_transformations([{
:transformations => [
{ :action => 'add-br',
:name => 'br0' } ,
{ :action => 'add-br',
:name => 'br1',
:provider => 'ovs' } ,
{ :action => 'override',
:override => 'br0',
:provider => 'xxx' },
{ :action => 'override',
:override => 'br1',
:provider => 'lnx' }
]
}])).to eq({
:transformations => [
{ :action => 'add-br',
:name => 'br0',
:provider => 'xxx' },
{ :action => 'add-br',
:name => 'br1',
:provider => 'lnx' },
]
})
is_expected.to run.with_params(
{
:transformations => [
{:action => 'add-br',
:name => 'br0'},
{:action => 'add-br',
:name => 'br1',
:provider => 'ovs'},
{:action => 'override',
:override => 'br0',
:provider => 'xxx'},
{:action => 'override',
:override => 'br1',
:provider => 'lnx'}
]
}
).and_return(
{
:transformations => [
{:action => 'add-br',
:name => 'br0',
:provider => 'xxx'},
{:action => 'add-br',
:name => 'br1',
:provider => 'lnx'},
]
}
)
end
it 'should has ability to remove existing fields' do
expect(scope.function_override_transformations([{
:transformations => [
{ :action => 'add-br',
:name => 'br0' } ,
{ :action => 'add-br',
:name => 'br1',
:provider => 'ovs' } ,
{ :action => 'override',
:override => 'br0',
:provider => '' },
{ :action => 'override',
:override => 'br1',
:provider => '' }
]
}])).to eq({
:transformations => [
{ :action => 'add-br',
:name => 'br0'},
{ :action => 'add-br',
:name => 'br1' }
]
})
is_expected.to run.with_params(
{
:transformations => [
{:action => 'add-br',
:name => 'br0'},
{:action => 'add-br',
:name => 'br1',
:provider => 'ovs'},
{:action => 'override',
:override => 'br0',
:provider => ''},
{:action => 'override',
:override => 'br1',
:provider => ''}
]
}
).and_return(
{
:transformations => [
{:action => 'add-br',
:name => 'br0'},
{:action => 'add-br',
:name => 'br1'}
]
}
)
end
it 'should has ability to change name and actions' do
expect(scope.function_override_transformations([{
:transformations => [
{ :action => 'add-br',
:name => 'br0' } ,
{ :action => 'add-br',
:name => 'br1' } ,
{ :action => 'override',
:override => 'br0',
:name => 'br0-new' },
{ :action => 'override',
:override => 'br1',
:'override-action' => 'noop' }
]
}])).to eq({
:transformations => [
{ :action => 'add-br',
:name => 'br0-new'},
{ :action => 'noop',
:name => 'br1' }
]
})
is_expected.to run.with_params(
{
:transformations => [
{:action => 'add-br',
:name => 'br0'},
{:action => 'add-br',
:name => 'br1'},
{:action => 'override',
:override => 'br0',
:name => 'br0-new'},
{:action => 'override',
:override => 'br1',
:'override-action' => 'noop'}
]
}
).and_return(
{
:transformations => [
{:action => 'add-br',
:name => 'br0-new'},
{:action => 'noop',
:name => 'br1'}
]
}
)
end
it 'should has ability to override "add-patch" action' do
expect(scope.function_override_transformations([{
:transformations => [
{ :action => 'add-br',
:name => 'br0' } ,
{ :action => 'add-br',
:name => 'br1' } ,
{ :action => 'add-br',
:name => 'br2' } , # this bridge will be removed by changing action to 'noop'
{ :action => 'add-patch',
:bridges => ['br1','br2'] } ,
{ :action => 'override', # override for existing patch
:override => 'patch-br1:br2',
:bridges => ['br0','br1'] },
{ :action => 'override', # override for non-existing patch
:override => 'patch-br4:br5',
:bridges => ['br0','br1'] },
{ :action => 'override',
:override => 'br2',
:'override-action' => 'noop' }
]
}])).to eq({
:transformations => [
{ :action => 'add-br',
:name => 'br0' } ,
{ :action => 'add-br',
:name => 'br1' } ,
{ :action => 'noop',
:name => 'br2' } ,
{ :action => 'add-patch',
:bridges => ['br0','br1'] }
]
})
is_expected.to run.with_params(
{
:transformations => [
{:action => 'add-br',
:name => 'br0'},
{:action => 'add-br',
:name => 'br1'},
{:action => 'add-br',
:name => 'br2'}, # this bridge will be removed by changing action to 'noop'
{:action => 'add-patch',
:bridges => ['br1', 'br2']},
{:action => 'override', # override for existing patch
:override => 'patch-br1:br2',
:bridges => ['br0', 'br1']},
{:action => 'override', # override for non-existing patch
:override => 'patch-br4:br5',
:bridges => ['br0', 'br1']},
{:action => 'override',
:override => 'br2',
:'override-action' => 'noop'}
]
}
).and_return(
{
:transformations => [
{:action => 'add-br',
:name => 'br0'},
{:action => 'add-br',
:name => 'br1'},
{:action => 'noop',
:name => 'br2'},
{:action => 'add-patch',
:bridges => ['br0', 'br1']}
]
}
)
end
end

View File

@ -1,43 +1,45 @@
require 'spec_helper'
require 'yaml'
describe 'remove empty interfaces and endpoints' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
before :each do
puppet_debug_override
end
describe 'remove_empty_members' do
it 'should exist' do
expect(Puppet::Parser::Functions.function('remove_empty_members')).to eq 'function_remove_empty_members'
is_expected.not_to be_nil
end
it 'should has ability to remove empty keys from config hashes' do
expect(scope.function_remove_empty_members([{
:endpoints => {
:"br-fw-admin"=>
{"IP"=>["10.88.0.7/24"],
"gateway"=>"",
"vendor_specific"=>{"provider_gateway"=>"10.88.0.2"}},
"br-mesh"=>""
},
:interfaces=> {
"enp0s3"=>{"vendor_specific"=>{"bus_info"=>"0000:00:03.0", "driver"=>"e1000"}},
"enp0s4"=> ""
},
:provider=>"lnx"
}])).to eq({
:endpoints => {
:"br-fw-admin"=>
{"IP"=>["10.88.0.7/24"],
"gateway"=>"",
"vendor_specific"=>{"provider_gateway"=>"10.88.0.2"}},
},
:interfaces=> {
"enp0s3"=>{"vendor_specific"=>{"bus_info"=>"0000:00:03.0", "driver"=>"e1000"}},
},
:provider=>"lnx",
})
is_expected.to run.with_params(
{
:endpoints => {
:'br-fw-admin' =>
{
'IP' => ['10.88.0.7/24'],
'gateway' => '',
'vendor_specific' => {'provider_gateway' => '10.88.0.2'}
},
'br-mesh' => ''
},
:interfaces => {
'enp0s3' => {'vendor_specific' => {'bus_info' => '0000:00:03.0', 'driver' => 'e1000'}},
'enp0s4' => ''
},
:provider => 'lnx',
}
).and_return(
{
:endpoints => {
:'br-fw-admin' =>
{
'IP' => ['10.88.0.7/24'],
'gateway' => '',
'vendor_specific' => {'provider_gateway' => '10.88.0.2'}
},
},
:interfaces => {
'enp0s3' => {'vendor_specific' => {'bus_info' => '0000:00:03.0', 'driver' => 'e1000'}},
},
:provider => 'lnx',
}
)
end
end

View File

@ -1,154 +1,171 @@
require 'spec_helper'
describe 'sanitize_bool_in_hash' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it 'should exist' do
expect(Puppet::Parser::Functions.function('sanitize_bool_in_hash')).to eq 'function_sanitize_bool_in_hash'
is_expected.not_to be_nil
end
it 'should convert string-boolean values to boolean' do
expect(scope.function_sanitize_bool_in_hash([{
:s_true => 'true',
:s_false => 'false',
:s_none => 'none',
:s_null => 'null',
:s_nil => 'nil',
:s_nill => 'nill',
}])).to eq({
:s_true => true,
:s_false => false,
:s_none => nil,
:s_null => nil,
:s_nil => nil,
:s_nill => nil,
})
is_expected.to run.with_params(
{
:s_true => 'true',
:s_false => 'false',
:s_none => 'none',
:s_null => 'null',
:s_nil => 'nil',
:s_nill => 'nill',
}
).and_return(
{
:s_true => true,
:s_false => false,
:s_none => nil,
:s_null => nil,
:s_nil => nil,
:s_nill => nil,
}
)
end
it 'should convert UP-sace string-boolean values to boolean' do
expect(scope.function_sanitize_bool_in_hash([{
:s_true => 'TRUE',
:s_false => 'FALSE',
:s_none => 'NONE',
:s_null => 'NULL',
:s_nil => 'NIL',
:s_nill => 'NILL',
}])).to eq({
:s_true => true,
:s_false => false,
:s_none => nil,
:s_null => nil,
:s_nil => nil,
:s_nill => nil,
})
is_expected.to run.with_params(
{
:s_true => 'TRUE',
:s_false => 'FALSE',
:s_none => 'NONE',
:s_null => 'NULL',
:s_nil => 'NIL',
:s_nill => 'NILL',
}
).and_return(
{
:s_true => true,
:s_false => false,
:s_none => nil,
:s_null => nil,
:s_nil => nil,
:s_nill => nil,
}
)
end
it 'should convert recursive hashes' do
#TODO: boolean values in arrays are not sanitized correctly, it should be fixed
#TODO: this function should somehow support ":undef" values at Puppet4
expect(scope.function_sanitize_bool_in_hash([{
:bool_hash1 => {
:str => 'aaa',
:int => 123,
:array => [111,222,333],
:hash => {
:str => 'aaa',
:int => 123,
:array => [111,222,333],
#:a_sbool => ['true', 'nil', 'false'],
:a_bool => [true, nil, false],
:hash => {
:str => 'aaa',
:int => 123,
:array => [111,222,333],
#:a_sbool => ['true', 'nil', 'false'],
:a_bool => [true, nil, false],
},
},
#:a_sbool => ['true', 'nil', 'false'],
:a_bool => [true, nil, false],
},
:bool_hash2 => {
:t => true,
:f => false,
:n => nil
},
}])).to eq({
:bool_hash1 => {
:str => 'aaa',
:int => 123,
:array => [111,222,333],
:hash => {
:str => 'aaa',
:int => 123,
:array => [111,222,333],
#:a_sbool => [true, nil, false],
:a_bool => [true, nil, false],
:hash => {
:str => 'aaa',
:int => 123,
:array => [111,222,333],
#:a_sbool => [true, nil, false],
:a_bool => [true, nil, false],
},
},
#:a_sbool => [true, nil, false],
:a_bool => [true, nil, false],
},
:bool_hash2 => {
:t => true,
:f => false,
:n => nil
},
})
is_expected.to run.with_params(
{
:bool_hash1 => {
:str => 'aaa',
:int => 123,
:array => [111, 222, 333],
:hash => {
:str => 'aaa',
:int => 123,
:array => [111, 222, 333],
#:a_sbool => ['true', 'nil', 'false'],
:a_bool => [true, nil, false],
:hash => {
:str => 'aaa',
:int => 123,
:array => [111, 222, 333],
#:a_sbool => ['true', 'nil', 'false'],
:a_bool => [true, nil, false],
},
},
#:a_sbool => ['true', 'nil', 'false'],
:a_bool => [true, nil, false],
},
:bool_hash2 => {
:t => true,
:f => false,
:n => nil
},
}
).and_return(
{
:bool_hash1 => {
:str => 'aaa',
:int => 123,
:array => [111, 222, 333],
:hash => {
:str => 'aaa',
:int => 123,
:array => [111, 222, 333],
#:a_sbool => [true, nil, false],
:a_bool => [true, nil, false],
:hash => {
:str => 'aaa',
:int => 123,
:array => [111, 222, 333],
#:a_sbool => [true, nil, false],
:a_bool => [true, nil, false],
},
},
#:a_sbool => [true, nil, false],
:a_bool => [true, nil, false],
},
:bool_hash2 => {
:t => true,
:f => false,
:n => nil
},
}
)
end
it 'should convert array of hashes' do
expect(scope.function_sanitize_bool_in_hash([{ :array => [
{:aaa=>1,"aaa"=>11, :bbb=>2,'bbb'=>12, :ccc=>3,'ccc'=>3},
{:t=>'true','tt'=>'true', :f=>'false','ff'=>'false', :n=>'nil','nn'=>'nil'},
{
:s_true => 'true',
:s_false => 'false',
:s_none => 'none',
:s_null => 'null',
:s_nil => 'nil',
:s_nill => 'nill',
},
{
:s_true => 'TRUE',
:s_false => 'FALSE',
:s_none => 'NONE',
:s_null => 'NULL',
:s_nil => 'NIL',
:s_nill => 'NILL',
},
]}])).to eq({ :array => [
{:aaa=>1,"aaa"=>11, :bbb=>2,'bbb'=>12, :ccc=>3,'ccc'=>3},
{:t=>true,'tt'=>true, :f=>false,'ff'=>false, :n=>nil,'nn'=>nil},
{
:s_true => true,
:s_false => false,
:s_none => nil,
:s_null => nil,
:s_nil => nil,
:s_nill => nil,
},
{
:s_true => true,
:s_false => false,
:s_none => nil,
:s_null => nil,
:s_nil => nil,
:s_nill => nil,
},
]})
is_expected.to run.with_params(
{
:array => [
{:aaa => 1, "aaa" => 11, :bbb => 2, 'bbb' => 12, :ccc => 3, 'ccc' => 3},
{:t => 'true', 'tt' => 'true', :f => 'false', 'ff' => 'false', :n => 'nil', 'nn' => 'nil'},
{
:s_true => 'true',
:s_false => 'false',
:s_none => 'none',
:s_null => 'null',
:s_nil => 'nil',
:s_nill => 'nill',
},
{
:s_true => 'TRUE',
:s_false => 'FALSE',
:s_none => 'NONE',
:s_null => 'NULL',
:s_nil => 'NIL',
:s_nill => 'NILL',
},
]
}
).and_return(
{
:array => [
{:aaa => 1, "aaa" => 11, :bbb => 2, 'bbb' => 12, :ccc => 3, 'ccc' => 3},
{:t => true, 'tt' => true, :f => false, 'ff' => false, :n => nil, 'nn' => nil},
{
:s_true => true,
:s_false => false,
:s_none => nil,
:s_null => nil,
:s_nil => nil,
:s_nill => nil,
},
{
:s_true => true,
:s_false => false,
:s_none => nil,
:s_null => nil,
:s_nil => nil,
:s_nill => nil,
},
]
}
)
end
it 'should throw an error' do
expect do
scope.function_sanitize_bool_in_hash(['xxx'])
end.to raise_error(Puppet::ParseError)
is_expected.to run.with_params('xxx').and_raise_error(Puppet::ParseError)
end
end

View File

@ -1,5 +1,7 @@
require 'rubygems'
require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
include RspecPuppetFacts
fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
@ -25,5 +27,3 @@ def puppet_debug_override
Puppet::Util::Log.newdestination(:console)
end
end
###