From 497078b09307f5bc800c970a9b87e5804b05a252 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 18:03:07 +0800 Subject: [PATCH 01/50] Remove support for Puppet <4.9.0 --- .travis.yml | 12 ------------ metadata.json | 4 ++-- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index aee927ea..6a63c6cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,22 +14,10 @@ script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake matrix: fast_finish: true include: - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 3.0" - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 3.0" - - rvm: 2.0.0 - env: PUPPET_GEM_VERSION="~> 3.0" - - rvm: 2.0.0 - env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes" - rvm: 2.1.9 env: PUPPET_GEM_VERSION="~> 4.0" - rvm: 2.4.1 env: PUPPET_GEM_VERSION="~> 5.0" - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" allow_failures: - rvm: 2.4.1 env: PUPPET_GEM_VERSION="~> 5.0" diff --git a/metadata.json b/metadata.json index de0b60d9..51a56380 100644 --- a/metadata.json +++ b/metadata.json @@ -11,7 +11,7 @@ "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">=2.3.0 <5.0.0" + "version_requirement": ">=4.24.0 <5.0.0" } ], "operatingsystem_support": [ @@ -35,7 +35,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">=2.7.20 <5.0.0" + "version_requirement": ">=4.9.0 <5.0.0" } ] } From 12d3127349ad585937969205170ea9caf6bd529e Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 18:03:57 +0800 Subject: [PATCH 02/50] Use typing in network::if --- manifests/if.pp | 29 ++++++++++------------------- spec/defines/network_if_spec.rb | 2 +- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/manifests/if.pp b/manifests/if.pp index 990a0224..5c6f1f61 100644 --- a/manifests/if.pp +++ b/manifests/if.pp @@ -34,20 +34,17 @@ # Copyright (C) 2017 Mike Arnold, unless otherwise noted. # define network::if ( - $ensure, - $manage_hwaddr = true, - $macaddress = undef, - $userctl = false, - $mtu = undef, - $ethtool_opts = undef, - $scope = undef, - $flush = false, - $zone = undef, - $restart = true, + Enum['up', 'down'] $ensure, + Boolean $manage_hwaddr = true, + Optional[Stdlib::MAC] $macaddress = undef, + Boolean $userctl = false, + Variant[Integer, String, Undef] $mtu = undef, + Optional[String] $ethtool_opts = undef, + Optional[String] $scope = undef, + Boolean $flush = false, + Optional[String] $zone = undef, + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') if ! is_mac_address($macaddress) { # Strip off any tailing VLAN (ie eth5.90 -> eth5). @@ -57,12 +54,6 @@ $macaddy = $macaddress } - # Validate booleans - validate_bool($userctl) - validate_bool($manage_hwaddr) - validate_bool($flush) - validate_bool($restart) - network_if_base { $title: ensure => $ensure, ipaddress => '', diff --git a/spec/defines/network_if_spec.rb b/spec/defines/network_if_spec.rb index ea20ced8..0e9bb184 100644 --- a/spec/defines/network_if_spec.rb +++ b/spec/defines/network_if_spec.rb @@ -11,7 +11,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth1')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-eth1')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end From 4f908443d442c484b6de43e8bf297b38521d8570 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 18:10:30 +0800 Subject: [PATCH 03/50] Use lookup() instead of hiera_hash() Because the later is deprecated. --- manifests/hiera.pp | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/manifests/hiera.pp b/manifests/hiera.pp index 0d350441..3f5d50c3 100644 --- a/manifests/hiera.pp +++ b/manifests/hiera.pp @@ -28,22 +28,33 @@ # class network::hiera { # Merge hashes from multiple hiera layers - $network_alias = hiera_hash('network::alias', undef) - $network_alias_range = hiera_hash('network::alias_range', undef) - $network_bond = hiera_hash('network::bond', undef) - $network_bond_bridge = hiera_hash('network::bond_bridge', undef) - $network_bond_dynamic = hiera_hash('network::bond_dynamic', undef) - $network_bond_slave = hiera_hash('network::bond_slave', undef) - $network_bond_static = hiera_hash('network::bond_static', undef) - $network_bridge = hiera_hash('network::bridge', undef) - $network_bridge_dynamic = hiera_hash('network::bridge_dynamic', undef) - $network_bridge_static = hiera_hash('network::bridge_static', undef) - $network_if = hiera_hash('network::if', undef) - $network_if_bridge = hiera_hash('network::if_bridge', undef) - $network_if_dynamic = hiera_hash('network::if_dynamic', undef) - $network_if_promisc = hiera_hash('network::if_promisc', undef) - $network_if_static = hiera_hash('network::if_static', undef) - $network_route = hiera_hash('network::route', undef) + $network_alias = lookup('network::alias', Optional[Hash], 'hash', undef) + $network_alias_range = lookup( + 'network::alias_range', Optional[Hash], 'hash', undef) + $network_bond = lookup('network::bond', Optional[Hash], 'hash', undef) + $network_bond_bridge = lookup( + 'network::bond_bridge', Optional[Hash], 'hash', undef) + $network_bond_dynamic = lookup( + 'network::bond_dynamic', Optional[Hash], 'hash', undef) + $network_bond_slave = lookup( + 'network::bond_slave', Optional[Hash], 'hash', undef) + $network_bond_static = lookup( + 'network::bond_static', Optional[Hash], 'hash', undef) + $network_bridge = lookup('network::bridge', Optional[Hash], 'hash', undef) + $network_bridge_dynamic = lookup( + 'network::bridge_dynamic', Optional[Hash], 'hash', undef) + $network_bridge_static = lookup( + 'network::bridge_static', Optional[Hash], 'hash', undef) + $network_if = lookup('network::if', Optional[Hash], 'hash', undef) + $network_if_bridge = lookup( + 'network::if_bridge', Optional[Hash], 'hash', undef) + $network_if_dynamic = lookup( + 'network::if_dynamic', Optional[Hash], 'hash', undef) + $network_if_promisc = lookup( + 'network::if_promisc', Optional[Hash], 'hash', undef) + $network_if_static = lookup( + 'network::if_static', Optional[Hash], 'hash', undef) + $network_route = lookup('network::route', Optional[Hash], 'hash', undef) if $network_alias { create_resources('network::alias', $network_alias) From 81cb36396b3211bdd3140b5e94d0030f52ac10a5 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 18:17:11 +0800 Subject: [PATCH 04/50] Use typing in network::bridge --- manifests/bridge.pp | 22 +++++++--------------- spec/defines/network_bridge_spec.rb | 4 ++-- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/manifests/bridge.pp b/manifests/bridge.pp index acb2102b..2f6998fb 100644 --- a/manifests/bridge.pp +++ b/manifests/bridge.pp @@ -33,22 +33,14 @@ # Copyright (C) 2013 Mike Arnold, unless otherwise noted. # define network::bridge ( - $ensure, - $userctl = false, - $stp = false, - $delay = '30', - $bridging_opts = undef, - $ipv6init = false, - $restart = true, + Enum['up', 'down'] $ensure, + Boolean $userctl = false, + Boolean $stp = false, + String $delay = '30', + Optional[String] $bridging_opts = undef, + Boolean $ipv6init = false, + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') - # Validate booleans - validate_bool($userctl) - validate_bool($stp) - validate_bool($ipv6init) - validate_bool($restart) ensure_packages(['bridge-utils']) diff --git a/spec/defines/network_bridge_spec.rb b/spec/defines/network_bridge_spec.rb index 787be1b9..87857e59 100644 --- a/spec/defines/network_bridge_spec.rb +++ b/spec/defines/network_bridge_spec.rb @@ -11,7 +11,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end @@ -23,7 +23,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /"notABool" is not a boolean./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a Boolean value/) end end From 9505bed7a3f7939f787118837e0f0185248652a9 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 18:46:18 +0800 Subject: [PATCH 05/50] Use typing in network::alias --- manifests/alias.pp | 27 +++++++++++---------------- spec/defines/network_alias_spec.rb | 4 ++-- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/manifests/alias.pp b/manifests/alias.pp index a9e9e82f..61041c28 100644 --- a/manifests/alias.pp +++ b/manifests/alias.pp @@ -37,23 +37,18 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::alias ( - $ensure, - $ipaddress, - $netmask, - $gateway = undef, - $noaliasrouting = false, - $ipv6address = undef, - $ipv6gateway = undef, - $userctl = false, - $zone = undef, - $metric = undef, - $restart = true, + Enum['up', 'down'] $ensure, + Stdlib::Compat::Ipv4 $ipaddress, + Stdlib::Compat::Ipv4 $netmask, + Optional[Stdlib::Compat::Ipv4] $gateway = undef, + Boolean $noaliasrouting = false, + Optional[Stdlib::Compat::Ipv6] $ipv6address = undef, + Optional[Stdlib::Compat::Ipv6] $ipv6gateway = undef, + Boolean $userctl = false, + Optional[String] $zone = undef, + Optional[String] $metric = undef, + Boolean $restart = true, ) { - # Validate our data - if ! is_ip_address($ipaddress) { fail("${ipaddress} is not an IP address.") } - # Validate our booleans - validate_bool($noaliasrouting) - validate_bool($userctl) network_if_base { $title: ensure => $ensure, diff --git a/spec/defines/network_alias_spec.rb b/spec/defines/network_alias_spec.rb index b5624604..3d961261 100644 --- a/spec/defines/network_alias_spec.rb +++ b/spec/defines/network_alias_spec.rb @@ -13,7 +13,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth1:1')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-eth1:1')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end @@ -26,7 +26,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth1:1')}.to raise_error(Puppet::Error, /notAnIP is not an IP address./) + expect {should contain_file('ifcfg-eth1:1')}.to raise_error(Puppet::Error, /expects a match for Stdlib::Compat::Ipv4/) end end From 3e67b7ad23bf689f3d089b3beb9af28f78a044d9 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 18:52:05 +0800 Subject: [PATCH 06/50] Use typing in network::alias::range --- manifests/alias/range.pp | 30 +++++++----------------- spec/defines/network_alias_range_spec.rb | 6 ++--- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/manifests/alias/range.pp b/manifests/alias/range.pp index 4746d94d..01121cc9 100644 --- a/manifests/alias/range.pp +++ b/manifests/alias/range.pp @@ -38,28 +38,16 @@ # Copyright (C) 2013 Mike Arnold, unless otherwise noted. # define network::alias::range ( - $ensure, - $ipaddress_start, - $ipaddress_end, - $clonenum_start, - $noaliasrouting = false, - $restart = true, - $netmask = false, - $broadcast = false, - $arpcheck = true, + Enum['up', 'down', 'absent'] $ensure, + Stdlib::Compat::Ipv4 $ipaddress_start, + Stdlib::Compat::Ipv4 $ipaddress_end, + String $clonenum_start, + Boolean $noaliasrouting = false, + Boolean $restart = true, + Optional[Stdlib::Compat::Ipv4] $netmask = undef, + Optional[Stdlib::Compat::Ipv4] $broadcast = undef, + Boolean $arpcheck = true, ) { - # Validate our data - if ! is_ip_address($ipaddress_start) { fail("${ipaddress_start} is not an IP address.") } - if ! is_ip_address($ipaddress_end) { fail("${ipaddress_end} is not an IP address.") } - if $netmask and !is_ip_address($netmask) { fail("${netmask} is not an IP address.") } - if $broadcast and !is_ip_address($broadcast) { fail("${broadcast} is not an IP address.") } - # Validate our booleans - validate_bool($noaliasrouting) - validate_bool($restart) - validate_bool($arpcheck) - # Validate our regular expressions - $states = [ '^up$', '^down$', '^absent$' ] - validate_re($ensure, $states, '$ensure must be either "up", "down", or "absent".') include '::network' diff --git a/spec/defines/network_alias_range_spec.rb b/spec/defines/network_alias_range_spec.rb index 3abc9512..b7e07f3d 100644 --- a/spec/defines/network_alias_range_spec.rb +++ b/spec/defines/network_alias_range_spec.rb @@ -14,7 +14,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /\$ensure must be either "up", "down", or "absent"./) + expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /expects a match for Enum\['absent', 'down', 'up'\]/) end end @@ -28,7 +28,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /notAnIP is not an IP address./) + expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /expects a match for Stdlib::Compat::Ipv4/) end end @@ -42,7 +42,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /notAnIP is not an IP address./) + expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /expects a match for Stdlib::Compat::Ipv4/) end end From 11fcab215ca811b62c4f4d2fc27c13983b75b180 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 18:57:20 +0800 Subject: [PATCH 07/50] Use typing in network::bond --- manifests/bond.pp | 15 ++++++--------- spec/defines/network_bond_spec.rb | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/manifests/bond.pp b/manifests/bond.pp index afc1a0a0..d3c4b7d3 100644 --- a/manifests/bond.pp +++ b/manifests/bond.pp @@ -32,16 +32,13 @@ # Copyright (C) 2015 Jason Vervlied, unless otherwise noted. # define network::bond ( - $ensure, - $mtu = undef, - $ethtool_opts = undef, - $bonding_opts = 'miimon=100', - $zone = undef, - $restart = true, + Enum['up', 'down'] $ensure, + Optional[String] $mtu = undef, + Optional[String] $ethtool_opts = undef, + String $bonding_opts = 'miimon=100', + Optional[String] $zone = undef, + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') network_if_base { $title: ensure => $ensure, diff --git a/spec/defines/network_bond_spec.rb b/spec/defines/network_bond_spec.rb index b28d4d4e..151ebd88 100644 --- a/spec/defines/network_bond_spec.rb +++ b/spec/defines/network_bond_spec.rb @@ -11,7 +11,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end From d68acaa8362e6c8b13be837191f779ebf2a9db0d Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 19:00:30 +0800 Subject: [PATCH 08/50] Use typing in network::if::bridge --- manifests/if/bridge.pp | 15 ++++++--------- spec/defines/network_if_bridge_spec.rb | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/manifests/if/bridge.pp b/manifests/if/bridge.pp index b8eef619..2c17e2af 100644 --- a/manifests/if/bridge.pp +++ b/manifests/if/bridge.pp @@ -31,16 +31,13 @@ # Copyright (C) 2013 Alex Barbur, unless otherwise noted. # define network::if::bridge ( - $ensure, - $bridge, - $mtu = undef, - $ethtool_opts = undef, - $macaddress = undef, - $restart = true, + Enum['up', 'down'] $ensure, + String $bridge, + Optional[String] $mtu = undef, + Optional[String] $ethtool_opts = undef, + Optional[Stdlib::MAC] $macaddress = undef, + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') if $macaddress == undef { $macaddy = '' # lint:ignore:empty_string_assignment diff --git a/spec/defines/network_if_bridge_spec.rb b/spec/defines/network_if_bridge_spec.rb index 1eaa6cb0..9d86e482 100644 --- a/spec/defines/network_if_bridge_spec.rb +++ b/spec/defines/network_if_bridge_spec.rb @@ -12,7 +12,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end From d5e3b7161affc3186a93eaefd41ff4c7fdc509f7 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 19:58:14 +0800 Subject: [PATCH 09/50] Use typing in network::if::static This commits adds a dependency toward thrnio/ip to ease matching IPv6 networks (stdlib's types only match addresses). --- .fixtures.yml | 7 ++- manifests/if/static.pp | 80 ++++++++++++-------------- metadata.json | 4 ++ spec/defines/network_if_static_spec.rb | 10 ++-- 4 files changed, 52 insertions(+), 49 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index a5de11f9..3d1fd6e9 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,5 +1,10 @@ fixtures: repositories: - stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git" + stdlib: + repo: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' + ref: '4.24.0' + ip: + repo: 'https://github.com/thrnio/puppet-ip.git' + ref: '1.0.1' symlinks: network: "#{source_dir}" diff --git a/manifests/if/static.pp b/manifests/if/static.pp index b32ccb63..db11d24f 100644 --- a/manifests/if/static.pp +++ b/manifests/if/static.pp @@ -56,45 +56,50 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::if::static ( - $ensure, - $ipaddress = undef, - $netmask = undef, - $gateway = undef, - $ipv6address = undef, - $ipv6init = false, - $ipv6gateway = undef, - $macaddress = undef, - $manage_hwaddr = true, - $ipv6autoconf = false, - $userctl = false, - $mtu = undef, - $ethtool_opts = undef, - $peerdns = false, - $ipv6peerdns = false, - $dns1 = undef, - $dns2 = undef, - $domain = undef, - $linkdelay = undef, - $scope = undef, - $flush = false, - $zone = undef, - $defroute = undef, - $metric = undef, - $restart = true, - $arpcheck = true, + Enum['up', 'down'] $ensure, + Optional[IP::Address::V4::NoSubnet] $ipaddress = undef, + Optional[IP::Address::V4::NoSubnet] $netmask = undef, + Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Optional[ + Variant[ + IP::Address::V6, + Tuple[IP::Address::V6, 1], + ] + ] $ipv6address = undef, + Boolean $ipv6init = false, + Optional[ + Variant[ + IP::Address::V6::NoSubnet::Full, + IP::Address::V6::NoSubnet::Compressed, + ] + ] $ipv6gateway = undef, + Optional[Stdlib::MAC] $macaddress = undef, + Boolean $manage_hwaddr = true, + Boolean $ipv6autoconf = false, + Boolean $userctl = false, + Optional[String] $mtu = undef, + Optional[String] $ethtool_opts = undef, + Boolean $peerdns = false, + Boolean $ipv6peerdns = false, + Optional[Stdlib::Compat::Ip_address] $dns1 = undef, + Optional[Stdlib::Compat::Ip_address] $dns2 = undef, + Optional[String] $domain = undef, + Optional[String] $linkdelay = undef, + Optional[String] $scope = undef, + Boolean $flush = false, + Optional[String] $zone = undef, + Optional[Enum['yes', 'no']] $defroute = undef, + Optional[String] $metric = undef, + Boolean $restart = true, + Boolean $arpcheck = true, ) { - # Validate our data - if $ipaddress { - if ! is_ip_address($ipaddress) { fail("${ipaddress} is not an IP address.") } - } + # Handle multiple IPv6 addresses if is_array($ipv6address) { if size($ipv6address) > 0 { - validate_ip_address { $ipv6address: } $primary_ipv6address = $ipv6address[0] $secondary_ipv6addresses = delete_at($ipv6address, 0) } } elsif $ipv6address { - if ! is_ip_address($ipv6address) { fail("${ipv6address} is not an IPv6 address.") } $primary_ipv6address = $ipv6address $secondary_ipv6addresses = undef } else { @@ -102,22 +107,13 @@ $secondary_ipv6addresses = undef } - if ! is_mac_address($macaddress) { + if !$macaddress { # Strip off any tailing VLAN (ie eth5.90 -> eth5). $title_clean = regsubst($title,'^(\w+)\.\d+$','\1') $macaddy = getvar("::macaddress_${title_clean}") } else { $macaddy = $macaddress } - # Validate booleans - validate_bool($userctl) - validate_bool($ipv6init) - validate_bool($ipv6autoconf) - validate_bool($peerdns) - validate_bool($ipv6peerdns) - validate_bool($manage_hwaddr) - validate_bool($flush) - validate_bool($arpcheck) network_if_base { $title: ensure => $ensure, diff --git a/metadata.json b/metadata.json index 51a56380..828b84cb 100644 --- a/metadata.json +++ b/metadata.json @@ -12,6 +12,10 @@ { "name": "puppetlabs/stdlib", "version_requirement": ">=4.24.0 <5.0.0" + }, + { + "name": "thrnio/ip", + "version_requirement": ">=1.0.1 < 2.0.0" } ], "operatingsystem_support": [ diff --git a/spec/defines/network_if_static_spec.rb b/spec/defines/network_if_static_spec.rb index 44095789..0734c3cd 100644 --- a/spec/defines/network_if_static_spec.rb +++ b/spec/defines/network_if_static_spec.rb @@ -13,7 +13,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /notAnIP is not an IP address\./) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet/) end end @@ -27,7 +27,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /notAnIP is not an IPv6 address\./) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /expects a value of type Undef, IP::Address::V6/) end end @@ -41,9 +41,7 @@ } end it 'should fail' do - # there are major differences in the way that different ruby versions translate a hash into a string - # which makes it hard to match the whole string - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /.*notAn.*IP.* is not an IPv6 address\./) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /expects a value of type Undef, IP::Address::V6/) end end @@ -61,7 +59,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /notAnIP is not an IP\(v6\) address\./) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /expects an IP::Address::V6/) end end From 62e3a942fac3b1d9991f0da1bee95823ca87e0d2 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 20:07:21 +0800 Subject: [PATCH 10/50] Use typing in network::if::promisc --- manifests/if/promisc.pp | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/manifests/if/promisc.pp b/manifests/if/promisc.pp index 291cdd62..20697859 100644 --- a/manifests/if/promisc.pp +++ b/manifests/if/promisc.pp @@ -41,41 +41,26 @@ # Copyright (C) 2015 Elyse Salberg, unless otherwise noted. # define network::if::promisc ( - $ensure, - $macaddress = undef, - $manage_hwaddr = true, - $bootproto = undef, - $userctl = false, - $mtu = undef, - $ethtool_opts = undef, - $restart = true, - $promisc = true, + Enum['up', 'down'] $ensure, + Optional[Stdlib::MAC] $macaddress = undef, + Boolean $manage_hwaddr = true, + Optional[String] $bootproto = undef, + Boolean $userctl = false, + Optional[String] $mtu = undef, + Optional[String] $ethtool_opts = undef, + Boolean $restart = true, + Boolean $promisc = true, ) { include '::network' $interface = $name - if ! is_mac_address($macaddress) { + if $macaddress { + $macaddy = $macaddress + } else { # Strip off any tailing VLAN (ie eth5.90 -> eth5). $title_clean = regsubst($title,'^(\w+)\.\d+$','\1') $macaddy = getvar("::macaddress_${title_clean}") - } else { - $macaddy = $macaddress - } - - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') - - # Validate booleans - validate_bool($userctl) - validate_bool($manage_hwaddr) - validate_bool($restart) - validate_bool($promisc) - - # Validate our data - if ! is_mac_address($macaddy) { - fail("${macaddy} is not a MAC address.") } $onboot = $ensure ? { From 674be8e15e98bd6cea13c4cf8816e893fdba03fc Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 20:13:44 +0800 Subject: [PATCH 11/50] Use typing in network::if::dynamic --- manifests/if/dynamic.pp | 43 +++++++++++-------------- spec/defines/network_if_dynamic_spec.rb | 2 +- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/manifests/if/dynamic.pp b/manifests/if/dynamic.pp index 1bc4b16b..77dc472c 100644 --- a/manifests/if/dynamic.pp +++ b/manifests/if/dynamic.pp @@ -46,37 +46,30 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::if::dynamic ( - $ensure, - $macaddress = undef, - $manage_hwaddr = true, - $bootproto = 'dhcp', - $userctl = false, - $mtu = undef, - $dhcp_hostname = undef, - $ethtool_opts = undef, - $peerdns = false, - $linkdelay = undef, - $check_link_down = false, - $defroute = undef, - $zone = undef, - $metric = undef, - $restart = true, + Enum['up', 'down'] $ensure, + Optional[Stdlib::MAC] $macaddress = undef, + Boolean $manage_hwaddr = true, + String $bootproto = 'dhcp', + Boolean $userctl = false, + Optional[String] $mtu = undef, + Optional[String] $dhcp_hostname = undef, + Optional[String] $ethtool_opts = undef, + Boolean $peerdns = false, + Optional[String] $linkdelay = undef, + Boolean $check_link_down = false, + Optional[String] $defroute = undef, + Optional[String] $zone = undef, + Optional[String] $metric = undef, + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') - if ! is_mac_address($macaddress) { + if $macaddress { + $macaddy = $macaddress + } else { # Strip off any tailing VLAN (ie eth5.90 -> eth5). $title_clean = regsubst($title,'^(\w+)\.\d+$','\1') $macaddy = getvar("::macaddress_${title_clean}") - } else { - $macaddy = $macaddress } - # Validate booleans - validate_bool($userctl) - validate_bool($peerdns) - validate_bool($manage_hwaddr) network_if_base { $title: ensure => $ensure, diff --git a/spec/defines/network_if_dynamic_spec.rb b/spec/defines/network_if_dynamic_spec.rb index 7ff23364..3f05572b 100644 --- a/spec/defines/network_if_dynamic_spec.rb +++ b/spec/defines/network_if_dynamic_spec.rb @@ -11,7 +11,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end From a63a23d72e45fdb728d6c919d2db4d62775fecd2 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 20:14:34 +0800 Subject: [PATCH 12/50] Fixures: fix ref for thrnio/ip --- .fixtures.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.fixtures.yml b/.fixtures.yml index 3d1fd6e9..0ab4e4c8 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -5,6 +5,6 @@ fixtures: ref: '4.24.0' ip: repo: 'https://github.com/thrnio/puppet-ip.git' - ref: '1.0.1' + ref: 'v1.0.1' symlinks: network: "#{source_dir}" From 7b83769fc7a8d6a52860d2d0a8432dd9a6de7d51 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 20:17:39 +0800 Subject: [PATCH 13/50] Use typing in network::bond::bridge --- manifests/bond/bridge.pp | 15 ++++++--------- spec/defines/network_bond_bridge_spec.rb | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/manifests/bond/bridge.pp b/manifests/bond/bridge.pp index 5381e4c1..964d354c 100644 --- a/manifests/bond/bridge.pp +++ b/manifests/bond/bridge.pp @@ -34,16 +34,13 @@ # Copyright (C) 2013 Mike Arnold, unless otherwise noted. # define network::bond::bridge ( - $ensure, - $bridge, - $mtu = undef, - $ethtool_opts = undef, - $bonding_opts = 'miimon=100', - $restart = true, + Enum['up', 'down'] $ensure, + String $bridge, + Optional[String] $mtu = undef, + Optional[String] $ethtool_opts = undef, + String $bonding_opts = 'miimon=100', + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') network_if_base { $title: ensure => $ensure, diff --git a/spec/defines/network_bond_bridge_spec.rb b/spec/defines/network_bond_bridge_spec.rb index 272557d2..42495a75 100644 --- a/spec/defines/network_bond_bridge_spec.rb +++ b/spec/defines/network_bond_bridge_spec.rb @@ -12,7 +12,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end From 4d7f15d9f37145f9e95b17d6a341ec0e83804732 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 20:21:38 +0800 Subject: [PATCH 14/50] Use typing in network::bond::slave --- manifests/bond/slave.pp | 27 +++++++++---------------- spec/defines/network_bond_slave_spec.rb | 2 +- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/manifests/bond/slave.pp b/manifests/bond/slave.pp index 87845845..ef154238 100644 --- a/manifests/bond/slave.pp +++ b/manifests/bond/slave.pp @@ -39,24 +39,17 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::bond::slave ( - $master, - $macaddress = undef, - $ethtool_opts = undef, - $zone = undef, - $defroute = undef, - $metric = undef, - $restart = true, - $userctl = false, - $bootproto = undef, - $onboot = undef, + String $master, + Optional[Stdlib::MAC] $macaddress = undef, + Optional[String] $ethtool_opts = undef, + Optional[String] $zone = undef, + Optional[String] $defroute = undef, + Optional[String] $metric = undef, + Boolean $restart = true, + Boolean $userctl = false, + Optional[String] $bootproto = undef, + Optional[String] $onboot = undef, ) { - # Validate our data - if $macaddress and ! is_mac_address($macaddress) { - fail("${macaddress} is not a MAC address.") - } - # Validate our booleans - validate_bool($restart) - validate_bool($userctl) include '::network' diff --git a/spec/defines/network_bond_slave_spec.rb b/spec/defines/network_bond_slave_spec.rb index d8840dae..d394b2fc 100644 --- a/spec/defines/network_bond_slave_spec.rb +++ b/spec/defines/network_bond_slave_spec.rb @@ -12,7 +12,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth6')}.to raise_error(Puppet::Error, /123456 is not a MAC address./) + expect {should contain_file('ifcfg-eth6')}.to raise_error(Puppet::Error, /expects a match for Stdlib::MAC/) end end From 046a3802c1fcc3b91219db09708a9c7f14f00407 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 21:25:51 +0800 Subject: [PATCH 15/50] Use typing in network::bond::static --- manifests/bond/static.pp | 53 +++++++++--------------- spec/defines/network_bond_static_spec.rb | 6 +-- 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/manifests/bond/static.pp b/manifests/bond/static.pp index 0f28f52c..36621e8a 100644 --- a/manifests/bond/static.pp +++ b/manifests/bond/static.pp @@ -41,40 +41,27 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::bond::static ( - $ensure, - $ipaddress = undef, - $netmask = undef, - $gateway = undef, - $mtu = undef, - $ethtool_opts = undef, - $bonding_opts = 'miimon=100', - $peerdns = false, - $ipv6init = false, - $ipv6address = undef, - $ipv6gateway = undef, - $ipv6peerdns = false, - $dns1 = undef, - $dns2 = undef, - $domain = undef, - $zone = undef, - $defroute = undef, - $metric = undef, - $restart = true, - $userctl = undef, + Enum['up', 'down'] $ensure, + Optional[IP::Address::V4::NoSubnet] $ipaddress = undef, + Optional[IP::Address::V4::NoSubnet] $netmask = undef, + Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Optional[String] $mtu = undef, + Optional[String] $ethtool_opts = undef, + String $bonding_opts = 'miimon=100', + Boolean $peerdns = false, + Boolean $ipv6init = false, + Optional[IP::Address::V6] $ipv6address = undef, + Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Boolean $ipv6peerdns = false, + Optional[IP::Address::NoSubnet] $dns1 = undef, + Optional[IP::Address::NoSubnet] $dns2 = undef, + Optional[String] $domain = undef, + Optional[String] $zone = undef, + Optional[String] $defroute = undef, + Optional[String] $metric = undef, + Boolean $restart = true, + Boolean $userctl = false, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') - # Validate our data - if $ipaddress { - if ! is_ip_address($ipaddress) { fail("${ipaddress} is not an IP address.") } - } - if $ipv6address { - if ! is_ip_address($ipv6address) { fail("${ipv6address} is not an IPv6 address.") } - } - # Validate booleans - validate_bool($ipv6init) - validate_bool($ipv6peerdns) network_if_base { $title: ensure => $ensure, diff --git a/spec/defines/network_bond_static_spec.rb b/spec/defines/network_bond_static_spec.rb index 90f14efd..9ecd89a5 100644 --- a/spec/defines/network_bond_static_spec.rb +++ b/spec/defines/network_bond_static_spec.rb @@ -13,7 +13,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end @@ -26,7 +26,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /notAnIP is not an IP address./) + expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet /) end end @@ -40,7 +40,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /notAnIP is not an IPv6 address./) + expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /expects an IP::Address::V6 /) end end From 7c8e5b3577066f7a12ec3fd8409c9efbca4e9058 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 21:29:43 +0800 Subject: [PATCH 16/50] Use typing in network::bond::dynamic --- manifests/bond/dynamic.pp | 19 ++++++++----------- spec/defines/network_bond_dynamic_spec.rb | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/manifests/bond/dynamic.pp b/manifests/bond/dynamic.pp index 65e3dbdb..cc6c025a 100644 --- a/manifests/bond/dynamic.pp +++ b/manifests/bond/dynamic.pp @@ -36,18 +36,15 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::bond::dynamic ( - $ensure, - $mtu = undef, - $ethtool_opts = undef, - $bonding_opts = 'miimon=100', - $zone = undef, - $defroute = undef, - $metric = undef, - $restart = true, + Enum['up', 'down'] $ensure, + Optional[String] $mtu = undef, + Optional[String] $ethtool_opts = undef, + String $bonding_opts = 'miimon=100', + Optional[String] $zone = undef, + Optional[String] $defroute = undef, + Optional[String] $metric = undef, + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') network_if_base { $title: ensure => $ensure, diff --git a/spec/defines/network_bond_dynamic_spec.rb b/spec/defines/network_bond_dynamic_spec.rb index 2b2d2f1f..32ceba6c 100644 --- a/spec/defines/network_bond_dynamic_spec.rb +++ b/spec/defines/network_bond_dynamic_spec.rb @@ -11,7 +11,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond1:1')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-bond1:1')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end From 2b7d2f69e4427977e16b7eb398293fe763a93a69 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 21:32:43 +0800 Subject: [PATCH 17/50] Use typing in network::route --- manifests/route.pp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/manifests/route.pp b/manifests/route.pp index 27c7534a..a30441ac 100644 --- a/manifests/route.pp +++ b/manifests/route.pp @@ -41,17 +41,11 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::route ( - $ipaddress, - $netmask, - $gateway, - $restart = true, + Array[IP::Address::V4::NoSubnet] $ipaddress, + Array[IP::Address::V4::NoSubnet] $netmask, + Array[IP::Address::V4::NoSubnet] $gateway, + Boolean $restart = true, ) { - # Validate our arrays - validate_array($ipaddress) - validate_array($netmask) - validate_array($gateway) - # Validate our booleans - validate_bool($restart) include '::network' From 11de7c17ef67d4d9d884cec230650b2678a2027a Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 21:44:14 +0800 Subject: [PATCH 18/50] Use typing in network::global --- manifests/global.pp | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/manifests/global.pp b/manifests/global.pp index 9ff8c67a..4ffa117f 100644 --- a/manifests/global.pp +++ b/manifests/global.pp @@ -62,35 +62,18 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # class network::global ( - $hostname = undef, - $gateway = undef, - $gatewaydev = undef, - $ipv6gateway = undef, - $ipv6defaultdev = undef, - $nisdomain = undef, - $vlan = undef, - $ipv6networking = false, - $nozeroconf = undef, - $restart = true, - $requestreopen = true, + Optional[String] $hostname = undef, + Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Optional[String] $gatewaydev = undef, + Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Optional[String] $ipv6defaultdev = undef, + Optional[String] $nisdomain = undef, + Optional[Enum['yes', 'no']] $vlan = undef, + Boolean $ipv6networking = false, + Optional[Enum['yes', 'no']] $nozeroconf = undef, + Boolean $restart = true, + Boolean $requestreopen = true, ) { - # Validate our data - if $gateway { - if ! is_ip_address($gateway) { fail("${gateway} is not an IP address.") } - } - if $ipv6gateway { - if ! is_ip_address($ipv6gateway) { fail("${ipv6gateway} is not an IPv6 address.") } - } - - validate_bool($ipv6networking) - validate_bool($restart) - validate_bool($requestreopen) - - # Validate our regular expressions - if $vlan { - $states = [ '^yes$', '^no$' ] - validate_re($vlan, $states, '$vlan must be either "yes" or "no".') - } include '::network' From 0e95a0c31727f6d446a80161f8346bd560cac44e Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 21:50:23 +0800 Subject: [PATCH 19/50] Use typing in network::bridge::static --- manifests/bridge/static.pp | 54 ++++++++-------------- spec/defines/network_bridge_static_spec.rb | 10 ++-- 2 files changed, 24 insertions(+), 40 deletions(-) diff --git a/manifests/bridge/static.pp b/manifests/bridge/static.pp index 95b3a47e..7cf186a9 100644 --- a/manifests/bridge/static.pp +++ b/manifests/bridge/static.pp @@ -50,42 +50,26 @@ # Copyright (C) 2013 Mike Arnold, unless otherwise noted. # define network::bridge::static ( - $ensure, - $ipaddress = undef, - $netmask = undef, - $gateway = undef, - $ipv6address = undef, - $ipv6gateway = undef, - $bootproto = 'static', - $userctl = false, - $peerdns = false, - $ipv6init = false, - $ipv6peerdns = false, - $dns1 = undef, - $dns2 = undef, - $domain = undef, - $stp = false, - $delay = '30', - $bridging_opts = undef, - $scope = undef, - $restart = true, + Enum['up', 'down'] $ensure, + Optional[IP::Address::V4::NoSubnet] $ipaddress = undef, + Optional[IP::Address::V4::NoSubnet] $netmask = undef, + Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Optional[IP::Address::V6] $ipv6address = undef, + Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + String $bootproto = 'static', + Boolean $userctl = false, + Boolean $peerdns = false, + Boolean $ipv6init = false, + Boolean $ipv6peerdns = false, + Optional[IP::Address::NoSubnet] $dns1 = undef, + Optional[IP::Address::NoSubnet] $dns2 = undef, + Optional[String] $domain = undef, + Boolean $stp = false, + String $delay = '30', + Optional[String] $bridging_opts = undef, + Optional[String] $scope = undef, + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') - # Validate our data - if $ipaddress { - if ! is_ip_address($ipaddress) { fail("${ipaddress} is not an IP address.") } - } - if $ipv6address { - if ! is_ip_address($ipv6address) { fail("${ipv6address} is not an IPv6 address.") } - } - # Validate booleans - validate_bool($userctl) - validate_bool($stp) - validate_bool($ipv6init) - validate_bool($ipv6peerdns) - validate_bool($restart) ensure_packages(['bridge-utils']) diff --git a/spec/defines/network_bridge_static_spec.rb b/spec/defines/network_bridge_static_spec.rb index a8dde126..8cb87022 100644 --- a/spec/defines/network_bridge_static_spec.rb +++ b/spec/defines/network_bridge_static_spec.rb @@ -13,7 +13,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end @@ -26,7 +26,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /notAnIP is not an IP address./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet /) end end @@ -40,7 +40,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /notAnIP is not an IPv6 address./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, / expects an IP::Address::V6 /) end end @@ -54,7 +54,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /"notABool" is not a boolean./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a Boolean/) end end @@ -68,7 +68,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /"notABool" is not a boolean./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a Boolean/) end end From 522959e8c8742854dc1e65148b5a1a759a68624a Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 21:52:39 +0800 Subject: [PATCH 20/50] Use typing in network::bridge::dynamic --- manifests/bridge/dynamic.pp | 14 +++++++------- spec/defines/network_bridge_dynamic_spec.rb | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifests/bridge/dynamic.pp b/manifests/bridge/dynamic.pp index 729d4648..2e592b15 100644 --- a/manifests/bridge/dynamic.pp +++ b/manifests/bridge/dynamic.pp @@ -36,13 +36,13 @@ # Copyright (C) 2013 Mike Arnold, unless otherwise noted. # define network::bridge::dynamic ( - $ensure, - $bootproto = 'dhcp', - $userctl = false, - $stp = false, - $delay = '30', - $bridging_opts = undef, - $restart = true, + Enum['up', 'down'] $ensure, + String $bootproto = 'dhcp', + Boolean $userctl = false, + Boolean $stp = false, + String $delay = '30', + Optional[String] $bridging_opts = undef, + Boolean $restart = true, ) { # Validate our regular expressions $states = [ '^up$', '^down$' ] diff --git a/spec/defines/network_bridge_dynamic_spec.rb b/spec/defines/network_bridge_dynamic_spec.rb index 77eeec3b..8c5faf16 100644 --- a/spec/defines/network_bridge_dynamic_spec.rb +++ b/spec/defines/network_bridge_dynamic_spec.rb @@ -11,7 +11,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end @@ -23,7 +23,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /"notABool" is not a boolean./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a Boolean/) end end From 6fef94721af31e59b41170f439d476bce3033289 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 22:45:37 +0800 Subject: [PATCH 21/50] Use typing in network_if_base --- manifests/alias.pp | 3 -- manifests/bond.pp | 6 --- manifests/bond/bridge.pp | 6 --- manifests/bond/dynamic.pp | 6 --- manifests/bond/static.pp | 1 - manifests/if.pp | 5 --- manifests/if/bridge.pp | 14 +----- manifests/if/dynamic.pp | 3 -- manifests/if/promisc.pp | 5 --- manifests/if/static.pp | 6 +-- manifests/init.pp | 89 ++++++++++++++++----------------------- 11 files changed, 40 insertions(+), 104 deletions(-) diff --git a/manifests/alias.pp b/manifests/alias.pp index 61041c28..ac09a52b 100644 --- a/manifests/alias.pp +++ b/manifests/alias.pp @@ -58,11 +58,8 @@ noaliasrouting => $noaliasrouting, ipv6address => $ipv6address, ipv6gateway => $ipv6gateway, - macaddress => '', bootproto => 'none', userctl => $userctl, - mtu => '', - ethtool_opts => '', isalias => true, zone => $zone, metric => $metric, diff --git a/manifests/bond.pp b/manifests/bond.pp index d3c4b7d3..9d101107 100644 --- a/manifests/bond.pp +++ b/manifests/bond.pp @@ -42,13 +42,7 @@ network_if_base { $title: ensure => $ensure, - ipaddress => '', - netmask => '', - gateway => '', - macaddress => '', bootproto => 'none', - ipv6address => '', - ipv6gateway => '', mtu => $mtu, ethtool_opts => $ethtool_opts, bonding_opts => $bonding_opts, diff --git a/manifests/bond/bridge.pp b/manifests/bond/bridge.pp index 964d354c..d9892104 100644 --- a/manifests/bond/bridge.pp +++ b/manifests/bond/bridge.pp @@ -44,13 +44,7 @@ network_if_base { $title: ensure => $ensure, - ipaddress => '', - netmask => '', - gateway => '', - macaddress => '', bootproto => 'none', - ipv6address => '', - ipv6gateway => '', mtu => $mtu, ethtool_opts => $ethtool_opts, bonding_opts => $bonding_opts, diff --git a/manifests/bond/dynamic.pp b/manifests/bond/dynamic.pp index cc6c025a..36bd0daa 100644 --- a/manifests/bond/dynamic.pp +++ b/manifests/bond/dynamic.pp @@ -48,13 +48,7 @@ network_if_base { $title: ensure => $ensure, - ipaddress => '', - netmask => '', - gateway => '', - macaddress => '', bootproto => 'dhcp', - ipv6address => '', - ipv6gateway => '', mtu => $mtu, ethtool_opts => $ethtool_opts, bonding_opts => $bonding_opts, diff --git a/manifests/bond/static.pp b/manifests/bond/static.pp index 36621e8a..90ac46d9 100644 --- a/manifests/bond/static.pp +++ b/manifests/bond/static.pp @@ -68,7 +68,6 @@ ipaddress => $ipaddress, netmask => $netmask, gateway => $gateway, - macaddress => '', bootproto => 'none', mtu => $mtu, ethtool_opts => $ethtool_opts, diff --git a/manifests/if.pp b/manifests/if.pp index 5c6f1f61..58e42366 100644 --- a/manifests/if.pp +++ b/manifests/if.pp @@ -56,14 +56,9 @@ network_if_base { $title: ensure => $ensure, - ipaddress => '', - netmask => '', - gateway => '', macaddress => $macaddy, manage_hwaddr => $manage_hwaddr, bootproto => 'none', - ipv6address => '', - ipv6gateway => '', userctl => $userctl, mtu => $mtu, ethtool_opts => $ethtool_opts, diff --git a/manifests/if/bridge.pp b/manifests/if/bridge.pp index 2c17e2af..b07a0e50 100644 --- a/manifests/if/bridge.pp +++ b/manifests/if/bridge.pp @@ -39,22 +39,10 @@ Boolean $restart = true, ) { - if $macaddress == undef { - $macaddy = '' # lint:ignore:empty_string_assignment - } - else { - $macaddy = $macaddress - } - network_if_base { $title: ensure => $ensure, - ipaddress => '', - netmask => '', - gateway => '', - macaddress => $macaddy, + macaddress => $macaddress, bootproto => 'none', - ipv6address => '', - ipv6gateway => '', mtu => $mtu, ethtool_opts => $ethtool_opts, bridge => $bridge, diff --git a/manifests/if/dynamic.pp b/manifests/if/dynamic.pp index 77dc472c..77681a2d 100644 --- a/manifests/if/dynamic.pp +++ b/manifests/if/dynamic.pp @@ -73,9 +73,6 @@ network_if_base { $title: ensure => $ensure, - ipaddress => '', - netmask => '', - gateway => '', macaddress => $macaddy, manage_hwaddr => $manage_hwaddr, bootproto => $bootproto, diff --git a/manifests/if/promisc.pp b/manifests/if/promisc.pp index 20697859..4d734cb8 100644 --- a/manifests/if/promisc.pp +++ b/manifests/if/promisc.pp @@ -129,14 +129,9 @@ network_if_base { $title: ensure => $ensure, - ipaddress => '', - netmask => '', - gateway => '', macaddress => $macaddy, manage_hwaddr => $manage_hwaddr, bootproto => 'none', - ipv6address => '', - ipv6gateway => '', mtu => $mtu, ethtool_opts => $ethtool_opts, promisc => $promisc, diff --git a/manifests/if/static.pp b/manifests/if/static.pp index db11d24f..859396a6 100644 --- a/manifests/if/static.pp +++ b/manifests/if/static.pp @@ -107,12 +107,12 @@ $secondary_ipv6addresses = undef } - if !$macaddress { + if $macaddress { + $macaddy = $macaddress + } else { # Strip off any tailing VLAN (ie eth5.90 -> eth5). $title_clean = regsubst($title,'^(\w+)\.\d+$','\1') $macaddy = getvar("::macaddress_${title_clean}") - } else { - $macaddy = $macaddress } network_if_base { $title: diff --git a/manifests/init.pp b/manifests/init.pp index 6e3798fd..f4026d72 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -53,7 +53,7 @@ # $ensure - required - up|down # $ipaddress - optional # $netmask - optional -# $macaddress - required +# $macaddress - optional # $manage_hwaddr - optional - defaults to true # $gateway - optional # $noaliasrouting - optional - defaults to false @@ -105,59 +105,42 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network_if_base ( - $ensure, - $macaddress, - $ipaddress = undef, - $netmask = undef, - $manage_hwaddr = true, - $gateway = undef, - $noaliasrouting = false, - $ipv6address = undef, - $ipv6gateway = undef, - $ipv6init = false, - $ipv6autoconf = false, - $ipv6secondaries = undef, - $bootproto = 'none', - $userctl = false, - $mtu = undef, - $dhcp_hostname = undef, - $ethtool_opts = undef, - $bonding_opts = undef, - $isalias = false, - $peerdns = false, - $ipv6peerdns = false, - $dns1 = undef, - $dns2 = undef, - $domain = undef, - $bridge = undef, - $linkdelay = undef, - $scope = undef, - $check_link_down = false, - $flush = false, - $defroute = undef, - $zone = undef, - $metric = undef, - $promisc = false, - $restart = true, - $arpcheck = true, + Enum['up', 'down'] $ensure, + Optional[Stdlib::MAC] $macaddress = undef, + Optional[IP::Address::V4::NoSubnet] $ipaddress = undef, + Optional[IP::Address::V4::NoSubnet] $netmask = undef, + Boolean $manage_hwaddr = true, + Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Boolean $noaliasrouting = false, + Optional[IP::Address::V6] $ipv6address = undef, + Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Boolean $ipv6init = false, + Boolean $ipv6autoconf = false, + Optional[Array[IP::Address::V6]] $ipv6secondaries = undef, + String $bootproto = 'none', + Boolean $userctl = false, + Optional[String] $mtu = undef, + Optional[String] $dhcp_hostname = undef, + Optional[String] $ethtool_opts = undef, + Optional[String] $bonding_opts = undef, + Boolean $isalias = false, + Boolean $peerdns = false, + Boolean $ipv6peerdns = false, + Optional[IP::Address::NoSubnet] $dns1 = undef, + Optional[IP::Address::NoSubnet] $dns2 = undef, + Optional[String] $domain = undef, + Optional[String] $bridge = undef, + Optional[String] $linkdelay = undef, + Optional[String] $scope = undef, + Boolean $check_link_down = false, + Boolean $flush = false, + Optional[String] $defroute = undef, + Optional[String] $zone = undef, + Optional[String] $metric = undef, + Boolean $promisc = false, + Boolean $restart = true, + Boolean $arpcheck = true, ) { - # Validate our booleans - validate_bool($noaliasrouting) - validate_bool($userctl) - validate_bool($isalias) - validate_bool($peerdns) - validate_bool($ipv6init) - validate_bool($ipv6autoconf) - validate_bool($ipv6peerdns) - validate_bool($check_link_down) - validate_bool($manage_hwaddr) - validate_bool($flush) - validate_bool($promisc) - validate_bool($restart) - validate_bool($arpcheck) - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') include '::network' From 43b3bc89ed19f5c981e41d347b2e3c449bded47b Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 22:48:05 +0800 Subject: [PATCH 22/50] Simplify if statement --- manifests/if.pp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/manifests/if.pp b/manifests/if.pp index 58e42366..432372a2 100644 --- a/manifests/if.pp +++ b/manifests/if.pp @@ -46,12 +46,12 @@ Boolean $restart = true, ) { - if ! is_mac_address($macaddress) { + if $macaddress { + $macaddy = $macaddress + } else { # Strip off any tailing VLAN (ie eth5.90 -> eth5). $title_clean = regsubst($title,'^(\w+)\.\d+$','\1') $macaddy = getvar("::macaddress_${title_clean}") - } else { - $macaddy = $macaddress } network_if_base { $title: From 2131838aa3bc45e75f97f876d00fbeed339da5ff Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 22:50:25 +0800 Subject: [PATCH 23/50] Remove useless calls to validate_* functions --- manifests/bridge/dynamic.pp | 7 ------- manifests/init.pp | 21 --------------------- 2 files changed, 28 deletions(-) diff --git a/manifests/bridge/dynamic.pp b/manifests/bridge/dynamic.pp index 2e592b15..7a7f668c 100644 --- a/manifests/bridge/dynamic.pp +++ b/manifests/bridge/dynamic.pp @@ -44,13 +44,6 @@ Optional[String] $bridging_opts = undef, Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') - # Validate booleans - validate_bool($userctl) - validate_bool($stp) - validate_bool($restart) ensure_packages(['bridge-utils']) diff --git a/manifests/init.pp b/manifests/init.pp index f4026d72..d478f561 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -202,24 +202,3 @@ } } } # define network_if_base - -# == Definition: validate_ip_address -# -# This definition can be used to call is_ip_address on an array of ip addresses. -# -# === Parameters: -# -# None -# -# === Actions: -# -# Runs is_ip_address on the name of the define and fails if it is not a valid IP address. -# -# === Sample Usage: -# -# $ips = [ '10.21.30.248', '123:4567:89ab:cdef:123:4567:89ab:cdef' ] -# validate_ip_address { $ips: } -# -define validate_ip_address { - if ! is_ip_address($name) { fail("${name} is not an IP(v6) address.") } -} # define validate_ip_address From 335a12052c0ae814190a3a307f116c6ec00474de Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 22:56:49 +0800 Subject: [PATCH 24/50] Use thrnio/ip types instead of stdlib types --- manifests/alias.pp | 10 +++++----- manifests/alias/range.pp | 8 ++++---- manifests/if/static.pp | 11 +++-------- spec/defines/network_alias_range_spec.rb | 4 ++-- spec/defines/network_alias_spec.rb | 2 +- 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/manifests/alias.pp b/manifests/alias.pp index ac09a52b..252989b2 100644 --- a/manifests/alias.pp +++ b/manifests/alias.pp @@ -38,12 +38,12 @@ # define network::alias ( Enum['up', 'down'] $ensure, - Stdlib::Compat::Ipv4 $ipaddress, - Stdlib::Compat::Ipv4 $netmask, - Optional[Stdlib::Compat::Ipv4] $gateway = undef, + IP::Address::V4::NoSubnet $ipaddress, + IP::Address::V4::NoSubnet $netmask, + Optional[IP::Address::V4::NoSubnet] $gateway = undef, Boolean $noaliasrouting = false, - Optional[Stdlib::Compat::Ipv6] $ipv6address = undef, - Optional[Stdlib::Compat::Ipv6] $ipv6gateway = undef, + Optional[IP::Address::V6] $ipv6address = undef, + Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, Boolean $userctl = false, Optional[String] $zone = undef, Optional[String] $metric = undef, diff --git a/manifests/alias/range.pp b/manifests/alias/range.pp index 01121cc9..2e21deb4 100644 --- a/manifests/alias/range.pp +++ b/manifests/alias/range.pp @@ -39,13 +39,13 @@ # define network::alias::range ( Enum['up', 'down', 'absent'] $ensure, - Stdlib::Compat::Ipv4 $ipaddress_start, - Stdlib::Compat::Ipv4 $ipaddress_end, + IP::Address::V4::NoSubnet $ipaddress_start, + IP::Address::V4::NoSubnet $ipaddress_end, String $clonenum_start, Boolean $noaliasrouting = false, Boolean $restart = true, - Optional[Stdlib::Compat::Ipv4] $netmask = undef, - Optional[Stdlib::Compat::Ipv4] $broadcast = undef, + Optional[IP::Address::V4::NoSubnet] $netmask = undef, + Optional[IP::Address::V4::NoSubnet] $broadcast = undef, Boolean $arpcheck = true, ) { diff --git a/manifests/if/static.pp b/manifests/if/static.pp index 859396a6..a45c8609 100644 --- a/manifests/if/static.pp +++ b/manifests/if/static.pp @@ -67,12 +67,7 @@ ] ] $ipv6address = undef, Boolean $ipv6init = false, - Optional[ - Variant[ - IP::Address::V6::NoSubnet::Full, - IP::Address::V6::NoSubnet::Compressed, - ] - ] $ipv6gateway = undef, + Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, Optional[Stdlib::MAC] $macaddress = undef, Boolean $manage_hwaddr = true, Boolean $ipv6autoconf = false, @@ -81,8 +76,8 @@ Optional[String] $ethtool_opts = undef, Boolean $peerdns = false, Boolean $ipv6peerdns = false, - Optional[Stdlib::Compat::Ip_address] $dns1 = undef, - Optional[Stdlib::Compat::Ip_address] $dns2 = undef, + Optional[IP::Address::NoSubnet] $dns1 = undef, + Optional[IP::Address::NoSubnet] $dns2 = undef, Optional[String] $domain = undef, Optional[String] $linkdelay = undef, Optional[String] $scope = undef, diff --git a/spec/defines/network_alias_range_spec.rb b/spec/defines/network_alias_range_spec.rb index b7e07f3d..74b587e0 100644 --- a/spec/defines/network_alias_range_spec.rb +++ b/spec/defines/network_alias_range_spec.rb @@ -28,7 +28,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /expects a match for Stdlib::Compat::Ipv4/) + expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet /) end end @@ -42,7 +42,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /expects a match for Stdlib::Compat::Ipv4/) + expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet /) end end diff --git a/spec/defines/network_alias_spec.rb b/spec/defines/network_alias_spec.rb index 3d961261..ca8cda73 100644 --- a/spec/defines/network_alias_spec.rb +++ b/spec/defines/network_alias_spec.rb @@ -26,7 +26,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth1:1')}.to raise_error(Puppet::Error, /expects a match for Stdlib::Compat::Ipv4/) + expect {should contain_file('ifcfg-eth1:1')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet /) end end From 020ef28dfecc48a902903d48d517a1595052fad1 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 22:57:33 +0800 Subject: [PATCH 25/50] Prevent rspec output truncation Without this, long lines are truncated, making Puppet 4 type matching errors unreadable. --- spec/spec_helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f5664..810c2dd1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,4 @@ require 'puppetlabs_spec_helper/module_spec_helper' + +# Prevent output truncation (useful for debugging) +RSpec::Support::ObjectFormatter.default_instance.max_formatted_output_length = 999 From 9cc223b7051aad3c44dbbc03aee649eb80c26423 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 23:10:29 +0800 Subject: [PATCH 26/50] Add type Network::If::Bootproto --- manifests/bond/slave.pp | 2 +- manifests/bridge/dynamic.pp | 2 +- manifests/bridge/static.pp | 2 +- manifests/if/dynamic.pp | 2 +- manifests/if/promisc.pp | 2 +- manifests/init.pp | 2 +- types/if/bootproto.pp | 8 ++++++++ 7 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 types/if/bootproto.pp diff --git a/manifests/bond/slave.pp b/manifests/bond/slave.pp index ef154238..ecfb5918 100644 --- a/manifests/bond/slave.pp +++ b/manifests/bond/slave.pp @@ -47,7 +47,7 @@ Optional[String] $metric = undef, Boolean $restart = true, Boolean $userctl = false, - Optional[String] $bootproto = undef, + Optional[Network::If::Bootproto] $bootproto = undef, Optional[String] $onboot = undef, ) { diff --git a/manifests/bridge/dynamic.pp b/manifests/bridge/dynamic.pp index 7a7f668c..0d0f8ffc 100644 --- a/manifests/bridge/dynamic.pp +++ b/manifests/bridge/dynamic.pp @@ -37,7 +37,7 @@ # define network::bridge::dynamic ( Enum['up', 'down'] $ensure, - String $bootproto = 'dhcp', + Network::If::Bootproto $bootproto = 'dhcp', Boolean $userctl = false, Boolean $stp = false, String $delay = '30', diff --git a/manifests/bridge/static.pp b/manifests/bridge/static.pp index 7cf186a9..1bb62839 100644 --- a/manifests/bridge/static.pp +++ b/manifests/bridge/static.pp @@ -56,7 +56,7 @@ Optional[IP::Address::V4::NoSubnet] $gateway = undef, Optional[IP::Address::V6] $ipv6address = undef, Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, - String $bootproto = 'static', + Network::If::Bootproto $bootproto = 'static', Boolean $userctl = false, Boolean $peerdns = false, Boolean $ipv6init = false, diff --git a/manifests/if/dynamic.pp b/manifests/if/dynamic.pp index 77681a2d..0e8b9477 100644 --- a/manifests/if/dynamic.pp +++ b/manifests/if/dynamic.pp @@ -49,7 +49,7 @@ Enum['up', 'down'] $ensure, Optional[Stdlib::MAC] $macaddress = undef, Boolean $manage_hwaddr = true, - String $bootproto = 'dhcp', + Network::If::Bootproto $bootproto = 'dhcp', Boolean $userctl = false, Optional[String] $mtu = undef, Optional[String] $dhcp_hostname = undef, diff --git a/manifests/if/promisc.pp b/manifests/if/promisc.pp index 4d734cb8..1186a162 100644 --- a/manifests/if/promisc.pp +++ b/manifests/if/promisc.pp @@ -44,7 +44,7 @@ Enum['up', 'down'] $ensure, Optional[Stdlib::MAC] $macaddress = undef, Boolean $manage_hwaddr = true, - Optional[String] $bootproto = undef, + Optional[Network::If::Bootproto] $bootproto = undef, Boolean $userctl = false, Optional[String] $mtu = undef, Optional[String] $ethtool_opts = undef, diff --git a/manifests/init.pp b/manifests/init.pp index d478f561..517507b0 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -117,7 +117,7 @@ Boolean $ipv6init = false, Boolean $ipv6autoconf = false, Optional[Array[IP::Address::V6]] $ipv6secondaries = undef, - String $bootproto = 'none', + Network::If::Bootproto $bootproto = 'none', Boolean $userctl = false, Optional[String] $mtu = undef, Optional[String] $dhcp_hostname = undef, diff --git a/types/if/bootproto.pp b/types/if/bootproto.pp new file mode 100644 index 00000000..3350d23b --- /dev/null +++ b/types/if/bootproto.pp @@ -0,0 +1,8 @@ +# Acceptable values for BOOTPROTO +# +# Only "dhcp" and "bootp" are used in /etc/sysconfig/network-scripts +# +# "static" and "none" are used in some parts of the module, +# and those values have no side effects, so we accept them too. +# +type Network::If::Bootproto = Enum['none', 'static', 'dhcp', 'bootp'] From 5f381773b1686ec530095ae8fa0e56d6d253c425 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 23:15:50 +0800 Subject: [PATCH 27/50] Accept thrnio/ip 1.0.0 Because there are no functional changes between 1.0.0 and 1.0.1 --- .fixtures.yml | 2 +- metadata.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index 0ab4e4c8..aea64a24 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -5,6 +5,6 @@ fixtures: ref: '4.24.0' ip: repo: 'https://github.com/thrnio/puppet-ip.git' - ref: 'v1.0.1' + ref: 'v1.0.0' symlinks: network: "#{source_dir}" diff --git a/metadata.json b/metadata.json index 828b84cb..4f25415d 100644 --- a/metadata.json +++ b/metadata.json @@ -15,7 +15,7 @@ }, { "name": "thrnio/ip", - "version_requirement": ">=1.0.1 < 2.0.0" + "version_requirement": ">=1.0.0 < 2.0.0" } ], "operatingsystem_support": [ From 7bcb6b806f1d0f2c5e46ecb586f11ac5912387c5 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Mon, 19 Feb 2018 23:45:12 +0800 Subject: [PATCH 28/50] Stop using $::macaddress_* legacy facts --- README.md | 2 +- TODO.md | 5 +- manifests/bond/slave.pp | 2 +- manifests/if.pp | 4 +- manifests/if/dynamic.pp | 6 +- manifests/if/promisc.pp | 4 +- manifests/if/static.pp | 6 +- spec/defines/network_bond_bridge_spec.rb | 8 ++- spec/defines/network_bond_dynamic_spec.rb | 16 ++++- spec/defines/network_bond_slave_spec.rb | 24 ++++++- spec/defines/network_bond_spec.rb | 8 ++- spec/defines/network_bond_static_spec.rb | 8 ++- spec/defines/network_if_bridge_spec.rb | 20 ++++-- spec/defines/network_if_dynamic_spec.rb | 40 +++++++++--- spec/defines/network_if_promisc_spec.rb | 16 ++++- spec/defines/network_if_spec.rb | 16 ++++- spec/defines/network_if_static_spec.rb | 80 ++++++++++++++++++----- tests/bond-static.pp | 4 +- tests/route.pp | 2 +- 19 files changed, 215 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 3d167aad..055b9d87 100644 --- a/README.md +++ b/README.md @@ -195,7 +195,7 @@ Bonded master interface - bridged (the corresponding network::bridge::* may also Bonded slave interface: network::bond::slave { 'eth1': - macaddress => $macaddress_eth1, + macaddress => $::networking['interfaces']['eth1']['mac'], ethtool_opts => 'autoneg off speed 1000 duplex full', master => 'bond0', } diff --git a/TODO.md b/TODO.md index ed1d4ebb..ba8b3fcb 100644 --- a/TODO.md +++ b/TODO.md @@ -30,7 +30,10 @@ and remove the interface. network::bond::dynamic { "bond2": slaves => [ "eth4", "eth7", ], - macaddress => [ $macaddress_eth4, $macaddress_eth7, ], + macaddress => [ + $::networking['interfaces']['eth4']['mac'], + $::networking['interfaces']['eth7']['mac'], + ], bonding_opts => "mode=active-backup", mtu => "1500", ethtool_opts => "speed 100 duplex full autoneg off", diff --git a/manifests/bond/slave.pp b/manifests/bond/slave.pp index ecfb5918..42136941 100644 --- a/manifests/bond/slave.pp +++ b/manifests/bond/slave.pp @@ -26,7 +26,7 @@ # === Sample Usage: # # network::bond::slave { 'eth1': -# macaddress => $::macaddress_eth1, +# macaddress => $::networking['interfaces']['eth1']['mac'], # master => 'bond0', # } # diff --git a/manifests/if.pp b/manifests/if.pp index 432372a2..fc3874a8 100644 --- a/manifests/if.pp +++ b/manifests/if.pp @@ -6,7 +6,7 @@ # # $ensure - required - up|down # $manage_hwaddr - optional - defaults to true -# $macaddress - optional - defaults to macaddress_$title +# $macaddress - optional - defaults to $::networking['interfaces'][$title]['mac'] # $userctl - optional - defaults to false # $mtu - optional # $ethtool_opts - optional @@ -51,7 +51,7 @@ } else { # Strip off any tailing VLAN (ie eth5.90 -> eth5). $title_clean = regsubst($title,'^(\w+)\.\d+$','\1') - $macaddy = getvar("::macaddress_${title_clean}") + $macaddy = $::networking['interfaces'][$title_clean]['mac'] } network_if_base { $title: diff --git a/manifests/if/dynamic.pp b/manifests/if/dynamic.pp index 0e8b9477..e9ad72e6 100644 --- a/manifests/if/dynamic.pp +++ b/manifests/if/dynamic.pp @@ -5,7 +5,7 @@ # === Parameters: # # $ensure - required - up|down -# $macaddress - optional - defaults to macaddress_$title +# $macaddress - optional - defaults to $::networking['interfaces'][$title]['mac'] # $manage_hwaddr - optional - defaults to true # $bootproto - optional - defaults to "dhcp" # $userctl - optional - defaults to false @@ -28,7 +28,7 @@ # # network::if::dynamic { 'eth2': # ensure => 'up', -# macaddress => $::macaddress_eth2, +# macaddress => $::networking['interfaces']['eth2']['mac'], # } # # network::if::dynamic { 'eth3': @@ -68,7 +68,7 @@ } else { # Strip off any tailing VLAN (ie eth5.90 -> eth5). $title_clean = regsubst($title,'^(\w+)\.\d+$','\1') - $macaddy = getvar("::macaddress_${title_clean}") + $macaddy = $::networking['interfaces'][$title_clean]['mac'] } network_if_base { $title: diff --git a/manifests/if/promisc.pp b/manifests/if/promisc.pp index 1186a162..baec3926 100644 --- a/manifests/if/promisc.pp +++ b/manifests/if/promisc.pp @@ -5,7 +5,7 @@ # === Parameters: # # $ensure - required - up|down -# $macaddress - optional, defaults to macaddress_$title +# $macaddress - optional - defaults to $::networking['interfaces'][$title]['mac'] # $manage_hwaddr - optional - defaults to true # $bootproto - optional, defaults to undef ('none') # $userctl - optional @@ -60,7 +60,7 @@ } else { # Strip off any tailing VLAN (ie eth5.90 -> eth5). $title_clean = regsubst($title,'^(\w+)\.\d+$','\1') - $macaddy = getvar("::macaddress_${title_clean}") + $macaddy = $::networking['interfaces'][$title_clean]['mac'] } $onboot = $ensure ? { diff --git a/manifests/if/static.pp b/manifests/if/static.pp index a45c8609..3ea0dcb6 100644 --- a/manifests/if/static.pp +++ b/manifests/if/static.pp @@ -12,7 +12,7 @@ # $ipv6init - optional - defaults to false # $ipv6gateway - optional # $manage_hwaddr - optional - defaults to true -# $macaddress - optional - defaults to macaddress_$title +# $macaddress - optional - defaults to $::networking['interfaces'][$title]['mac'] # $ipv6autoconf - optional - defaults to false # $userctl - optional - defaults to false # $mtu - optional @@ -40,7 +40,7 @@ # ensure => 'up', # ipaddress => '10.21.30.248', # netmask => '255.255.255.128', -# macaddress => $::macaddress_eth0, +# macaddress => $::networking['interfaces']['eth0']['mac'], # domain => 'is.domain.com domain.com', # ipv6init => true, # ipv6address => '123:4567:89ab:cdef:123:4567:89ab:cdef', @@ -107,7 +107,7 @@ } else { # Strip off any tailing VLAN (ie eth5.90 -> eth5). $title_clean = regsubst($title,'^(\w+)\.\d+$','\1') - $macaddy = getvar("::macaddress_${title_clean}") + $macaddy = $::networking['interfaces'][$title_clean]['mac'] } network_if_base { $title: diff --git a/spec/defines/network_bond_bridge_spec.rb b/spec/defines/network_bond_bridge_spec.rb index 42495a75..2036d073 100644 --- a/spec/defines/network_bond_bridge_spec.rb +++ b/spec/defines/network_bond_bridge_spec.rb @@ -27,7 +27,13 @@ :osfamily => 'RedHat', :operatingsystem => 'RedHat', :operatingsystemrelease => '6.0', - :macaddress_bond0 => 'fe:fe:fe:aa:aa:aa', + :networking => { + :interfaces => { + :bond0 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-bond0').with( diff --git a/spec/defines/network_bond_dynamic_spec.rb b/spec/defines/network_bond_dynamic_spec.rb index 32ceba6c..f8559076 100644 --- a/spec/defines/network_bond_dynamic_spec.rb +++ b/spec/defines/network_bond_dynamic_spec.rb @@ -25,7 +25,13 @@ :osfamily => 'RedHat', :operatingsystem => 'RedHat', :operatingsystemrelease => '6.0', - :macaddress_bond2 => 'ff:aa:ff:aa:ff:aa', + :networking => { + :interfaces => { + :bond2 => { + :mac => 'ff:aa:ff:aa:ff:aa' + } + } + } } end it { should contain_file('ifcfg-bond2').with( @@ -109,7 +115,13 @@ :osfamily => 'RedHat', :operatingsystem => 'RedHat', :operatingsystemrelease => '6.0', - :macaddress_bond2 => 'ff:aa:ff:aa:ff:aa', + :networking => { + :interfaces => { + :bond2 => { + :mac => 'ff:aa:ff:aa:ff:aa' + } + } + } } end it { should contain_file('ifcfg-bond2').with( diff --git a/spec/defines/network_bond_slave_spec.rb b/spec/defines/network_bond_slave_spec.rb index d394b2fc..b567e129 100644 --- a/spec/defines/network_bond_slave_spec.rb +++ b/spec/defines/network_bond_slave_spec.rb @@ -27,7 +27,13 @@ :osfamily => 'RedHat', :operatingsystem => 'RedHat', :operatingsystemrelease => '6.0', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( @@ -62,7 +68,13 @@ end let :facts do { :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( @@ -103,7 +115,13 @@ :osfamily => 'RedHat', :operatingsystem => 'RedHat', :operatingsystemrelease => '6.0', - :macaddress_eth3 => 'fe:fe:fe:aa:aa:aa', + :networking => { + :interfaces => { + :eth3 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth3').with( diff --git a/spec/defines/network_bond_spec.rb b/spec/defines/network_bond_spec.rb index 151ebd88..7e41786c 100644 --- a/spec/defines/network_bond_spec.rb +++ b/spec/defines/network_bond_spec.rb @@ -25,7 +25,13 @@ :osfamily => 'RedHat', :operatingsystem => 'RedHat', :operatingsystemrelease => '6.0', - :macaddress_bond0 => 'fe:fe:fe:aa:aa:aa', + :networking => { + :interfaces => { + :bond0 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-bond0').with( diff --git a/spec/defines/network_bond_static_spec.rb b/spec/defines/network_bond_static_spec.rb index 9ecd89a5..71801282 100644 --- a/spec/defines/network_bond_static_spec.rb +++ b/spec/defines/network_bond_static_spec.rb @@ -56,7 +56,13 @@ :osfamily => 'RedHat', :operatingsystem => 'RedHat', :operatingsystemrelease => '6.0', - :macaddress_bond0 => 'fe:fe:fe:aa:aa:aa', + :networking => { + :interfaces => { + :bond0 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-bond0').with( diff --git a/spec/defines/network_if_bridge_spec.rb b/spec/defines/network_if_bridge_spec.rb index 9d86e482..9ca5f273 100644 --- a/spec/defines/network_if_bridge_spec.rb +++ b/spec/defines/network_if_bridge_spec.rb @@ -24,8 +24,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :osfamily => 'RedHat', + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( @@ -62,8 +68,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :osfamily => 'RedHat', + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( diff --git a/spec/defines/network_if_dynamic_spec.rb b/spec/defines/network_if_dynamic_spec.rb index 3f05572b..42dc1a51 100644 --- a/spec/defines/network_if_dynamic_spec.rb +++ b/spec/defines/network_if_dynamic_spec.rb @@ -22,8 +22,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth99 => 'ff:aa:ff:aa:ff:aa', + :osfamily => 'RedHat', + :networking => { + :interfaces => { + :eth99 => { + :mac => 'ff:aa:ff:aa:ff:aa' + } + } + } } end it { should contain_file('ifcfg-eth99').with( @@ -67,8 +73,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth99 => 'ff:aa:ff:aa:ff:aa', + :osfamily => 'RedHat', + :networking => { + :interfaces => { + :eth99 => { + :mac => 'ff:aa:ff:aa:ff:aa' + } + } + } } end it { should contain_file('ifcfg-eth99').with( @@ -105,8 +117,14 @@ let(:title) { 'eth45.302' } let(:params) {{ :ensure => 'up' }} let :facts do { - :osfamily => 'RedHat', - :macaddress_eth45 => 'bb:cc:bb:cc:bb:cc', + :osfamily => 'RedHat', + :networking => { + :interfaces => { + :eth45 => { + :mac => 'bb:cc:bb:cc:bb:cc' + } + } + } } end it { should contain_file('ifcfg-eth45.302').with( @@ -139,8 +157,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth0 => 'bb:cc:bb:cc:bb:cc', + :osfamily => 'RedHat', + :networking => { + :interfaces => { + :eth0 => { + :mac => 'bb:cc:bb:cc:bb:cc' + } + } + } } end it { should contain_file('ifcfg-eth0').with( diff --git a/spec/defines/network_if_promisc_spec.rb b/spec/defines/network_if_promisc_spec.rb index c4e32f55..b5b8e198 100644 --- a/spec/defines/network_if_promisc_spec.rb +++ b/spec/defines/network_if_promisc_spec.rb @@ -15,7 +15,13 @@ :operatingsystem => 'RedHat', :operatingsystemrelease => '6.0', :operatingsystemmajrelease => '6', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( @@ -72,7 +78,13 @@ :operatingsystem => 'RedHat', :operatingsystemrelease => '6.0', :operatingsystemmajrelease => '6', - :macaddress_eth3 => 'fe:fe:fe:aa:aa:aa', + :networking => { + :interfaces => { + :eth3 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth3').with( diff --git a/spec/defines/network_if_spec.rb b/spec/defines/network_if_spec.rb index 0e9bb184..a42e1919 100644 --- a/spec/defines/network_if_spec.rb +++ b/spec/defines/network_if_spec.rb @@ -25,7 +25,13 @@ :osfamily => 'RedHat', :operatingsystem => 'RedHat', :operatingsystemrelease => '6.0', - :macaddress_eth0 => 'fe:fe:fe:aa:aa:aa', + :networking => { + :interfaces => { + :eth0 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth0').with( @@ -62,7 +68,13 @@ :osfamily => 'RedHat', :operatingsystem => 'RedHat', :operatingsystemrelease => '6.0', - :macaddress_eth0 => 'fe:fe:fe:aa:aa:aa', + :networking => { + :interfaces => { + :eth0 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth0').with( diff --git a/spec/defines/network_if_static_spec.rb b/spec/defines/network_if_static_spec.rb index 0734c3cd..06079420 100644 --- a/spec/defines/network_if_static_spec.rb +++ b/spec/defines/network_if_static_spec.rb @@ -72,8 +72,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :osfamily => 'RedHat', + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( @@ -112,8 +118,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :osfamily => 'RedHat', + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( @@ -170,8 +182,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :osfamily => 'RedHat', + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( @@ -226,8 +244,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth6 => 'bb:cc:bb:cc:bb:cc', + :osfamily => 'RedHat', + :networking => { + :interfaces => { + :eth6 => { + :mac => 'bb:cc:bb:cc:bb:cc' + } + } + } } end it { should contain_file('ifcfg-eth6.203').with( @@ -264,8 +288,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth0 => 'bb:cc:bb:cc:bb:cc', + :osfamily => 'RedHat', + :networking => { + :interfaces => { + :eth0 => { + :mac => 'bb:cc:bb:cc:bb:cc' + } + } + } } end it { should contain_file('ifcfg-eth0').with( @@ -301,8 +331,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :osfamily => 'RedHat', + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_exec('network-flush').with_command('ip addr flush dev eth1').that_comes_before('Service[network]') } @@ -321,8 +357,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :osfamily => 'RedHat', + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( @@ -367,8 +409,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :osfamily => 'RedHat', + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( diff --git a/tests/bond-static.pp b/tests/bond-static.pp index de052353..24974b0c 100644 --- a/tests/bond-static.pp +++ b/tests/bond-static.pp @@ -27,14 +27,14 @@ # bonded slave interface - static network::bond::slave { 'eth1': - macaddress => $::macaddress_eth1, + macaddress => $::networking['interfaces']['eth1']['mac'], ethtool_opts => 'speed 1000 duplex full autoneg off', master => 'bond0', } # bonded slave interface - static network::bond::slave { 'eth3': - macaddress => $::macaddress_eth3, + macaddress => $::networking['interfaces']['eth3']['mac'], ethtool_opts => 'speed 100 duplex half autoneg off', master => 'bond0', } diff --git a/tests/route.pp b/tests/route.pp index 5b95026b..af963733 100644 --- a/tests/route.pp +++ b/tests/route.pp @@ -9,5 +9,5 @@ network::if::dynamic { 'eth2': ensure => 'down', - macaddress => $::macaddress_eth2, + macaddress => $::networking['interfaces']['eth2']['mac'], } From 220aa34f4f189429a4a520e623e1d8a7cf2219c3 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Tue, 20 Feb 2018 00:27:47 +0800 Subject: [PATCH 29/50] Stop using $::osfamily and $::operatingsystem* legact facts --- manifests/bond.pp | 8 +-- manifests/bond/bridge.pp | 8 +-- manifests/bond/dynamic.pp | 8 +-- manifests/bond/static.pp | 8 +-- manifests/global.pp | 8 +-- manifests/if/promisc.pp | 4 +- manifests/init.pp | 2 +- spec/classes/network_global_spec.rb | 64 ++++++++++++++------- spec/classes/network_init_spec.rb | 4 +- spec/defines/network_alias_range_spec.rb | 10 ++-- spec/defines/network_alias_spec.rb | 4 +- spec/defines/network_bond_bridge_spec.rb | 42 +++++++++----- spec/defines/network_bond_dynamic_spec.rb | 42 +++++++++----- spec/defines/network_bond_slave_spec.rb | 28 ++++++--- spec/defines/network_bond_spec.rb | 42 +++++++++----- spec/defines/network_bond_static_spec.rb | 42 +++++++++----- spec/defines/network_bridge_dynamic_spec.rb | 16 +++++- spec/defines/network_bridge_spec.rb | 12 +++- spec/defines/network_bridge_static_spec.rb | 12 +++- spec/defines/network_if_bridge_spec.rb | 8 ++- spec/defines/network_if_dynamic_spec.rb | 16 ++++-- spec/defines/network_if_promisc_spec.rb | 22 ++++--- spec/defines/network_if_spec.rb | 20 +++++-- spec/defines/network_if_static_spec.rb | 32 ++++++++--- spec/defines/network_route_spec.rb | 21 ++++++- 25 files changed, 330 insertions(+), 153 deletions(-) diff --git a/manifests/bond.pp b/manifests/bond.pp index 9d101107..e70312fe 100644 --- a/manifests/bond.pp +++ b/manifests/bond.pp @@ -52,10 +52,10 @@ # Only install "alias bondN bonding" on old OSs that support # /etc/modprobe.conf. - case $::operatingsystem { + case $::os['name'] { /^(RedHat|CentOS|OEL|OracleLinux|SLC|Scientific)$/: { - case $::operatingsystemrelease { - /^[45]/: { + case $::os['release']['major'] { + /^[45]$/: { augeas { "modprobe.conf_${title}": context => '/files/etc/modprobe.conf', changes => [ @@ -70,7 +70,7 @@ } } 'Fedora': { - case $::operatingsystemrelease { + case $::os['release']['major'] { /^(1|2|3|4|5|6|7|8|9|10|11)$/: { augeas { "modprobe.conf_${title}": context => '/files/etc/modprobe.conf', diff --git a/manifests/bond/bridge.pp b/manifests/bond/bridge.pp index d9892104..43af3285 100644 --- a/manifests/bond/bridge.pp +++ b/manifests/bond/bridge.pp @@ -54,10 +54,10 @@ # Only install "alias bondN bonding" on old OSs that support # /etc/modprobe.conf. - case $::operatingsystem { + case $::os['name'] { /^(RedHat|CentOS|OEL|OracleLinux|SLC|Scientific)$/: { - case $::operatingsystemrelease { - /^[45]/: { + case $::os['release']['major'] { + /^[45]$/: { augeas { "modprobe.conf_${title}": context => '/files/etc/modprobe.conf', changes => [ @@ -72,7 +72,7 @@ } } 'Fedora': { - case $::operatingsystemrelease { + case $::os['release']['major'] { /^(1|2|3|4|5|6|7|8|9|10|11)$/: { augeas { "modprobe.conf_${title}": context => '/files/etc/modprobe.conf', diff --git a/manifests/bond/dynamic.pp b/manifests/bond/dynamic.pp index 36bd0daa..357a49f0 100644 --- a/manifests/bond/dynamic.pp +++ b/manifests/bond/dynamic.pp @@ -60,10 +60,10 @@ # Only install "alias bondN bonding" on old OSs that support # /etc/modprobe.conf. - case $::operatingsystem { + case $::os['name'] { /^(RedHat|CentOS|OEL|OracleLinux|SLC|Scientific)$/: { - case $::operatingsystemrelease { - /^[45]/: { + case $::os['release']['major'] { + /^[45]$/: { augeas { "modprobe.conf_${title}": context => '/files/etc/modprobe.conf', changes => [ @@ -78,7 +78,7 @@ } } 'Fedora': { - case $::operatingsystemrelease { + case $::os['release']['major'] { /^(1|2|3|4|5|6|7|8|9|10|11)$/: { augeas { "modprobe.conf_${title}": context => '/files/etc/modprobe.conf', diff --git a/manifests/bond/static.pp b/manifests/bond/static.pp index 90ac46d9..5980254d 100644 --- a/manifests/bond/static.pp +++ b/manifests/bond/static.pp @@ -89,10 +89,10 @@ # Only install "alias bondN bonding" on old OSs that support # /etc/modprobe.conf. - case $::operatingsystem { + case $::os['name'] { /^(RedHat|CentOS|OEL|OracleLinux|SLC|Scientific)$/: { - case $::operatingsystemrelease { - /^[45]/: { + case $::os['release']['major'] { + /^[45]$/: { augeas { "modprobe.conf_${title}": context => '/files/etc/modprobe.conf', changes => [ @@ -107,7 +107,7 @@ } } 'Fedora': { - case $::operatingsystemrelease { + case $::os['release']['major'] { /^(1|2|3|4|5|6|7|8|9|10|11)$/: { augeas { "modprobe.conf_${title}": context => '/files/etc/modprobe.conf', diff --git a/manifests/global.pp b/manifests/global.pp index 4ffa117f..28fdc421 100644 --- a/manifests/global.pp +++ b/manifests/global.pp @@ -77,15 +77,15 @@ include '::network' - case $::operatingsystem { + case $::os['name'] { /^(RedHat|CentOS|OEL|OracleLinux|SLC|Scientific)$/: { - case $::operatingsystemrelease { - /^[456]/: { $has_systemd = false } + case $::os['release']['major'] { + /^[456]$/: { $has_systemd = false } default: { $has_systemd = true } } } 'Fedora': { - case $::operatingsystemrelease { + case $::os['release']['major'] { /^(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17)$/: { $has_systemd = false } default: { $has_systemd = true } } diff --git a/manifests/if/promisc.pp b/manifests/if/promisc.pp index baec3926..105160ec 100644 --- a/manifests/if/promisc.pp +++ b/manifests/if/promisc.pp @@ -70,9 +70,9 @@ } if $promisc { - case $::operatingsystem { + case $::os['name'] { /^(RedHat|CentOS|OEL|OracleLinux|SLC|Scientific)$/: { - case $::operatingsystemmajrelease { + case $::os['release']['major'] { '5': { $ifup_source = "puppet:///modules/${module_name}/promisc/ifup-local-promisc_5" $ifdown_source = "puppet:///modules/${module_name}/promisc/ifdown-local-promisc_5" diff --git a/manifests/init.pp b/manifests/init.pp index 517507b0..32c5ae10 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -24,7 +24,7 @@ # class network { # Only run on RedHat derived systems. - case $::osfamily { + case $::os['family'] { 'RedHat': { } default: { fail('This network module only supports RedHat-based systems.') diff --git a/spec/classes/network_global_spec.rb b/spec/classes/network_global_spec.rb index 52318527..e254fdf9 100644 --- a/spec/classes/network_global_spec.rb +++ b/spec/classes/network_global_spec.rb @@ -6,7 +6,7 @@ context 'on a non-supported operatingsystem' do let :facts do { - :osfamily => 'foo', + :os => { :family => 'foo' } } end it 'should fail' do @@ -19,10 +19,14 @@ context 'on a supported operatingsystem, default parameters' do let(:params) {{}} let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '7.0', - :fqdn => 'localhost.localdomain', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '7', + } + }, + :fqdn => 'localhost.localdomain', } end it { should contain_class('network') } @@ -51,10 +55,14 @@ :restart => false }} let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '7.0', - :fqdn => 'localhost.localdomain', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '7', + } + }, + :fqdn => 'localhost.localdomain', } end it { should contain_class('network') } @@ -87,10 +95,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '7.0', - :fqdn => 'localhost.localdomain', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '7', + } + }, + :fqdn => 'localhost.localdomain', } end it 'should contain File[network.sysconfig] with correct contents' do @@ -119,10 +131,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :fqdn => 'localhost.localdomain', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, + :fqdn => 'localhost.localdomain', } end it 'should contain File[network.sysconfig] with correct contents' do @@ -134,7 +150,7 @@ end context 'on a supported operatingsystem, bad parameters' do - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} context 'gateway = foo' do let(:params) {{ :gateway => 'foo' }} @@ -213,10 +229,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :fqdn => 'localhost.localdomain', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, + :fqdn => 'localhost.localdomain', } end it 'should contain File[network.sysconfig] with correct contents' do diff --git a/spec/classes/network_init_spec.rb b/spec/classes/network_init_spec.rb index c44d4165..2f44bf1f 100644 --- a/spec/classes/network_init_spec.rb +++ b/spec/classes/network_init_spec.rb @@ -5,7 +5,7 @@ describe 'network', :type => 'class' do context 'on a non-supported operatingsystem' do - let(:facts) {{ :osfamily => 'foo' }} + let(:facts) {{ :os => { :family => 'foo' }}} it 'should fail' do expect { @@ -15,7 +15,7 @@ end context 'on a supported operatingsystem' do - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} it { should contain_service('network').with( :ensure => 'running', diff --git a/spec/defines/network_alias_range_spec.rb b/spec/defines/network_alias_range_spec.rb index 74b587e0..4dcc2d13 100644 --- a/spec/defines/network_alias_range_spec.rb +++ b/spec/defines/network_alias_range_spec.rb @@ -57,7 +57,7 @@ :clonenum_start => '3', } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} it { should contain_file('ifcfg-eth99-range3').with( :ensure => 'present', :mode => '0644', @@ -91,7 +91,7 @@ :restart => false, } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} it { should contain_file('ifcfg-eth99-range3').with( :ensure => 'present', :mode => '0644', @@ -124,7 +124,7 @@ :noaliasrouting => true, } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} it { should contain_file('ifcfg-bond7-range9').with( :ensure => 'present', :mode => '0644', @@ -156,7 +156,7 @@ :clonenum_start => '9', } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} it { should contain_file('ifcfg-bond6-range9').with( :ensure => 'absent', :path => '/etc/sysconfig/network-scripts/ifcfg-bond6-range9', @@ -179,7 +179,7 @@ :arpcheck => false, } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} it { should contain_file('ifcfg-eth8-range9').with( :ensure => 'present', :mode => '0644', diff --git a/spec/defines/network_alias_spec.rb b/spec/defines/network_alias_spec.rb index ca8cda73..1545df6d 100644 --- a/spec/defines/network_alias_spec.rb +++ b/spec/defines/network_alias_spec.rb @@ -38,7 +38,7 @@ :netmask => '255.255.255.0', } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} it { should contain_file('ifcfg-bond2:1').with( :ensure => 'present', :mode => '0644', @@ -75,7 +75,7 @@ :zone => 'trusted', } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} it { should contain_file('ifcfg-bond3:2').with( :ensure => 'present', :mode => '0644', diff --git a/spec/defines/network_bond_bridge_spec.rb b/spec/defines/network_bond_bridge_spec.rb index 2036d073..e2732ba1 100644 --- a/spec/defines/network_bond_bridge_spec.rb +++ b/spec/defines/network_bond_bridge_spec.rb @@ -24,9 +24,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, :networking => { :interfaces => { :bond0 => { @@ -63,12 +67,16 @@ context 'on an older operatingsystem with /etc/modprobe.conf' do (['RedHat', 'CentOS', 'OEL', 'OracleLinux', 'SLC', 'Scientific']).each do |os| context "for operatingsystem #{os}" do - (['4.8', '5.9']).each do |osv| + (['4', '5']).each do |osv| context "for operatingsystemrelease #{osv}" do let :facts do { - :osfamily => 'RedHat', - :operatingsystem => os, - :operatingsystemrelease => osv, + :os => { + :family => 'RedHat', + :name => os, + :release => { + :major => osv + } + } } end it { should contain_augeas('modprobe.conf_bond0').with( @@ -86,9 +94,13 @@ (['6', '9', '11']).each do |osv| context "for operatingsystemrelease #{osv}" do let :facts do { - :osfamily => 'RedHat', - :operatingsystem => os, - :operatingsystemrelease => osv, + :os => { + :family => 'RedHat', + :name => os, + :release => { + :major => osv + } + } } end it { should contain_augeas('modprobe.conf_bond0').with( @@ -114,9 +126,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0' + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + } } end it { should contain_file('ifcfg-bond0').with( diff --git a/spec/defines/network_bond_dynamic_spec.rb b/spec/defines/network_bond_dynamic_spec.rb index f8559076..2872d33e 100644 --- a/spec/defines/network_bond_dynamic_spec.rb +++ b/spec/defines/network_bond_dynamic_spec.rb @@ -22,9 +22,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6' + } + }, :networking => { :interfaces => { :bond2 => { @@ -59,12 +63,16 @@ context 'on an older operatingsystem with /etc/modprobe.conf' do (['RedHat', 'CentOS', 'OEL', 'OracleLinux', 'SLC', 'Scientific']).each do |os| context "for operatingsystem #{os}" do - (['4.8', '5.9']).each do |osv| + (['4', '5']).each do |osv| context "for operatingsystemrelease #{osv}" do let :facts do { - :osfamily => 'RedHat', - :operatingsystem => os, - :operatingsystemrelease => osv, + :os => { + :family => 'RedHat', + :name => os, + :release => { + :major => osv + } + } } end it { should contain_augeas('modprobe.conf_bond2').with( @@ -82,9 +90,13 @@ (['6', '9', '11']).each do |osv| context "for operatingsystemrelease #{osv}" do let :facts do { - :osfamily => 'RedHat', - :operatingsystem => os, - :operatingsystemrelease => osv, + :os => { + :family => 'RedHat', + :name => os, + :release => { + :major => osv + } + } } end it { should contain_augeas('modprobe.conf_bond2').with( @@ -112,9 +124,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, :networking => { :interfaces => { :bond2 => { diff --git a/spec/defines/network_bond_slave_spec.rb b/spec/defines/network_bond_slave_spec.rb index b567e129..44cef221 100644 --- a/spec/defines/network_bond_slave_spec.rb +++ b/spec/defines/network_bond_slave_spec.rb @@ -24,9 +24,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, :networking => { :interfaces => { :eth1 => { @@ -67,7 +71,13 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, :networking => { :interfaces => { :eth1 => { @@ -112,9 +122,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, :networking => { :interfaces => { :eth3 => { diff --git a/spec/defines/network_bond_spec.rb b/spec/defines/network_bond_spec.rb index 7e41786c..c65285ca 100644 --- a/spec/defines/network_bond_spec.rb +++ b/spec/defines/network_bond_spec.rb @@ -22,9 +22,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, :networking => { :interfaces => { :bond0 => { @@ -59,12 +63,16 @@ context 'on an older operatingsystem with /etc/modprobe.conf' do (['RedHat', 'CentOS', 'OEL', 'OracleLinux', 'SLC', 'Scientific']).each do |os| context "for operatingsystem #{os}" do - (['4.8', '5.9']).each do |osv| + (['4', '5']).each do |osv| context "for operatingsystemrelease #{osv}" do let :facts do { - :osfamily => 'RedHat', - :operatingsystem => os, - :operatingsystemrelease => osv, + :os => { + :family => 'RedHat', + :name => os, + :release => { + :major => osv + } + } } end it { should contain_augeas('modprobe.conf_bond0').with( @@ -82,9 +90,13 @@ (['6', '9', '11']).each do |osv| context "for operatingsystemrelease #{osv}" do let :facts do { - :osfamily => 'RedHat', - :operatingsystem => os, - :operatingsystemrelease => osv, + :os => { + :family => 'RedHat', + :name => os, + :release => { + :major => osv + } + } } end it { should contain_augeas('modprobe.conf_bond0').with( @@ -110,9 +122,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0' + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + } } end it { should contain_file('ifcfg-bond0').with( diff --git a/spec/defines/network_bond_static_spec.rb b/spec/defines/network_bond_static_spec.rb index 71801282..d404ed33 100644 --- a/spec/defines/network_bond_static_spec.rb +++ b/spec/defines/network_bond_static_spec.rb @@ -53,9 +53,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, :networking => { :interfaces => { :bond0 => { @@ -93,12 +97,16 @@ context 'on an older operatingsystem with /etc/modprobe.conf' do (['RedHat', 'CentOS', 'OEL', 'OracleLinux', 'SLC', 'Scientific']).each do |os| context "for operatingsystem #{os}" do - (['4.8', '5.9']).each do |osv| + (['4', '5']).each do |osv| context "for operatingsystemrelease #{osv}" do let :facts do { - :osfamily => 'RedHat', - :operatingsystem => os, - :operatingsystemrelease => osv, + :os => { + :family => 'RedHat', + :name => os, + :release => { + :major => osv + } + } } end it { should contain_augeas('modprobe.conf_bond0').with( @@ -116,9 +124,13 @@ (['6', '9', '11']).each do |osv| context "for operatingsystemrelease #{osv}" do let :facts do { - :osfamily => 'RedHat', - :operatingsystem => os, - :operatingsystemrelease => osv, + :os => { + :family => 'RedHat', + :name => os, + :release => { + :major => osv + } + } } end it { should contain_augeas('modprobe.conf_bond0').with( @@ -158,9 +170,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0' + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + } } end it { should contain_file('ifcfg-bond0').with( diff --git a/spec/defines/network_bridge_dynamic_spec.rb b/spec/defines/network_bridge_dynamic_spec.rb index 8c5faf16..84664113 100644 --- a/spec/defines/network_bridge_dynamic_spec.rb +++ b/spec/defines/network_bridge_dynamic_spec.rb @@ -34,7 +34,13 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + } } end it { should contain_file('ifcfg-br1').with( @@ -70,7 +76,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + } } end it { should contain_file('ifcfg-br1').with( @@ -109,7 +117,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + } } end it { should contain_file('ifcfg-br1').with( diff --git a/spec/defines/network_bridge_spec.rb b/spec/defines/network_bridge_spec.rb index 87857e59..cd90d6e8 100644 --- a/spec/defines/network_bridge_spec.rb +++ b/spec/defines/network_bridge_spec.rb @@ -34,7 +34,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + } } end it { should contain_file('ifcfg-br1').with( @@ -70,7 +72,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + } } end it { should contain_file('ifcfg-br1').with( @@ -108,7 +112,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + } } end it { should contain_file('ifcfg-br1').with( diff --git a/spec/defines/network_bridge_static_spec.rb b/spec/defines/network_bridge_static_spec.rb index 8cb87022..00d2942a 100644 --- a/spec/defines/network_bridge_static_spec.rb +++ b/spec/defines/network_bridge_static_spec.rb @@ -81,7 +81,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + } } end it { should contain_file('ifcfg-br1').with( @@ -119,7 +121,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + } } end it { should contain_file('ifcfg-br1').with( @@ -169,7 +173,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + } } end it { should contain_file('ifcfg-br1').with( diff --git a/spec/defines/network_if_bridge_spec.rb b/spec/defines/network_if_bridge_spec.rb index 9ca5f273..ec24ef4c 100644 --- a/spec/defines/network_if_bridge_spec.rb +++ b/spec/defines/network_if_bridge_spec.rb @@ -24,7 +24,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + }, :networking => { :interfaces => { :eth1 => { @@ -68,7 +70,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + }, :networking => { :interfaces => { :eth1 => { diff --git a/spec/defines/network_if_dynamic_spec.rb b/spec/defines/network_if_dynamic_spec.rb index 42dc1a51..599be0ac 100644 --- a/spec/defines/network_if_dynamic_spec.rb +++ b/spec/defines/network_if_dynamic_spec.rb @@ -22,7 +22,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + }, :networking => { :interfaces => { :eth99 => { @@ -73,7 +75,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + }, :networking => { :interfaces => { :eth99 => { @@ -117,7 +121,9 @@ let(:title) { 'eth45.302' } let(:params) {{ :ensure => 'up' }} let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + }, :networking => { :interfaces => { :eth45 => { @@ -157,7 +163,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + }, :networking => { :interfaces => { :eth0 => { diff --git a/spec/defines/network_if_promisc_spec.rb b/spec/defines/network_if_promisc_spec.rb index b5b8e198..adac4dd3 100644 --- a/spec/defines/network_if_promisc_spec.rb +++ b/spec/defines/network_if_promisc_spec.rb @@ -11,10 +11,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :operatingsystemmajrelease => '6', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, :networking => { :interfaces => { :eth1 => { @@ -74,10 +77,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :operatingsystemmajrelease => '6', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, :networking => { :interfaces => { :eth3 => { diff --git a/spec/defines/network_if_spec.rb b/spec/defines/network_if_spec.rb index a42e1919..2a77da88 100644 --- a/spec/defines/network_if_spec.rb +++ b/spec/defines/network_if_spec.rb @@ -22,9 +22,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, :networking => { :interfaces => { :eth0 => { @@ -65,9 +69,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, :networking => { :interfaces => { :eth0 => { diff --git a/spec/defines/network_if_static_spec.rb b/spec/defines/network_if_static_spec.rb index 06079420..9f7cd855 100644 --- a/spec/defines/network_if_static_spec.rb +++ b/spec/defines/network_if_static_spec.rb @@ -72,7 +72,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + }, :networking => { :interfaces => { :eth1 => { @@ -118,7 +120,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + }, :networking => { :interfaces => { :eth1 => { @@ -182,7 +186,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + }, :networking => { :interfaces => { :eth1 => { @@ -244,7 +250,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + }, :networking => { :interfaces => { :eth6 => { @@ -288,7 +296,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + }, :networking => { :interfaces => { :eth0 => { @@ -331,7 +341,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + }, :networking => { :interfaces => { :eth1 => { @@ -357,7 +369,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + }, :networking => { :interfaces => { :eth1 => { @@ -409,7 +423,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + }, :networking => { :interfaces => { :eth1 => { diff --git a/spec/defines/network_route_spec.rb b/spec/defines/network_route_spec.rb index 8908418a..36e5c317 100644 --- a/spec/defines/network_route_spec.rb +++ b/spec/defines/network_route_spec.rb @@ -13,7 +13,12 @@ :gateway => [ '192.168.1.2', ], } end - let(:facts) {{ :osfamily => 'RedHat' }} + let :facts do { + :os => { + :family => 'RedHat' + } + } + end it { should contain_file('route-eth1').with( :ensure => 'present', :mode => '0644', @@ -42,7 +47,12 @@ :restart => false, } end - let(:facts) {{ :osfamily => 'RedHat' }} + let :facts do { + :os => { + :family => 'RedHat' + } + } + end it { should contain_file('route-eth1').with( :ensure => 'present', :mode => '0644', @@ -70,7 +80,12 @@ :gateway => [ '192.168.1.1', '10.0.0.1', ] } end - let(:facts) {{ :osfamily => 'RedHat' }} + let :facts do { + :os => { + :family => 'RedHat' + } + } + end it { should contain_file('route-eth2').with( :ensure => 'present', :mode => '0644', From 4fc403be6e5cf68b9081da7c7d95b8f46e355265 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Tue, 20 Feb 2018 00:46:07 +0800 Subject: [PATCH 30/50] Remove rspec output truncation hack Because it makes rspec fail with some versions. --- spec/spec_helper.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 810c2dd1..2c6f5664 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1 @@ require 'puppetlabs_spec_helper/module_spec_helper' - -# Prevent output truncation (useful for debugging) -RSpec::Support::ObjectFormatter.default_instance.max_formatted_output_length = 999 From 03c72f512e5e7353b14dd7dc4a4d63b108669ecc Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Tue, 20 Feb 2018 00:50:37 +0800 Subject: [PATCH 31/50] Tests: no longer allow failures for Puppet 5 --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6a63c6cd..28d5712c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,9 +18,6 @@ matrix: env: PUPPET_GEM_VERSION="~> 4.0" - rvm: 2.4.1 env: PUPPET_GEM_VERSION="~> 5.0" - allow_failures: - - rvm: 2.4.1 - env: PUPPET_GEM_VERSION="~> 5.0" notifications: email: - github@razorsedge.org From 0834c90b13175c98f84ed6ccd83aad3c6ea09225 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Tue, 20 Feb 2018 01:05:39 +0800 Subject: [PATCH 32/50] Fix tests for Puppet 4 Of course, Puppet 4 and Puppet 5 have different messages for the same errors! --- spec/defines/network_bond_static_spec.rb | 2 +- spec/defines/network_bridge_static_spec.rb | 2 +- spec/defines/network_if_static_spec.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/defines/network_bond_static_spec.rb b/spec/defines/network_bond_static_spec.rb index d404ed33..8371d4ee 100644 --- a/spec/defines/network_bond_static_spec.rb +++ b/spec/defines/network_bond_static_spec.rb @@ -40,7 +40,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /expects an IP::Address::V6 /) + expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /(expects an IP::Address::V6 |expects a match for Variant\[IP::Address::V6::Full .*, IP::Address::V6::Compressed)/) end end diff --git a/spec/defines/network_bridge_static_spec.rb b/spec/defines/network_bridge_static_spec.rb index 00d2942a..d55f0732 100644 --- a/spec/defines/network_bridge_static_spec.rb +++ b/spec/defines/network_bridge_static_spec.rb @@ -40,7 +40,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, / expects an IP::Address::V6 /) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /(expects an IP::Address::V6 |expects a match for Variant\[IP::Address::V6::Full .*, IP::Address::V6::Compressed)/) end end diff --git a/spec/defines/network_if_static_spec.rb b/spec/defines/network_if_static_spec.rb index 9f7cd855..4f4058c9 100644 --- a/spec/defines/network_if_static_spec.rb +++ b/spec/defines/network_if_static_spec.rb @@ -27,7 +27,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /expects a value of type Undef, IP::Address::V6/) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /(expects a value of type Undef, IP::Address::V6|expects a match for Variant\[IP::Address::V6::Full .*, IP::Address::V6::Compressed)/) end end @@ -41,7 +41,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /expects a value of type Undef, IP::Address::V6/) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /(expects a value of type Undef, IP::Address::V6|expects a match for Variant\[IP::Address::V6::Full .*, IP::Address::V6::Compressed)/) end end @@ -59,7 +59,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /expects an IP::Address::V6/) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /(expects an IP::Address::V6 |expects a match for Variant\[IP::Address::V6::Full .*, IP::Address::V6::Compressed)/) end end From 4b69ddef3acad8e52bd028d31a5a87e357d8e587 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Tue, 20 Feb 2018 01:14:34 +0800 Subject: [PATCH 33/50] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 055b9d87..a64a68da 100644 --- a/README.md +++ b/README.md @@ -322,7 +322,7 @@ The Hiera naming substitutes underscore for any secondary double colons, i.e. sp Notes ----- -* Runs under Puppet 2.7 and later. +* Runs under Puppet 4.9 and later. * Only works with RedHat-ish systems. * Read /usr/share/doc/initscripts-*/sysconfig.txt for underlying details. * Read /usr/share/doc/kernel-doc-*/Documentation/networking/bonding.txt for underlying details. From 44b0ef47e98995fc6a466295ba901babad3bf216 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Tue, 20 Feb 2018 09:54:01 +0800 Subject: [PATCH 34/50] Use EPP in network::route --- manifests/route.pp | 6 +++++- templates/route-eth.epp | 12 ++++++++++++ templates/route-eth.erb | 12 ------------ 3 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 templates/route-eth.epp delete mode 100644 templates/route-eth.erb diff --git a/manifests/route.pp b/manifests/route.pp index a30441ac..a8034569 100644 --- a/manifests/route.pp +++ b/manifests/route.pp @@ -57,7 +57,11 @@ owner => 'root', group => 'root', path => "/etc/sysconfig/network-scripts/route-${interface}", - content => template('network/route-eth.erb'), + content => epp("${module_name}/route-eth.epp", { + ipaddress => $ipaddress, + netmask => $netmask, + gateway => $gateway, + }), before => File["ifcfg-${interface}"], } diff --git a/templates/route-eth.epp b/templates/route-eth.epp new file mode 100644 index 00000000..af0da8a3 --- /dev/null +++ b/templates/route-eth.epp @@ -0,0 +1,12 @@ +### +### File managed by Puppet +### +<% $ipaddress.each |$index, $item| { -%> +ADDRESS<%= $index %>=<%= $item %> +<% } -%> +<% $netmask.each |$index, $item| { -%> +NETMASK<%= $index %>=<%= $item %> +<% } -%> +<% $gateway.each |$index, $item| { -%> +GATEWAY<%= $index %>=<%= $item %> +<% } -%> diff --git a/templates/route-eth.erb b/templates/route-eth.erb deleted file mode 100644 index 237df750..00000000 --- a/templates/route-eth.erb +++ /dev/null @@ -1,12 +0,0 @@ -### -### File managed by Puppet -### -<% num = 0; @ipaddress.each do |addr| -%> -ADDRESS<%= num %>=<%= addr %> -<% num += 1; end -%> -<% num = 0; @netmask.each do |mask| -%> -NETMASK<%= num %>=<%= mask %> -<% num += 1; end -%> -<% num = 0; @gateway.each do |gw| -%> -GATEWAY<%= num %>=<%= gw %> -<% num += 1; end -%> From 086ed5c6696d317a7b071084eff31d066cedf1ab Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Tue, 20 Feb 2018 10:43:55 +0800 Subject: [PATCH 35/50] Use EPP in network_if_base for ifcfg-alias --- manifests/init.pp | 14 +++++++++++++- templates/ifcfg-alias.epp | 16 ++++++++++++++++ templates/ifcfg-alias.erb | 25 ------------------------- 3 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 templates/ifcfg-alias.epp delete mode 100644 templates/ifcfg-alias.erb diff --git a/manifests/init.pp b/manifests/init.pp index 32c5ae10..9f9f58fa 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -166,7 +166,19 @@ 'down' => 'no', default => undef, } - $iftemplate = template('network/ifcfg-alias.erb') + $iftemplate = epp("${module_name}/ifcfg-alias.epp", { + interface => $interface, + bootproto => $bootproto, + onparent => $onparent, + ipaddress => $ipaddress, + netmask => $netmask, + gateway => $gateway, + ipv6address => $ipv6address, + noaliasrouting => $noaliasrouting, + userctl => $userctl, + zone => $zone, + metric => $metric, + }) } else { $onboot = $ensure ? { 'up' => 'yes', diff --git a/templates/ifcfg-alias.epp b/templates/ifcfg-alias.epp new file mode 100644 index 00000000..0f239957 --- /dev/null +++ b/templates/ifcfg-alias.epp @@ -0,0 +1,16 @@ +### +### File managed by Puppet +### +DEVICE=<%= $interface %> +BOOTPROTO=<%= $bootproto %> +ONPARENT=<%= $onparent %> +TYPE=Ethernet +<% if $ipaddress { %>IPADDR=<%= $ipaddress %><% } %> +<% if $netmask { %>NETMASK=<%= $netmask %><% } %> +<% if $gateway { %>GATEWAY=<%= $gateway %><% } %> +<% if $ipv6address { %>IPV6ADDR=<%= $ipv6address %><% } %> +NO_ALIASROUTING=<%= bool2str($noaliasrouting, 'yes', 'no') %> +<% if $userctl { %>USERCTL=yes<% } %> +<% if $zone { %>ZONE=<%= $zone %><% } %> +<% if $metric { %>METRIC=<%= $metric %><% } %> +NM_CONTROLLED=no diff --git a/templates/ifcfg-alias.erb b/templates/ifcfg-alias.erb deleted file mode 100644 index 3961edbd..00000000 --- a/templates/ifcfg-alias.erb +++ /dev/null @@ -1,25 +0,0 @@ -### -### File managed by Puppet -### -DEVICE=<%= @interface %> -BOOTPROTO=<%= @bootproto %> -ONPARENT=<%= @onparent %> -TYPE=Ethernet -<% if @ipaddress %>IPADDR=<%= @ipaddress %> -<% end -%> -<% if @netmask %>NETMASK=<%= @netmask %> -<% end -%> -<% if @gateway %>GATEWAY=<%= @gateway %> -<% end -%> -<% if @ipv6address %>IPV6ADDR=<%= @ipv6address %> -<% end -%> -<% if !@noaliasrouting %>NO_ALIASROUTING=no -<% else %>NO_ALIASROUTING=yes -<% end -%> -<% if @userctl %>USERCTL=yes -<% end -%> -<% if @zone %>ZONE=<%= @zone %> -<% end -%> -<% if @metric %>METRIC=<%= @metric %> -<% end -%> -NM_CONTROLLED=no From 81c922cb5ba3b74b42cefcde704c0476a6073350 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Tue, 20 Feb 2018 10:50:33 +0800 Subject: [PATCH 36/50] Use EPP in network::alias::range --- manifests/alias/range.pp | 11 ++++++++++- templates/ifcfg-alias-range.epp | 12 ++++++++++++ templates/ifcfg-alias-range.erb | 17 ----------------- 3 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 templates/ifcfg-alias-range.epp delete mode 100644 templates/ifcfg-alias-range.erb diff --git a/manifests/alias/range.pp b/manifests/alias/range.pp index 2e21deb4..652401c7 100644 --- a/manifests/alias/range.pp +++ b/manifests/alias/range.pp @@ -70,7 +70,16 @@ owner => 'root', group => 'root', path => "/etc/sysconfig/network-scripts/ifcfg-${interface}-range${clonenum_start}", - content => template('network/ifcfg-alias-range.erb'), + content => epp("${module_name}/ifcfg-alias-range.epp", { + ipaddress_start => $ipaddress_start, + ipaddress_end => $ipaddress_end, + clonenum_start => $clonenum_start, + noaliasrouting => $noaliasrouting, + netmask => $netmask, + broadcast => $broadcast, + arpcheck => $arpcheck, + onparent => $onparent, + }), before => File["ifcfg-${interface}"], } diff --git a/templates/ifcfg-alias-range.epp b/templates/ifcfg-alias-range.epp new file mode 100644 index 00000000..2ceee0f2 --- /dev/null +++ b/templates/ifcfg-alias-range.epp @@ -0,0 +1,12 @@ +### +### File managed by Puppet +### +IPADDR_START=<%= $ipaddress_start %> +IPADDR_END=<%= $ipaddress_end %> +CLONENUM_START=<%= $clonenum_start %> +NO_ALIASROUTING=<%= bool2str($noaliasrouting, 'yes', 'no') %> +<% if $netmask { %>NETMASK=<%= $netmask %><% } %> +<% if $broadcast { %>BROADCAST=<%= $broadcast %><% } %> +<% if !$arpcheck { %>ARPCHECK=no<% } %> +ONPARENT=<%= $onparent %> +NM_CONTROLLED=no diff --git a/templates/ifcfg-alias-range.erb b/templates/ifcfg-alias-range.erb deleted file mode 100644 index 018f55ee..00000000 --- a/templates/ifcfg-alias-range.erb +++ /dev/null @@ -1,17 +0,0 @@ -### -### File managed by Puppet -### -IPADDR_START=<%= @ipaddress_start %> -IPADDR_END=<%= @ipaddress_end %> -CLONENUM_START=<%= @clonenum_start %> -<% if !@noaliasrouting %>NO_ALIASROUTING=no -<% else %>NO_ALIASROUTING=yes -<% end -%> -<% if @netmask %>NETMASK=<%= @netmask %> -<% end -%> -<% if @broadcast %>BROADCAST=<%= @broadcast %> -<% end -%> -<% if !@arpcheck %>ARPCHECK=no -<% end -%> -ONPARENT=<%= @onparent %> -NM_CONTROLLED=no From a2e133b29ce17f421c49bbd10532dc3a78ec9792 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Tue, 20 Feb 2018 11:08:05 +0800 Subject: [PATCH 37/50] Use EPP in network::bond::slave --- manifests/bond/slave.pp | 13 ++++++++++++- templates/ifcfg-bond.epp | 16 ++++++++++++++++ templates/ifcfg-bond.erb | 24 ------------------------ 3 files changed, 28 insertions(+), 25 deletions(-) create mode 100644 templates/ifcfg-bond.epp delete mode 100644 templates/ifcfg-bond.erb diff --git a/manifests/bond/slave.pp b/manifests/bond/slave.pp index 42136941..e6b90370 100644 --- a/manifests/bond/slave.pp +++ b/manifests/bond/slave.pp @@ -61,7 +61,18 @@ owner => 'root', group => 'root', path => "/etc/sysconfig/network-scripts/ifcfg-${interface}", - content => template('network/ifcfg-bond.erb'), + content => epp("${module_name}/ifcfg-bond.epp", { + interface => $interface, + macaddress => $macaddress, + master => $master, + ethtool_opts => $ethtool_opts, + defroute => $defroute, + zone => $zone, + metric => $metric, + bootproto => $bootproto, + onboot => $onboot, + userctl => $userctl, + }), before => File["ifcfg-${master}"], } diff --git a/templates/ifcfg-bond.epp b/templates/ifcfg-bond.epp new file mode 100644 index 00000000..0305543b --- /dev/null +++ b/templates/ifcfg-bond.epp @@ -0,0 +1,16 @@ +### +### File managed by Puppet +### +DEVICE=<%= $interface %> +<% if $macaddress { %>HWADDR=<%= $macaddress %><% } %> +MASTER=<%= $master %> +SLAVE=yes +TYPE=Ethernet +<% if $ethtool_opts { %>ETHTOOL_OPTS="<%= $ethtool_opts %>"<% } %> +<% if $defroute { %>DEFROUTE=<%= $defroute %><% } %> +<% if $zone { %>ZONE=<%= $zone %><% } %> +<% if $metric { %>METRIC=<%= $metric %><% } %> +<% if $bootproto { %>BOOTPROTO=<%= $bootproto %><% } %> +<% if $onboot { %>ONBOOT=<%= $onboot %><% } %> +<% if $userctl { %>USERCTL=yes<% } %> +NM_CONTROLLED=no diff --git a/templates/ifcfg-bond.erb b/templates/ifcfg-bond.erb deleted file mode 100644 index 3055d476..00000000 --- a/templates/ifcfg-bond.erb +++ /dev/null @@ -1,24 +0,0 @@ -### -### File managed by Puppet -### -DEVICE=<%= @interface %> -<% if @macaddress and @macaddress != '' %>HWADDR=<%= @macaddress %> -<% end -%> -MASTER=<%= @master %> -SLAVE=yes -TYPE=Ethernet -<% if @ethtool_opts %>ETHTOOL_OPTS="<%= @ethtool_opts %>" -<% end -%> -<% if @defroute %>DEFROUTE=<%= @defroute %> -<% end -%> -<% if @zone %>ZONE=<%= @zone %> -<% end -%> -<% if @metric %>METRIC=<%= @metric %> -<% end -%> -<% if @bootproto %>BOOTPROTO=<%= @bootproto %> -<% end -%> -<% if @onboot %>ONBOOT=<%= @onboot %> -<% end -%> -<% if @userctl %>USERCTL=yes -<% end -%> -NM_CONTROLLED=no From 7db97fa803ad0af85661febf8dbc212c643ff58c Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Tue, 20 Feb 2018 16:37:26 +0800 Subject: [PATCH 38/50] Use EPP in network::bridge 3 defines were using the same template, because of code duplication. As I had to update all 3 for this commit, I chose to re-use network::bridge in network::bridge::dynamic and network::bridge::static, thus removing previous code duplication. --- manifests/bridge.pp | 68 ++++++++++++++++++++++++++++++++----- manifests/bridge/dynamic.pp | 38 +++++---------------- manifests/bridge/static.pp | 61 ++++++++++++--------------------- templates/ifcfg-br.epp | 26 ++++++++++++++ templates/ifcfg-br.erb | 41 ---------------------- 5 files changed, 115 insertions(+), 119 deletions(-) create mode 100644 templates/ifcfg-br.epp delete mode 100644 templates/ifcfg-br.erb diff --git a/manifests/bridge.pp b/manifests/bridge.pp index 2f6998fb..1bf8ed32 100644 --- a/manifests/bridge.pp +++ b/manifests/bridge.pp @@ -5,10 +5,23 @@ # === Parameters: # # $ensure - required - up|down +# $ipaddress - optional +# $netmask - optional +# $gateway - optional +# $ipv6address - optional +# $ipv6gateway - optional +# $bootproto - optional - defaults to 'none' # $userctl - optional - defaults to false # $stp - optional - defaults to false # $delay - optional - defaults to 30 # $bridging_opts - optional +# $scope - optional +# $peerdns - optional - dedaults to false +# $ipv6init - optional - defaults to false +# $ipv6peerdns - optional - defaults to false +# $dns1 - optional +# $dns2 - optional +# $domain - optional # $restart - optional - defaults to true # # === Actions: @@ -34,11 +47,23 @@ # define network::bridge ( Enum['up', 'down'] $ensure, + Optional[IP::Address::V4::NoSubnet] $ipaddress = undef, + Optional[IP::Address::V4::NoSubnet] $netmask = undef, + Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Optional[IP::Address::V6] $ipv6address = undef, + Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Network::If::Bootproto $bootproto = 'none', Boolean $userctl = false, Boolean $stp = false, String $delay = '30', Optional[String] $bridging_opts = undef, + Optional[String] $scope = undef, + Boolean $peerdns = false, Boolean $ipv6init = false, + Boolean $ipv6peerdns = false, + Optional[IP::Address::NoSubnet] $dns1 = undef, + Optional[IP::Address::NoSubnet] $dns2 = undef, + Optional[String] $domain = undef, Boolean $restart = true, ) { @@ -47,26 +72,53 @@ include '::network' $interface = $name - $bootproto = 'none' - $ipaddress = undef - $netmask = undef - $gateway = undef - $ipv6address = undef - $ipv6gateway = undef - $onboot = $ensure ? { 'up' => 'yes', 'down' => 'no', default => undef, } + # Deal with the case where $dns2 is non-empty and $dns1 is empty. + if $dns2 { + if !$dns1 { + $dns1_real = $dns2 + $dns2_real = undef + } else { + $dns1_real = $dns1 + $dns2_real = $dns2 + } + } else { + $dns1_real = $dns1 + $dns2_real = $dns2 + } + file { "ifcfg-${interface}": ensure => 'present', mode => '0644', owner => 'root', group => 'root', path => "/etc/sysconfig/network-scripts/ifcfg-${interface}", - content => template('network/ifcfg-br.erb'), + content => epp("${module_name}/ifcfg-br.epp", { + interface => $interface, + bootproto => $bootproto, + onboot => $onboot, + ipv6init => $ipv6init, + userctl => $userctl, + delay => $delay, + stp => $stp, + bridging_opts => $bridging_opts, + ipaddress => $ipaddress, + netmask => $netmask, + gateway => $gateway, + ipv6address => $ipv6address, + ipv6gateway => $ipv6gateway, + scope => $scope, + peerdns => $peerdns, + ipv6peerdns => $ipv6peerdns, + dns1 => $dns1_real, + dns2 => $dns2_real, + domain => $domain, + }), require => Package['bridge-utils'], } diff --git a/manifests/bridge/dynamic.pp b/manifests/bridge/dynamic.pp index 0d0f8ffc..42fd85e2 100644 --- a/manifests/bridge/dynamic.pp +++ b/manifests/bridge/dynamic.pp @@ -45,36 +45,14 @@ Boolean $restart = true, ) { - ensure_packages(['bridge-utils']) - - include '::network' - - $interface = $name - $ipaddress = undef - $netmask = undef - $gateway = undef - $ipv6address = undef - $ipv6gateway = undef - - $onboot = $ensure ? { - 'up' => 'yes', - 'down' => 'no', - default => undef, + network::bridge { $title: + ensure => $ensure, + bootproto => $bootproto, + userctl => $userctl, + stp => $stp, + delay => $delay, + bridging_opts => $bridging_opts, + restart => $restart, } - file { "ifcfg-${interface}": - ensure => 'present', - mode => '0644', - owner => 'root', - group => 'root', - path => "/etc/sysconfig/network-scripts/ifcfg-${interface}", - content => template('network/ifcfg-br.erb'), - require => Package['bridge-utils'], - } - - if $restart { - File["ifcfg-${interface}"] { - notify => Service['network'], - } - } } # define network::bridge::dynamic diff --git a/manifests/bridge/static.pp b/manifests/bridge/static.pp index 1bb62839..146cd3b1 100644 --- a/manifests/bridge/static.pp +++ b/manifests/bridge/static.pp @@ -11,7 +11,7 @@ # $ipv6address - optional # $ipv6gateway - optional # $userctl - optional - defaults to false -# $peerdns - optional +# $peerdns - optional - defaults to false # $ipv6init - optional - defaults to false # $ipv6peerdns - optional - defaults to false # $dns1 - optional @@ -71,45 +71,26 @@ Boolean $restart = true, ) { - ensure_packages(['bridge-utils']) - - include '::network' - - $interface = $name - - # Deal with the case where $dns2 is non-empty and $dns1 is empty. - if $dns2 { - if !$dns1 { - $dns1_real = $dns2 - $dns2_real = undef - } else { - $dns1_real = $dns1 - $dns2_real = $dns2 - } - } else { - $dns1_real = $dns1 - $dns2_real = $dns2 - } - - $onboot = $ensure ? { - 'up' => 'yes', - 'down' => 'no', - default => undef, - } - - file { "ifcfg-${interface}": - ensure => 'present', - mode => '0644', - owner => 'root', - group => 'root', - path => "/etc/sysconfig/network-scripts/ifcfg-${interface}", - content => template('network/ifcfg-br.erb'), - require => Package['bridge-utils'], + network::bridge { $title: + ensure => $ensure, + ipaddress => $ipaddress, + netmask => $netmask, + gateway => $gateway, + ipv6address => $ipv6address, + ipv6gateway => $ipv6gateway, + bootproto => $bootproto, + userctl => $userctl, + peerdns => $peerdns, + ipv6init => $ipv6init, + ipv6peerdns => $ipv6peerdns, + dns1 => $dns1, + dns2 => $dns2, + domain => $domain, + stp => $stp, + delay => $delay, + bridging_opts => $bridging_opts, + scope => $scope, + restart => $restart, } - if $restart { - File["ifcfg-${interface}"] { - notify => Service['network'], - } - } } # define network::bridge::static diff --git a/templates/ifcfg-br.epp b/templates/ifcfg-br.epp new file mode 100644 index 00000000..c6a0d388 --- /dev/null +++ b/templates/ifcfg-br.epp @@ -0,0 +1,26 @@ +### +### File managed by Puppet +### +DEVICE=<%= $interface %> +BOOTPROTO=<%= $bootproto %> +ONBOOT=<%= $onboot %> +TYPE=Bridge +<% if $ipaddress { %>IPADDR=<%= $ipaddress %><% } %> +<% if $netmask { %>NETMASK=<%= $netmask %><% } %> +<% if $gateway { %>GATEWAY=<%= $gateway %><% } %> +<%- if $ipv6init { -%> +IPV6INIT=yes +<% if $ipv6address { %>IPV6ADDR=<%= $ipv6address %><% } %> +<% if $ipv6gateway { %>IPV6_DEFAULTGW=<%= $ipv6gateway %><% } %> +<% if $ipv6peerdns { %>IPV6_PEERDNS=yes<% } %> +<%- } -%> +PEERDNS=<%= bool2str($peerdns, 'yes', 'no') %> +<% if $dns1 { %>DNS1=<%= $dns1 %><% } %> +<% if $dns2 { %>DNS2=<%= $dns2 %><% } %> +<% if $domain { %>DOMAIN="<%= $domain %>"<% } %> +<% if $userctl { %>USERCTL=yes<% } %> +DELAY=<%= $delay %> +STP=<%= bool2str($stp, 'yes', 'no') %> +<% if $bridging_opts { %>BRIDGING_OPTS="<%= $bridging_opts %>"<% } %> +<% if $scope { %>SCOPE="<%= $scope %>"<% } %> +NM_CONTROLLED=no diff --git a/templates/ifcfg-br.erb b/templates/ifcfg-br.erb deleted file mode 100644 index dfba2d6a..00000000 --- a/templates/ifcfg-br.erb +++ /dev/null @@ -1,41 +0,0 @@ -### -### File managed by Puppet -### -DEVICE=<%= @interface %> -BOOTPROTO=<%= @bootproto %> -ONBOOT=<%= @onboot %> -TYPE=Bridge -<% if @ipaddress %>IPADDR=<%= @ipaddress %> -<% end -%> -<% if @netmask %>NETMASK=<%= @netmask %> -<% end -%> -<% if @gateway %>GATEWAY=<%= @gateway %> -<% end -%> -<% if @ipv6init %>IPV6INIT=yes -<% if @ipv6address %>IPV6ADDR=<%= @ipv6address %> -<% end -%> -<% if @ipv6gateway %>IPV6_DEFAULTGW=<%= @ipv6gateway %> -<% end -%> -<% if @ipv6peerdns %>IPV6_PEERDNS=yes -<% end -%> -<% end -%> -<% if !@peerdns %>PEERDNS=no -<% else %>PEERDNS=yes -<% end -%> -<% if @dns1_real %>DNS1=<%= @dns1_real %> -<% end -%> -<% if @dns2_real %>DNS2=<%= @dns2_real %> -<% end -%> -<% if @domain %>DOMAIN="<%= @domain %>" -<% end -%> -<% if @userctl %>USERCTL=yes -<% end -%> -DELAY=<%= @delay %> -<% if !@stp %>STP=no -<% else %>STP=yes -<% end -%> -<% if @bridging_opts %>BRIDGING_OPTS="<%= @bridging_opts %>" -<% end -%> -<% if @scope %>SCOPE="<%= @scope %>" -<% end -%> -NM_CONTROLLED=no From 647e94f4b1493da7c9c5ac07becf6c1c66ee1834 Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Tue, 20 Feb 2018 17:18:40 +0800 Subject: [PATCH 39/50] Use EPP in network::global --- manifests/global.pp | 18 +++++++++++++++++- spec/classes/network_global_spec.rb | 10 +++++----- templates/network.epp | 16 ++++++++++++++++ templates/network.erb | 26 -------------------------- 4 files changed, 38 insertions(+), 32 deletions(-) create mode 100644 templates/network.epp delete mode 100644 templates/network.erb diff --git a/manifests/global.pp b/manifests/global.pp index 28fdc421..dec04f91 100644 --- a/manifests/global.pp +++ b/manifests/global.pp @@ -101,13 +101,29 @@ } } + $effective_hostname = $hostname ? { + String => $hostname, + default => $::networking['fqdn'], + } + file { 'network.sysconfig': ensure => 'present', mode => '0644', owner => 'root', group => 'root', path => '/etc/sysconfig/network', - content => template('network/network.erb'), + content => epp("${module_name}/network.epp", { + ipv6networking => $ipv6networking, + ipv6gateway => $ipv6gateway, + ipv6defaultdev => $ipv6defaultdev, + hostname => $effective_hostname, + gateway => $gateway, + gatewaydev => $gatewaydev, + nisdomain => $nisdomain, + vlan => $vlan, + nozeroconf => $nozeroconf, + requestreopen => $requestreopen, + }), } if $restart { diff --git a/spec/classes/network_global_spec.rb b/spec/classes/network_global_spec.rb index e254fdf9..9659ba35 100644 --- a/spec/classes/network_global_spec.rb +++ b/spec/classes/network_global_spec.rb @@ -26,7 +26,7 @@ :major => '7', } }, - :fqdn => 'localhost.localdomain', + :networking => { :fqdn => 'localhost.localdomain' } } end it { should contain_class('network') } @@ -62,7 +62,7 @@ :major => '7', } }, - :fqdn => 'localhost.localdomain', + :networking => { :fqdn => 'localhost.localdomain' } } end it { should contain_class('network') } @@ -102,7 +102,7 @@ :major => '7', } }, - :fqdn => 'localhost.localdomain', + :networking => { :fqdn => 'localhost.localdomain' } } end it 'should contain File[network.sysconfig] with correct contents' do @@ -138,7 +138,7 @@ :major => '6', } }, - :fqdn => 'localhost.localdomain', + :networking => { :fqdn => 'localhost.localdomain' } } end it 'should contain File[network.sysconfig] with correct contents' do @@ -236,7 +236,7 @@ :major => '6', } }, - :fqdn => 'localhost.localdomain', + :networking => { :fqdn => 'localhost.localdomain' } } end it 'should contain File[network.sysconfig] with correct contents' do diff --git a/templates/network.epp b/templates/network.epp new file mode 100644 index 00000000..e7f7b3c3 --- /dev/null +++ b/templates/network.epp @@ -0,0 +1,16 @@ +### +### File managed by Puppet +### +NETWORKING=yes +NETWORKING_IPV6=<%= bool2str($ipv6networking, 'yes', 'no') %> +<%- if $ipv6networking { -%> +<% if $ipv6gateway { %>IPV6_DEFAULTGW=<%= $ipv6gateway %><% } %> +<% if $ipv6defaultdev { %>IPV6_DEFAULTDEV=<%= $ipv6defaultdev %><% } %> +<% } -%> +HOSTNAME=<%= $hostname %> +<% if $gateway { %>GATEWAY=<%= $gateway %><% } %> +<% if $gatewaydev { %>GATEWAYDEV=<%= $gatewaydev %><% } %> +<% if $nisdomain { %>NISDOMAIN=<%= $nisdomain %><% } %> +<% if $vlan { %>VLAN=<%= $vlan %><% } %> +<% if $nozeroconf { %>NOZEROCONF=<%= $nozeroconf %><% } %> +<% if $requestreopen { %>RES_OPTIONS="single-request-reopen"<% } %> diff --git a/templates/network.erb b/templates/network.erb deleted file mode 100644 index d3ce54a4..00000000 --- a/templates/network.erb +++ /dev/null @@ -1,26 +0,0 @@ -### -### File managed by Puppet -### -NETWORKING=yes -<% if !@ipv6networking %>NETWORKING_IPV6=no -<% else %>NETWORKING_IPV6=yes -<% if @ipv6gateway %>IPV6_DEFAULTGW=<%= @ipv6gateway %> -<% end -%> -<% if @ipv6defaultdev %>IPV6_DEFAULTDEV=<%= @ipv6defaultdev %> -<% end -%> -<% end -%> -<% if @hostname %>HOSTNAME=<%= @hostname %> -<% else %>HOSTNAME=<%= scope.lookupvar('::fqdn') %> -<% end -%> -<% if @gateway %>GATEWAY=<%= @gateway %> -<% end -%> -<% if @gatewaydev %>GATEWAYDEV=<%= @gatewaydev %> -<% end -%> -<% if @nisdomain %>NISDOMAIN=<%= @nisdomain %> -<% end -%> -<% if @vlan %>VLAN=<%= @vlan %> -<% end -%> -<% if @nozeroconf %>NOZEROCONF=<%= @nozeroconf %> -<% end -%> -<% if @requestreopen %>RES_OPTIONS="single-request-reopen" -<% end -%> From 86a43492f9d53dc257c5c0d754144819cf9e9dfa Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Tue, 20 Feb 2018 17:51:03 +0800 Subject: [PATCH 40/50] Use EPP in network_if_base for ifcfg-eth --- manifests/init.pp | 35 +++++++++++++++++++- templates/ifcfg-eth.epp | 45 +++++++++++++++++++++++++ templates/ifcfg-eth.erb | 73 ----------------------------------------- 3 files changed, 79 insertions(+), 74 deletions(-) create mode 100644 templates/ifcfg-eth.epp delete mode 100644 templates/ifcfg-eth.erb diff --git a/manifests/init.pp b/manifests/init.pp index 9f9f58fa..e07b6d9c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -185,7 +185,40 @@ 'down' => 'no', default => undef, } - $iftemplate = template('network/ifcfg-eth.erb') + $iftemplate = epp("${module_name}/ifcfg-eth.epp", { + interface => $interface, + bootproto => $bootproto, + manage_hwaddr => $manage_hwaddr, + macaddress => $macaddress, + onboot => $onboot, + ipaddress => $ipaddress, + netmask => $netmask, + gateway => $gateway, + mtu => $mtu, + bonding_opts => $bonding_opts, + dhcp_hostname => $dhcp_hostname, + ethtool_opts => $ethtool_opts, + peerdns => $peerdns, + dns1 => $dns1_real, + dns2 => $dns2_real, + domain => $domain, + userctl => $userctl, + ipv6init => $ipv6init, + ipv6autoconf => $ipv6autoconf, + ipv6address => $ipv6address, + ipv6gateway => $ipv6gateway, + ipv6peerdns => $ipv6peerdns, + ipv6secondaries => $ipv6secondaries, + bridge => $bridge, + linkdelay => $linkdelay, + scope => $scope, + check_link_down => $check_link_down, + defroute => $defroute, + zone => $zone, + metric => $metric, + promisc => $promisc, + arpcheck => $arpcheck, + }) } if $flush { diff --git a/templates/ifcfg-eth.epp b/templates/ifcfg-eth.epp new file mode 100644 index 00000000..08d1af29 --- /dev/null +++ b/templates/ifcfg-eth.epp @@ -0,0 +1,45 @@ +### +### File managed by Puppet +### +DEVICE=<%= $interface %> +BOOTPROTO=<%= $bootproto %> +<% if $manage_hwaddr and $macaddress { %>HWADDR=<%= $macaddress %><% } %> +ONBOOT=<%= $onboot %> +HOTPLUG=<%= $onboot %> +TYPE=Ethernet +<% if $ipaddress { %>IPADDR=<%= $ipaddress %><% } %> +<% if $netmask { %>NETMASK=<%= $netmask %><% } %> +<% if $gateway { %>GATEWAY=<%= $gateway %><% } %> +<% if $mtu { %>MTU=<%= $mtu %><% } %> +<% if $bonding_opts { %>BONDING_OPTS="<%= $bonding_opts %>"<% } %> +<% if $dhcp_hostname { %>DHCP_HOSTNAME="<%= $dhcp_hostname %>"<% } %> +<% if $ethtool_opts { %>ETHTOOL_OPTS="<%= $ethtool_opts %>"<% } %> +PEERDNS=<%= bool2str($peerdns, 'yes', 'no') %> +<% if $dns1 { %>DNS1=<%= $dns1 %><% } %> +<% if $dns2 { %>DNS2=<%= $dns2 %><% } %> +<% if $domain { %>DOMAIN="<%= $domain %>"<% } %> +<% if $userctl { %>USERCTL=yes<% } %> +<%- if $ipv6init { -%> +IPV6INIT=yes +IPV6_AUTOCONF=<%= bool2str($ipv6autoconf, 'yes', 'no') %> +<% if $ipv6address { %>IPV6ADDR=<%= $ipv6address %><% } %> +<% if $ipv6gateway { %>IPV6_DEFAULTGW=<%= $ipv6gateway %><% } %> +IPV6_PEERDNS=<%= bool2str($ipv6peerdns, 'yes', 'no') %> +<%- if $ipv6secondaries { -%> +IPV6ADDR_SECONDARIES="<%= join($ipv6secondaries, ' ') %>" +<%- } -%> +<%- } -%> +<% if $bridge { %>BRIDGE=<%= $bridge %><% } %> +<% if $linkdelay { %>LINKDELAY=<%= $linkdelay %><% } %> +<% if $scope { %>SCOPE="<%= $scope %>"<% } %> +<% if $check_link_down { %> +check_link_down() { + return 1; +} +<% } -%> +<% if $defroute { %>DEFROUTE=<%= $defroute %><% } %> +<% if $zone { %>ZONE=<%= $zone %><% } %> +<% if $metric { %>METRIC=<%= $metric %><% } %> +<% if $promisc { %>PROMISC=yes<% } %> +<% if !$arpcheck { %>ARPCHECK=no<% } %> +NM_CONTROLLED=no diff --git a/templates/ifcfg-eth.erb b/templates/ifcfg-eth.erb deleted file mode 100644 index 2f1addb5..00000000 --- a/templates/ifcfg-eth.erb +++ /dev/null @@ -1,73 +0,0 @@ -### -### File managed by Puppet -### -DEVICE=<%= @interface %> -BOOTPROTO=<%= @bootproto %> -<% if @manage_hwaddr and @macaddress and @macaddress != '' -%> -HWADDR=<%= @macaddress %> -<% end -%> -ONBOOT=<%= @onboot %> -HOTPLUG=<%= @onboot %> -TYPE=Ethernet -<% if @ipaddress and @ipaddress != '' %>IPADDR=<%= @ipaddress %> -<% end -%> -<% if @netmask and @netmask != '' %>NETMASK=<%= @netmask %> -<% end -%> -<% if @gateway and @gateway != '' %>GATEWAY=<%= @gateway %> -<% end -%> -<% if @mtu %>MTU=<%= @mtu %> -<% end -%> -<% if @bonding_opts %>BONDING_OPTS="<%= @bonding_opts %>" -<% end -%> -<% if @dhcp_hostname %>DHCP_HOSTNAME="<%= @dhcp_hostname %>" -<% end -%> -<% if @ethtool_opts %>ETHTOOL_OPTS="<%= @ethtool_opts %>" -<% end -%> -<% if !@peerdns %>PEERDNS=no -<% else %>PEERDNS=yes -<% end -%> -<% if @dns1_real %>DNS1=<%= @dns1_real %> -<% end -%> -<% if @dns2_real %>DNS2=<%= @dns2_real %> -<% end -%> -<% if @domain %>DOMAIN="<%= @domain %>" -<% end -%> -<% if @userctl %>USERCTL=yes -<% end -%> -<% if @ipv6init %> -IPV6INIT=yes -<% if !@ipv6autoconf %>IPV6_AUTOCONF=no -<% else %>IPV6_AUTOCONF=yes -<% end -%> -<% if @ipv6address %>IPV6ADDR=<%= @ipv6address %> -<% end -%> -<% if @ipv6gateway %>IPV6_DEFAULTGW=<%= @ipv6gateway %> -<% end -%> -<% if !@ipv6peerdns %>IPV6_PEERDNS=no -<% else %>IPV6_PEERDNS=yes -<% end -%> -<% if @ipv6secondaries and @ipv6secondaries.length > 0 %>IPV6ADDR_SECONDARIES="<%= @ipv6secondaries.join(' ') %>" -<% end -%> -<% end -%> -<% if @bridge %>BRIDGE=<%= @bridge %> -<% end -%> -<% if @linkdelay %>LINKDELAY=<%= @linkdelay %> -<% end -%> -<% if @scope %>SCOPE="<%= @scope %>" -<% end -%> -<% if @check_link_down %> -check_link_down() { - return 1; -} -<% end -%> -<% if @defroute %>DEFROUTE=<%= @defroute %> -<% end -%> -<% if @zone %>ZONE=<%= @zone %> -<% end -%> -<% if @metric %>METRIC=<%= @metric %> -<% end -%> -<% if @promisc %>PROMISC=yes -<% end -%> -<% if !@arpcheck %>ARPCHECK=no -<% end -%> -NM_CONTROLLED=no From c3c6b448870821aab9b2ec45454befb03396da6b Mon Sep 17 00:00:00 2001 From: Philippe Muller Date: Tue, 20 Feb 2018 19:02:54 +0800 Subject: [PATCH 41/50] Tests: remove useless facts --- spec/defines/network_bond_slave_spec.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/spec/defines/network_bond_slave_spec.rb b/spec/defines/network_bond_slave_spec.rb index 44cef221..d4535b03 100644 --- a/spec/defines/network_bond_slave_spec.rb +++ b/spec/defines/network_bond_slave_spec.rb @@ -71,13 +71,7 @@ } end let :facts do { - :os => { - :family => 'RedHat', - :name => 'RedHat', - :release => { - :major => '6', - } - }, + :os => { :family => 'RedHat' }, :networking => { :interfaces => { :eth1 => { From a4359ba1f20957fe49a99db9201f000d0f102adc Mon Sep 17 00:00:00 2001 From: m4rx0 Date: Wed, 24 Apr 2019 12:11:07 +0200 Subject: [PATCH 42/50] Add augeas_core as dependency for >= Puppet 6 --- .fixtures.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index aea64a24..e5d36e31 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,10 +1,8 @@ fixtures: repositories: - stdlib: - repo: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' - ref: '4.24.0' - ip: - repo: 'https://github.com/thrnio/puppet-ip.git' - ref: 'v1.0.0' + stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git" + augeas_core: + repo: "https://github.com/puppetlabs/puppetlabs-augeas_core.git" + puppet_version: ">= 6.0.0" symlinks: network: "#{source_dir}" From 56cfd92b4accd11c695b84a4cf1a516b825e551d Mon Sep 17 00:00:00 2001 From: m4rx0 Date: Wed, 24 Apr 2019 12:12:14 +0200 Subject: [PATCH 43/50] Add Puppet 6 in CI --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 28d5712c..1143bae7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,8 @@ matrix: env: PUPPET_GEM_VERSION="~> 4.0" - rvm: 2.4.1 env: PUPPET_GEM_VERSION="~> 5.0" + - rvm: 2.5.0 + env: PUPPET_GEM_VERSION="~> 6.0" notifications: email: - github@razorsedge.org From 13212eba117622477a0ab07499ae5e12498bd0b7 Mon Sep 17 00:00:00 2001 From: m4rx0 Date: Wed, 24 Apr 2019 14:00:52 +0200 Subject: [PATCH 44/50] Update dependencies and requirements --- metadata.json | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/metadata.json b/metadata.json index 4f25415d..599c3182 100644 --- a/metadata.json +++ b/metadata.json @@ -11,11 +11,7 @@ "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">=4.24.0 <5.0.0" - }, - { - "name": "thrnio/ip", - "version_requirement": ">=1.0.0 < 2.0.0" + "version_requirement": ">=4.3.0 <6.0.0" } ], "operatingsystem_support": [ @@ -39,7 +35,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">=4.9.0 <5.0.0" + "version_requirement": ">=4 <7.0.0" } ] } From 0ca1816fec5a74a3b47d03459626a197e04930cd Mon Sep 17 00:00:00 2001 From: m4rx0 Date: Wed, 24 Apr 2019 14:00:57 +0200 Subject: [PATCH 45/50] Change to Stdlib::IP resource types --- manifests/alias.pp | 10 +++++----- manifests/alias/range.pp | 8 ++++---- manifests/bond/static.pp | 14 +++++++------- manifests/bridge.pp | 14 +++++++------- manifests/bridge/static.pp | 14 +++++++------- manifests/global.pp | 4 ++-- manifests/if/static.pp | 16 ++++++++-------- manifests/init.pp | 16 ++++++++-------- manifests/route.pp | 6 +++--- spec/defines/network_alias_range_spec.rb | 4 ++-- spec/defines/network_alias_spec.rb | 2 +- spec/defines/network_bond_static_spec.rb | 4 ++-- spec/defines/network_bridge_static_spec.rb | 4 ++-- spec/defines/network_if_static_spec.rb | 8 ++++---- 14 files changed, 62 insertions(+), 62 deletions(-) diff --git a/manifests/alias.pp b/manifests/alias.pp index 252989b2..a3551190 100644 --- a/manifests/alias.pp +++ b/manifests/alias.pp @@ -38,12 +38,12 @@ # define network::alias ( Enum['up', 'down'] $ensure, - IP::Address::V4::NoSubnet $ipaddress, - IP::Address::V4::NoSubnet $netmask, - Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Stdlib::IP::Address::V4::Nosubnet $ipaddress, + Stdlib::IP::Address::V4::Nosubnet $netmask, + Optional[Stdlib::IP::Address::V4::Nosubnet] $gateway = undef, Boolean $noaliasrouting = false, - Optional[IP::Address::V6] $ipv6address = undef, - Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Optional[Stdlib::IP::Address::V6] $ipv6address = undef, + Optional[Stdlib::IP::Address::V6::Nosubnet] $ipv6gateway = undef, Boolean $userctl = false, Optional[String] $zone = undef, Optional[String] $metric = undef, diff --git a/manifests/alias/range.pp b/manifests/alias/range.pp index 652401c7..66faa233 100644 --- a/manifests/alias/range.pp +++ b/manifests/alias/range.pp @@ -39,13 +39,13 @@ # define network::alias::range ( Enum['up', 'down', 'absent'] $ensure, - IP::Address::V4::NoSubnet $ipaddress_start, - IP::Address::V4::NoSubnet $ipaddress_end, + Stdlib::IP::Address::V4::Nosubnet $ipaddress_start, + Stdlib::IP::Address::V4::Nosubnet $ipaddress_end, String $clonenum_start, Boolean $noaliasrouting = false, Boolean $restart = true, - Optional[IP::Address::V4::NoSubnet] $netmask = undef, - Optional[IP::Address::V4::NoSubnet] $broadcast = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $netmask = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $broadcast = undef, Boolean $arpcheck = true, ) { diff --git a/manifests/bond/static.pp b/manifests/bond/static.pp index 5980254d..73127fd3 100644 --- a/manifests/bond/static.pp +++ b/manifests/bond/static.pp @@ -42,19 +42,19 @@ # define network::bond::static ( Enum['up', 'down'] $ensure, - Optional[IP::Address::V4::NoSubnet] $ipaddress = undef, - Optional[IP::Address::V4::NoSubnet] $netmask = undef, - Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $ipaddress = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $netmask = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $gateway = undef, Optional[String] $mtu = undef, Optional[String] $ethtool_opts = undef, String $bonding_opts = 'miimon=100', Boolean $peerdns = false, Boolean $ipv6init = false, - Optional[IP::Address::V6] $ipv6address = undef, - Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Optional[Stdlib::IP::Address::V6] $ipv6address = undef, + Optional[Stdlib::IP::Address::V6::Nosubnet] $ipv6gateway = undef, Boolean $ipv6peerdns = false, - Optional[IP::Address::NoSubnet] $dns1 = undef, - Optional[IP::Address::NoSubnet] $dns2 = undef, + Optional[Stdlib::IP::Address::Nosubnet] $dns1 = undef, + Optional[Stdlib::IP::Address::Nosubnet] $dns2 = undef, Optional[String] $domain = undef, Optional[String] $zone = undef, Optional[String] $defroute = undef, diff --git a/manifests/bridge.pp b/manifests/bridge.pp index 1bf8ed32..1aa35507 100644 --- a/manifests/bridge.pp +++ b/manifests/bridge.pp @@ -47,11 +47,11 @@ # define network::bridge ( Enum['up', 'down'] $ensure, - Optional[IP::Address::V4::NoSubnet] $ipaddress = undef, - Optional[IP::Address::V4::NoSubnet] $netmask = undef, - Optional[IP::Address::V4::NoSubnet] $gateway = undef, - Optional[IP::Address::V6] $ipv6address = undef, - Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $ipaddress = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $netmask = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $gateway = undef, + Optional[Stdlib::IP::Address::V6] $ipv6address = undef, + Optional[Stdlib::IP::Address::V6::Nosubnet] $ipv6gateway = undef, Network::If::Bootproto $bootproto = 'none', Boolean $userctl = false, Boolean $stp = false, @@ -61,8 +61,8 @@ Boolean $peerdns = false, Boolean $ipv6init = false, Boolean $ipv6peerdns = false, - Optional[IP::Address::NoSubnet] $dns1 = undef, - Optional[IP::Address::NoSubnet] $dns2 = undef, + Optional[Stdlib::IP::Address::Nosubnet] $dns1 = undef, + Optional[Stdlib::IP::Address::Nosubnet] $dns2 = undef, Optional[String] $domain = undef, Boolean $restart = true, ) { diff --git a/manifests/bridge/static.pp b/manifests/bridge/static.pp index 146cd3b1..0bd70f27 100644 --- a/manifests/bridge/static.pp +++ b/manifests/bridge/static.pp @@ -51,18 +51,18 @@ # define network::bridge::static ( Enum['up', 'down'] $ensure, - Optional[IP::Address::V4::NoSubnet] $ipaddress = undef, - Optional[IP::Address::V4::NoSubnet] $netmask = undef, - Optional[IP::Address::V4::NoSubnet] $gateway = undef, - Optional[IP::Address::V6] $ipv6address = undef, - Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $ipaddress = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $netmask = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $gateway = undef, + Optional[Stdlib::IP::Address::V6] $ipv6address = undef, + Optional[Stdlib::IP::Address::V6::Nosubnet] $ipv6gateway = undef, Network::If::Bootproto $bootproto = 'static', Boolean $userctl = false, Boolean $peerdns = false, Boolean $ipv6init = false, Boolean $ipv6peerdns = false, - Optional[IP::Address::NoSubnet] $dns1 = undef, - Optional[IP::Address::NoSubnet] $dns2 = undef, + Optional[Stdlib::IP::Address::Nosubnet] $dns1 = undef, + Optional[Stdlib::IP::Address::Nosubnet] $dns2 = undef, Optional[String] $domain = undef, Boolean $stp = false, String $delay = '30', diff --git a/manifests/global.pp b/manifests/global.pp index dec04f91..d6ba3f58 100644 --- a/manifests/global.pp +++ b/manifests/global.pp @@ -63,9 +63,9 @@ # class network::global ( Optional[String] $hostname = undef, - Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $gateway = undef, Optional[String] $gatewaydev = undef, - Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Optional[Stdlib::IP::Address::V6::Nosubnet] $ipv6gateway = undef, Optional[String] $ipv6defaultdev = undef, Optional[String] $nisdomain = undef, Optional[Enum['yes', 'no']] $vlan = undef, diff --git a/manifests/if/static.pp b/manifests/if/static.pp index 3ea0dcb6..30225a83 100644 --- a/manifests/if/static.pp +++ b/manifests/if/static.pp @@ -57,17 +57,17 @@ # define network::if::static ( Enum['up', 'down'] $ensure, - Optional[IP::Address::V4::NoSubnet] $ipaddress = undef, - Optional[IP::Address::V4::NoSubnet] $netmask = undef, - Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $ipaddress = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $netmask = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $gateway = undef, Optional[ Variant[ - IP::Address::V6, - Tuple[IP::Address::V6, 1], + Stdlib::IP::Address::V6, + Tuple[Stdlib::IP::Address::V6, 1], ] ] $ipv6address = undef, Boolean $ipv6init = false, - Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Optional[Stdlib::IP::Address::V6::Nosubnet] $ipv6gateway = undef, Optional[Stdlib::MAC] $macaddress = undef, Boolean $manage_hwaddr = true, Boolean $ipv6autoconf = false, @@ -76,8 +76,8 @@ Optional[String] $ethtool_opts = undef, Boolean $peerdns = false, Boolean $ipv6peerdns = false, - Optional[IP::Address::NoSubnet] $dns1 = undef, - Optional[IP::Address::NoSubnet] $dns2 = undef, + Optional[Stdlib::IP::Address::Nosubnet] $dns1 = undef, + Optional[Stdlib::IP::Address::Nosubnet] $dns2 = undef, Optional[String] $domain = undef, Optional[String] $linkdelay = undef, Optional[String] $scope = undef, diff --git a/manifests/init.pp b/manifests/init.pp index e07b6d9c..11a9e6e2 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -107,16 +107,16 @@ define network_if_base ( Enum['up', 'down'] $ensure, Optional[Stdlib::MAC] $macaddress = undef, - Optional[IP::Address::V4::NoSubnet] $ipaddress = undef, - Optional[IP::Address::V4::NoSubnet] $netmask = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $ipaddress = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $netmask = undef, Boolean $manage_hwaddr = true, - Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Optional[Stdlib::IP::Address::V4::Nosubnet] $gateway = undef, Boolean $noaliasrouting = false, - Optional[IP::Address::V6] $ipv6address = undef, - Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Optional[Stdlib::IP::Address::V6] $ipv6address = undef, + Optional[Stdlib::IP::Address::V6::Nosubnet] $ipv6gateway = undef, Boolean $ipv6init = false, Boolean $ipv6autoconf = false, - Optional[Array[IP::Address::V6]] $ipv6secondaries = undef, + Optional[Array[Stdlib::IP::Address::V6]] $ipv6secondaries = undef, Network::If::Bootproto $bootproto = 'none', Boolean $userctl = false, Optional[String] $mtu = undef, @@ -126,8 +126,8 @@ Boolean $isalias = false, Boolean $peerdns = false, Boolean $ipv6peerdns = false, - Optional[IP::Address::NoSubnet] $dns1 = undef, - Optional[IP::Address::NoSubnet] $dns2 = undef, + Optional[Stdlib::IP::Address::Nosubnet] $dns1 = undef, + Optional[Stdlib::IP::Address::Nosubnet] $dns2 = undef, Optional[String] $domain = undef, Optional[String] $bridge = undef, Optional[String] $linkdelay = undef, diff --git a/manifests/route.pp b/manifests/route.pp index a8034569..17995f39 100644 --- a/manifests/route.pp +++ b/manifests/route.pp @@ -41,9 +41,9 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::route ( - Array[IP::Address::V4::NoSubnet] $ipaddress, - Array[IP::Address::V4::NoSubnet] $netmask, - Array[IP::Address::V4::NoSubnet] $gateway, + Array[Stdlib::IP::Address::V4::Nosubnet] $ipaddress, + Array[Stdlib::IP::Address::V4::Nosubnet] $netmask, + Array[Stdlib::IP::Address::V4::Nosubnet] $gateway, Boolean $restart = true, ) { diff --git a/spec/defines/network_alias_range_spec.rb b/spec/defines/network_alias_range_spec.rb index 4dcc2d13..e7af15e2 100644 --- a/spec/defines/network_alias_range_spec.rb +++ b/spec/defines/network_alias_range_spec.rb @@ -28,7 +28,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet /) + expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /expects a match for Stdlib::IP::Address::V4::Nosubnet /) end end @@ -42,7 +42,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet /) + expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /expects a match for Stdlib::IP::Address::V4::Nosubnet /) end end diff --git a/spec/defines/network_alias_spec.rb b/spec/defines/network_alias_spec.rb index 1545df6d..849625fb 100644 --- a/spec/defines/network_alias_spec.rb +++ b/spec/defines/network_alias_spec.rb @@ -26,7 +26,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth1:1')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet /) + expect {should contain_file('ifcfg-eth1:1')}.to raise_error(Puppet::Error, /expects a match for Stdlib::IP::Address::V4::Nosubnet /) end end diff --git a/spec/defines/network_bond_static_spec.rb b/spec/defines/network_bond_static_spec.rb index 8371d4ee..fbc529f7 100644 --- a/spec/defines/network_bond_static_spec.rb +++ b/spec/defines/network_bond_static_spec.rb @@ -26,7 +26,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet /) + expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /expects a match for Stdlib::IP::Address::V4::Nosubnet /) end end @@ -40,7 +40,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /(expects an IP::Address::V6 |expects a match for Variant\[IP::Address::V6::Full .*, IP::Address::V6::Compressed)/) + expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /(expects a Stdlib::IP::Address::V6 |expects a match for Variant\[Stdlib::IP::Address::V6::Full .*, Stdlib::IP::Address::V6::Compressed)/) end end diff --git a/spec/defines/network_bridge_static_spec.rb b/spec/defines/network_bridge_static_spec.rb index d55f0732..20cd0833 100644 --- a/spec/defines/network_bridge_static_spec.rb +++ b/spec/defines/network_bridge_static_spec.rb @@ -26,7 +26,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet /) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a match for Stdlib::IP::Address::V4::Nosubnet /) end end @@ -40,7 +40,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /(expects an IP::Address::V6 |expects a match for Variant\[IP::Address::V6::Full .*, IP::Address::V6::Compressed)/) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /(expects a Stdlib::IP::Address::V6 |expects a match for Variant\[Stdlib::IP::Address::V6::Full .*, Stdlib::IP::Address::V6::Compressed)/) end end diff --git a/spec/defines/network_if_static_spec.rb b/spec/defines/network_if_static_spec.rb index 4f4058c9..2eb26747 100644 --- a/spec/defines/network_if_static_spec.rb +++ b/spec/defines/network_if_static_spec.rb @@ -13,7 +13,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet/) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /expects a match for Stdlib::IP::Address::V4::Nosubnet/) end end @@ -27,7 +27,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /(expects a value of type Undef, IP::Address::V6|expects a match for Variant\[IP::Address::V6::Full .*, IP::Address::V6::Compressed)/) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /(expects a value of type Undef, Stdlib::IP::Address::V6|expects a match for Variant\[Stdlib::IP::Address::V6::Full .*, Stdlib::IP::Address::V6::Compressed)/) end end @@ -41,7 +41,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /(expects a value of type Undef, IP::Address::V6|expects a match for Variant\[IP::Address::V6::Full .*, IP::Address::V6::Compressed)/) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /(expects a value of type Undef, Stdlib::IP::Address::V6|expects a match for Variant\[Stdlib::IP::Address::V6::Full .*, Stdlib::IP::Address::V6::Compressed)/) end end @@ -59,7 +59,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /(expects an IP::Address::V6 |expects a match for Variant\[IP::Address::V6::Full .*, IP::Address::V6::Compressed)/) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /(expects a Stdlib::IP::Address::V6 |expects a match for Variant\[Stdlib::IP::Address::V6::Full .*, Stdlib::IP::Address::V6::Compressed)/) end end From 5959959a363112d746a93473be019288ebad6574 Mon Sep 17 00:00:00 2001 From: m4rx0 Date: Fri, 26 Apr 2019 15:50:40 +0200 Subject: [PATCH 46/50] introduce possibility for interfaces without an ip --- README.md | 6 ++ manifests/if/none.pp | 65 +++++++++++++++++++++ spec/defines/network_if_none_spec.rb | 85 ++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 manifests/if/none.pp create mode 100644 spec/defines/network_if_none_spec.rb diff --git a/README.md b/README.md index a64a68da..1a4fe540 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,12 @@ Normal interface - promiscuous: ensure => 'up', } +Normal interface - none: + + network::if::none { 'eth1': + ensure => 'up', + } + Aliased interface IPv4: network::alias { 'eth0:1': diff --git a/manifests/if/none.pp b/manifests/if/none.pp new file mode 100644 index 00000000..cbb1a802 --- /dev/null +++ b/manifests/if/none.pp @@ -0,0 +1,65 @@ +# == Definition: network::if::none +# +# Creates a normal interface without any ip +# +# === Parameters: +# +# $ensure - required - up|down +# $macaddress - optional - defaults to macaddress_$title +# $userctl - optional - defaults to false +# $mtu - optional +# $ethtool_opts - optional +# +# === Actions: +# +# Deploys the file /etc/sysconfig/network-scripts/ifcfg-$name. +# +# === Sample Usage: +# +# network::if::none { 'eth1': +# ensure => 'up', +# macaddress => $::macaddress_eth0, +# } +# +# === Authors: +# +# Mike Arnold +# +# === Copyright: +# +# Copyright (C) 2011 Mike Arnold, unless otherwise noted. +# +define network::if::none ( + $ensure, + $macaddress = '', + $userctl = false, + $mtu = '', + $ethtool_opts = '', + $linkdelay = '' +) { + if ! is_mac_address($macaddress) and ($macaddress != 'unmanaged') { + # Strip off any tailing VLAN (ie eth5.90 -> eth5). + $title_clean = regsubst($title,'^(\w+)\.\d+$','\1') + $macaddy = getvar("::macaddress_${title_clean}") + } elsif $macaddress == 'unmanaged' { + $macaddy = '' + } else { + $macaddy = $macaddress + } + # Validate booleans + validate_bool($userctl) + + network_if_base { $title: + ensure => $ensure, + ipv6init => false, + macaddress => $macaddy, + bootproto => 'none', + userctl => $userctl, + mtu => $mtu, + ethtool_opts => $ethtool_opts, + linkdelay => $linkdelay, + ipaddress => undef, + netmask => undef, + gateway => undef, + } +} # define network::if::none diff --git a/spec/defines/network_if_none_spec.rb b/spec/defines/network_if_none_spec.rb new file mode 100644 index 00000000..a95563f3 --- /dev/null +++ b/spec/defines/network_if_none_spec.rb @@ -0,0 +1,85 @@ +#!/usr/bin/env rspec + +require 'spec_helper' + +describe 'network::if::none', :type => 'define' do + context 'without parameters' do + let(:title) { 'eth1' } + let(:params){ + { + :ensure => 'up' + } + } + let :facts do { + :os => { + :family => 'RedHat' + }, + :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + } + end + it { should contain_file('ifcfg-eth1').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-eth1', + :notify => 'Service[network]' + )} + it 'should contain File[ifcfg-eth1] with required contents' do + verify_contents(catalogue, 'ifcfg-eth1', [ + 'DEVICE=eth1', + 'BOOTPROTO=none', + 'HWADDR=fe:fe:fe:aa:aa:aa', + 'ONBOOT=yes', + 'HOTPLUG=yes', + 'TYPE=Ethernet', + 'NM_CONTROLLED=no', + ]) + end + it { should contain_service('network') } + end + + context 'optional parameters' do + let(:title) { 'eth1' } + let :params do { + :ensure => 'down', + :macaddress => 'ef:ef:ef:ef:ef:ef', + :userctl => true, + :mtu => '9000', + :ethtool_opts => 'speed 1000 duplex full autoneg off', + :linkdelay => '5', + } + end + let :facts do { + :os => { + :family => 'RedHat' + }, + :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + } + end + it { should contain_file('ifcfg-eth1').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-eth1', + :notify => 'Service[network]' + )} + it 'should contain File[ifcfg-eth1] with required contents' do + verify_contents(catalogue, 'ifcfg-eth1', [ + 'DEVICE=eth1', + 'BOOTPROTO=none', + 'HWADDR=ef:ef:ef:ef:ef:ef', + 'ONBOOT=no', + 'HOTPLUG=no', + 'TYPE=Ethernet', + 'MTU=9000', + 'ETHTOOL_OPTS="speed 1000 duplex full autoneg off"', + 'USERCTL=yes', + 'LINKDELAY=5', + 'NM_CONTROLLED=no', + ]) + end + it { should contain_service('network') } + end +end From e37beabf624570d93f5b6c5951122e28e116cfbb Mon Sep 17 00:00:00 2001 From: m4rx0 Date: Fri, 26 Apr 2019 16:24:06 +0200 Subject: [PATCH 47/50] Remove restriction for CI jobs --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1143bae7..749e3839 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,6 @@ cache: - vendor/bundle # - spec/fixtures/modules sudo: false -branches: - only: - - master - - develop bundler_args: --without system_tests script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'" matrix: From c34ac778bbd4ee3a42fc9d5afc7121fb39fea72a Mon Sep 17 00:00:00 2001 From: m4rx0 Date: Fri, 26 Apr 2019 16:57:35 +0200 Subject: [PATCH 48/50] Adapt CI jobs --- .travis.yml | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 749e3839..51533431 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,20 +2,18 @@ language: ruby cache: directories: - - vendor/bundle -# - spec/fixtures/modules + - vendor/bundle sudo: false -bundler_args: --without system_tests -script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'" +script: + - 'bundle exec rake validate' + - 'bundle exec rake lint' + - 'bundle exec rake spec SPEC_OPTS="--format documentation"' matrix: fast_finish: true include: - - rvm: 2.1.9 - env: PUPPET_GEM_VERSION="~> 4.0" - - rvm: 2.4.1 - env: PUPPET_GEM_VERSION="~> 5.0" - - rvm: 2.5.0 - env: PUPPET_GEM_VERSION="~> 6.0" -notifications: - email: - - github@razorsedge.org + - rvm: 2.1.9 + env: PUPPET_GEM_VERSION="~> 4.0" + - rvm: 2.4.1 + env: PUPPET_GEM_VERSION="~> 5.0" + - rvm: 2.5.0 + env: PUPPET_GEM_VERSION="~> 6.0" From 6efb894e2ce12aa1da3f3346d09b87d914a64119 Mon Sep 17 00:00:00 2001 From: m4rx0 Date: Fri, 26 Apr 2019 17:06:54 +0200 Subject: [PATCH 49/50] Add and fix data types in network::if::none --- manifests/if/none.pp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/manifests/if/none.pp b/manifests/if/none.pp index cbb1a802..fe9b6616 100644 --- a/manifests/if/none.pp +++ b/manifests/if/none.pp @@ -30,19 +30,19 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::if::none ( - $ensure, - $macaddress = '', - $userctl = false, - $mtu = '', - $ethtool_opts = '', - $linkdelay = '' + Enum['up', 'down'] $ensure, + Optional[Stdlib::MAC] $macaddress = undef, + Boolean $userctl = false, + Optional[String] $mtu = undef, + Optional[String] $ethtool_opts = undef, + Optional[String] $linkdelay = undef ) { if ! is_mac_address($macaddress) and ($macaddress != 'unmanaged') { # Strip off any tailing VLAN (ie eth5.90 -> eth5). $title_clean = regsubst($title,'^(\w+)\.\d+$','\1') $macaddy = getvar("::macaddress_${title_clean}") } elsif $macaddress == 'unmanaged' { - $macaddy = '' + $macaddy = undef } else { $macaddy = $macaddress } From 4ebb2b435f436603fa151712ee9e6ab79cc03256 Mon Sep 17 00:00:00 2001 From: m4rx0 Date: Fri, 26 Apr 2019 17:15:05 +0200 Subject: [PATCH 50/50] Bump version --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index 599c3182..bd081a24 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "razorsedge-network", - "version": "3.11.1", + "version": "3.12.0", "author": "razorsedge", "summary": "Manage RedHat traditional network configuration via static and dhcp configuration of normal and bonded interfaces as well as bridges and VLANs.", "license": "Apache-2.0",