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 group :development, :test do
gem 'rake', :require => false gem 'rake', :require => false
gem 'pry', :require => false gem 'pry', :require => false
gem 'rspec', '~>3.3', :require => false gem 'rspec', :require => false
gem 'rspec-puppet', '~>2.2.0', :require => false gem 'rspec-puppet', :require => false
gem 'puppetlabs_spec_helper', :require => false gem 'puppetlabs_spec_helper', :require => false
gem 'puppet-lint', '~> 1.1' gem 'puppet-lint', '~> 1.1'
gem 'rspec-puppet-facts'
end end
if puppetversion = ENV['PUPPET_GEM_VERSION'] if puppetversion = ENV['PUPPET_GEM_VERSION']
@ -14,5 +15,3 @@ if puppetversion = ENV['PUPPET_GEM_VERSION']
else else
gem 'puppet', :require => false gem 'puppet', :require => false
end end
# vim:ft=ruby

View File

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

View File

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

View File

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

View File

@ -10,8 +10,8 @@ describe 'l23network::l3::ifconfig', :type => :define do
:kernel => 'Linux', :kernel => 'Linux',
:netrings => { :netrings => {
'eth4' => { 'eth4' => {
'maximums' => {'RX'=>'4096', 'TX'=>'4096'}, 'maximums' => {'rx'=>'4096', 'tx'=>'4096'},
'current' => {'RX'=>'256', 'TX'=>'256'} '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 # this is a workaround for run spec tests not only on Linux platform
if $::l23network::params::network_manager_name != undef { Package <||> { provider => 'apt' }
Package<| title == $::l23network::params::network_manager_name |> { provider => apt } ###
}
###

View File

@ -1,32 +1,21 @@
require 'spec_helper' require 'spec_helper'
describe 'array_or_string_to_array' do 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 it 'should throw an error on invalid types' do
expect { is_expected.to run.with_params({:foo => :bar}).and_raise_error(Puppet::ParseError)
scope.function_array_or_string_to_array([{:foo => :bar}])
}.to(raise_error(Puppet::ParseError))
end end
it 'should throw an error on invalid arguments number' do it 'should throw an error on invalid arguments number' do
expect { is_expected.to run.with_params().and_raise_error(Puppet::ParseError)
scope.function_array_or_string_to_array([]) is_expected.to run.with_params([1,2],[3,4]).and_raise_error(Puppet::ParseError)
}.to(raise_error(Puppet::ParseError))
expect {
scope.function_array_or_string_to_array([[1,2],[3,4]])
}.to(raise_error(Puppet::ParseError))
end end
it 'should return array if given array' do 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 end
it 'should return array of strings if given string with separators' do 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 end

View File

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

View File

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

View File

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

View File

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

View File

@ -1,14 +1,18 @@
require 'spec_helper' require 'spec_helper'
describe 'default_provider_for' do 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) } on_supported_os.each do |os, facts|
it { is_expected.to run.with_params('file').and_return('posix') } context "on #{os}" do
end 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 'yaml'
require_relative '../../lib/puppetx/l23_hash_tools' require_relative '../../lib/puppetx/l23_hash_tools'
describe Puppet::Parser::Functions.function(:get_default_gateways) do describe 'get_default_gateways' do
let(:network_scheme) do
<<eof let(:network_scheme) do
<<-eof
--- ---
version: 1.1 version: 1.1
provider: lnx provider: lnx
@ -40,15 +41,10 @@ let(:network_scheme) do
br-floating: br-floating:
IP: none IP: none
eof eof
end end
it 'should exist' do
is_expected.not_to be_nil
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
subject do
function_name = Puppet::Parser::Functions.function(:get_default_gateways)
scope.method(function_name)
end end
context ":get_default_gateways() usage" do context ":get_default_gateways() usage" do
@ -60,12 +56,8 @@ end
) )
end end
it 'should exist' do
subject == Puppet::Parser::Functions.function(:get_default_gateways)
end
it do 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
end end

View File

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

View File

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

View File

@ -1,11 +1,9 @@
require 'spec_helper' require 'spec_helper'
describe Puppet::Parser::Functions.function(:get_network_role_property) do describe 'get_network_role_property' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
subject do it 'should exist' do
function_name = Puppet::Parser::Functions.function(:get_network_role_property) is_expected.not_to be_nil
scope.method(function_name)
end end
context "mtk" do 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') #Puppet::Parser::Scope.any_instance.stubs(:lookupvar).with('l3_fqdn_hostname').returns('node1.tld')
scope.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'), { L23network::Scheme.set_config(scope.lookupvar('l3_fqdn_hostname'), {
:transformations => [ { :transformations => [
:bridge => 'br-ex', {
:name => 'bond0', :bridge => 'br-ex',
:mtu => 1450, :name => 'bond0',
:interfaces => ["eth1", "eth2"], :mtu => 1450,
}, ], :interfaces => ["eth1", "eth2"],
:interfaces => { },
:eth0 => {}, ],
}, :interfaces => {
:endpoints => { :eth0 => {},
:eth0 => {:IP => 'dhcp'}, },
:"br-ex" => { :endpoints => {
:gateway => '10.1.3.1', :eth0 => {:IP => 'dhcp'},
:IP => ['10.1.3.11/24'], :"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 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 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 end
it 'should raise for non-existing role name' do 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 end
it 'should return ip address for "management" network role' do 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 end
it 'should return cidr-notated ip address for "management" network role' do 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 end
it 'should return cidr-notated network address for "management" network role' do 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 end
it 'should return netmask for "management" network role' do 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 end
it 'should return ip address and netmask for "management" network role' do 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 end
it 'should return physical device name for "ex" network role' do 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 end
it 'should return NIL for "admin" network role' do 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 end
it 'should return NIL for "admin" network role' do 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 end
it 'should return NIL for "admin" network role' do 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 end
it 'should return NIL for "admin" network role' do 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 end
it 'should return eth0 for "admin" network role phys_dev' do 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
end end

View File

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

View File

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

View File

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

View File

@ -1,38 +1,29 @@
require 'spec_helper' require 'spec_helper'
describe 'get_route_resource_name' do describe 'get_route_resource_name' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
subject do it 'should exist' do
function_name = Puppet::Parser::Functions.function(:get_route_resource_name) is_expected.not_to be_nil
scope.method(function_name)
end end
context "get_route_resource_name" do it 'should throw an error if called without args' do
is_expected.to run.with_params().and_raise_error(Puppet::ParseError)
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
end 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 end

View File

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

View File

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

View File

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

View File

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

View File

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