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:
parent
8c911cc4c9
commit
14a5becf1d
|
@ -100,6 +100,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
|
||||
|
@ -111,14 +115,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
|
||||
|
@ -131,7 +137,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,
|
||||
},
|
||||
})
|
||||
|
|
|
@ -6,6 +6,8 @@ class Puppet::Provider::L23_stored_config_ovs_centos < Puppet::Provider::L23_sto
|
|||
rv = super
|
||||
rv.merge!({
|
||||
:devicetype => 'DEVICETYPE',
|
||||
:vlan_id => 'OVS_OPTIONS',
|
||||
:jacks => 'OVS_PATCH_PEER',
|
||||
:bridge => 'OVS_BRIDGE',
|
||||
:lnx_bridge => 'BRIDGE',
|
||||
:bond_slaves => 'BOND_IFACES',
|
||||
|
@ -22,6 +24,12 @@ class Puppet::Provider::L23_stored_config_ovs_centos < Puppet::Provider::L23_sto
|
|||
return rv
|
||||
end
|
||||
|
||||
def self.boolean_properties
|
||||
rv = super
|
||||
rv.delete(:vlan_id)
|
||||
return rv
|
||||
end
|
||||
|
||||
def self.properties_fake
|
||||
rv = super
|
||||
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)
|
||||
val = "OVS#{val.to_s.capitalize}".to_sym
|
||||
val = 'OVSIntPort' if val.to_s == 'OVSVport'
|
||||
val = 'OVSPort' if val.to_s == 'OVSEthernet'
|
||||
val = 'OVSPatchPort' if val.to_s == 'OVSPatch'
|
||||
val
|
||||
end
|
||||
|
||||
def self.mangle__if_type(val)
|
||||
val = val.gsub('OVS', '').downcase.to_sym
|
||||
val = :vport if val.to_s == 'intport'
|
||||
val = :ethernet if val.to_s == 'port'
|
||||
val = :patch if val.to_s == 'patchport'
|
||||
val
|
||||
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)
|
||||
"\"#{val.join(' ')}\""
|
||||
end
|
||||
|
@ -148,7 +168,14 @@ class Puppet::Provider::L23_stored_config_ovs_centos < Puppet::Provider::L23_sto
|
|||
val.split(' ')
|
||||
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
|
||||
|
||||
|
|
|
@ -22,7 +22,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
|
||||
|
|
|
@ -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}":
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
BOOTPROTO=none
|
||||
DEVICE=ovs2ovs-patch1
|
||||
ONBOOT=yes
|
||||
TYPE=OVSPatchPort
|
||||
OVS_BRIDGE=ovs-br1
|
||||
OVS_PATCH_PEER=ovs2ovs-patch2
|
||||
DEVICETYPE=ovs
|
|
@ -0,0 +1,7 @@
|
|||
BOOTPROTO=none
|
||||
DEVICE=ovs2ovs-patch2
|
||||
ONBOOT=yes
|
||||
TYPE=OVSPatchPort
|
||||
OVS_BRIDGE=ovs-br2
|
||||
OVS_PATCH_PEER=ovs2ovs-patch1
|
||||
DEVICETYPE=ovs
|
|
@ -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
|
|
@ -0,0 +1,5 @@
|
|||
BOOTPROTO=none
|
||||
DEVICE=lnx-port
|
||||
ONBOOT=yes
|
||||
MTU=9000
|
||||
TYPE=Ethernet
|
|
@ -0,0 +1,4 @@
|
|||
BOOTPROTO=none
|
||||
DEVICE=lnx-port2
|
||||
ONBOOT=yes
|
||||
MTU=9000
|
|
@ -0,0 +1,6 @@
|
|||
BOOTPROTO=none
|
||||
DEVICE=ovs-port
|
||||
ONBOOT=yes
|
||||
MTU=9000
|
||||
TYPE=OVSPort
|
||||
DEVICETYPE=ovs
|
|
@ -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
|
|
@ -0,0 +1,2 @@
|
|||
auto p2p2
|
||||
iface p2p2 inet manual
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -1,22 +1,18 @@
|
|||
require 'spec_helper'
|
||||
require 'yaml'
|
||||
|
||||
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',
|
||||
resources_map = {
|
||||
:'p2p1' => {
|
||||
:name => 'p2p1',
|
||||
:if_type => 'ethernet',
|
||||
:bridge => 'br-ovs1',
|
||||
:vlan_id => '100',
|
||||
:provider => 'ovs_ubuntu',
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
describe Puppet::Type.type(:l23_stored_config).provider(:ovs_ubuntu) do
|
||||
|
||||
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
|
||||
|
@ -48,7 +44,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)
|
||||
|
@ -59,34 +55,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
|
||||
|
||||
|
|
Loading…
Reference in New Issue