Skip to content

Commit

Permalink
Do not create config file for ovs2ovs patchcord
Browse files Browse the repository at this point in the history
Ubuntu with OVS < 2.4 does not support such configs at all.

FUEL-Change-Id: I9161e282f285dffc018a9d7d3fe91cb3760486ad

Closes: #144
  • Loading branch information
Sergey Vasilenko committed Sep 16, 2015
1 parent bb2bb95 commit 83ae6d1
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 52 deletions.
25 changes: 7 additions & 18 deletions lib/puppet/parser/functions/get_provider_for.rb
Original file line number Diff line number Diff line change
@@ -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
65 changes: 41 additions & 24 deletions manifests/l2/patch.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,24 @@
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 {
Expand All @@ -41,27 +52,33 @@
$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]: }
}
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
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[$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,
Expand All @@ -73,4 +90,4 @@
Anchor['l23network::init'] -> K_mod<||> -> L2_patch<||>
}
}
# vim: set ts=2 sw=2 et :
# vim: set ts=2 sw=2 et :
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
end

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

end

end
Expand Down
111 changes: 111 additions & 0 deletions spec/classes/ovs2ovs__ovs_patch__spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 83ae6d1

Please sign in to comment.