Implement Ovs2Ovs patch support CentOS7/RHEL7

*Implement tags for ovs2ovs patch for Centos7/RHEL7
*Implement ovs port for Ubuntu and Centos7/RHEL7
*Test coverage

Change-Id: I553a9d152f83b6a24ab5a5a3e4bb6bf41edbb303
Closes-bug: #1514421
This commit is contained in:
Stanislav Makar 2015-11-09 13:02:26 +00:00
parent 8c911cc4c9
commit 14a5becf1d
17 changed files with 589 additions and 47 deletions

View File

@ -100,6 +100,10 @@ Puppet::Type.type(:l23_stored_config).provide(:ovs_ubuntu, :parent => Puppet::Pr
header << "allow-#{bridge} #{provider.name}" header << "allow-#{bridge} #{provider.name}"
props[:bridge] = bridge props[:bridge] = bridge
provider.jacks = nil provider.jacks = nil
elsif provider.if_type.to_s == 'ethernet'
header << "allow-#{bridge} #{provider.name}"
props[:bridge] = bridge
provider.jacks = nil
else else
header << "auto #{provider.name}" if provider.onboot header << "auto #{provider.name}" if provider.onboot
end end
@ -111,14 +115,16 @@ Puppet::Type.type(:l23_stored_config).provide(:ovs_ubuntu, :parent => Puppet::Pr
def self.unmangle__if_type(provider, val) def self.unmangle__if_type(provider, val)
val = "OVS#{val.to_s.capitalize}".to_sym 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 = 'OVSIntPort' if val.to_s == 'OVSVport'
val val
end end
def self.mangle__if_type(val) def self.mangle__if_type(val)
val = val.gsub('OVS', '').downcase.to_sym 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 = :vport if val.to_s == 'intport'
val val
end end
@ -131,7 +137,7 @@ Puppet::Type.type(:l23_stored_config).provide(:ovs_ubuntu, :parent => Puppet::Pr
:detect_shift => 3, :detect_shift => 3,
}, },
:vlan_id => { :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, :detect_shift => 3,
}, },
}) })

View File

@ -6,6 +6,8 @@ class Puppet::Provider::L23_stored_config_ovs_centos < Puppet::Provider::L23_sto
rv = super rv = super
rv.merge!({ rv.merge!({
:devicetype => 'DEVICETYPE', :devicetype => 'DEVICETYPE',
:vlan_id => 'OVS_OPTIONS',
:jacks => 'OVS_PATCH_PEER',
:bridge => 'OVS_BRIDGE', :bridge => 'OVS_BRIDGE',
:lnx_bridge => 'BRIDGE', :lnx_bridge => 'BRIDGE',
:bond_slaves => 'BOND_IFACES', :bond_slaves => 'BOND_IFACES',
@ -22,6 +24,12 @@ class Puppet::Provider::L23_stored_config_ovs_centos < Puppet::Provider::L23_sto
return rv return rv
end end
def self.boolean_properties
rv = super
rv.delete(:vlan_id)
return rv
end
def self.properties_fake def self.properties_fake
rv = super rv = super
rv.push(:devicetype) rv.push(:devicetype)
@ -119,15 +127,27 @@ class Puppet::Provider::L23_stored_config_ovs_centos < Puppet::Provider::L23_sto
def self.unmangle__if_type(provider, val) def self.unmangle__if_type(provider, val)
val = "OVS#{val.to_s.capitalize}".to_sym val = "OVS#{val.to_s.capitalize}".to_sym
val = 'OVSIntPort' if val.to_s == 'OVSVport' val = 'OVSIntPort' if val.to_s == 'OVSVport'
val = 'OVSPort' if val.to_s == 'OVSEthernet'
val = 'OVSPatchPort' if val.to_s == 'OVSPatch'
val val
end end
def self.mangle__if_type(val) def self.mangle__if_type(val)
val = val.gsub('OVS', '').downcase.to_sym val = val.gsub('OVS', '').downcase.to_sym
val = :vport if val.to_s == 'intport' val = :vport if val.to_s == 'intport'
val = :ethernet if val.to_s == 'port'
val = :patch if val.to_s == 'patchport'
val val
end end
def self.unmangle__jacks(provider, val)
val.join()
end
def self.mangle__jacks(val)
val.split(' ')
end
def self.unmangle__bond_slaves(provider, val) def self.unmangle__bond_slaves(provider, val)
"\"#{val.join(' ')}\"" "\"#{val.join(' ')}\""
end end
@ -148,7 +168,14 @@ class Puppet::Provider::L23_stored_config_ovs_centos < Puppet::Provider::L23_sto
val.split(' ') val.split(' ')
end end
def self.unmangle__vlan_id(provider, val)
"\"tag=#{val}\""
end
def self.mangle__vlan_id(val)
val = val.gsub('"', '').split('=')[1]
val
end
end end

View File

@ -22,7 +22,7 @@ Puppet::Type.type(:l2_port).provide(:ovs, :parent => Puppet::Provider::Ovs_base)
@old_property_hash = {} @old_property_hash = {}
@property_flush = {}.merge! @resource @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 # # tag and trunks for port
# port_properties = @resource[:port_properties] # port_properties = @resource[:port_properties]
# if ![nil, :absent].include? @resource[:vlan_id] and @resource[:vlan_id] > 0 # if ![nil, :absent].include? @resource[:vlan_id] and @resource[:vlan_id] > 0
@ -97,4 +97,4 @@ Puppet::Type.type(:l2_port).provide(:ovs, :parent => Puppet::Provider::Ovs_base)
end end
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) { 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 # # 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 # 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 # 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 |> { L23_stored_config <| title == $port_name |> {
ensure => $ensure, ensure => $ensure,
if_type => $if_type, if_type => $real_if_type,
bridge => $bridge, bridge => $bridge,
vlan_id => $port_vlan_id, vlan_id => $port_vlan_id,
vlan_dev => $port_vlan_dev, vlan_dev => $port_vlan_dev,
@ -168,7 +174,7 @@ define l23network::l2::port (
ensure => present, ensure => present,
owner => 'root', owner => 'root',
mode => '0755', mode => '0755',
content => template("l23network/centos_post_up.erb"), content => template('l23network/centos_post_up.erb'),
} -> L23_stored_config <| title == $port_name |> } -> L23_stored_config <| title == $port_name |>
} else { } else {
file {"${::l23network::params::interfaces_dir}/interface-up-script-${port_name}": file {"${::l23network::params::interfaces_dir}/interface-up-script-${port_name}":

View File

@ -0,0 +1,7 @@
BOOTPROTO=none
DEVICE=ovs2ovs-patch1
ONBOOT=yes
TYPE=OVSPatchPort
OVS_BRIDGE=ovs-br1
OVS_PATCH_PEER=ovs2ovs-patch2
DEVICETYPE=ovs

View File

@ -0,0 +1,7 @@
BOOTPROTO=none
DEVICE=ovs2ovs-patch2
ONBOOT=yes
TYPE=OVSPatchPort
OVS_BRIDGE=ovs-br2
OVS_PATCH_PEER=ovs2ovs-patch1
DEVICETYPE=ovs

View File

@ -0,0 +1,8 @@
BOOTPROTO=none
DEVICE=ovs2ovs-tag
ONBOOT=yes
OVS_OPTIONS="tag=3"
TYPE=OVSPatchPort
OVS_BRIDGE=ovs-brt2
OVS_PATCH_PEER=ovs2ovs-patcht1
DEVICETYPE=ovs

View File

@ -0,0 +1,5 @@
BOOTPROTO=none
DEVICE=lnx-port
ONBOOT=yes
MTU=9000
TYPE=Ethernet

View File

@ -0,0 +1,4 @@
BOOTPROTO=none
DEVICE=lnx-port2
ONBOOT=yes
MTU=9000

View File

@ -0,0 +1,6 @@
BOOTPROTO=none
DEVICE=ovs-port
ONBOOT=yes
MTU=9000
TYPE=OVSPort
DEVICETYPE=ovs

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

@ -0,0 +1,123 @@
require 'spec_helper'
require 'yaml'
describe Puppet::Type.type(:l23_stored_config).provider(:lnx_centos7) do
let(:facts) do
{
:osfamily => 'Redhat',
:operatingsystem => 'CentOS',
:l23_os => 'centos7',
}
end
let(:input_data) do
{
:lnx_port => {
:name => 'lnx-port',
:ensure => 'present',
:if_type => 'ethernet',
:mtu => '9000',
:onboot => true,
:method => 'manual',
:provider => 'lnx_centos7',
},
:lnx_port_without_type => {
:name => 'lnx-port2',
:ensure => 'present',
:mtu => '9000',
:onboot => true,
:method => 'manual',
:provider => 'lnx_centos7',
},
}
end
let(:resources) do
resources = {}
input_data.each do |name, res|
resources.store name, Puppet::Type.type(:l23_stored_config).new(res)
end
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
providers
end
before(:each) do
puppet_debug_override()
end
def fixture_path
File.join(PROJECT_ROOT, 'spec', 'fixtures', 'provider', 'l23_stored_config', 'centos7_ports')
end
def fixture_file(file)
File.join(fixture_path, file)
end
def fixture_data(file)
File.read(fixture_file(file))
end
context "lnx port" do
context 'format file for lnx-port' do
subject { providers[:lnx_port] }
let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
it { expect(cfg_file).to match(%r{DEVICE=lnx-port}) }
it { expect(cfg_file).to match(%r{BOOTPROTO=none}) }
it { expect(cfg_file).to match(%r{ONBOOT=yes}) }
it { expect(cfg_file).to match(%r{TYPE=Ethernet}) }
it { expect(cfg_file).to match(%r{MTU=9000}) }
it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(5) } # no more lines in the interface file
end
context 'format file for lnx-port2 without type' do
subject { providers[:lnx_port_without_type] }
let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
it { expect(cfg_file).to match(%r{DEVICE=lnx-port2}) }
it { expect(cfg_file).to match(%r{BOOTPROTO=none}) }
it { expect(cfg_file).to match(%r{ONBOOT=yes}) }
it { expect(cfg_file).to match(%r{MTU=9000}) }
it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(4) } # no more lines in the interface file
end
context "parse port lnx-port data from fixture" do
let(:res) { subject.class.parse_file('lnx-port', fixture_data('ifcfg-lnx-port'))[0] }
it { expect(res[:name]).to eq 'lnx-port' }
it { expect(res[:if_type].to_s).to eq 'ethernet' }
it { expect(res[:method].to_s).to eq 'manual' }
it { expect(res[:mtu]).to eq '9000' }
it { expect(res[:onboot]).to eq true }
it { expect(res[:provider]).to eq :lnx_centos7 }
end
context "parse port lnx-port2 data from fixture" do
let(:res) { subject.class.parse_file('lnx-port2', fixture_data('ifcfg-lnx-port2'))[0] }
it { expect(res[:name]).to eq 'lnx-port2' }
it { expect(res[:method].to_s).to eq 'manual' }
it { expect(res[:mtu]).to eq '9000' }
it { expect(res[:onboot]).to eq true }
it { expect(res[:provider]).to eq :lnx_centos7 }
end
end
end

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

@ -0,0 +1,169 @@
require 'spec_helper'
require 'yaml'
describe Puppet::Type.type(:l23_stored_config).provider(:ovs_centos7) do
let(:facts) do
{
:osfamily => 'Redhat',
:operatingsystem => 'CentOS',
:l23_os => 'centos7',
}
end
let(:input_data) do
{
:ovs2ovs_patch1 => {
:name => 'ovs2ovs-patch1',
:ensure => 'present',
:if_type => 'patch',
:bridge => ['ovs-br1'],
:jacks => ['ovs2ovs-patch2'],
:onboot => true,
:method => 'manual',
:provider => 'ovs_centos7',
},
:ovs2ovs_patch2 => {
:name => 'ovs2ovs-patch2',
:ensure => 'present',
:if_type => 'patch',
:bridge => ['ovs-br2'],
:jacks => ['ovs2ovs-patch1'],
:onboot => true,
:method => 'manual',
:provider => 'ovs_centos7',
},
:ovs2ovs_patch_with_tag => {
:name => 'ovs2ovs-tag',
:ensure => 'present',
:if_type => 'patch',
:bridge => ['ovs-brt2'],
:jacks => ['ovs2ovs-patcht1'],
:vlan_id => 3,
:onboot => true,
:method => 'manual',
:provider => 'ovs_centos7',
},
}
end
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
providers
end
before(:each) do
puppet_debug_override()
end
def fixture_path
File.join(PROJECT_ROOT, 'spec', 'fixtures', 'provider', 'l23_stored_config', 'centos7_patches')
end
def fixture_file(file)
File.join(fixture_path, file)
end
def fixture_data(file)
File.read(fixture_file(file))
end
context "ovs2ovs patch" do
context 'format ovs2ovs-patch2 file' do
subject { providers[:ovs2ovs_patch1] }
let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
it { expect(cfg_file).to match(%r{DEVICE=ovs2ovs-patch1}) }
it { expect(cfg_file).to match(%r{BOOTPROTO=none}) }
it { expect(cfg_file).to match(%r{ONBOOT=yes}) }
it { expect(cfg_file).to match(%r{TYPE=OVSPatchPort}) }
it { expect(cfg_file).to match(%r{OVS_BRIDGE=ovs-br1}) }
it { expect(cfg_file).to match(%r{OVS_PATCH_PEER=ovs2ovs-patch2}) }
it { expect(cfg_file).to match(%r{DEVICETYPE=ovs}) }
it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(7) } # no more lines in the interface file
end
context 'format ovs2ovs-patch2 file' do
subject { providers[:ovs2ovs_patch2] }
let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
it { expect(cfg_file).to match(%r{DEVICE=ovs2ovs-patch2}) }
it { expect(cfg_file).to match(%r{BOOTPROTO=none}) }
it { expect(cfg_file).to match(%r{ONBOOT=yes}) }
it { expect(cfg_file).to match(%r{TYPE=OVSPatchPort}) }
it { expect(cfg_file).to match(%r{OVS_BRIDGE=ovs-br2}) }
it { expect(cfg_file).to match(%r{OVS_PATCH_PEER=ovs2ovs-patch1}) }
it { expect(cfg_file).to match(%r{DEVICETYPE=ovs}) }
it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(7) } # no more lines in the interface file
end
context 'format ovs2ovs-patch with tag file' do
subject { providers[:ovs2ovs_patch_with_tag] }
let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
it { expect(cfg_file).to match(%r{DEVICE=ovs2ovs-tag}) }
it { expect(cfg_file).to match(%r{BOOTPROTO=none}) }
it { expect(cfg_file).to match(%r{ONBOOT=yes}) }
it { expect(cfg_file).to match(%r{TYPE=OVSPatchPort}) }
it { expect(cfg_file).to match(%r{OVS_BRIDGE=ovs-brt2}) }
it { expect(cfg_file).to match(%r{OVS_PATCH_PEER=ovs2ovs-patcht1}) }
it { expect(cfg_file).to match(%r{OVS_OPTIONS="tag=3"}) }
it { expect(cfg_file).to match(%r{DEVICETYPE=ovs}) }
it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(8) } # no more lines in the interface file
end
context "parse ovs2ovs-patch1 data from fixture" do
let(:res) { subject.class.parse_file('ovs2ovs-patch1', fixture_data('ifcfg-ovs2ovs-patch1'))[0] }
it { expect(res[:name]).to eq 'ovs2ovs-patch1' }
it { expect(res[:if_type].to_s).to eq 'patch' }
it { expect(res[:bridge]).to match_array(['ovs-br1']) }
it { expect(res[:jacks]).to match_array(['ovs2ovs-patch2']) }
it { expect(res[:method].to_s).to eq 'manual' }
it { expect(res[:onboot]).to eq true }
it { expect(res[:provider].to_s).to eq 'ovs_centos7' }
end
context "parse ovs2ovs-patch2 data from fixture" do
let(:res) { subject.class.parse_file('ovs2ovs-patch2', fixture_data('ifcfg-ovs2ovs-patch2'))[0] }
it { expect(res[:name]).to eq 'ovs2ovs-patch2' }
it { expect(res[:if_type].to_s).to eq 'patch' }
it { expect(res[:bridge]).to match_array(['ovs-br2']) }
it { expect(res[:jacks]).to match_array(['ovs2ovs-patch1']) }
it { expect(res[:method].to_s).to eq 'manual' }
it { expect(res[:onboot]).to eq true }
it { expect(res[:provider].to_s).to eq 'ovs_centos7' }
end
context "parse ovs2ovs-tag data from fixture" do
let(:res) { subject.class.parse_file('ovs2ovs-tag', fixture_data('ifcfg-ovs2ovs-tag'))[0] }
it { expect(res[:name]).to eq 'ovs2ovs-tag' }
it { expect(res[:if_type].to_s).to eq 'patch' }
it { expect(res[:bridge]).to match_array(['ovs-brt2']) }
it { expect(res[:jacks]).to match_array(['ovs2ovs-patcht1']) }
it { expect(res[:vlan_id]).to eq('3') }
it { expect(res[:method].to_s).to eq 'manual' }
it { expect(res[:onboot]).to eq true }
it { expect(res[:provider].to_s).to eq 'ovs_centos7' }
end
end
end

View File

@ -0,0 +1,96 @@
require 'spec_helper'
require 'yaml'
describe Puppet::Type.type(:l23_stored_config).provider(:ovs_centos7) do
let(:facts) do
{
:osfamily => 'Redhat',
:operatingsystem => 'CentOS',
:l23_os => 'centos7',
}
end
let(:input_data) do
{
:ovs_port => {
:name => 'ovs-port',
:ensure => 'present',
:if_type => 'ethernet',
:mtu => '9000',
:onboot => true,
:method => 'manual',
:provider => 'ovs_centos7',
},
}
end
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
providers
end
before(:each) do
puppet_debug_override()
end
def fixture_path
File.join(PROJECT_ROOT, 'spec', 'fixtures', 'provider', 'l23_stored_config', 'centos7_ports')
end
def fixture_file(file)
File.join(fixture_path, file)
end
def fixture_data(file)
File.read(fixture_file(file))
end
context "OVS port" do
context 'format file for ovs-port' do
subject { providers[:ovs_port] }
let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
it { expect(cfg_file).to match(%r{DEVICE=ovs-port}) }
it { expect(cfg_file).to match(%r{BOOTPROTO=none}) }
it { expect(cfg_file).to match(%r{ONBOOT=yes}) }
it { expect(cfg_file).to match(%r{TYPE=OVSPort}) }
it { expect(cfg_file).to match(%r{MTU=9000}) }
it { expect(cfg_file).to match(%r{DEVICETYPE=ovs}) }
it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(6) } # no more lines in the interface file
end
context "parse port ovs-port data from fixture" do
let(:res) { subject.class.parse_file('ovs-port', fixture_data('ifcfg-ovs-port'))[0] }
it { expect(res[:name]).to eq 'ovs-port' }
it { expect(res[:if_type].to_s).to eq 'ethernet' }
it { expect(res[:method].to_s).to eq 'manual' }
it { expect(res[:mtu]).to eq '9000' }
it { expect(res[:onboot]).to eq true }
it { expect(res[:provider]).to eq :ovs_centos7 }
end
end
end

View File

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