Refactor native linux bonding

It's a stage #1 of blueprint linux-bonding :
  Refactoring incoming parameters for puppet ifconfig resource.
  Now we should use bond_properties hash instead set of dedicated parameters (backward compotibility saved).
  bond_properties => {
     mode   => 1, # mode is a obligatory option
     miimon => 100,
     ....
  }
  Full set of properties we can see here: https://www.kernel.org/doc/Documentation/networking/bonding.txt

Implements: blueprint linux-bonding
Change-Id: I260cf17eb5a4ee4ca89235ccd4db8e63498fa13d
This commit is contained in:
Sergey Vasilenko 2014-04-01 19:27:49 +04:00 committed by Gerrit Code Review
parent 0e4c251a1a
commit 45f9ad1095
18 changed files with 486 additions and 93 deletions

View File

@ -0,0 +1,44 @@
module Puppet::Parser::Functions
newfunction(:get_hash_with_defaults_and_deprecations, :type => :rvalue, :doc => <<-EOS
This function get three hashes:
* hash with incoming parameters
* hash with default values
* hash with deprecations
It's returns a hash
EOS
) do |arguments|
if arguments.size != 3
raise(Puppet::ParseError, "get_hash_with_defaults_and_deprecations(): Wrong number of arguments " +
"given (#{arguments.size} for 3)")
end
(0..2).each{ |i|
if ! arguments[i].is_a? Hash
raise(Puppet::ParseError,
"#{i}-argument of get_hash_with_defaults_and_deprecations() has wrong type." +
" Should be a Hash."
)
end
}
inp, defa, depre = arguments
rv = Marshal.load(Marshal.dump(inp))
# Add deprecated properties
depre.each { |k,v|
if rv[k].nil?
rv[k] = v
end
}
defa.each { |k,v|
if rv[k].nil?
rv[k] = v
end
}
return rv
end
end

View File

@ -3,15 +3,15 @@ class l23network::examples::bond_lnx (
$interfaces = ['eth4','eth5'],
$ipaddr = '1.2.3.4/27',
#$bond_master = undef,
$bond_mode = 1,
$bond_miimon = 100,
$bond_lacp_rate = 1,
$bond_properties = {
mode => 1,
miimon => 100,
lacp_rate => 1,
},
) {
l23network::l3::ifconfig {$bond:
ipaddr => $ipaddr,
bond_mode => $bond_mode,
bond_miimon => $bond_miimon,
bond_lacp_rate => $bond_lacp_rate,
bond_properties => $bond_properties,
} ->
l23network::l3::ifconfig {$interfaces[0]: ipaddr=>'none', bond_master=>$bond} ->
l23network::l3::ifconfig {$interfaces[1]: ipaddr=>'none', bond_master=>$bond}

View File

@ -0,0 +1,19 @@
class l23network::examples::bond_lnx_old_style (
$bond = $name,
$interfaces = ['eth4','eth5'],
$ipaddr = '1.2.3.4/27',
#$bond_master = undef,
$bond_mode = 1,
$bond_miimon = 100,
$bond_lacp_rate = 1,
) {
l23network::l3::ifconfig {$bond:
ipaddr => $ipaddr,
bond_mode => $bond_mode,
bond_miimon => $bond_miimon,
bond_lacp_rate => $bond_lacp_rate,
} ->
l23network::l3::ifconfig {$interfaces[0]: ipaddr=>'none', bond_master=>$bond} ->
l23network::l3::ifconfig {$interfaces[1]: ipaddr=>'none', bond_master=>$bond}
}
###

View File

@ -27,15 +27,17 @@
# This parameter sets the bond_master interface and says that this interface
# is a slave for bondX interface.
#
# [*bond_mode*]
# This parameter specifies a bond mode for interfaces like bondNN.
# All bond_* properties are ignored for non-bond-master interfaces.
# [*bond_properties*]
# This parameter specifies a bond properties for interfaces like bondNN.
# It's a property hash, that should contains native linux bonding options, ex:
# bond_properties => {
# mode => 1, # mode is a obligatory option
# miimon => 100,
# ....
# }
#
# [*bond_miimon*]
# lacp MII monitor period.
#
# [*bond_lacp_rate*]
# lacp MII rate
# bond_properties will be ignored for bond-slave interfaces
# Full set of properties we can see here: https://www.kernel.org/doc/Documentation/networking/bonding.txt
#
# [*ifname_order_prefix*]
# Sets the interface startup order
@ -88,9 +90,10 @@ define l23network::l3::ifconfig (
$gateway = undef,
$vlandev = undef,
$bond_master = undef,
$bond_mode = undef,
$bond_miimon = 100,
$bond_lacp_rate = 1,
$bond_properties = {},
$bond_mode = undef, # deprecated, should be used $bond_properties hash
$bond_miimon = undef, # deprecated, should be used $bond_properties hash
$bond_lacp_rate = undef, # deprecated, should be used $bond_properties hash
$mtu = undef,
$macaddr = undef,
$ethtool = undef,
@ -106,6 +109,12 @@ define l23network::l3::ifconfig (
){
include ::l23network::params
$bond_properties_defaults = {
mode => 1,
miimon => 100,
lacp_rate => 1,
}
$bond_modes = [
'balance-rr',
'active-backup',
@ -116,6 +125,20 @@ define l23network::l3::ifconfig (
'balance-alb'
]
if $bond_properties[mode] or $bond_mode {
$actual_bond_properties = get_hash_with_defaults_and_deprecations(
$bond_properties,
$bond_properties_defaults,
{
mode => $bond_mode,
miimon => $bond_miimon,
lacp_rate => $bond_lacp_rate,
}
)
} else {
$actual_bond_properties = { mode => undef, }
}
if $macaddr and $macaddr !~ /^([0-9a-fA-F]{2}\:){5}[0-9a-fA-F]{2}$/ {
fail("Invalid MAC address '${macaddr}' for interface '${interface}'")
}
@ -229,11 +252,11 @@ define l23network::l3::ifconfig (
$vlan_dev = $1
}
/^(bond\d+)/: {
if ! $bond_mode {
fail("To configure the interface bonding you must the bond_mode parameter is required and must be between 0..6.")
if ! $actual_bond_properties[mode] {
fail("To configure the interface bonding you should the mode properties for bond is required and must be between 0..6.")
}
if $bond_mode <0 or $bond_mode>6 {
fail("For interface bonding the bond_mode must be between 0..6, not '${bond_mode}'.")
if $actual_bond_properties[mode] <0 or $actual_bond_properties[mode] >6 {
fail("For interface bonding the bond mode should be between 0..6, not '${actual_bond_properties[mode]}'.")
}
$vlan_mode = undef
}

View File

@ -12,9 +12,11 @@ describe 'l23network::examples::bond_lnx', :type => :class do
:bond => 'bond0',
:ipaddr => '1.1.1.1/27',
:interfaces => ['eth4','eth5'],
:bond_mode => 1,
:bond_miimon => 100,
:bond_lacp_rate => 1,
:bond_properties => {
'mode' => 2,
'miimon' => 150,
'lacp_rate' => 0,
},
} }
let(:facts) { {
:osfamily => 'Debian',
@ -38,9 +40,9 @@ describe 'l23network::examples::bond_lnx', :type => :class do
it 'Should contains bond-specific parameters' do
rv = contain_file("#{interface_file_start}#{params[:bond]}")
should rv.with_content(/slaves\s+none/)
should rv.with_content(/bond-mode\s+#{params[:bond_mode]}/)
should rv.with_content(/bond-miimon\s+#{params[:bond_miimon]}/)
should rv.with_content(/bond-lacp-rate\s+#{params[:bond_lacp_rate]}/)
should rv.with_content(/bond-mode\s+#{params[:bond_properties]['mode']}/)
should rv.with_content(/bond-miimon\s+#{params[:bond_properties]['miimon']}/)
should rv.with_content(/bond-lacp-rate\s+#{params[:bond_properties]['lacp_rate']}/)
end
it 'Should contains interface files for bond-slave interfaces' do
@ -61,7 +63,12 @@ describe 'l23network::examples::bond_lnx', :type => :class do
let(:params) { {
:bond => 'bond0',
:ipaddr => '1.1.1.1/27',
:interfaces => ['eth4','eth5']
:interfaces => ['eth4','eth5'],
:bond_properties => {
'mode' => 2,
'miimon' => 150,
'lacp_rate' => 0,
},
} }
let(:facts) { {
:osfamily => 'RedHat',
@ -70,6 +77,15 @@ describe 'l23network::examples::bond_lnx', :type => :class do
} }
let(:interface_file_start) { '/etc/sysconfig/network-scripts/ifcfg-' }
let(:interface_up_file_start) { '/etc/sysconfig/network-scripts/interface-up-script-' }
let(:bond_modes) { [
'balance-rr',
'active-backup',
'balance-xor',
'broadcast',
'802.3ad',
'balance-tlb',
'balance-alb'
] }
it 'Should contains interface_file with IP-addr' do
rv = contain_file("#{interface_file_start}#{params[:bond]}")
@ -77,7 +93,8 @@ describe 'l23network::examples::bond_lnx', :type => :class do
should rv.with_content(/BOOTPROTO=none/)
should rv.with_content(/ONBOOT=yes/)
should rv.with_content(/IPADDR=1.1.1.1/)
should rv.with_content(/NETMASK=255.255.255.224/) end
should rv.with_content(/NETMASK=255.255.255.224/)
end
it 'Should contains interface files for bond-slave interfaces' do
params[:interfaces].each do |iface|
@ -90,4 +107,24 @@ describe 'l23network::examples::bond_lnx', :type => :class do
end
end
it 'Should contains Bonding-opts line' do
rv = contain_file("#{interface_file_start}#{params[:bond]}")
should rv.with_content(/DEVICE=#{params[:bond]}/)
should rv.with_content(/BONDING_OPTS="mode=/)
end
it 'Should contains Bond mode' do
rv = contain_file("#{interface_file_start}#{params[:bond]}")
should rv.with_content(/BONDING_OPTS.*mode=#{bond_modes[params[:bond_properties]['mode']]}/)
end
it 'Should contains miimon' do
rv = contain_file("#{interface_file_start}#{params[:bond]}")
should rv.with_content(/BONDING_OPTS.*miimon=#{params[:bond_properties]['miimon']}/)
end
it 'Should contains lacp_rate' do
rv = contain_file("#{interface_file_start}#{params[:bond]}")
should rv.with_content(/BONDING_OPTS.*lacp_rate=#{params[:bond_properties]['lacp_rate']}/)
end
end

View File

@ -0,0 +1,126 @@
# require 'puppet'
# require 'rspec'
require 'rspec-puppet'
require 'spec_helper'
require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
# Ubintu, static
describe 'l23network::examples::bond_lnx_old_style', :type => :class do
let(:module_path) { '../' }
#let(:title) { 'bond0' }
let(:params) { {
:bond => 'bond0',
:ipaddr => '1.1.1.1/27',
:interfaces => ['eth4','eth5'],
:bond_mode => 2,
:bond_miimon => 200,
:bond_lacp_rate => 2,
} }
let(:facts) { {
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:kernel => 'Linux'
} }
let(:interface_file_start) { '/etc/network/interfaces.d/ifcfg-' }
it "Should contains interface_file" do
should contain_file('/etc/network/interfaces').with_content(/\*/)
end
it 'Should contains interface_file with IP-addr' do
rv = contain_file("#{interface_file_start}#{params[:bond]}")
should rv.with_content(/auto\s+#{params[:bond]}/)
should rv.with_content(/iface\s+#{params[:bond]}/)
should rv.with_content(/address\s+1.1.1.1/)
should rv.with_content(/netmask\s+255.255.255.224/)
end
it 'Should contains bond-specific parameters' do
rv = contain_file("#{interface_file_start}#{params[:bond]}")
should rv.with_content(/slaves\s+none/)
should rv.with_content(/bond-mode\s+#{params[:bond_mode]}/)
should rv.with_content(/bond-miimon\s+#{params[:bond_miimon]}/)
should rv.with_content(/bond-lacp-rate\s+#{params[:bond_lacp_rate]}/)
end
it 'Should contains interface files for bond-slave interfaces' do
params[:interfaces].each do |iface|
rv = contain_file("#{interface_file_start}#{iface}")
should rv.with_content(/auto\s+#{iface}/)
should rv.with_content(/iface\s+#{iface}/)
should rv.with_content(/bond-master\s+#{params[:bond]}/)
end
end
end
# Centos, static
describe 'l23network::examples::bond_lnx_old_style', :type => :class do
let(:module_path) { '../' }
#let(:title) { 'bond0' }
let(:params) { {
:bond => 'bond0',
:ipaddr => '1.1.1.1/27',
:interfaces => ['eth4','eth5'],
:bond_mode => 2,
:bond_miimon => 200,
:bond_lacp_rate => 0,
} }
let(:facts) { {
:osfamily => 'RedHat',
:operatingsystem => 'Centos',
:kernel => 'Linux'
} }
let(:interface_file_start) { '/etc/sysconfig/network-scripts/ifcfg-' }
let(:interface_up_file_start) { '/etc/sysconfig/network-scripts/interface-up-script-' }
let(:bond_modes) { [
'balance-rr',
'active-backup',
'balance-xor',
'broadcast',
'802.3ad',
'balance-tlb',
'balance-alb'
] }
it 'Should contains interface_file with IP-addr' do
rv = contain_file("#{interface_file_start}#{params[:bond]}")
should rv.with_content(/DEVICE=#{params[:bond]}/)
should rv.with_content(/BOOTPROTO=none/)
should rv.with_content(/ONBOOT=yes/)
should rv.with_content(/IPADDR=1.1.1.1/)
should rv.with_content(/NETMASK=255.255.255.224/)
end
it 'Should contains interface files for bond-slave interfaces' do
params[:interfaces].each do |iface|
rv = contain_file("#{interface_file_start}#{iface}")
should rv.with_content(/DEVICE=#{iface}/)
should rv.with_content(/BOOTPROTO=none/)
should rv.with_content(/ONBOOT=yes/)
should rv.with_content(/MASTER=#{params[:bond]}/)
should rv.with_content(/SLAVE=yes/)
end
end
it 'Should contains Bonding-opts line' do
rv = contain_file("#{interface_file_start}#{params[:bond]}")
should rv.with_content(/DEVICE=#{params[:bond]}/)
should rv.with_content(/BONDING_OPTS="mode=/)
end
it 'Should contains Bond mode' do
rv = contain_file("#{interface_file_start}#{params[:bond]}")
should rv.with_content(/BONDING_OPTS.*mode=#{bond_modes[params[:bond_mode]]}/)
end
it 'Should contains miimon' do
rv = contain_file("#{interface_file_start}#{params[:bond]}")
should rv.with_content(/BONDING_OPTS.*miimon=#{params[:miimon]}/)
end
it 'Should contains lacp_rate' do
rv = contain_file("#{interface_file_start}#{params[:bond]}")
should rv.with_content(/BONDING_OPTS.*lacp_rate=#{params[:lacp_rate]}/)
end
end

View File

@ -4,7 +4,7 @@ require 'rspec-puppet'
require 'spec_helper'
require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
# Ubintu, static
# Ubintu, dhcp
describe 'l23network::l3::ifconfig', :type => :define do
let(:module_path) { '../' }
let(:title) { 'ifconfig simple test' }
@ -19,24 +19,31 @@ describe 'l23network::l3::ifconfig', :type => :define do
} }
let(:interface_file_start) { '/etc/network/interfaces.d/ifcfg-' }
it "Should contain interface_file" do
it "Ubintu/dhcp: Should contain interface_file" do
should contain_file('/etc/network/interfaces').with_content(/\*/)
end
it 'interface file should contain DHCP ipaddr and netmask' do
it 'Ubintu/dhcp: interface file should contain DHCP ipaddr and netmask' do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.with_content(/auto\s+#{params[:interface]}/)
should rv.with_content(/iface\s+#{params[:interface]}\s+inet\s+dhcp/)
end
it "interface file shouldn't contain ipaddr and netmask" do
it "Ubintu/dhcp: interface file shouldn't contain ipaddr and netmask" do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.without_content(/address/)
should rv.without_content(/netmask/)
end
it "Ubintu/dhcp: interface file shouldn't contains bond-master options" do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.without_content(/bond-mode/)
should rv.without_content(/slaves/)
end
end
# Ubintu, static, ordered iface
# Ubintu, dhcp, ordered iface
describe 'l23network::l3::ifconfig', :type => :define do
let(:module_path) { '../' }
let(:title) { 'ifconfig simple test' }
@ -52,21 +59,27 @@ describe 'l23network::l3::ifconfig', :type => :define do
} }
let(:interface_file_start) { '/etc/network/interfaces.d/ifcfg-' }
it "Should contain interface_file" do
it "Ubintu/dhcp: ordered.ifaces: Should contain interface_file" do
should contain_file('/etc/network/interfaces').with_content(/\*/)
end
it "interface file shouldn't contain ipaddr and netmask" do
it "Ubintu/dhcp: ordered.ifaces: interface file shouldn't contain ipaddr and netmask" do
rv = contain_file("#{interface_file_start}#{params[:ifname_order_prefix]}-#{params[:interface]}")
should rv.without_content(/address/)
should rv.without_content(/netmask/)
end
it "interface file should contain ifup/ifdn commands" do
it "Ubintu/dhcp: ordered.ifaces: interface file should contain ifup/ifdn commands" do
rv = contain_file("#{interface_file_start}#{params[:ifname_order_prefix]}-#{params[:interface]}")
should rv.without_content(/address/)
should rv.without_content(/netmask/)
end
it "Ubintu/dhcp: ordered.ifaces: interface file shouldn't contains bond-master options" do
rv = contain_file("#{interface_file_start}#{params[:ifname_order_prefix]}-#{params[:interface]}")
should rv.without_content(/bond-mode/)
should rv.without_content(/slaves/)
end
end
# Centos, dhcp
@ -85,21 +98,21 @@ describe 'l23network::l3::ifconfig', :type => :define do
let(:interface_file_start) { '/etc/sysconfig/network-scripts/ifcfg-' }
let(:interface_up_file_start) { '/etc/sysconfig/network-scripts/interface-up-script-' }
it 'interface file should contains true header' do
it 'Centos/dhcp: interface file should contains true header' do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.with_content(/DEVICE=#{params[:interface]}/)
should rv.with_content(/BOOTPROTO=dhcp/)
should rv.with_content(/ONBOOT=yes/)
end
it "Shouldn't contains interface_file with IP-addr" do
it "Centos/dhcp: Shouldn't contains interface_file with IP-addr" do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.without_content(/IPADDR=/)
should rv.without_content(/NETMASK=/)
end
end
# Centos, manual, ordered iface
# Centos, dhcp, ordered iface
describe 'l23network::l3::ifconfig', :type => :define do
let(:module_path) { '../' }
let(:title) { 'ifconfig simple test' }
@ -116,14 +129,14 @@ describe 'l23network::l3::ifconfig', :type => :define do
let(:interface_file_start) { '/etc/sysconfig/network-scripts/ifcfg-' }
let(:interface_up_file_start) { '/etc/sysconfig/network-scripts/interface-up-script-' }
it 'interface file should contains true header' do
it 'Centos/dhcp: ordered.ifaces: interface file should contains true header' do
rv = contain_file("#{interface_file_start}#{params[:ifname_order_prefix]}-#{params[:interface]}")
should rv.with_content(/DEVICE=#{params[:interface]}/)
should rv.with_content(/BOOTPROTO=dhcp/)
should rv.with_content(/ONBOOT=yes/)
end
it 'Should contains interface_file with IP-addr' do
it 'Centos/dhcp: ordered.ifaces: Should contains interface_file with IP-addr' do
rv = contain_file("#{interface_file_start}#{params[:ifname_order_prefix]}-#{params[:interface]}")
should rv.without_content(/IPADDR=/)
should rv.without_content(/NETMASK=/)

View File

@ -19,30 +19,36 @@ describe 'l23network::l3::ifconfig', :type => :define do
} }
let(:interface_file_start) { '/etc/network/interfaces.d/ifcfg-' }
it "Should contain interface_file" do
it "Ubintu/manual: Should contain interface_file" do
should contain_file('/etc/network/interfaces').with_content(/\*/)
end
it 'interface file should contain DHCP ipaddr and netmask' do
it 'Ubintu/manual: interface file should contain DHCP ipaddr and netmask' do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.with_content(/auto\s+#{params[:interface]}/)
should rv.with_content(/iface\s+#{params[:interface]}\s+inet\s+manual/)
end
it "interface file shouldn't contain ipaddr and netmask" do
it "Ubintu/manual: interface file shouldn't contain ipaddr and netmask" do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.without_content(/address/)
should rv.without_content(/netmask/)
end
it "interface file should contain ifup/ifdn commands" do
it "Ubintu/manual: interface file should contain ifup/ifdn commands" do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.with_content(/up\s+ip\s+l\s+set\s+#{params[:interface]}\s+up/)
should rv.with_content(/down\s+ip\s+l\s+set\s+#{params[:interface]}\s+down/)
end
it "Ubintu/manual: interface file shouldn't contains bond-master options" do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.without_content(/bond-mode/)
should rv.without_content(/slaves/)
end
end
# Ubintu, static, ordered iface
# Ubintu, manual, ordered iface
describe 'l23network::l3::ifconfig', :type => :define do
let(:module_path) { '../' }
let(:title) { 'ifconfig simple test' }
@ -58,21 +64,27 @@ describe 'l23network::l3::ifconfig', :type => :define do
} }
let(:interface_file_start) { '/etc/network/interfaces.d/ifcfg-' }
it "Should contain interface_file" do
it "Ubintu/manual: ordered.ifaces:Should contain interface_file" do
should contain_file('/etc/network/interfaces').with_content(/\*/)
end
it "interface file shouldn't contain ipaddr and netmask" do
it "Ubintu/manual: interface file shouldn't contain ipaddr and netmask" do
rv = contain_file("#{interface_file_start}#{params[:ifname_order_prefix]}-#{params[:interface]}")
should rv.without_content(/address/)
should rv.without_content(/netmask/)
end
it "interface file should contain ifup/ifdn commands" do
it "Ubintu/manual: ordered.ifaces:interface file should contain ifup/ifdn commands" do
rv = contain_file("#{interface_file_start}#{params[:ifname_order_prefix]}-#{params[:interface]}")
should rv.with_content(/up\s+ip\s+l\s+set\s+#{params[:interface]}\s+up/)
should rv.with_content(/down\s+ip\s+l\s+set\s+#{params[:interface]}\s+down/)
end
it "Ubintu/manual: ordered.ifaces:interface file shouldn't contains bond-master options" do
rv = contain_file("#{interface_file_start}#{params[:ifname_order_prefix]}-#{params[:interface]}")
should rv.without_content(/bond-mode/)
should rv.without_content(/slaves/)
end
end
@ -93,14 +105,14 @@ describe 'l23network::l3::ifconfig', :type => :define do
let(:interface_file_start) { '/etc/sysconfig/network-scripts/ifcfg-' }
let(:interface_up_file_start) { '/etc/sysconfig/network-scripts/interface-up-script-' }
it 'interface file should contains true header' do
it 'Centos/manual: interface file should contains true header' do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.with_content(/DEVICE=#{params[:interface]}/)
should rv.with_content(/BOOTPROTO=none/)
should rv.with_content(/ONBOOT=yes/)
end
it "Shouldn't contains interface_file with IP-addr" do
it "Centos/manual: Shouldn't contains interface_file with IP-addr" do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.without_content(/IPADDR=/)
should rv.without_content(/NETMASK=/)
@ -124,14 +136,14 @@ describe 'l23network::l3::ifconfig', :type => :define do
let(:interface_file_start) { '/etc/sysconfig/network-scripts/ifcfg-' }
let(:interface_up_file_start) { '/etc/sysconfig/network-scripts/interface-up-script-' }
it 'interface file should contains true header' do
it 'Centos/manual: ordered.ifaces: interface file should contains true header' do
rv = contain_file("#{interface_file_start}#{params[:ifname_order_prefix]}-#{params[:interface]}")
should rv.with_content(/DEVICE=#{params[:interface]}/)
should rv.with_content(/BOOTPROTO=none/)
should rv.with_content(/ONBOOT=yes/)
end
it 'Should contains interface_file with IP-addr' do
it 'Centos/manual: ordered.ifaces: Should contains interface_file with IP-addr' do
rv = contain_file("#{interface_file_start}#{params[:ifname_order_prefix]}-#{params[:interface]}")
should rv.without_content(/IPADDR=/)
should rv.without_content(/NETMASK=/)

View File

@ -19,21 +19,27 @@ describe 'l23network::l3::ifconfig', :type => :define do
} }
let(:interface_file_start) { '/etc/network/interfaces.d/ifcfg-' }
it "Should contain interface_file" do
it "Ubintu/static: Should contain interface_file" do
should contain_file('/etc/network/interfaces').with_content(/\*/)
end
it '(static) interface file should contain ipaddr and netmask' do
it 'Ubintu/static: interface file should contain ipaddr and netmask' do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.with_content(/auto\s+#{params[:interface]}/)
should rv.with_content(/iface\s+#{params[:interface]}\s+inet\s+static/)
end
it 'interface file should contain ipaddr and netmask' do
it 'Ubintu/static: interface file should contain ipaddr and netmask' do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.with_content(/address\s+1.2.3.4/)
should rv.with_content(/netmask\s+255.255.0.0/)
end
it "Ubintu/static: interface file shouldn't contain bond-master options" do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.without_content(/bond-mode/)
should rv.without_content(/slaves/)
end
end
# Ubintu, static, netmask as additional parameter
@ -52,21 +58,27 @@ describe 'l23network::l3::ifconfig', :type => :define do
} }
let(:interface_file_start) { '/etc/network/interfaces.d/ifcfg-' }
it "Should contains interface_file" do
it "Ubintu/static: old.netmask: Should contains interface_file" do
should contain_file('/etc/network/interfaces').with_content(/\*/)
end
it 'interface file should contains true header' do
it 'Ubintu/static: old.netmask: interface file should contains true header' do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.with_content(/auto\s+#{params[:interface]}/)
should rv.with_content(/iface\s+#{params[:interface]}\s+inet\s+static/)
end
it 'interface file should contains ipaddr and netmask' do
it 'Ubintu/static: old.netmask: interface file should contains ipaddr and netmask' do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.with_content(/address\s+#{params[:ipaddr]}/)
should rv.with_content(/netmask\s+#{params[:netmask]}/)
end
it "Ubintu/static: old.netmask: interface file shouldn't contains bond-master options" do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.without_content(/bond-mode/)
should rv.without_content(/slaves/)
end
end
# Ubintu, static, ordered iface
@ -85,17 +97,17 @@ describe 'l23network::l3::ifconfig', :type => :define do
} }
let(:interface_file_start) { '/etc/network/interfaces.d/ifcfg-' }
it "Should contain interface_file" do
it "Ubintu/static: ordered.ifaces: Should contain interface_file" do
should contain_file('/etc/network/interfaces').with_content(/\*/)
end
it '(static) interface file should contain ipaddr and netmask' do
it 'Ubintu/static: ordered.ifaces: interface file should contain ipaddr and netmask' do
rv = contain_file("#{interface_file_start}#{params[:ifname_order_prefix]}-#{params[:interface]}")
should rv.with_content(/auto\s+#{params[:interface]}/)
should rv.with_content(/iface\s+#{params[:interface]}\s+inet\s+static/)
end
it 'interface file should contain ipaddr and netmask' do
it 'Ubintu/static: ordered.ifaces: interface file should contain ipaddr and netmask' do
rv = contain_file("#{interface_file_start}#{params[:ifname_order_prefix]}-#{params[:interface]}")
should rv.with_content(/address\s+1.2.3.4/)
should rv.with_content(/netmask\s+255.255.0.0/)
@ -120,14 +132,14 @@ describe 'l23network::l3::ifconfig', :type => :define do
let(:interface_file_start) { '/etc/sysconfig/network-scripts/ifcfg-' }
let(:interface_up_file_start) { '/etc/sysconfig/network-scripts/interface-up-script-' }
it 'interface file should contains true header' do
it 'Centos/static: interface file should contains true header' do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.with_content(/DEVICE=#{params[:interface]}/)
should rv.with_content(/BOOTPROTO=none/)
should rv.with_content(/ONBOOT=yes/)
end
it 'Should contains interface_file with IP-addr' do
it 'Centos/static: Should contains interface_file with IP-addr' do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.with_content(/IPADDR=1.2.3.4/)
should rv.with_content(/NETMASK=255.255.0.0/)
@ -152,14 +164,14 @@ describe 'l23network::l3::ifconfig', :type => :define do
let(:interface_file_start) { '/etc/sysconfig/network-scripts/ifcfg-' }
let(:interface_up_file_start) { '/etc/sysconfig/network-scripts/interface-up-script-' }
it 'interface file should contains true header' do
it 'Centos/static: old.netmask: interface file should contains true header' do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.with_content(/DEVICE=#{params[:interface]}/)
should rv.with_content(/BOOTPROTO=none/)
should rv.with_content(/ONBOOT=yes/)
end
it 'Should contains interface_file with IP-addr' do
it 'Centos/static: old.netmask: Should contains interface_file with IP-addr' do
rv = contain_file("#{interface_file_start}#{params[:interface]}")
should rv.with_content(/IPADDR=#{params[:ipaddr]}/)
should rv.with_content(/NETMASK=#{params[:netmask]}/)
@ -183,14 +195,14 @@ describe 'l23network::l3::ifconfig', :type => :define do
let(:interface_file_start) { '/etc/sysconfig/network-scripts/ifcfg-' }
let(:interface_up_file_start) { '/etc/sysconfig/network-scripts/interface-up-script-' }
it 'interface file should contains true header' do
it 'Centos/static: ordered.ifaces: interface file should contains true header' do
rv = contain_file("#{interface_file_start}#{params[:ifname_order_prefix]}-#{params[:interface]}")
should rv.with_content(/DEVICE=#{params[:interface]}/)
should rv.with_content(/BOOTPROTO=none/)
should rv.with_content(/ONBOOT=yes/)
end
it 'Should contains interface_file with IP-addr' do
it 'Centos/static: ordered.ifaces: Should contains interface_file with IP-addr' do
rv = contain_file("#{interface_file_start}#{params[:ifname_order_prefix]}-#{params[:interface]}")
should rv.with_content(/IPADDR=1.2.3.4/)
should rv.with_content(/NETMASK=255.255.0.0/)

View File

@ -0,0 +1,115 @@
# require 'puppet'
# require 'rspec'
# require 'rspec-puppet'
require 'spec_helper'
require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
describe 'get_hash_with_defaults_and_deprecations' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it 'should exist' do
expect(Puppet::Parser::Functions.function('get_hash_with_defaults_and_deprecations')).to eq 'function_get_hash_with_defaults_and_deprecations'
end
it 'should throw an error on invalid arguments number #1' do
expect {
scope.function_get_hash_with_defaults_and_deprecations([])
}.to raise_error(Puppet::ParseError)
end
it 'should throw an error on invalid arguments number #2' do
expect {
scope.function_get_hash_with_defaults_and_deprecations([{},{}])
}.to raise_error(Puppet::ParseError)
end
it 'should throw an error on invalid arguments number #3' do
expect {
scope.function_get_hash_with_defaults_and_deprecations([{},{},{},{}])
}.to raise_error(Puppet::ParseError)
end
it 'should throw an error on invalid argument type' do
expect {
scope.function_get_hash_with_defaults_and_deprecations(['qweqwe'])
}.to raise_error(Puppet::ParseError)
end
it 'should return hash with sum of two hashes' do
rv = scope.function_get_hash_with_defaults_and_deprecations([{
'aaa' => 1,
'bbb' => 2,
}, {
'ccc' => 3,
'ddd' => 4,
}, {}])
expect(rv).to eq({
'aaa' => 1,
'bbb' => 2,
'ccc' => 3,
'ddd' => 4,
})
end
it 'should return hash with sum of two hashes, add defaults if need' do
rv = scope.function_get_hash_with_defaults_and_deprecations([{
'aaa' => 1,
'bbb' => 2,
}, {
'bbb' => -1,
'ccc' => 3,
'ddd' => 4,
}, {}])
expect(rv).to eq({
'aaa' => 1,
'bbb' => 2,
'ccc' => 3,
'ddd' => 4,
})
end
it 'should return hash with sum of three hashes' do
rv = scope.function_get_hash_with_defaults_and_deprecations([{
'aaa' => 1,
'bbb' => 2,
}, {
'bbb' => -1,
'ccc' => 3,
'ddd' => 4,
}, {
'eee' => 5,
}])
expect(rv).to eq({
'aaa' => 1,
'bbb' => 2,
'ccc' => 3,
'ddd' => 4,
'eee' => 5,
})
end
# it 'should return hash with three sort of options with different case' do
# rv = scope.function_get_hash_with_defaults_and_deprecations([{
# :s => [
# 'xxx off',
# 'yyy off'
# ],
# :K => [
# 'gso off',
# 'gro off'
# ],
# :"set-channels" => [
# 'rx 1',
# 'tx 2',
# 'other 3',
# ]
# }])
# expect(rv).to eq({
# '-s' => 'xxx off yyy off',
# '-K' => 'gso off gro off',
# '--set-channels' => 'rx 1 tx 2 other 3'
# })
# end
end

View File

@ -0,0 +1,6 @@
<%- if @actual_bond_properties['mode'].to_s != 'undef' -%>
slaves none
<%- @actual_bond_properties.each do |key, val| -%>
bond-<%= key.tr('_','-') %> <%= val %>
<%- end -%>
<%- end -%>

View File

@ -0,0 +1,4 @@
<%- if @actual_bond_properties['mode'].to_s != 'undef' -%>
BONDING_OPTS="mode=<%= @bond_modes[@actual_bond_properties['mode'].to_i] -%>
<%- @actual_bond_properties.select{|k,v| k!='mode'}.each do |key, val| -%> <%= key %>=<%= val %><%- end -%>"
<% end %>

View File

@ -5,12 +5,8 @@ hwaddress ether <%= @macaddr.downcase %>
<% end -%>
<% if @dhcp_hostname %>hostname <%= @dhcp_hostname %><% end %>
<% if @vlan_mode %>vlan_raw_device <%= @vlan_dev %><% end %>
<% if @bond_mode %>slaves none
bond-mode <%= @bond_mode %><% if @bond_miimon %>
bond-miimon <%= @bond_miimon %><% end %><% if @bond_lacp_rate %>
bond-lacp-rate <%= @bond_lacp_rate %><% end %>
<% end %>
<% if @mtu -%>
mtu <%= @mtu %>
<% end -%>
<%= scope.function_template(['l23network/bonding_Debian.erb']) %>
<%= scope.function_template(['l23network/ethtool_Debian.erb']) %>

View File

@ -9,9 +9,5 @@ mtu <%= @mtu %>
<% if @vlan_mode %>vlan_raw_device <%= @vlan_dev %><% end %>
up ip l set <%= @interface %> up
down ip l set <%= @interface %> down
<% if @bond_mode %>slaves none
bond-mode <%= @bond_mode %><% if @bond_miimon %>
bond-miimon <%= @bond_miimon %><% end %><% if @bond_lacp_rate %>
bond-lacp-rate <%= @bond_lacp_rate %><% end %>
<% end %>
<%= scope.function_template(['l23network/bonding_Debian.erb']) %>
<%= scope.function_template(['l23network/ethtool_Debian.erb']) %>

View File

@ -13,13 +13,9 @@ netmask <%= @effective_netmask %>
<% if @dns_nameservers_1 or @dns_nameservers_2 %>dns-nameservers <% if @dns_nameservers_1 %><%= @dns_nameservers_1 %><% end %> <% if @dns_nameservers_2 %><%= @dns_nameservers_2 %><% end %><% end %>
<% if @dns_search_string %>dns-search <%= @dns_search_string %><% end %>
<% if @dns_domain_string %>dns-domain <%= @dns_domain_string %><% end %>
<% if @bond_mode %>slaves none
bond-mode <%= @bond_mode %><% if @bond_miimon %>
bond-miimon <%= @bond_miimon %><% end %><% if @bond_lacp_rate %>
bond-lacp-rate <%= @bond_lacp_rate %><% end %>
<% end %>
<%- if @ipaddr_aliases -%><%- @ipaddr_aliases.each do |addr| -%>
post-up ip addr add <%= addr %> dev <%= @interface %>
pre-down ip addr del <%= addr %> dev <%= @interface %>
<%- end -%><%- end -%>
<%= scope.function_template(['l23network/bonding_Debian.erb']) %>
<%= scope.function_template(['l23network/ethtool_Debian.erb']) %>

View File

@ -18,9 +18,7 @@ MTU=<%= @mtu %>
<% if @macaddr -%>
MACADDR=<%= @macaddr.upcase %>
<% end -%>
<% if @bond_mode -%>
BONDING_OPTS="mode=<%= @bond_mode %><% if @bond_miimon %> miimon=<%= @bond_miimon %><% end %><% if @bond_lacp_rate %> bond-lacp-rate=<%= @bond_lacp_rate %><% end %>"
<% end -%>
<% if @mtu -%>
MTU=<%= @mtu %>
<% end -%>
<%= scope.function_template(['l23network/bonding_RedHat.erb']) %>

View File

@ -15,6 +15,4 @@ MTU=<%= @mtu %>
<% if @macaddr -%>
MACADDR=<%= @macaddr.upcase %>
<% end -%>
<% if @bond_mode -%>
BONDING_OPTS="mode=<%= @bond_mode %><% if @bond_miimon %> miimon=<%= @bond_miimon %><% end %><% if @bond_lacp_rate %> bond-lacp-rate=<%= @bond_lacp_rate %><% end %>"
<% end -%>
<%= scope.function_template(['l23network/bonding_RedHat.erb']) %>

View File

@ -29,6 +29,4 @@ SEARCH=<%= @dns_search_string %>
<% if @mtu -%>
MTU=<%= @mtu %>
<% end -%>
<% if @bond_mode -%>
BONDING_OPTS="mode=<%= @bond_mode %><% if @bond_miimon %> miimon=<%= @bond_miimon %><% end %><% if @bond_lacp_rate %> bond-lacp-rate=<%= @bond_lacp_rate %><% end %>"
<% end -%>
<%= scope.function_template(['l23network/bonding_RedHat.erb']) %>