Fix config for ovs ethernet ports

L23module generates incorrect configuration file for
ethernet ports and corresponding bridges are missing it
after the reboot.

Change-Id: I0666a623352e42e999c181c29279a8c3566466d8
Closes-bug: #1514421
This commit is contained in:
Stanislav Makar 2015-11-09 13:02:26 +00:00 committed by slava
parent 46d42cdddb
commit 7d7b076fe5
9 changed files with 150 additions and 55 deletions

View File

@ -87,6 +87,10 @@ Puppet::Type.type(:l23_stored_config).provide(:ovs_ubuntu, :parent => Puppet::Pr
header << "allow-#{bridge} #{provider.name}"
props[:bridge] = bridge
provider.jacks = nil
elsif provider.if_type.to_s == 'ethernet'
header << "allow-#{bridge} #{provider.name}"
props[:bridge] = bridge
provider.jacks = nil
else
header << "auto #{provider.name}" if provider.onboot
end
@ -98,14 +102,16 @@ Puppet::Type.type(:l23_stored_config).provide(:ovs_ubuntu, :parent => Puppet::Pr
def self.unmangle__if_type(provider, val)
val = "OVS#{val.to_s.capitalize}".to_sym
val = 'OVSPort' if val.to_s == 'OVSPatch'
val = 'OVSPort' if val.to_s == 'OVSEthernet'
val = 'OVSPort' if val.to_s == 'OVSPatch' # this is hack due to ovs 2.3 scripts do not support OVSPatchPort
val = 'OVSIntPort' if val.to_s == 'OVSVport'
val
end
def self.mangle__if_type(val)
val = val.gsub('OVS', '').downcase.to_sym
val = :patch if val.to_s == 'port'
val = :ethernet if val.to_s == 'port'
val = :patch if val.to_s == 'port' # this is hack due to ovs 2.3 scripts do not support OVSPatchPort
val = :vport if val.to_s == 'intport'
val
end
@ -118,7 +124,7 @@ Puppet::Type.type(:l23_stored_config).provide(:ovs_ubuntu, :parent => Puppet::Pr
:detect_shift => 3,
},
:vlan_id => {
:detect_re => /(ovs_)?extra\s+--\s+set\s+Port\s+(p_.*-[0 1])\s+tag=(\d+)/,
:detect_re => /(ovs_)?extra\s+--\s+set\s+Port\s+(.*[\d+])\s+tag=(\d+)/,
:detect_shift => 3,
},
})

View File

@ -24,7 +24,7 @@ Puppet::Type.type(:l2_port).provide(:ovs, :parent => Puppet::Provider::Ovs_base)
@old_property_hash = {}
@property_flush = {}.merge! @resource
#
cmd = ["add-port", @resource[:bridge], @resource[:interface]]
cmd = ['--may-exist', 'add-port', @resource[:bridge], @resource[:interface]]
# # tag and trunks for port
# port_properties = @resource[:port_properties]
# if ![nil, :absent].include? @resource[:vlan_id] and @resource[:vlan_id] > 0
@ -45,6 +45,9 @@ Puppet::Type.type(:l2_port).provide(:ovs, :parent => Puppet::Provider::Ovs_base)
tt = "type=" + @resource[:type].to_s
elsif File.exist? "/sys/class/net/#{@resource[:interface]}"
tt = nil
# Flush ipaddr and routes for interface, then adding to the bridge
iproute('route', 'flush', 'dev', @resource[:interface])
iproute('addr', 'flush', 'dev', @resource[:interface])
else
tt = "type=internal"
end
@ -99,4 +102,4 @@ Puppet::Type.type(:l2_port).provide(:ovs, :parent => Puppet::Provider::Ovs_base)
end
end
# vim: set ts=2 sw=2 et :
# vim: set ts=2 sw=2 et :

View File

@ -96,7 +96,7 @@ define l23network::l2::port (
}
if $delay_while_up and ! is_numeric($delay_while_up) {
fail("Delay for waiting after UP interface ${port} should be numeric, not an '$delay_while_up'.")
fail("Delay for waiting after UP interface ${port} should be numeric, not an '${delay_while_up}'.")
}
# # implicitly create bridge, if it given and not exists
@ -123,9 +123,15 @@ define l23network::l2::port (
# the device is treated as an Ethernet device
# https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-networkscripts-interfaces_network-bridge.html
if $provider =~ /ovs/ {
$real_if_type = 'ethernet'
} else {
$real_if_type = $if_type
}
L23_stored_config <| title == $port_name |> {
ensure => $ensure,
if_type => $if_type,
if_type => $real_if_type,
bridge => $bridge,
vlan_id => $port_vlan_id,
vlan_dev => $port_vlan_dev,
@ -168,7 +174,7 @@ define l23network::l2::port (
ensure => present,
owner => 'root',
mode => '0755',
content => template("l23network/centos_post_up.erb"),
content => template('l23network/centos_post_up.erb'),
} -> L23_stored_config <| title == $port_name |>
} else {
file {"${::l23network::params::interfaces_dir}/interface-up-script-${port_name}":

View File

@ -0,0 +1,5 @@
allow-br-ovs1 p2p1
iface p2p1 inet manual
ovs_type OVSPort
ovs_bridge br-ovs1
ovs_extra -- set Port p2p1 tag=100

View File

@ -0,0 +1,2 @@
auto p2p2
iface p2p2 inet manual

View File

@ -22,4 +22,12 @@ RSpec.configure do |c|
c.mock_with(:mocha)
end
def puppet_debug_override
if ENV['SPEC_PUPPET_DEBUG']
Puppet::Util::Log.level = :debug
Puppet::Util::Log.newdestination(:console)
end
end
###

View File

@ -41,10 +41,7 @@ describe Puppet::Type.type(:l23_stored_config).provider(:lnx_ubuntu) do
end
before(:each) do
if ENV['SPEC_PUPPET_DEBUG']
Puppet::Util::Log.level = :debug
Puppet::Util::Log.newdestination(:console)
end
puppet_debug_override()
end
def fixture_path
@ -119,10 +116,7 @@ describe Puppet::Type.type(:l23_stored_config).provider(:ovs_ubuntu) do
end
before(:each) do
if ENV['SPEC_PUPPET_DEBUG']
Puppet::Util::Log.level = :debug
Puppet::Util::Log.newdestination(:console)
end
puppet_debug_override()
end
context "just eth interface with OVS provider" do

View File

@ -0,0 +1,80 @@
require 'spec_helper'
resources_map = {
:'p2p2' => {
:name => 'p2p2',
:if_type => 'ethernet',
:provider => 'lnx_ubuntu',
},
}
describe Puppet::Type.type(:l23_stored_config).provider(:lnx_ubuntu) do
let(:input_data) { resources_map}
let(:resources) do
resources = {}
input_data.each do |name, res|
resources.store name, Puppet::Type.type(:l23_stored_config).new(res)
end
return resources
end
let(:providers) do
providers = {}
resources.each do |name, resource|
provider = resource.provider
if ENV['SPEC_PUPPET_DEBUG']
class << provider
def debug(msg)
puts msg
end
end
end
provider.create
providers.store name, provider
end
return providers
end
before(:each) do
puppet_debug_override()
end
def fixture_path
File.join(PROJECT_ROOT, 'spec', 'fixtures', 'provider', 'l23_stored_config', 'ubuntu_ports')
end
def fixture_file(file)
File.join(fixture_path, file)
end
def fixture_data(file)
File.read(fixture_file(file))
end
context "formating config files" do
context 'OVS port p2p2 ' do
subject { providers[:'p2p2'] }
let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
it { expect(cfg_file).to match(/auto\s+p2p2/) }
it { expect(cfg_file).to match(/iface\s+p2p2\s+inet\s+manual/) }
it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(2) }
end
end
context "parsing config files" do
context 'OVS port p2p2' do
let(:res) { subject.class.parse_file('p2p2', fixture_data('ifcfg-p2p2'))[0] }
it { expect(res[:method]).to eq :manual }
it { expect(res[:onboot]).to eq true }
it { expect(res[:name]).to eq 'p2p2' }
it { expect(res[:if_provider].to_s).to eq 'lnx' }
end
end
end

View File

@ -1,22 +1,18 @@
require 'spec_helper'
require 'yaml'
resources_map = {
:'p2p1' => {
:name => 'p2p1',
:if_type => 'ethernet',
:bridge => 'br-ovs1',
:vlan_id => '100',
:provider => 'ovs_ubuntu',
},
}
describe Puppet::Type.type(:l23_stored_config).provider(:ovs_ubuntu) do
let(:input_data) do
{
:ttt0 => {
:name => 'ttt0',
:ensure => 'present',
:bridge => 'br9',
:if_type => 'vport',
:mtu => '6000',
:onboot => true,
:method => 'manual',
:provider => 'ovs_ubuntu',
},
}
end
let(:input_data) { resources_map}
let(:resources) do
resources = {}
@ -40,7 +36,7 @@ describe Puppet::Type.type(:l23_stored_config).provider(:ovs_ubuntu) do
provider.create
providers.store name, provider
end
providers
return providers
end
before(:each) do
@ -51,7 +47,7 @@ describe Puppet::Type.type(:l23_stored_config).provider(:ovs_ubuntu) do
end
def fixture_path
File.join(PROJECT_ROOT, 'spec', 'fixtures', 'provider', 'l23_stored_config', 'ovs_ubuntu__spec')
File.join(PROJECT_ROOT, 'spec', 'fixtures', 'provider', 'l23_stored_config', 'ubuntu_ports')
end
def fixture_file(file)
@ -62,34 +58,29 @@ describe Puppet::Type.type(:l23_stored_config).provider(:ovs_ubuntu) do
File.read(fixture_file(file))
end
# context "the method property" do
# context 'when dhcp' do
# let(:data) { subject.class.parse_file('eth0', fixture_data('ifcfg-eth0'))[0] }
# it { expect(data[:method]).to eq :dhcp }
# end
# end
context "formating config files" do
context "one OVS port, included to the OVS bridge" do
context 'format file' do
subject { providers[:ttt0] }
context 'OVS port p2p1 ' do
subject { providers[:'p2p1'] }
let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
it { expect(cfg_file).to match(/auto\s+ttt0/) }
it { expect(cfg_file).to match(/allow-br9\s+ttt0/) }
it { expect(cfg_file).to match(/iface\s+ttt0\s+inet\s+manual/) }
it { expect(cfg_file).to match(/mtu\s+6000/) }
it { expect(cfg_file).to match(/ovs_type\s+OVSIntPort/) }
it { expect(cfg_file).to match(/ovs_bridge\s+br9/) }
it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(6) } # no more lines in the interface file
it { expect(cfg_file).to match(/allow-br-ovs1\s+p2p1/) }
it { expect(cfg_file).to match(/iface\s+p2p1\s+inet\s+manual/) }
it { expect(cfg_file).to match(/ovs_type\s+OVSPort/) }
it { expect(cfg_file).to match(/ovs_bridge\s+br-ovs1/) }
it { expect(cfg_file).to match(/ovs_extra\s+--\s+set\s+Port\s+p2p1\st+ag=100/) }
it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(5) }
end
context "parse data from fixture" do
let(:res) { subject.class.parse_file('bond_lacp', fixture_data('ifcfg-port'))[0] }
end
context "parsing config files" do
context 'OVS port p2p1' do
let(:res) { subject.class.parse_file('p2p1', fixture_data('ifcfg-p2p1'))[0] }
it { expect(res[:method]).to eq :manual }
it { expect(res[:mtu]).to eq '6000' }
it { expect(res[:bridge]).to eq 'br9' }
it { expect(res[:if_type].to_s).to eq 'vport' }
it { expect(res[:name]).to eq 'p2p1' }
it { expect(res[:bridge]).to eq "br-ovs1" }
it { expect(res[:vlan_id]).to eq '100' }
it { expect(res[:if_provider].to_s).to eq 'ovs' }
end