Spec-tests for l23network::l2::port and l23network::l2::patch

Partial-bug: #1310646
Blueprint: refactor-l23-linux-bridges

Change-Id: I8ca14db3593fa58392e8b8df52f52df31ed7ee7f
This commit is contained in:
Sergey Vasilenko 2015-03-18 02:28:14 +03:00
parent 08aeb3b051
commit 234e643705
5 changed files with 341 additions and 14 deletions

View File

@ -1,9 +1,5 @@
require 'spec_helper'
# Ubintu, manual -- no IP addresses, but interface in UP state
#describe 'l23network::l3::ifconfig', :type => :define do
# let(:module_path) { '../' }
#describe 'l23network::l3::ifconfig', :type => :define do
describe 'l23network::l3::ifconfig', :type => :define do
context 'ifconfig with dhcp' do
let(:title) { 'ifconfig simple test' }
@ -22,14 +18,6 @@ describe 'l23network::l3::ifconfig', :type => :define do
should compile
end
it do
should contain_l3_ifconfig('eth4').with({
'ensure' => 'present',
'ipaddr' => 'dhcp',
'gateway' => nil,
})
end
it do
should contain_l23_stored_config('eth4').only_with({
'name' => 'eth4',
@ -39,6 +27,15 @@ describe 'l23network::l3::ifconfig', :type => :define do
})
end
it do
should contain_l3_ifconfig('eth4').with({
'ensure' => 'present',
'ipaddr' => 'dhcp',
'gateway' => nil,
}).that_requires('L23_stored_config[eth4]')
end
end
end
@ -142,4 +139,4 @@ end
# should rv.without_content(/NETMASK=/)
# end
# end
###
# vim: set ts=2 sw=2 et

View File

@ -0,0 +1,111 @@
require 'spec_helper'
describe 'l23network::l2::patch', :type => :define do
let(:title) { 'Spec for l23network::l2::port' }
let(:facts) { {
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:kernel => 'Linux',
:l23_os => 'ubuntu',
:l3_fqdn_hostname => 'stupid_hostname',
} }
context 'Just a patch between two bridges' do
let(:params) do
{
:bridges => ['br1', 'br2'],
}
end
it do
should compile
end
it do
should contain_l23_stored_config('p_br1-0').only_with({
'use_ovs' => nil,
'method' => nil,
'ipaddr' => nil,
'gateway' => nil,
'onboot' => true,
'bridge' => ['br1', 'br2'],
'jacks' => ['p_br1-0', 'p_br2-1']
})
end
it do
should contain_l2_patch('patch__br1--br2').only_with({
'ensure' => 'present',
'use_ovs' => nil,
'bridges' => ['br1', 'br2'],
}).that_requires('L23_stored_config[p_br1-0]')
end
end
context 'Patch, which has jumbo frames' do
let(:params) do
{
:bridges => ['br1', 'br2'],
:mtu => 9000,
}
end
it do
should compile
should contain_l23_stored_config('p_br1-0').with({
'bridge' => ['br1', 'br2'],
'jacks' => ['p_br1-0', 'p_br2-1'],
'mtu' => 9000,
})
should contain_l2_patch('patch__br1--br2').with({
'ensure' => 'present',
'mtu' => 9000,
'bridges' => ['br1', 'br2'],
}).that_requires('L23_stored_config[p_br1-0]')
end
end
context 'Patch, which has vendor-specific properties' do
let(:params) do
{
:bridges => ['br1', 'br2'],
:vendor_specific => {
'aaa' => '111',
'bbb' => {
'bbb1' => 1111,
'bbb2' => ['b1','b2','b3']
},
},
}
end
it do
should compile
should contain_l23_stored_config('p_br1-0').with({
'bridge' => ['br1', 'br2'],
'jacks' => ['p_br1-0', 'p_br2-1'],
'vendor_specific' => {
'aaa' => '111',
'bbb' => {
'bbb1' => 1111,
'bbb2' => ['b1','b2','b3']
},
},
})
should contain_l2_patch('patch__br1--br2').with({
'ensure' => 'present',
'bridges' => ['br1', 'br2'],
'vendor_specific' => {
'aaa' => '111',
'bbb' => {
'bbb1' => 1111,
'bbb2' => ['b1','b2','b3']
},
},
}).that_requires('L23_stored_config[p_br1-0]')
end
end
end
# vim: set ts=2 sw=2 et

View File

@ -0,0 +1,181 @@
require 'spec_helper'
describe 'l23network::l2::port', :type => :define do
let(:title) { 'Spec for l23network::l2::port' }
let(:facts) { {
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:kernel => 'Linux',
:l23_os => 'ubuntu',
:l3_fqdn_hostname => 'stupid_hostname',
} }
context 'Port without anythyng' do
let(:params) do
{
:name => 'eth4',
}
end
it do
should compile
end
it do
should contain_l23_stored_config('eth4').only_with({
'use_ovs' => nil,
'method' => nil,
'ipaddr' => nil,
'gateway' => nil,
})
end
it do
should contain_l2_port('eth4').only_with({
'ensure' => 'present',
'use_ovs' => nil,
}).that_requires('L23_stored_config[eth4]')
end
end
context 'Native linux subinterface' do
let(:params) do
{
:name => 'eth4.102',
}
end
it do
should compile
end
it do
should contain_l23_stored_config('eth4.102').only_with({
'use_ovs' => nil,
'method' => nil,
'ipaddr' => nil,
'gateway' => nil,
'vlan_id' => '102',
'vlan_dev' => 'eth4',
'vlan_mode' => 'eth'
})
end
it do
should contain_l2_port('eth4.102').only_with({
'ensure' => 'present',
'use_ovs' => nil,
'vlan_id' => '102',
'vlan_dev' => 'eth4',
'vlan_mode' => 'eth'
}).that_requires('L23_stored_config[eth4.102]')
end
end
context 'Alternative VLAN definition' do
let(:params) do
{
:name => 'vlan102',
:vlan_dev => 'eth4',
:vlan_id => '102',
}
end
it do
should compile
end
it do
should contain_l23_stored_config('vlan102').only_with({
'use_ovs' => nil,
'method' => nil,
'ipaddr' => nil,
'gateway' => nil,
'vlan_id' => '102',
'vlan_dev' => 'eth4',
'vlan_mode' => 'vlan'
})
end
it do
should contain_l2_port('vlan102').only_with({
'ensure' => 'present',
'use_ovs' => nil,
'vlan_id' => '102',
'vlan_dev' => 'eth4',
'vlan_mode' => 'vlan'
}).that_requires('L23_stored_config[vlan102]')
end
end
context 'Port, which not ensured' do
let(:params) do
{
:name => 'eth2',
:ensure => 'absent',
}
end
it do
should compile
should contain_l23_stored_config('eth2').with({
'ensure' => 'absent',
})
should contain_l2_port('eth2').with({
'ensure' => 'absent',
}).that_requires('L23_stored_config[eth2]')
end
end
context 'Port, which has jumbo frames' do
let(:params) do
{
:name => 'eth2',
:mtu => 9000,
}
end
it do
should compile
should contain_l23_stored_config('eth2').only_with({
'use_ovs' => nil,
'method' => nil,
'ipaddr' => nil,
'gateway' => nil,
'mtu' => 9000,
})
should contain_l2_port('eth2').with({
'ensure' => 'present',
'mtu' => 9000,
'use_ovs' => nil,
}).that_requires('L23_stored_config[eth2]')
end
end
context 'Port, which an a member of bridge' do
let(:params) do
{
:name => 'eth2',
:bridge => 'br-floating',
}
end
it do
should compile
should contain_l23_stored_config('eth2').only_with({
'use_ovs' => nil,
'method' => nil,
'ipaddr' => nil,
'gateway' => nil,
'bridge' => 'br-floating',
})
should contain_l2_port('eth2').with({
'ensure' => 'present',
'use_ovs' => nil,
'bridge' => 'br-floating',
}).that_requires('L23_stored_config[eth2]')
end
end
end
# vim: set ts=2 sw=2 et

View File

@ -32,4 +32,5 @@ describe 'get_pair_of_jack_names' do
end
end
end
end
# vim: set ts=2 sw=2 et

View File

@ -0,0 +1,37 @@
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)
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)
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)
end
it 'should return numbered interface names' do
should 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"])
# end
end
end
# vim: set ts=2 sw=2 et