Do not create config file for ovs2ovs patchcord

Ubuntu with OVS < 2.4 does not support such configs at all.

Change-Id: I9161e282f285dffc018a9d7d3fe91cb3760486ad
Closes-bug: #1495534
This commit is contained in:
Sergey Vasilenko 2015-09-14 18:04:28 -05:00 committed by Stanislav Makar
parent 3864463078
commit c2b2f795ec
5 changed files with 247 additions and 52 deletions

View File

@ -1,24 +1,13 @@
module Puppet::Parser::Functions
newfunction(:get_provider_for, :type => :rvalue, :doc => <<-EOS
Get the default provider of a type
Get resource provider by given name and type
EOS
) do |argv|
type_name = argv[0]
res_name = argv[1]
type_name = argv[0].to_s
resource_name = argv[1].to_s
fail('No type name provided!') if ! type_name
Puppet::Type.loadall()
type_name = type_name.capitalize.to_sym
return 'undef' if ! Puppet::Type.const_defined? type_name
type = Puppet::Type.const_get type_name
# require 'pry'
# binding.pry
type.loadall()
rv = type.instances.select{|i| i.name.to_s.downcase == res_name.to_s.downcase}.map{|j| j[:provider].to_s}
# require 'pry'
# binding.pry
rv = rv[0]
debug("Provider for '#{type_name}[#{res_name}]' is a '#{rv}'.")
return rv
# type.loadall()
resource = catalog.resources.select{|res| res.type.to_s==type_name and res.title.to_s==resource_name }[0]
( resource.nil? ? nil : resource[:provider].to_s )
end
end
end

View File

@ -26,13 +26,24 @@ define l23network::l2::patch (
include ::stdlib
include ::l23network::params
#$provider_1 = get_provider_for('L2_bridge', bridges[0]) # this didn't work, because parser functions
#$provider_2 = get_provider_for('L2_bridge', bridges[1]) # executed before resources prefetch
# Architecture limitation.
# We can't create more one patch between same bridges.
$patch_name = get_patch_name($bridges)
$patch_jacks_names = get_pair_of_jack_names($bridges)
# We can't create more then one patch between the same bridges.
$bridge1_provider = get_provider_for('L2_bridge', $bridges[0])
$bridge2_provider = get_provider_for('L2_bridge', $bridges[1])
if $bridge1_provider == 'ovs' and $bridge2_provider == 'ovs' {
$act_bridges = sort($bridges)
$do_not_create_stored_config = true
} elsif $bridge1_provider == 'ovs' and $bridge2_provider == 'lnx' {
$act_bridges = [$bridges[0], $bridges[1]]
} elsif $bridge1_provider == 'lnx' and $bridge2_provider == 'ovs' {
$act_bridges = [$bridges[1], $bridges[0]]
} else {
$act_bridges = $bridges
}
$patch_name = get_patch_name($act_bridges)
$patch_jacks_names = get_pair_of_jack_names($act_bridges)
if ! defined(L2_patch[$patch_name]) {
if $provider {
@ -41,27 +52,33 @@ define l23network::l2::patch (
$config_provider = undef
}
if ! defined(L23_stored_config[$patch_jacks_names[0]]) {
# we use only one (last) patch jack name here and later,
# because a both jacks for patch
# creates by one command. This command stores in one config file.
l23_stored_config { $patch_jacks_names[0]: }
if ! $do_not_create_stored_config {
# we do not create any configs for ovs2ovs patchcords, because
# neither CenOS5 nor Ubuntu with OVS < 2.4 supports creating patch resources
# from network config files. But OVSDB stores patch configuration and this is
# enough to restore after reboot
if ! defined(L23_stored_config[$patch_jacks_names[0]]) {
# we use only one (first) patch jack name here and later,
# because a both jacks for patch are created by
# one command. This command stores in one config file.
l23_stored_config { $patch_jacks_names[0]: }
}
L23_stored_config <| title == $patch_jacks_names[0] |> {
ensure => $ensure,
if_type => 'ethernet',
bridge => $act_bridges,
jacks => $patch_jacks_names,
mtu => $mtu,
onboot => true,
vendor_specific => $vendor_specific,
provider => $config_provider
}
L23_stored_config[$patch_jacks_names[0]] -> L2_patch[$patch_name]
}
L23_stored_config <| title == $patch_jacks_names[0] |> {
ensure => $ensure,
if_type => 'ethernet',
bridge => $bridges,
jacks => $patch_jacks_names,
mtu => $mtu,
onboot => true,
vendor_specific => $vendor_specific,
provider => $config_provider
}
L23_stored_config[$patch_jacks_names[0]] -> L2_patch[$patch_name]
l2_patch{ $patch_name :
ensure => $ensure,
bridges => $bridges,
bridges => $act_bridges,
use_ovs => $use_ovs,
jacks => $patch_jacks_names,
vlan_ids => $vlan_ids,
@ -73,4 +90,4 @@ define l23network::l2::patch (
Anchor['l23network::init'] -> K_mod<||> -> L2_patch<||>
}
}
# vim: set ts=2 sw=2 et :
# vim: set ts=2 sw=2 et :

View File

@ -30,7 +30,6 @@ eof
end
context 'Patch between OVS and LNX bridges.' do
let(:title) { 'Centos has delay for port after boot' }
let(:facts) {
{
:osfamily => 'Debian',
@ -116,7 +115,6 @@ end
'provider' => 'ovs_ubuntu'
})
end
end
end

View File

@ -0,0 +1,111 @@
require 'spec_helper'
describe 'l23network::examples::run_network_scheme', :type => :class do
let(:network_scheme) do
<<eof
---
network_scheme:
version: 1.1
provider: lnx
interfaces:
eth1: {}
transformations:
- action: add-br
name: br-ovs2
provider: ovs
- action: add-br
name: br-ovs1
provider: ovs
- action: add-patch
bridges:
- br-ovs2
- br-ovs1
provider: ovs
endpoints: {}
roles: {}
eof
end
context 'Patch between two OVS bridges.' do
let(:facts) {
{
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:kernel => 'Linux',
:l23_os => 'ubuntu',
:l3_fqdn_hostname => 'stupid_hostname',
}
}
let(:params) do {
:settings_yaml => network_scheme,
} end
get_provider_for = {}
before(:each) do
if ENV['SPEC_PUPPET_DEBUG']
Puppet::Util::Log.level = :debug
Puppet::Util::Log.newdestination(:console)
end
Puppet::Parser::Functions.newfunction(:get_provider_for, :type => :rvalue) {
|args| get_provider_for.call(args[0], args[1])
}
get_provider_for.stubs(:call).with('L2_bridge', 'br-ovs1').returns('ovs')
get_provider_for.stubs(:call).with('L2_bridge', 'br-ovs2').returns('ovs')
end
it do
should compile.with_all_deps
end
it do
should contain_l23_stored_config('br-ovs1').with({
'ensure' => 'present',
'provider' => 'ovs_ubuntu'
})
end
it do
should contain_l23_stored_config('br-ovs2').with({
'ensure' => 'present',
'provider' => 'ovs_ubuntu'
})
end
it do
should contain_l2_bridge('br-ovs1').with({
'ensure' => 'present',
'provider' => 'ovs'
})
end
it do
should contain_l2_bridge('br-ovs2').with({
'ensure' => 'present',
'provider' => 'ovs'
})
end
it do
should contain_l2_patch('patch__br-ovs1--br-ovs2').with({
'ensure' => 'present',
'bridges' => ['br-ovs1', 'br-ovs2'],
'vlan_ids' => ['0', '0'],
'provider' => 'ovs'
})
end
it do
should contain_l2_patch('patch__br-ovs1--br-ovs2').with_jacks(['p_f277dc2b-0', 'p_f277dc2b-1'])
end
it do
should_not contain_l23_stored_config('p_f277dc2b-0')
end
end
end
# vim: set ts=2 sw=2 et

View File

@ -6,7 +6,7 @@ require 'spec_helper'
# names, that connected by patchcord.
describe 'l23network::l2::patch', :type => :define do
let(:title) { 'Spec for l23network::l2::port' }
let(:title) { 'test ovs2lnx patchcord' }
let(:facts) { {
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
@ -14,6 +14,17 @@ describe 'l23network::l2::patch', :type => :define do
:l23_os => 'ubuntu',
:l3_fqdn_hostname => 'stupid_hostname',
} }
get_provider_for = {}
before(:each) {
Puppet::Parser::Functions.newfunction(:get_provider_for, :type => :rvalue) {
|args| get_provider_for.call(args[0], args[1])
}
get_provider_for.stubs(:call).with('L2_bridge', 'br1').returns('ovs')
get_provider_for.stubs(:call).with('L2_bridge', 'br2').returns('lnx')
}
let(:pre_condition) { [
"class {'l23network': }"
] }
@ -64,7 +75,7 @@ describe 'l23network::l2::patch', :type => :define do
'ipaddr' => nil,
'gateway' => nil,
'onboot' => true,
'bridge' => ['br2', 'br1'],
'bridge' => ['br1', 'br2'],
'jacks' => ['p_39a440c1-0', 'p_39a440c1-1']
})
end
@ -72,12 +83,12 @@ describe 'l23network::l2::patch', :type => :define do
it do
should contain_l2_patch('patch__br1--br2').with({
'ensure' => 'present',
'bridges' => ['br2', 'br1'],
'bridges' => ['br1', 'br2'],
}).that_requires('L23_stored_config[p_39a440c1-0]')
end
end
context 'Just a patch between two OVS bridges' do
context 'Patch between two bridges, with explicitly defined OVS provider.' do
let(:params) do
{
:bridges => ['br1', 'br2'],
@ -117,12 +128,18 @@ describe 'l23network::l2::patch', :type => :define do
end
it do
should compile
should compile.with_all_deps
end
it do
should contain_l23_stored_config('p_39a440c1-0').with({
'bridge' => ['br1', 'br2'],
'jacks' => ['p_39a440c1-0', 'p_39a440c1-1'],
'mtu' => 9000,
})
end
it do
should contain_l2_patch('patch__br1--br2').with({
'ensure' => 'present',
'mtu' => 9000,
@ -146,7 +163,10 @@ describe 'l23network::l2::patch', :type => :define do
end
it do
should compile
should compile.with_all_deps
end
it do
should contain_l23_stored_config('p_39a440c1-0').with({
'bridge' => ['br1', 'br2'],
'jacks' => ['p_39a440c1-0', 'p_39a440c1-1'],
@ -158,6 +178,9 @@ describe 'l23network::l2::patch', :type => :define do
},
},
})
end
it do
should contain_l2_patch('patch__br1--br2').with({
'ensure' => 'present',
'bridges' => ['br1', 'br2'],
@ -172,7 +195,7 @@ describe 'l23network::l2::patch', :type => :define do
end
end
context 'Tagged patchcord between OVS bridges' do
context 'Tagged patchcord with explicitly defined OVS provider.' do
let(:params) do
{
:bridges => ['br1', 'br2'],
@ -201,6 +224,63 @@ describe 'l23network::l2::patch', :type => :define do
end
end
end
describe 'l23network::l2::patch', :type => :define do
let(:title) { 'test ovs2ovs patchcord' }
let(:facts) { {
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:kernel => 'Linux',
:l23_os => 'ubuntu',
:l3_fqdn_hostname => 'stupid_hostname',
} }
get_provider_for = {}
before(:each) {
Puppet::Parser::Functions.newfunction(:get_provider_for, :type => :rvalue) {
|args| get_provider_for.call(args[0], args[1])
}
get_provider_for.stubs(:call).with('L2_bridge', 'br1').returns('ovs')
get_provider_for.stubs(:call).with('L2_bridge', 'br2').returns('ovs')
}
let(:pre_condition) { [
"class {'l23network': }"
] }
context 'Just a ovs2ovs patch between two bridges' do
let(:params) do
{
:bridges => ['br1', 'br2'],
}
end
it do
should compile.with_all_deps
end
it do
should_not contain_l23_stored_config('p_39a440c1-0').with({
'ipaddr' => nil,
'gateway' => nil,
'onboot' => true,
'bridge' => ['br1', 'br2'],
'jacks' => ['p_39a440c1-0', 'p_39a440c1-1']
})
end
it do
should contain_l2_patch('patch__br1--br2').with({
'ensure' => 'present',
'bridges' => ['br1', 'br2'],
})
end
end
end
# vim: set ts=2 sw=2 et
# vim: set ts=2 sw=2 et