From d4200124f18934d35ecf11e7358d6c62d34748d0 Mon Sep 17 00:00:00 2001 From: Elyse Salberg Date: Thu, 5 Oct 2017 16:42:23 -0400 Subject: [PATCH] Add ability to set a default restart value ( restart_default, boolean); add schedule and default schedule options to enable network restarts during change windows rspec fixes --- README.md | 26 ++++++ manifests/alias.pp | 12 ++- manifests/alias/range.pp | 9 ++- manifests/bond.pp | 9 ++- manifests/bond/bridge.pp | 9 ++- manifests/bond/dynamic.pp | 11 ++- manifests/bond/slave.pp | 9 ++- manifests/bond/static.pp | 9 ++- manifests/bridge.pp | 9 ++- manifests/bridge/dynamic.pp | 9 ++- manifests/bridge/static.pp | 9 ++- manifests/global.pp | 5 +- manifests/if.pp | 9 ++- manifests/if/bridge.pp | 9 ++- manifests/if/dynamic.pp | 9 ++- manifests/if/promisc.pp | 11 ++- manifests/if/static.pp | 9 ++- manifests/init.pp | 14 +++- manifests/route.pp | 9 ++- spec/defines/network_alias_range_spec.rb | 15 ++++ spec/defines/network_alias_spec.rb | 42 ++++++++++ spec/defines/network_bond_bridge_spec.rb | 55 ++++++++++++- spec/defines/network_bond_dynamic_spec.rb | 48 ++++++++++- spec/defines/network_bond_slave_spec.rb | 77 ++++++++++-------- spec/defines/network_bond_spec.rb | 48 ++++++++++- spec/defines/network_bond_static_spec.rb | 53 ++++++++++++ spec/defines/network_bridge_dynamic_spec.rb | 65 ++++++++------- spec/defines/network_bridge_spec.rb | 59 ++++++++------ spec/defines/network_bridge_static_spec.rb | 89 ++++++++++++--------- spec/defines/network_if_bridge_spec.rb | 49 +++++++++++- spec/defines/network_if_dynamic_spec.rb | 55 +++++++++++-- spec/defines/network_if_promisc_spec.rb | 64 ++++++++++++++- spec/defines/network_if_spec.rb | 47 ++++++++++- spec/defines/network_if_static_spec.rb | 31 ++++++- spec/defines/network_route_spec.rb | 7 +- spec/spec_helper.rb | 4 + 36 files changed, 810 insertions(+), 194 deletions(-) diff --git a/README.md b/README.md index 3d167aa..b4842f2 100644 --- a/README.md +++ b/README.md @@ -293,6 +293,32 @@ By default, all changes notify the network service, thus triggering a restart of restart => false, } +Schedule network restarts: + +If restart is true (default), then an optional schedule can be specified for the network restarts by passing the `sched` parameter. The specified schedule must be defined in the catalog separately from the network module. + + network::if::static { 'eth0': + ensure => 'up', + ipaddress => '1.2.3.4', + netmask => '255.255.255.0', + sched => 'after_hours', + } + +Defaults for restart and/or schedule: +By default, network restarts are enabled (true) and schedules are not set (undef). The defaults can be overridden for all resources by passing the `restart_default` and/or `sched_default` parameters for the network class. + +Code Example: + class {'network': + restart_default => false, + sched_default => 'myschedule', + } + +Hiera Example: + network::restart_default: false + network::sched_default: myschedule + +The defaults can be overridden normally in specific network resources by using the `restart` and/or `sched` parameters. As before, the schedule only applies in cases where restart is true. + Hiera ----- diff --git a/manifests/alias.pp b/manifests/alias.pp index a9e9e82..541d122 100644 --- a/manifests/alias.pp +++ b/manifests/alias.pp @@ -13,7 +13,8 @@ # $userctl - optional - defaults to false # $zone - optional # $metric - optional -# $restart - optional - defaults to true +# $restart - optional - defaults to $::network::restart_default (true) +# $sched - optional - defaults to $::network::sched_default (undef) # # === Actions: # @@ -47,13 +48,19 @@ $userctl = false, $zone = undef, $metric = undef, - $restart = true, + $restart = $::network::restart_default, + $sched = $::network::sched_default, ) { # Validate our data if ! is_ip_address($ipaddress) { fail("${ipaddress} is not an IP address.") } # Validate our booleans validate_bool($noaliasrouting) validate_bool($userctl) + # Validate our regular expressions + $states = [ '^up$', '^down$' ] + validate_re($ensure, $states, '$ensure must be either "up" or "down".') + + include '::network' network_if_base { $title: ensure => $ensure, @@ -72,5 +79,6 @@ zone => $zone, metric => $metric, restart => $restart, + sched => $sched, } } # define network::alias diff --git a/manifests/alias/range.pp b/manifests/alias/range.pp index 4746d94..6afd99e 100644 --- a/manifests/alias/range.pp +++ b/manifests/alias/range.pp @@ -10,9 +10,10 @@ # $ipaddress_start - required # $clonenum_start - required # $noaliasrouting - optional - false|true -# $restart - optional - defaults to true +# $restart - optional - defaults to $::network::restart_default (true) # $netmask - optional - an IP address (CIDR not supported) # $broadcast - optional - an IP address +# $sched - optional - defaults to $::network::sched_default (undef) # # === Actions: # @@ -43,10 +44,11 @@ $ipaddress_end, $clonenum_start, $noaliasrouting = false, - $restart = true, + $restart = $::network::restart_default, $netmask = false, $broadcast = false, $arpcheck = true, + $sched = $::network::sched_default, ) { # Validate our data if ! is_ip_address($ipaddress_start) { fail("${ipaddress_start} is not an IP address.") } @@ -88,7 +90,8 @@ if $restart { File["ifcfg-${interface}-range${clonenum_start}"] { - notify => Service['network'], + notify => Service['network'], + schedule => $sched, } } diff --git a/manifests/bond.pp b/manifests/bond.pp index afc1a0a..0f0e13d 100644 --- a/manifests/bond.pp +++ b/manifests/bond.pp @@ -10,7 +10,8 @@ # $ethtool_opts - optional # $bonding_opts - optional # $zone - optional -# $restart - optional - defaults to true +# $restart - optional - defaults to $::network::restart_default (true) +# $sched - optional - defaults to $::network::sched_default (undef) # # === Actions: # @@ -37,12 +38,15 @@ $ethtool_opts = undef, $bonding_opts = 'miimon=100', $zone = undef, - $restart = true, + $restart = $::network::restart_default, + $sched = $::network::sched_default, ) { # Validate our regular expressions $states = [ '^up$', '^down$' ] validate_re($ensure, $states, '$ensure must be either "up" or "down".') + include '::network' + network_if_base { $title: ensure => $ensure, ipaddress => '', @@ -57,6 +61,7 @@ bonding_opts => $bonding_opts, zone => $zone, restart => $restart, + sched => $sched, } # Only install "alias bondN bonding" on old OSs that support diff --git a/manifests/bond/bridge.pp b/manifests/bond/bridge.pp index 5381e4c..3f38464 100644 --- a/manifests/bond/bridge.pp +++ b/manifests/bond/bridge.pp @@ -9,7 +9,8 @@ # $mtu - optional # $ethtool_opts - optional # $bonding_opts - optional -# $restart - optional - defaults to true +# $restart - optional - defaults to $::network::restart_default (true) +# $sched - optional - defaults to $::network::sched_default (undef) # # === Actions: # @@ -39,12 +40,15 @@ $mtu = undef, $ethtool_opts = undef, $bonding_opts = 'miimon=100', - $restart = true, + $restart = $::network::restart_default, + $sched = $::network::sched_default, ) { # Validate our regular expressions $states = [ '^up$', '^down$' ] validate_re($ensure, $states, '$ensure must be either "up" or "down".') + include '::network' + network_if_base { $title: ensure => $ensure, ipaddress => '', @@ -59,6 +63,7 @@ bonding_opts => $bonding_opts, bridge => $bridge, restart => $restart, + sched => $sched, } # Only install "alias bondN bonding" on old OSs that support diff --git a/manifests/bond/dynamic.pp b/manifests/bond/dynamic.pp index 65e3dbd..b0cab0d 100644 --- a/manifests/bond/dynamic.pp +++ b/manifests/bond/dynamic.pp @@ -13,8 +13,9 @@ # $zone - optional # $metric - optional # $defroute - optional -# $restart - optional - defaults to true - +# $restart - optional - defaults to $::network::restart_default (true) +# $sched - optional - defaults to $::network::sched_default (undef) +# # # === Actions: # @@ -43,12 +44,15 @@ $zone = undef, $defroute = undef, $metric = undef, - $restart = true, + $restart = $::network::restart_default, + $sched = $::network::sched_default, ) { # Validate our regular expressions $states = [ '^up$', '^down$' ] validate_re($ensure, $states, '$ensure must be either "up" or "down".') + include '::network' + network_if_base { $title: ensure => $ensure, ipaddress => '', @@ -65,6 +69,7 @@ defroute => $defroute, metric => $metric, restart => $restart, + sched => $sched, } # Only install "alias bondN bonding" on old OSs that support diff --git a/manifests/bond/slave.pp b/manifests/bond/slave.pp index 8784584..959357b 100644 --- a/manifests/bond/slave.pp +++ b/manifests/bond/slave.pp @@ -7,13 +7,14 @@ # $master - required # $macaddress - optional # $ethtool_opts - optional -# $restart - optional, defaults to true +# $restart - optional - defaults to $::network::restart_default (true) # $zone - optional # $defroute - optional # $metric - optional # $userctl - optional - defaults to false # $bootproto - optional # $onboot - optional +# $sched - optional - defaults to $::network::sched_default (undef) # # === Actions: # @@ -45,10 +46,11 @@ $zone = undef, $defroute = undef, $metric = undef, - $restart = true, + $restart = $::network::restart_default, $userctl = false, $bootproto = undef, $onboot = undef, + $sched = $::network::sched_default, ) { # Validate our data if $macaddress and ! is_mac_address($macaddress) { @@ -74,7 +76,8 @@ if $restart { File["ifcfg-${interface}"] { - notify => Service['network'], + notify => Service['network'], + schedule => $sched, } } } # define network::bond::slave diff --git a/manifests/bond/static.pp b/manifests/bond/static.pp index 0f28f52..951c377 100644 --- a/manifests/bond/static.pp +++ b/manifests/bond/static.pp @@ -14,9 +14,10 @@ # $bonding_opts - optional # $zone - optional # $defroute - optional -# $restart - optional - defaults to true +# $restart - optional - defaults to $::network::restart_default (true) # $metric - optional # $userctl - optional +# $sched - optional - defaults to $::network::sched_default (undef) # # === Actions: # @@ -59,8 +60,9 @@ $zone = undef, $defroute = undef, $metric = undef, - $restart = true, + $restart = $::network::restart_default, $userctl = undef, + $sched = $::network::sched_default, ) { # Validate our regular expressions $states = [ '^up$', '^down$' ] @@ -76,6 +78,8 @@ validate_bool($ipv6init) validate_bool($ipv6peerdns) + include '::network' + network_if_base { $title: ensure => $ensure, ipaddress => $ipaddress, @@ -99,6 +103,7 @@ metric => $metric, restart => $restart, userctl => $userctl, + sched => $sched, } # Only install "alias bondN bonding" on old OSs that support diff --git a/manifests/bridge.pp b/manifests/bridge.pp index acb2102..d280b3d 100644 --- a/manifests/bridge.pp +++ b/manifests/bridge.pp @@ -9,7 +9,8 @@ # $stp - optional - defaults to false # $delay - optional - defaults to 30 # $bridging_opts - optional -# $restart - optional - defaults to true +# $restart - optional - defaults to $::network::restart_default (true) +# $sched - optional - defaults to $::network::sched_default (undef) # # === Actions: # @@ -39,7 +40,8 @@ $delay = '30', $bridging_opts = undef, $ipv6init = false, - $restart = true, + $restart = $::network::restart_default, + $sched = $::network::sched_default, ) { # Validate our regular expressions $states = [ '^up$', '^down$' ] @@ -80,7 +82,8 @@ if $restart { File["ifcfg-${interface}"] { - notify => Service['network'], + notify => Service['network'], + schedule => $sched, } } } # define network::bridge diff --git a/manifests/bridge/dynamic.pp b/manifests/bridge/dynamic.pp index 729d464..09fb37f 100644 --- a/manifests/bridge/dynamic.pp +++ b/manifests/bridge/dynamic.pp @@ -10,7 +10,8 @@ # $stp - optional - defaults to false # $delay - optional - defaults to 30 # $bridging_opts - optional -# $restart - optional - defaults to true +# $restart - optional - defaults to $::network::restart_default (true) +# $sched - optional - defaults to $::network::sched_default (undef) # # === Actions: # @@ -42,7 +43,8 @@ $stp = false, $delay = '30', $bridging_opts = undef, - $restart = true, + $restart = $::network::restart_default, + $sched = $::network::sched_default, ) { # Validate our regular expressions $states = [ '^up$', '^down$' ] @@ -81,7 +83,8 @@ if $restart { File["ifcfg-${interface}"] { - notify => Service['network'], + notify => Service['network'], + schedule => $sched, } } } # define network::bridge::dynamic diff --git a/manifests/bridge/static.pp b/manifests/bridge/static.pp index 95b3a47..acbd79d 100644 --- a/manifests/bridge/static.pp +++ b/manifests/bridge/static.pp @@ -21,7 +21,8 @@ # $delay - optional - defaults to 30 # $bridging_opts - optional # $scope - optional -# $restart - optional - defaults to true +# $restart - optional - defaults to $::network::restart_default (true) +# $sched - optional - defaults to $::network::sched_default (undef) # # === Actions: # @@ -68,7 +69,8 @@ $delay = '30', $bridging_opts = undef, $scope = undef, - $restart = true, + $restart = $::network::restart_default, + $sched = $::network::sched_default, ) { # Validate our regular expressions $states = [ '^up$', '^down$' ] @@ -125,7 +127,8 @@ if $restart { File["ifcfg-${interface}"] { - notify => Service['network'], + notify => Service['network'], + schedule => $sched, } } } # define network::bridge::static diff --git a/manifests/global.pp b/manifests/global.pp index 9ff8c67..b29ba4b 100644 --- a/manifests/global.pp +++ b/manifests/global.pp @@ -25,6 +25,7 @@ # $nozeroconf - optional # $restart - optional - defaults to true # $requestreopen - optional - defaults to true +# $sched - optional # # === Actions: # @@ -73,6 +74,7 @@ $nozeroconf = undef, $restart = true, $requestreopen = true, + $sched = undef, ) { # Validate our data if $gateway { @@ -129,7 +131,8 @@ if $restart { File['network.sysconfig'] { - notify => Service['network'], + notify => Service['network'], + schedule => $sched, } } } # class global diff --git a/manifests/if.pp b/manifests/if.pp index 990a022..9c66b9f 100644 --- a/manifests/if.pp +++ b/manifests/if.pp @@ -13,7 +13,8 @@ # $scope - optional # $flush - optional - defaults to false # $zone - optional -# $restart - optional - defaults to true +# $restart - optional - defaults to $::network::restart_default (true) +# $sched - optional - defaults to $::network::sched_default (undef) # # === Actions: # @@ -43,7 +44,8 @@ $scope = undef, $flush = false, $zone = undef, - $restart = true, + $restart = $::network::restart_default, + $sched = $::network::sched_default, ) { # Validate our regular expressions $states = [ '^up$', '^down$' ] @@ -63,6 +65,8 @@ validate_bool($flush) validate_bool($restart) + include '::network' + network_if_base { $title: ensure => $ensure, ipaddress => '', @@ -80,5 +84,6 @@ flush => $flush, zone => $zone, restart => $restart, + sched => $sched, } } # define network::if diff --git a/manifests/if/bridge.pp b/manifests/if/bridge.pp index b8eef61..e6f6ea5 100644 --- a/manifests/if/bridge.pp +++ b/manifests/if/bridge.pp @@ -9,7 +9,8 @@ # $mtu - optional # $ethtool_opts - optional # $macaddress - optional -# $restart - optional - defaults to true +# $restart - optional - defaults to $::network::restart_default (true) +# $sched - optional - defaults to $::network::sched_default (undef) # # === Actions: # @@ -36,7 +37,8 @@ $mtu = undef, $ethtool_opts = undef, $macaddress = undef, - $restart = true, + $restart = $::network::restart_default, + $sched = $::network::sched_default, ) { # Validate our regular expressions $states = [ '^up$', '^down$' ] @@ -49,6 +51,8 @@ $macaddy = $macaddress } + include '::network' + network_if_base { $title: ensure => $ensure, ipaddress => '', @@ -62,5 +66,6 @@ ethtool_opts => $ethtool_opts, bridge => $bridge, restart => $restart, + sched => $sched, } } # define network::if::bridge diff --git a/manifests/if/dynamic.pp b/manifests/if/dynamic.pp index 1bc4b16..19b0028 100644 --- a/manifests/if/dynamic.pp +++ b/manifests/if/dynamic.pp @@ -18,7 +18,8 @@ # $zone - optional # $metric - optional # $defroute - optional -# $restart - optional - defaults to true +# $restart - optional - defaults to $::network::restart_default (true) +# $sched - optional - defaults to $::network::sched_default (undef) # # === Actions: # @@ -60,7 +61,8 @@ $defroute = undef, $zone = undef, $metric = undef, - $restart = true, + $restart = $::network::restart_default, + $sched = $::network::sched_default, ) { # Validate our regular expressions $states = [ '^up$', '^down$' ] @@ -78,6 +80,8 @@ validate_bool($peerdns) validate_bool($manage_hwaddr) + include '::network' + network_if_base { $title: ensure => $ensure, ipaddress => '', @@ -97,5 +101,6 @@ zone => $zone, metric => $metric, restart => $restart, + sched => $sched, } } # define network::if::dynamic diff --git a/manifests/if/promisc.pp b/manifests/if/promisc.pp index 291cdd6..c35b0fe 100644 --- a/manifests/if/promisc.pp +++ b/manifests/if/promisc.pp @@ -5,13 +5,15 @@ # === Parameters: # # $ensure - required - up|down -# $macaddress - optional, defaults to macaddress_$title +# $macaddress - optional - defaults to macaddress_$title # $manage_hwaddr - optional - defaults to true -# $bootproto - optional, defaults to undef ('none') +# $bootproto - optional - defaults to undef ('none') # $userctl - optional # $mtu - optional # $ethtool_opts - optional +# $restart - optional - defaults to $::network::restart_default (true) # $promisc - defaults to true +# $sched - optional - defaults to $::network::sched_default (undef) # # === Actions: # @@ -48,8 +50,9 @@ $userctl = false, $mtu = undef, $ethtool_opts = undef, - $restart = true, + $restart = $::network::restart_default, $promisc = true, + $sched = $::network::sched_default, ) { include '::network' @@ -154,6 +157,8 @@ ipv6gateway => '', mtu => $mtu, ethtool_opts => $ethtool_opts, + restart => $restart, promisc => $promisc, + sched => $sched, } } # define network::if::promisc diff --git a/manifests/if/static.pp b/manifests/if/static.pp index b32ccb6..c5f0089 100644 --- a/manifests/if/static.pp +++ b/manifests/if/static.pp @@ -27,8 +27,9 @@ # $zone - optional # $metric - optional # $defroute - optional -# $restart - optional - defaults to true +# $restart - optional - defaults to $::network::restart_default (true) # $arpcheck - optional - defaults to true +# $sched - optional - defaults to $::network::sched_default (undef) # # === Actions: # @@ -80,8 +81,9 @@ $zone = undef, $defroute = undef, $metric = undef, - $restart = true, + $restart = $::network::restart_default, $arpcheck = true, + $sched = $::network::sched_default, ) { # Validate our data if $ipaddress { @@ -119,6 +121,8 @@ validate_bool($flush) validate_bool($arpcheck) + include '::network' + network_if_base { $title: ensure => $ensure, ipv6init => $ipv6init, @@ -148,5 +152,6 @@ metric => $metric, restart => $restart, arpcheck => $arpcheck, + sched => $sched, } } # define network::if::static diff --git a/manifests/init.pp b/manifests/init.pp index 6e3798f..2e00dc9 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -22,7 +22,10 @@ # # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # -class network { +class network ( + $restart_default = true, + $sched_default = undef, +) { # Only run on RedHat derived systems. case $::osfamily { 'RedHat': { } @@ -77,8 +80,9 @@ # $metric - optional # $defroute - optional # $promisc - optional - defaults to false -# $restart - optional - defaults to true +# $restart - optional - defaults to $::network::restart_default (true) # $arpcheck - optional - defaults to true +# $sched - optional - defaults to $::network::sched_default (undef) # # === Actions: # @@ -138,8 +142,9 @@ $zone = undef, $metric = undef, $promisc = false, - $restart = true, + $restart = $network::restart_default, $arpcheck = true, + $sched = $network::sched_default, ) { # Validate our booleans validate_bool($noaliasrouting) @@ -215,7 +220,8 @@ if $restart { File["ifcfg-${interface}"] { - notify => Service['network'], + notify => Service['network'], + schedule => $sched, } } } # define network_if_base diff --git a/manifests/route.pp b/manifests/route.pp index 27c7534..ae04840 100644 --- a/manifests/route.pp +++ b/manifests/route.pp @@ -7,7 +7,8 @@ # $ipaddress - required # $netmask - required # $gateway - required -# $restart - optional - defaults to true +# $restart - optional - defaults to $::network::restart_default (true) +# $sched - optional - defaults to $::network::sched_default (undef) # # === Actions: # @@ -44,7 +45,8 @@ $ipaddress, $netmask, $gateway, - $restart = true, + $restart = $::network::restart_default, + $sched = $::network::sched_default, ) { # Validate our arrays validate_array($ipaddress) @@ -69,7 +71,8 @@ if $restart { File["route-${interface}"] { - notify => Service['network'], + notify => Service['network'], + schedule => $sched, } } } # define network::route diff --git a/spec/defines/network_alias_range_spec.rb b/spec/defines/network_alias_range_spec.rb index 3abc951..0809fc1 100644 --- a/spec/defines/network_alias_range_spec.rb +++ b/spec/defines/network_alias_range_spec.rb @@ -11,6 +11,8 @@ :ipaddress_start => '1.2.3.4', :ipaddress_end => '1.2.3.4', :clonenum_start => '0', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -25,6 +27,8 @@ :ipaddress_start => 'notAnIP', :ipaddress_end => '1.2.3.4', :clonenum_start => '0', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -39,6 +43,8 @@ :ipaddress_start => '1.2.3.4', :ipaddress_end => 'notAnIP', :clonenum_start => '0', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -55,6 +61,8 @@ :ipaddress_start => '1.2.3.99', :ipaddress_end => '1.2.3.200', :clonenum_start => '3', + :restart => true, + :sched => nil, } end let(:facts) {{ :osfamily => 'RedHat' }} @@ -89,6 +97,7 @@ :ipaddress_end => '1.2.3.200', :clonenum_start => '3', :restart => false, + :sched => nil, } end let(:facts) {{ :osfamily => 'RedHat' }} @@ -122,6 +131,8 @@ :ipaddress_end => '1.2.3.4', :clonenum_start => '9', :noaliasrouting => true, + :restart => true, + :sched => nil, } end let(:facts) {{ :osfamily => 'RedHat' }} @@ -154,6 +165,8 @@ :ipaddress_start => '1.2.3.3', :ipaddress_end => '1.2.3.4', :clonenum_start => '9', + :restart => true, + :sched => nil, } end let(:facts) {{ :osfamily => 'RedHat' }} @@ -177,6 +190,8 @@ :netmask => '255.255.255.0', :broadcast => '1.2.3.0', :arpcheck => false, + :restart => true, + :sched => nil, } end let(:facts) {{ :osfamily => 'RedHat' }} diff --git a/spec/defines/network_alias_spec.rb b/spec/defines/network_alias_spec.rb index b562460..471cb56 100644 --- a/spec/defines/network_alias_spec.rb +++ b/spec/defines/network_alias_spec.rb @@ -10,6 +10,8 @@ :ensure => 'blah', :ipaddress => '1.2.3.4', :netmask => '255.255.255.0', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -23,6 +25,8 @@ :ensure => 'up', :ipaddress => 'notAnIP', :netmask => '255.255.255.0', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -36,6 +40,8 @@ :ensure => 'up', :ipaddress => '1.2.3.6', :netmask => '255.255.255.0', + :restart => true, + :sched => nil, } end let(:facts) {{ :osfamily => 'RedHat' }} @@ -73,6 +79,8 @@ :userctl => true, :metric => '10', :zone => 'trusted', + :restart => true, + :sched => nil, } end let(:facts) {{ :osfamily => 'RedHat' }} @@ -103,4 +111,38 @@ it { should contain_service('network') } end + context 'optional parameters: restart => false' do + let(:title) { 'bond2:1' } + let :params do { + :ensure => 'up', + :ipaddress => '1.2.3.6', + :netmask => '255.255.255.0', + :restart => false, + :sched => nil, + } + end + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('ifcfg-bond2:1').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-bond2:1', + )} + it 'should contain File[ifcfg-bond2:1] with required contents' do + verify_contents(catalogue, 'ifcfg-bond2:1', [ + 'DEVICE=bond2:1', + 'BOOTPROTO=none', + 'ONPARENT=yes', + 'TYPE=Ethernet', + 'IPADDR=1.2.3.6', + 'NETMASK=255.255.255.0', + 'NO_ALIASROUTING=no', + 'NM_CONTROLLED=no', + ]) + end + it { should contain_service('network') } + it { is_expected.to_not contain_file('ifcfg-bond2:1').that_notifies('Service[network]') } + end + end diff --git a/spec/defines/network_bond_bridge_spec.rb b/spec/defines/network_bond_bridge_spec.rb index 272557d..e33a933 100644 --- a/spec/defines/network_bond_bridge_spec.rb +++ b/spec/defines/network_bond_bridge_spec.rb @@ -7,8 +7,10 @@ context 'incorrect value: ensure' do let(:title) { 'bond1' } let :params do { - :ensure => 'blah', - :bridge => 'br0', + :ensure => 'blah', + :bridge => 'br0', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -19,8 +21,10 @@ context 'required parameters' do let(:title) { 'bond0' } let :params do { - :ensure => 'up', - :bridge => 'br0', + :ensure => 'up', + :bridge => 'br0', + :restart => true, + :sched => nil, } end let :facts do { @@ -105,6 +109,8 @@ :mtu => '9000', :ethtool_opts => 'speed 1000 duplex full autoneg off', :bonding_opts => 'mode=active-backup miimon=100', + :restart => true, + :sched => nil, } end let :facts do { @@ -139,4 +145,45 @@ it { should_not contain_augeas('modprobe.conf_bond0') } end + context 'optional parameters: restart => false' do + let(:title) { 'bond0' } + let :params do { + :ensure => 'up', + :bridge => 'br0', + :restart => false, + :sched => nil, + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '6.0', + :macaddress_bond0 => 'fe:fe:fe:aa:aa:aa', + } + end + it { should contain_file('ifcfg-bond0').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-bond0', + )} + it 'should contain File[ifcfg-bond0] with required contents' do + verify_contents(catalogue, 'ifcfg-bond0', [ + 'DEVICE=bond0', + 'BOOTPROTO=none', + 'ONBOOT=yes', + 'HOTPLUG=yes', + 'TYPE=Ethernet', + 'BONDING_OPTS="miimon=100"', + 'PEERDNS=no', + 'BRIDGE=br0', + 'NM_CONTROLLED=no', + ]) + end + it { should contain_service('network') } + it { should_not contain_augeas('modprobe.conf_bond0') } + it { is_expected.to_not contain_file('ifcfg-bond0').that_notifies('Service[network]') } + end + end diff --git a/spec/defines/network_bond_dynamic_spec.rb b/spec/defines/network_bond_dynamic_spec.rb index 2b2d2f1..c829966 100644 --- a/spec/defines/network_bond_dynamic_spec.rb +++ b/spec/defines/network_bond_dynamic_spec.rb @@ -7,7 +7,9 @@ context 'incorrect value: ensure' do let(:title) { 'bond1:1' } let :params do { - :ensure => 'blah' + :ensure => 'blah', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -18,7 +20,9 @@ context 'required parameters' do let(:title) { 'bond2' } let :params do { - :ensure => 'up', + :ensure => 'up', + :restart => true, + :sched => nil, } end let :facts do { @@ -93,6 +97,44 @@ end end + context 'required parameters: restart => false' do + let(:title) { 'bond2' } + let :params do { + :ensure => 'up', + :restart => false, + :sched => nil, + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '6.0', + :macaddress_bond2 => 'ff:aa:ff:aa:ff:aa', + } + end + it { should contain_file('ifcfg-bond2').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-bond2', + )} + it 'should contain File[ifcfg-bond2] with required contents' do + verify_contents(catalogue, 'ifcfg-bond2', [ + 'DEVICE=bond2', + 'BOOTPROTO=dhcp', + 'ONBOOT=yes', + 'HOTPLUG=yes', + 'TYPE=Ethernet', + 'BONDING_OPTS="miimon=100"', + 'NM_CONTROLLED=no', + ]) + end + it { should contain_service('network') } + it { should_not contain_augeas('modprobe.conf_bond2') } + it { is_expected.to_not contain_file('ifcfg-bond2').that_notifies('Service[network]') } + end + context 'optional parameters' do let(:title) { 'bond2' } let :params do { @@ -103,6 +145,8 @@ :defroute => 'yes', :metric => '10', :zone => 'trusted', + :restart => true, + :sched => nil, } end let :facts do { diff --git a/spec/defines/network_bond_slave_spec.rb b/spec/defines/network_bond_slave_spec.rb index d8840da..a1ef16a 100644 --- a/spec/defines/network_bond_slave_spec.rb +++ b/spec/defines/network_bond_slave_spec.rb @@ -9,6 +9,8 @@ let :params do { :macaddress => '123456', :master => 'bond0', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -21,6 +23,8 @@ let(:title) { 'eth1' } let :params do { :master => 'bond0', + :restart => true, + :sched => nil, } end let :facts do { @@ -51,41 +55,6 @@ it { is_expected.to contain_file('ifcfg-eth1').that_notifies('Service[network]') } end - context 'required parameters, restart => false' do - let(:pre_condition) { "file { 'ifcfg-bond0': }" } - let(:title) { 'eth1' } - let :params do { - :macaddress => 'fe:fe:fe:aa:aa:a1', - :master => 'bond0', - :restart => false, - } - end - let :facts do { - :osfamily => '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' - )} - it 'should contain File[ifcfg-eth1] with required contents' do - verify_contents(catalogue, 'ifcfg-eth1', [ - 'DEVICE=eth1', - 'HWADDR=fe:fe:fe:aa:aa:a1', - 'MASTER=bond0', - 'SLAVE=yes', - 'TYPE=Ethernet', - 'NM_CONTROLLED=no', - ]) - end - it { should contain_service('network') } - it { is_expected.to_not contain_file('ifcfg-eth1').that_notifies('Service[network]') } - end - context 'optional parameters' do let(:pre_condition) { "file { 'ifcfg-bond0': }" } let(:title) { 'eth3' } @@ -96,6 +65,8 @@ :userctl => true, :bootproto => 'dhcp', :onboot => 'yes', + :restart => true, + :sched => nil, } end @@ -131,4 +102,40 @@ it { should contain_service('network') } end + context 'optional parameters, restart => false' do + let(:pre_condition) { "file { 'ifcfg-bond0': }" } + let(:title) { 'eth1' } + let :params do { + :macaddress => 'fe:fe:fe:aa:aa:a1', + :master => 'bond0', + :restart => false, + :sched => nil, + } + end + let :facts do { + :osfamily => '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' + )} + it 'should contain File[ifcfg-eth1] with required contents' do + verify_contents(catalogue, 'ifcfg-eth1', [ + 'DEVICE=eth1', + 'HWADDR=fe:fe:fe:aa:aa:a1', + 'MASTER=bond0', + 'SLAVE=yes', + 'TYPE=Ethernet', + 'NM_CONTROLLED=no', + ]) + end + it { should contain_service('network') } + it { is_expected.to_not contain_file('ifcfg-eth1').that_notifies('Service[network]') } + end + end diff --git a/spec/defines/network_bond_spec.rb b/spec/defines/network_bond_spec.rb index b28d4d4..94ea50c 100644 --- a/spec/defines/network_bond_spec.rb +++ b/spec/defines/network_bond_spec.rb @@ -7,7 +7,9 @@ context 'incorrect value: ensure' do let(:title) { 'bond1' } let :params do { - :ensure => 'blah', + :ensure => 'blah', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -18,7 +20,9 @@ context 'required parameters' do let(:title) { 'bond0' } let :params do { - :ensure => 'up', + :ensure => 'up', + :restart => true, + :sched => nil, } end let :facts do { @@ -101,6 +105,8 @@ :ethtool_opts => 'speed 1000 duplex full autoneg off', :bonding_opts => 'mode=active-backup miimon=100', :zone => 'trusted', + :restart => true, + :sched => nil, } end let :facts do { @@ -135,4 +141,42 @@ it { should_not contain_augeas('modprobe.conf_bond0') } end + context 'optional parameters: restart => false' do + let(:title) { 'bond0' } + let :params do { + :ensure => 'up', + :restart => false, + :sched => nil, + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '6.0', + :macaddress_bond0 => 'fe:fe:fe:aa:aa:aa', + } + end + it { should contain_file('ifcfg-bond0').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-bond0', + )} + it 'should contain File[ifcfg-bond0] with required contents' do + verify_contents(catalogue, 'ifcfg-bond0', [ + 'DEVICE=bond0', + 'BOOTPROTO=none', + 'ONBOOT=yes', + 'HOTPLUG=yes', + 'TYPE=Ethernet', + 'BONDING_OPTS="miimon=100"', + 'NM_CONTROLLED=no', + ]) + end + it { should contain_service('network') } + it { should_not contain_augeas('modprobe.conf_bond0') } + it { is_expected.to_not contain_file('ifcfg-bond0').that_notifies('Service[network]') } + end + end diff --git a/spec/defines/network_bond_static_spec.rb b/spec/defines/network_bond_static_spec.rb index 90f14ef..4d5ac5d 100644 --- a/spec/defines/network_bond_static_spec.rb +++ b/spec/defines/network_bond_static_spec.rb @@ -10,6 +10,8 @@ :ensure => 'blah', :ipaddress => '1.2.3.4', :netmask => '255.255.255.0', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -23,6 +25,8 @@ :ensure => 'up', :ipaddress => 'notAnIP', :netmask => '255.255.255.0', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -37,6 +41,8 @@ :ipaddress => '1.2.3.4', :netmask => '255.255.255.0', :ipv6address => 'notAnIP', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -50,6 +56,8 @@ :ensure => 'up', # :ipaddress => '1.2.3.5', # :netmask => '255.255.255.0', + :restart => true, + :sched => nil, } end let :facts do { @@ -149,6 +157,8 @@ :metric => '10', :zone => 'trusted', :userctl => true, + :restart => true, + :sched => nil, } end let :facts do { @@ -197,4 +207,47 @@ it { should_not contain_augeas('modprobe.conf_bond0') } end + context 'optional parameters: restart => false' do + let(:title) { 'bond0' } + let :params do { + :ensure => 'up', +# :ipaddress => '1.2.3.5', +# :netmask => '255.255.255.0', + :restart => false, + :sched => nil, + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '6.0', + :macaddress_bond0 => 'fe:fe:fe:aa:aa:aa', + } + end + it { should contain_file('ifcfg-bond0').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-bond0', + )} + it 'should contain File[ifcfg-bond0] with required contents' do + verify_contents(catalogue, 'ifcfg-bond0', [ + 'DEVICE=bond0', + 'BOOTPROTO=none', + 'ONBOOT=yes', + 'HOTPLUG=yes', + 'TYPE=Ethernet', +# 'IPADDR=1.2.3.5', +# 'NETMASK=255.255.255.0', + 'BONDING_OPTS="miimon=100"', + 'PEERDNS=no', + 'NM_CONTROLLED=no', + ]) + end + it { should contain_service('network') } + it { should_not contain_augeas('modprobe.conf_bond0') } + it { is_expected.to_not contain_file('ifcfg-bond0').that_notifies('Service[network]') } + end + end diff --git a/spec/defines/network_bridge_dynamic_spec.rb b/spec/defines/network_bridge_dynamic_spec.rb index 77eeec3..6317fff 100644 --- a/spec/defines/network_bridge_dynamic_spec.rb +++ b/spec/defines/network_bridge_dynamic_spec.rb @@ -7,7 +7,9 @@ context 'incorrect value: ensure' do let(:title) { 'br77' } let :params do { - :ensure => 'blah', + :ensure => 'blah', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -18,8 +20,10 @@ context 'incorrect value: stp' do let(:title) { 'br77' } let :params do { - :ensure => 'up', - :stp => 'notABool', + :ensure => 'up', + :stp => 'notABool', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -30,7 +34,9 @@ context 'required parameters' do let(:title) { 'br1' } let :params do { - :ensure => 'up', + :ensure => 'up', + :restart => true, + :sched => nil, } end let :facts do { @@ -62,11 +68,17 @@ it { should contain_package('bridge-utils') } end - context 'required parameters, restart => false' do + context 'optional parameters' do let(:title) { 'br1' } let :params do { - :ensure => 'up', - :restart => false, + :ensure => 'down', + :bootproto => 'bootp', + :userctl => true, + :stp => true, + :delay => '1000', + :bridging_opts => 'hello_time=200 priority=65535', + :restart => true, + :sched => nil, } end let :facts do { @@ -78,34 +90,31 @@ :mode => '0644', :owner => 'root', :group => 'root', - :path => '/etc/sysconfig/network-scripts/ifcfg-br1' + :path => '/etc/sysconfig/network-scripts/ifcfg-br1', + :notify => 'Service[network]' )} it 'should contain File[ifcfg-br1] with required contents' do verify_contents(catalogue, 'ifcfg-br1', [ 'DEVICE=br1', - 'BOOTPROTO=dhcp', - 'ONBOOT=yes', + 'BOOTPROTO=bootp', + 'ONBOOT=no', 'TYPE=Bridge', - 'PEERDNS=no', - 'DELAY=30', - 'STP=no', + 'DELAY=1000', + 'STP=yes', + 'BRIDGING_OPTS="hello_time=200 priority=65535"', 'NM_CONTROLLED=no', ]) end it { should contain_service('network') } - it { is_expected.to_not contain_file('ifcfg-br1').that_notifies('Service[network]') } it { should contain_package('bridge-utils') } end - context 'optional parameters' do + context 'optional parameters, restart => false' do let(:title) { 'br1' } let :params do { - :ensure => 'down', - :bootproto => 'bootp', - :userctl => true, - :stp => true, - :delay => '1000', - :bridging_opts => 'hello_time=200 priority=65535', + :ensure => 'up', + :restart => false, + :sched => nil, } end let :facts do { @@ -117,22 +126,22 @@ :mode => '0644', :owner => 'root', :group => 'root', - :path => '/etc/sysconfig/network-scripts/ifcfg-br1', - :notify => 'Service[network]' + :path => '/etc/sysconfig/network-scripts/ifcfg-br1' )} it 'should contain File[ifcfg-br1] with required contents' do verify_contents(catalogue, 'ifcfg-br1', [ 'DEVICE=br1', - 'BOOTPROTO=bootp', - 'ONBOOT=no', + 'BOOTPROTO=dhcp', + 'ONBOOT=yes', 'TYPE=Bridge', - 'DELAY=1000', - 'STP=yes', - 'BRIDGING_OPTS="hello_time=200 priority=65535"', + 'PEERDNS=no', + 'DELAY=30', + 'STP=no', 'NM_CONTROLLED=no', ]) end it { should contain_service('network') } + it { is_expected.to_not contain_file('ifcfg-br1').that_notifies('Service[network]') } it { should contain_package('bridge-utils') } end diff --git a/spec/defines/network_bridge_spec.rb b/spec/defines/network_bridge_spec.rb index 787be1b..4dc039a 100644 --- a/spec/defines/network_bridge_spec.rb +++ b/spec/defines/network_bridge_spec.rb @@ -7,7 +7,9 @@ context 'incorrect value: ensure' do let(:title) { 'br77' } let :params do { - :ensure => 'blah', + :ensure => 'blah', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -18,8 +20,10 @@ context 'incorrect value: stp' do let(:title) { 'br77' } let :params do { - :ensure => 'up', - :stp => 'notABool', + :ensure => 'up', + :stp => 'notABool', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -30,7 +34,9 @@ context 'required parameters' do let(:title) { 'br1' } let :params do { - :ensure => 'up', + :ensure => 'up', + :restart => true, + :sched => nil, } end let :facts do { @@ -62,11 +68,16 @@ it { should contain_package('bridge-utils') } end - context 'required parameters, restart => false' do + context 'optional parameters' do let(:title) { 'br1' } let :params do { - :ensure => 'up', - :restart => false, + :ensure => 'down', + :userctl => true, + :stp => true, + :delay => '1000', + :bridging_opts => 'hello_time=200 priority=65535', + :restart => true, + :sched => nil, } end let :facts do { @@ -78,33 +89,31 @@ :mode => '0644', :owner => 'root', :group => 'root', - :path => '/etc/sysconfig/network-scripts/ifcfg-br1' + :path => '/etc/sysconfig/network-scripts/ifcfg-br1', + :notify => 'Service[network]' )} it 'should contain File[ifcfg-br1] with required contents' do verify_contents(catalogue, 'ifcfg-br1', [ 'DEVICE=br1', 'BOOTPROTO=none', - 'ONBOOT=yes', + 'ONBOOT=no', 'TYPE=Bridge', - 'PEERDNS=no', - 'DELAY=30', - 'STP=no', + 'DELAY=1000', + 'STP=yes', + 'BRIDGING_OPTS="hello_time=200 priority=65535"', 'NM_CONTROLLED=no', ]) end it { should contain_service('network') } - it { is_expected.to_not contain_file('ifcfg-br1').that_notifies('Service[network]') } it { should contain_package('bridge-utils') } end - context 'optional parameters' do + context 'optional parameters, restart => false' do let(:title) { 'br1' } let :params do { - :ensure => 'down', - :userctl => true, - :stp => true, - :delay => '1000', - :bridging_opts => 'hello_time=200 priority=65535', + :ensure => 'up', + :restart => false, + :sched => nil, } end let :facts do { @@ -116,22 +125,22 @@ :mode => '0644', :owner => 'root', :group => 'root', - :path => '/etc/sysconfig/network-scripts/ifcfg-br1', - :notify => 'Service[network]' + :path => '/etc/sysconfig/network-scripts/ifcfg-br1' )} it 'should contain File[ifcfg-br1] with required contents' do verify_contents(catalogue, 'ifcfg-br1', [ 'DEVICE=br1', 'BOOTPROTO=none', - 'ONBOOT=no', + 'ONBOOT=yes', 'TYPE=Bridge', - 'DELAY=1000', - 'STP=yes', - 'BRIDGING_OPTS="hello_time=200 priority=65535"', + 'PEERDNS=no', + 'DELAY=30', + 'STP=no', 'NM_CONTROLLED=no', ]) end it { should contain_service('network') } + it { is_expected.to_not contain_file('ifcfg-br1').that_notifies('Service[network]') } it { should contain_package('bridge-utils') } end diff --git a/spec/defines/network_bridge_static_spec.rb b/spec/defines/network_bridge_static_spec.rb index a8dde12..fc18040 100644 --- a/spec/defines/network_bridge_static_spec.rb +++ b/spec/defines/network_bridge_static_spec.rb @@ -10,6 +10,8 @@ :ensure => 'blah', :ipaddress => '1.2.3.4', :netmask => '255.255.255.0', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -23,6 +25,8 @@ :ensure => 'up', :ipaddress => 'notAnIP', :netmask => '255.255.255.0', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -37,6 +41,8 @@ :ipaddress => '1.2.3.4', :netmask => '255.255.255.0', :ipv6address => 'notAnIP', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -51,6 +57,8 @@ :ipaddress => '1.2.3.4', :netmask => '255.255.255.0', :stp => 'notABool', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -65,6 +73,8 @@ :ipaddress => '1.2.3.4', :netmask => '255.255.255.0', :ipv6init => 'notABool', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -78,6 +88,8 @@ :ensure => 'up', # :ipaddress => '1.2.3.4', # :netmask => '255.255.255.0', + :restart => true, + :sched => nil, } end let :facts do { @@ -109,43 +121,6 @@ it { should contain_package('bridge-utils') } end - context 'required parameters, restart => false' do - let(:title) { 'br1' } - let :params do { - :ensure => 'up', - :ipaddress => '1.2.3.4', - :netmask => '255.255.255.0', - :restart => false, - } - end - let :facts do { - :osfamily => 'RedHat', - } - end - it { should contain_file('ifcfg-br1').with( - :ensure => 'present', - :mode => '0644', - :owner => 'root', - :group => 'root', - :path => '/etc/sysconfig/network-scripts/ifcfg-br1' - )} - it 'should contain File[ifcfg-br1] with required contents' do - verify_contents(catalogue, 'ifcfg-br1', [ - 'DEVICE=br1', - 'BOOTPROTO=static', - 'ONBOOT=yes', - 'TYPE=Bridge', - 'PEERDNS=no', - 'DELAY=30', - 'STP=no', - 'NM_CONTROLLED=no', - ]) - end - it { should contain_service('network') } - it { is_expected.to_not contain_file('ifcfg-br1').that_notifies('Service[network]') } - it { should contain_package('bridge-utils') } - end - context 'optional parameters' do let(:title) { 'br1' } let :params do { @@ -166,6 +141,8 @@ :delay => '1000', :bridging_opts => 'hello_time=200 priority=65535', :scope => 'peer 1.2.3.1', + :restart => true, + :sched => nil, } end let :facts do { @@ -208,4 +185,42 @@ it { should contain_package('bridge-utils') } end + context 'optional parameters, restart => false' do + let(:title) { 'br1' } + let :params do { + :ensure => 'up', + :ipaddress => '1.2.3.4', + :netmask => '255.255.255.0', + :restart => false, + :sched => nil, + } + end + let :facts do { + :osfamily => 'RedHat', + } + end + it { should contain_file('ifcfg-br1').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-br1' + )} + it 'should contain File[ifcfg-br1] with required contents' do + verify_contents(catalogue, 'ifcfg-br1', [ + 'DEVICE=br1', + 'BOOTPROTO=static', + 'ONBOOT=yes', + 'TYPE=Bridge', + 'PEERDNS=no', + 'DELAY=30', + 'STP=no', + 'NM_CONTROLLED=no', + ]) + end + it { should contain_service('network') } + it { is_expected.to_not contain_file('ifcfg-br1').that_notifies('Service[network]') } + it { should contain_package('bridge-utils') } + end + end diff --git a/spec/defines/network_if_bridge_spec.rb b/spec/defines/network_if_bridge_spec.rb index 1eaa6cb..a558ced 100644 --- a/spec/defines/network_if_bridge_spec.rb +++ b/spec/defines/network_if_bridge_spec.rb @@ -7,8 +7,10 @@ context 'incorrect value: ensure' do let(:title) { 'eth77' } let :params do { - :ensure => 'blah', - :bridge => 'br0', + :ensure => 'blah', + :bridge => 'br0', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -19,8 +21,10 @@ context 'required parameters' do let(:title) { 'eth1' } let :params do { - :ensure => 'up', - :bridge => 'br0', + :ensure => 'up', + :bridge => 'br0', + :restart => true, + :sched => nil, } end let :facts do { @@ -59,6 +63,8 @@ :mtu => '9000', :ethtool_opts => 'speed 1000 duplex full autoneg off', :macaddress => '00:00:00:00:00:00', + :restart => true, + :sched => nil, } end let :facts do { @@ -91,4 +97,39 @@ it { should contain_service('network') } end + context 'optional parameters: restart => false' do + let(:title) { 'eth1' } + let :params do { + :ensure => 'up', + :bridge => 'br0', + :restart => false, + :sched => nil, + } + end + let :facts do { + :osfamily => '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', + )} + it 'should contain File[ifcfg-eth1] with required contents' do + verify_contents(catalogue, 'ifcfg-eth1', [ + 'DEVICE=eth1', + 'BOOTPROTO=none', + 'ONBOOT=yes', + 'HOTPLUG=yes', + 'TYPE=Ethernet', + 'PEERDNS=no', + 'BRIDGE=br0', + 'NM_CONTROLLED=no', + ]) + end + end + end diff --git a/spec/defines/network_if_dynamic_spec.rb b/spec/defines/network_if_dynamic_spec.rb index 7ff2336..f038f59 100644 --- a/spec/defines/network_if_dynamic_spec.rb +++ b/spec/defines/network_if_dynamic_spec.rb @@ -7,7 +7,9 @@ context 'incorrect value: ensure' do let(:title) { 'eth77' } let :params do { - :ensure => 'blah', + :ensure => 'blah', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -18,7 +20,9 @@ context 'required parameters' do let(:title) { 'eth99' } let :params do { - :ensure => 'up', + :ensure => 'up', + :restart => true, + :sched => nil, } end let :facts do { @@ -64,6 +68,8 @@ :defroute => 'yes', :metric => '10', :zone => 'trusted', + :restart => true, + :sched => nil, } end let :facts do { @@ -103,7 +109,12 @@ context 'optional parameters - vlan' do let(:title) { 'eth45.302' } - let(:params) {{ :ensure => 'up' }} + let :params do { + :ensure => 'up', + :restart => true, + :sched => nil, + } + end let :facts do { :osfamily => 'RedHat', :macaddress_eth45 => 'bb:cc:bb:cc:bb:cc', @@ -115,7 +126,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth45.302', - :notify => 'Service[network]' + :notify => 'Service[network]', )} it 'should contain File[ifcfg-eth45.302] with required contents' do verify_contents(catalogue, 'ifcfg-eth45.302', [ @@ -136,6 +147,8 @@ let :params do { :ensure => 'up', :manage_hwaddr => false, + :restart => true, + :sched => nil, } end let :facts do { @@ -149,7 +162,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth0', - :notify => 'Service[network]' + :notify => 'Service[network]', )} it 'should contain File[ifcfg-eth0] with required contents' do verify_contents(catalogue, 'ifcfg-eth0', [ @@ -164,5 +177,37 @@ it { should contain_service('network') } end + context 'optional parameters - restart => false' do + let(:title) { 'eth0' } + let :params do { + :ensure => 'up', + :restart => false, + :sched => nil, + } + end + let :facts do { + :osfamily => 'RedHat', + :macaddress_eth0 => 'bb:cc:bb:cc:bb:cc', + } + end + it { should contain_file('ifcfg-eth0').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-eth0', + )} + it 'should contain File[ifcfg-eth0] with required contents' do + verify_contents(catalogue, 'ifcfg-eth0', [ + 'DEVICE=eth0', + 'BOOTPROTO=dhcp', + 'HWADDR=bb:cc:bb:cc:bb:cc', + 'ONBOOT=yes', + 'HOTPLUG=yes', + 'TYPE=Ethernet', + 'NM_CONTROLLED=no', + ]) + end + end end diff --git a/spec/defines/network_if_promisc_spec.rb b/spec/defines/network_if_promisc_spec.rb index c4e32f5..eb7c5d3 100644 --- a/spec/defines/network_if_promisc_spec.rb +++ b/spec/defines/network_if_promisc_spec.rb @@ -7,7 +7,9 @@ context 'required parameters' do let(:title) { 'eth1' } let :params do { - :ensure => 'up', + :ensure => 'up', + :restart => true, + :sched => nil, } end let :facts do { @@ -65,6 +67,8 @@ let :params do { :ensure => 'up', :macaddress => 'ef:ef:ef:ef:ef:ef', + :restart => true, + :sched => nil, } end let :facts do { @@ -98,4 +102,62 @@ it { should contain_service('network') } end + context 'optional parameters: restart => false' do + let(:title) { 'eth1' } + let :params do { + :ensure => 'up', + :restart => false, + :sched => nil, + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '6.0', + :operatingsystemmajrelease => '6', + :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', + )} + 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', + 'PEERDNS=no', + 'PROMISC=yes', + 'NM_CONTROLLED=no', + ]) + end + it { should contain_service('network') } + it { should contain_file('/sbin/ifup-local') } + it { should contain_file('/sbin/ifdown-local') } + it { should contain_file('ifup-local-promisc').with( + :ensure => 'file', + :mode => '0755', + :owner => 'root', + :group => 'root', + :path => '/sbin/ifup-local-promisc', + :source => 'puppet:///modules/network/promisc/ifup-local-promisc_6' + )} + it { should contain_file('ifdown-local-promisc').with( + :ensure => 'file', + :mode => '0755', + :owner => 'root', + :group => 'root', + :path => '/sbin/ifdown-local-promisc', + :source => 'puppet:///modules/network/promisc/ifdown-local-promisc_6' + )} + it { is_expected.to_not contain_file('ifcfg-eth1').that_notifies('Service[network]') } + end + end diff --git a/spec/defines/network_if_spec.rb b/spec/defines/network_if_spec.rb index ea20ced..d82d384 100644 --- a/spec/defines/network_if_spec.rb +++ b/spec/defines/network_if_spec.rb @@ -7,7 +7,9 @@ context 'incorrect value: ensure' do let(:title) { 'eth1' } let :params do { - :ensure => 'blah', + :ensure => 'blah', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -18,7 +20,9 @@ context 'required parameters' do let(:title) { 'eth0' } let :params do { - :ensure => 'up', + :ensure => 'up', + :restart => true, + :sched => nil, } end let :facts do { @@ -56,6 +60,8 @@ :mtu => '9000', :ethtool_opts => 'speed 1000 duplex full autoneg off', :zone => 'trusted', + :restart => true, + :sched => nil, } end let :facts do { @@ -89,5 +95,40 @@ it { should contain_service('network') } end -end + context 'optional parameters: restart => false' do + let(:title) { 'eth0' } + let :params do { + :ensure => 'up', + :restart => false, + :sched => nil, + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '6.0', + :macaddress_eth0 => 'fe:fe:fe:aa:aa:aa', + } + end + it { should contain_file('ifcfg-eth0').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-eth0', + )} + it 'should contain File[ifcfg-eth0] with required contents' do + verify_contents(catalogue, 'ifcfg-eth0', [ + 'DEVICE=eth0', + 'BOOTPROTO=none', + 'ONBOOT=yes', + 'HOTPLUG=yes', + 'TYPE=Ethernet', + 'NM_CONTROLLED=no', + ]) + end + it { should contain_service('network') } + it { is_expected.to_not contain_file('ifcfg-eth0').that_notifies('Service[network]') } + end +end diff --git a/spec/defines/network_if_static_spec.rb b/spec/defines/network_if_static_spec.rb index 4409578..d6ab359 100644 --- a/spec/defines/network_if_static_spec.rb +++ b/spec/defines/network_if_static_spec.rb @@ -10,6 +10,8 @@ :ensure => 'up', :ipaddress => 'notAnIP', :netmask => '255.255.255.0', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -24,6 +26,8 @@ :ipaddress => '1.2.3.4', :netmask => '255.255.255.0', :ipv6address => 'notAnIP', + :restart => true, + :sched => nil, } end it 'should fail' do @@ -38,6 +42,8 @@ :ipaddress => '1.2.3.4', :netmask => '255.255.255.0', :ipv6address => { 'notAn' => 'IP' }, + :restart => true, + :sched => nil, } end it 'should fail' do @@ -57,7 +63,13 @@ '123:4567:89ab:cdef:123:4567:89ab:cdee', 'notAnIP', '123:4567:89ab:cdef:123:4567:89ab:cdef', - ] + ], + :restart => true, + :sched => nil, + } + end + let :facts do { + :osfamily => 'RedHat', } end it 'should fail' do @@ -71,6 +83,8 @@ :ensure => 'up', # :ipaddress => '1.2.3.4', # :netmask => '255.255.255.0', + :restart => true, + :sched => nil, } end let :facts do { @@ -111,6 +125,7 @@ :ipaddress => '1.2.3.4', :netmask => '255.255.255.0', :restart => false, + :sched => nil, } end let :facts do { @@ -169,6 +184,8 @@ :metric => '10', :zone => 'trusted', :arpcheck => false, + :restart => true, + :sched => nil, } end let :facts do { @@ -225,6 +242,8 @@ :ensure => 'up', :ipaddress => '1.2.3.4', :netmask => '255.255.255.0', + :restart => true, + :sched => nil, } end let :facts do { @@ -263,6 +282,8 @@ :ipaddress => '1.2.3.4', :netmask => '255.255.255.0', :manage_hwaddr => false, + :restart => true, + :sched => nil, } end let :facts do { @@ -299,7 +320,9 @@ :ensure => 'up', :ipaddress => '1.2.3.4', :netmask => '255.255.255.0', - :flush => true + :flush => true, + :restart => true, + :sched => nil, } end let :facts do { @@ -320,6 +343,8 @@ :ipv6address => [ '123:4567:89ab:cdef:123:4567:89ab:cdee', ], + :restart => true, + :sched => nil, } end let :facts do { @@ -366,6 +391,8 @@ '123:4567:89ab:cdef:123:4567:89ab:cdee', '123:4567:89ab:cdef:123:4567:89ab:cdef', ], + :restart => true, + :sched => nil, } end let :facts do { diff --git a/spec/defines/network_route_spec.rb b/spec/defines/network_route_spec.rb index 8908418..2e47be5 100644 --- a/spec/defines/network_route_spec.rb +++ b/spec/defines/network_route_spec.rb @@ -11,6 +11,8 @@ :ipaddress => [ '192.168.2.1', ], :netmask => [ '255.255.255.1', ], :gateway => [ '192.168.1.2', ], + :restart => true, + :sched => nil, } end let(:facts) {{ :osfamily => 'RedHat' }} @@ -40,6 +42,7 @@ :netmask => [ '255.255.255.1', ], :gateway => [ '192.168.1.2', ], :restart => false, + :sched => nil, } end let(:facts) {{ :osfamily => 'RedHat' }} @@ -67,7 +70,9 @@ let :params do { :ipaddress => [ '192.168.2.0', '10.0.0.0', ], :netmask => [ '255.255.255.0', '255.0.0.0', ], - :gateway => [ '192.168.1.1', '10.0.0.1', ] + :gateway => [ '192.168.1.1', '10.0.0.1', ], + :restart => true, + :sched => nil, } end let(:facts) {{ :osfamily => 'RedHat' }} diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f566..00c3e57 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,5 @@ require 'puppetlabs_spec_helper/module_spec_helper' + +RSpec.configure do |config| + config.before(:all) {Facter.clear} +end