From c095b9264b02609ac947097995a0f60783c9a26b Mon Sep 17 00:00:00 2001 From: Manfred Pusch Date: Mon, 8 Jun 2020 12:37:49 +0000 Subject: [PATCH 1/3] added support for policy based routing --- manifests/route.pp | 62 ++++++++++++++++------ manifests/rule.pp | 84 ++++++++++++++++++++++++++++++ spec/defines/network_route_spec.rb | 74 ++++++++++++++++++++++++++ spec/defines/network_rule_spec.rb | 79 ++++++++++++++++++++++++++++ templates/route-eth-v4.erb | 16 ++++++ templates/route-eth-v6.erb | 16 ++++++ templates/rule-eth-v4.erb | 47 +++++++++++++++++ templates/rule-eth-v6.erb | 47 +++++++++++++++++ 8 files changed, 410 insertions(+), 15 deletions(-) create mode 100644 manifests/rule.pp create mode 100644 spec/defines/network_rule_spec.rb create mode 100644 templates/route-eth-v4.erb create mode 100644 templates/route-eth-v6.erb create mode 100644 templates/rule-eth-v4.erb create mode 100644 templates/rule-eth-v6.erb diff --git a/manifests/route.pp b/manifests/route.pp index 27c7534..cca6421 100644 --- a/manifests/route.pp +++ b/manifests/route.pp @@ -41,15 +41,19 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::route ( - $ipaddress, - $netmask, - $gateway, - $restart = true, + $ipaddress = [], + $netmask = [], + $gateway = [], + $ipv4_routes = [], + $ipv6_routes = [], + $restart = true, ) { # Validate our arrays validate_array($ipaddress) validate_array($netmask) validate_array($gateway) + validate_array($ipv4_routes) + validate_array($ipv6_routes) # Validate our booleans validate_bool($restart) @@ -57,19 +61,47 @@ $interface = $name - file { "route-${interface}": - ensure => 'present', - mode => '0644', - owner => 'root', - group => 'root', - path => "/etc/sysconfig/network-scripts/route-${interface}", - content => template('network/route-eth.erb'), - before => File["ifcfg-${interface}"], + if $restart { + $notify = Service['network'] + } else { + $notify = undef } - if $restart { - File["route-${interface}"] { - notify => Service['network'], + if empty($ipaddress) and (!empty($ipv4_routes) or !empty($ipv6_routes)) { + if ! empty($ipv4_routes) { + file { "route-${interface}": + ensure => 'present', + mode => '0644', + owner => 'root', + group => 'root', + path => "/etc/sysconfig/network-scripts/route-${interface}", + content => template('network/route-eth-v4.erb'), + before => File["ifcfg-${interface}"], + notify => $notify, + } + } + if ! empty($ipv6_routes) { + file { "route6-${interface}": + ensure => 'present', + mode => '0644', + owner => 'root', + group => 'root', + path => "/etc/sysconfig/network-scripts/route6-${interface}", + content => template('network/route-eth-v6.erb'), + before => File["ifcfg-${interface}"], + notify => $notify, + } + } + } else { + file { "route-${interface}": + ensure => 'present', + mode => '0644', + owner => 'root', + group => 'root', + path => "/etc/sysconfig/network-scripts/route-${interface}", + content => template('network/route-eth.erb'), + before => File["ifcfg-${interface}"], + notify => $notify, } } } # define network::route diff --git a/manifests/rule.pp b/manifests/rule.pp new file mode 100644 index 0000000..bc955f7 --- /dev/null +++ b/manifests/rule.pp @@ -0,0 +1,84 @@ +# == Definition: network::rule +# +# Configures /etc/sysconfig/networking-scripts/rule-$name. +# +# === Parameters: +# +# $ipv4_rules +# $ipv6_rules +# +# === Actions: +# +# Deploys the file /etc/sysconfig/network-scripts/rule-$name. +# +# === Requires: +# +# File["ifcfg-$name"] +# Service['network'] +# +# === Sample Usage: +# +# network::route { 'eth0': +# ipv4_rules => [{ +# iif => 'eth0', +# table => 1, +# },{ +# from => '192.168.200.100', +# table => 1, +# },] +# } +# +# === Authors: +# +# Manfred Pusch +# +# === Copyright: +# +# Copyright (C) 2016 Manfred Pusch, unless otherwise noted. +# +define network::rule ( + $ipv4_rules = [], + $ipv6_rules = [], + $restart = true, +) { + # Validate our arrays + validate_array($ipv4_rules) + validate_array($ipv6_rules) + # Validate our booleans + validate_bool($restart) + + include '::network' + + $interface = $name + + if $restart { + $notify = Service['network'] + } else { + $notify = undef + } + + if ! empty($ipv4_rules) { + file { "rule-${interface}": + ensure => 'present', + mode => '0644', + owner => 'root', + group => 'root', + path => "/etc/sysconfig/network-scripts/rule-${interface}", + content => template('network/rule-eth-v4.erb'), + before => File["ifcfg-${interface}"], + notify => $notify, + } + } + if ! empty($ipv6_rules) { + file { "rule6-${interface}": + ensure => 'present', + mode => '0644', + owner => 'root', + group => 'root', + path => "/etc/sysconfig/network-scripts/rule6-${interface}", + content => template('network/rule-eth-v6.erb'), + before => File["ifcfg-${interface}"], + notify => $notify, + } + } +} # define network::rule diff --git a/spec/defines/network_route_spec.rb b/spec/defines/network_route_spec.rb index 8908418..50d34f2 100644 --- a/spec/defines/network_route_spec.rb +++ b/spec/defines/network_route_spec.rb @@ -91,4 +91,78 @@ it { should contain_service('network') } end + context 'new parameters v4' do + let(:pre_condition) {'network::if{"eth0": ensure => "up"}'} + let(:title) { 'eth0' } + let :params do { + :ipv4_routes => [ + { + 'dest' => '192.168.254.0/24', + 'gateway' => '192.168.18.1', + },{ + 'dest' => '192.168.253.0/24', + 'table' => '1', + },{ + 'dest' => '192.168.252.0/24', + 'gateway' => '192.168.18.15', + 'table' => '2', + }, + ] + } + end + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('route-eth0').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/route-eth0' + )} + it 'should contain File[route-eth0] with contents "192.168.254.0/24 via 192.168.18.1 dev eth0\n192.168.253.0/24 dev eth0 table 1\n192.168.252.0/24 via 192.168.18.15 dev eth0 table 1"' do + verify_contents(catalogue, 'route-eth0', [ + '192.168.254.0/24 via 192.168.18.1 dev eth0', + '192.168.253.0/24 dev eth0 table 1', + '192.168.252.0/24 via 192.168.18.15 dev eth0 table 2', + ]) + end + it { should contain_service('network') } + end + + context 'new parameters v6' do + let(:pre_condition) {'network::if{"eth0": ensure => "up"}'} + let(:title) { 'eth0' } + let :params do { + :ipv6_routes => [ + { + 'dest' => '0:0:0:0:0:ffff:c0a8:fe00/120', + 'gateway' => '0:0:0:0:0:ffff:c0a8:1201', + },{ + 'dest' => '0:0:0:0:0:ffff:c0a8:fd00/120', + 'table' => '1', + },{ + 'dest' => '0:0:0:0:0:ffff:c0a8:fc00/120', + 'gateway' => '0:0:0:0:0:ffff:c0a8:120f', + 'table' => '2', + }, + ] + } + end + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('route6-eth0').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/route6-eth0' + )} + it 'should contain File[route6-eth0] with contents "0:0:0:0:0:ffff:c0a8:fe00/120 via 0:0:0:0:0:ffff:c0a8:1201 dev eth0\n0:0:0:0:0:ffff:c0a8:fd00/120 dev eth0 table 1\n0:0:0:0:0:ffff:c0a8:fc00/120 via 0:0:0:0:0:ffff:c0a8:120f dev eth0 table 2"' do + verify_contents(catalogue, 'route6-eth0', [ + '0:0:0:0:0:ffff:c0a8:fe00/120 via 0:0:0:0:0:ffff:c0a8:1201 dev eth0', + '0:0:0:0:0:ffff:c0a8:fd00/120 dev eth0 table 1', + '0:0:0:0:0:ffff:c0a8:fc00/120 via 0:0:0:0:0:ffff:c0a8:120f dev eth0 table 2', + ]) + end + it { should contain_service('network') } + end + end diff --git a/spec/defines/network_rule_spec.rb b/spec/defines/network_rule_spec.rb new file mode 100644 index 0000000..cfb86d7 --- /dev/null +++ b/spec/defines/network_rule_spec.rb @@ -0,0 +1,79 @@ +#!/usr/bin/env rspec + +require 'spec_helper' + +describe 'network::rule', :type => 'define' do + + context 'new ipv4' do + let(:pre_condition) {'network::if{"eth0": ensure => "up"}'} + let(:title) { 'eth0' } + let :params do { + :ipv4_rules => [ + { + 'iif' => 'eth0', + 'table' => '1', + },{ + 'from' => '192.168.253.254', + 'table' => '1', + },{ + 'from' => '192.168.252.0/24', + 'reject' => true, + }, + ] + } + end + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('rule-eth0').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/rule-eth0' + )} + it 'should contain File[rule-eth0] with contents "iif eth0 table 1 \nfrom 192.168.253.254 table 1 \nfrom 192.168.252.0/24 reject "' do + verify_contents(catalogue, 'rule-eth0', [ + 'iif eth0 table 1 ', + 'from 192.168.253.254 table 1 ', + 'from 192.168.252.0/24 reject ', + ]) + end + it { should contain_service('network') } + end + + context 'new ipv6' do + let(:pre_condition) {'network::if{"eth0": ensure => "up"}'} + let(:title) { 'eth0' } + let :params do { + :ipv6_rules => [ + { + 'iif' => 'eth0', + 'table' => '1', + },{ + 'from' => '0:0:0:0:0:ffff:c0a8:fdfe', + 'table' => '1', + },{ + 'from' => '0:0:0:0:0:ffff:c0a8:fc00/120', + 'reject' => true, + }, + ] + } + end + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_file('rule6-eth0').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/rule6-eth0' + )} + it 'should contain File[rule6-eth0] with contents "iif eth0 table 1 \nfrom 0:0:0:0:0:ffff:c0a8:fdfe table 1 \nfrom 0:0:0:0:0:ffff:c0a8:fc00/120 reject "' do + verify_contents(catalogue, 'rule6-eth0', [ + 'iif eth0 table 1 ', + 'from 0:0:0:0:0:ffff:c0a8:fdfe table 1 ', + 'from 0:0:0:0:0:ffff:c0a8:fc00/120 reject ', + ]) + end + it { should contain_service('network') } + end + +end diff --git a/templates/route-eth-v4.erb b/templates/route-eth-v4.erb new file mode 100644 index 0000000..653dfcb --- /dev/null +++ b/templates/route-eth-v4.erb @@ -0,0 +1,16 @@ +### +### File managed by Puppet +### +<% if !@ipv4_routes.empty? -%> +<% [@ipv4_routes].flatten.each do |v4| -%> +<%= "#{v4["dest"]}" -%> +<% if v4["gateway"] != nil -%> +<%= " via #{v4["gateway"]}" -%> +<% end -%> +<%= " dev #{@interface}" -%> +<% if v4["table"] != nil -%> +<%= " table #{v4["table"]}" -%> +<% end -%> + +<% end -%> +<% end -%> diff --git a/templates/route-eth-v6.erb b/templates/route-eth-v6.erb new file mode 100644 index 0000000..299e069 --- /dev/null +++ b/templates/route-eth-v6.erb @@ -0,0 +1,16 @@ +### +### File managed by Puppet +### +<% if !@ipv6_routes.empty? -%> +<% [@ipv6_routes].flatten.each do |v6| -%> +<%= "#{v6["dest"]}" -%> +<% if v6["gateway"] != nil -%> +<%= " via #{v6["gateway"]}" -%> +<% end -%> +<%= " dev #{@interface}" -%> +<% if v6["table"] != nil -%> +<%= " table #{v6["table"]}" -%> +<% end -%> + +<% end -%> +<% end -%> diff --git a/templates/rule-eth-v4.erb b/templates/rule-eth-v4.erb new file mode 100644 index 0000000..03498aa --- /dev/null +++ b/templates/rule-eth-v4.erb @@ -0,0 +1,47 @@ +### +### File managed by Puppet +### +<% if !@ipv4_rules.empty? -%> +<% [@ipv4_rules].flatten.each do |v4| -%> +<% if v4["from"] != nil -%> +<%= "from #{v4["from"]} " -%> +<% end -%> +<% if v4["to"] != nil -%> +<%= "to #{v4["to"]} " -%> +<% end -%> +<% if v4["tos"] != nil -%> +<%= "tos #{v4["tos"]} " -%> +<% end -%> +<% if v4["fwmark"] != nil -%> +<%= "fwmark #{v4["fwmark"]} " -%> +<% end -%> +<% if v4["iif"] != nil -%> +<%= "iif #{v4["iif"]} " -%> +<% end -%> +<% if v4["oif"] != nil -%> +<%= "oif #{v4["oif"]} " -%> +<% end -%> +<% if v4["pref"] != nil -%> +<%= "pref #{v4["pref"]} " -%> +<% end -%> +<% if v4["table"] != nil -%> +<%= "table #{v4["table"]} " -%> +<% end -%> +<% if v4["nat"] != nil -%> +<%= "nat #{v4["nat"]} " -%> +<% end -%> +<% if v4["prohibit"] != nil -%> +<%= "prohibit " -%> +<% end -%> +<% if v4["reject"] != nil -%> +<%= "reject " -%> +<% end -%> +<% if v4["unreachable"] != nil -%> +<%= "unreachable " -%> +<% end -%> +<% if v4["realms"] != nil -%> +<%= "realms #{v4["realms"]} " -%> +<% end -%> + +<% end -%> +<% end -%> diff --git a/templates/rule-eth-v6.erb b/templates/rule-eth-v6.erb new file mode 100644 index 0000000..478e500 --- /dev/null +++ b/templates/rule-eth-v6.erb @@ -0,0 +1,47 @@ +### +### File managed by Puppet +### +<% if !@ipv6_rules.empty? -%> +<% [@ipv6_rules].flatten.each do |v6| -%> +<% if v6["from"] != nil -%> +<%= "from #{v6["from"]} " -%> +<% end -%> +<% if v6["to"] != nil -%> +<%= "to #{v6["to"]} " -%> +<% end -%> +<% if v6["tos"] != nil -%> +<%= "tos #{v6["tos"]} " -%> +<% end -%> +<% if v6["fwmark"] != nil -%> +<%= "fwmark #{v6["fwmark"]} " -%> +<% end -%> +<% if v6["iif"] != nil -%> +<%= "iif #{v6["iif"]} " -%> +<% end -%> +<% if v6["oif"] != nil -%> +<%= "oif #{v6["oif"]} " -%> +<% end -%> +<% if v6["pref"] != nil -%> +<%= "pref #{v6["pref"]} " -%> +<% end -%> +<% if v6["table"] != nil -%> +<%= "table #{v6["table"]} " -%> +<% end -%> +<% if v6["nat"] != nil -%> +<%= "nat #{v6["nat"]} " -%> +<% end -%> +<% if v6["prohibit"] != nil -%> +<%= "prohibit " -%> +<% end -%> +<% if v6["reject"] != nil -%> +<%= "reject " -%> +<% end -%> +<% if v6["unreachable"] != nil -%> +<%= "unreachable " -%> +<% end -%> +<% if v6["realms"] != nil -%> +<%= "realms #{v6["realms"]} " -%> +<% end -%> + +<% end -%> +<% end -%> From 0bee9414e9d9de051f7c7c7677aa24d16b7ddbf9 Mon Sep 17 00:00:00 2001 From: Manfred Pusch Date: Wed, 3 Jun 2020 12:16:10 +0000 Subject: [PATCH 2/3] added support for rhel8 --- manifests/alias/range.pp | 7 +- manifests/bond/slave.pp | 9 ++- manifests/bridge.pp | 7 +- manifests/bridge/dynamic.pp | 7 +- manifests/bridge/static.pp | 7 +- manifests/global.pp | 4 +- manifests/hiera.pp | 2 +- manifests/if/promisc.pp | 2 +- manifests/init.pp | 21 +++--- manifests/route.pp | 4 +- manifests/rule.pp | 4 +- manifests/service.pp | 37 +++++++++++ spec/classes/network_global_spec.rb | 6 +- spec/classes/network_init_spec.rb | 12 ++-- spec/classes/network_service_spec.rb | 32 +++++++++ spec/defines/network_alias_range_spec.rb | 73 +++++++++++++++++--- spec/defines/network_alias_spec.rb | 57 ++++++++++++++-- spec/defines/network_bond_bridge_spec.rb | 45 ++++++++++++- spec/defines/network_bond_dynamic_spec.rb | 50 +++++++++++++- spec/defines/network_bond_slave_spec.rb | 53 +++++++++++++-- spec/defines/network_bond_spec.rb | 45 ++++++++++++- spec/defines/network_bond_static_spec.rb | 73 +++++++++++++++++++- spec/defines/network_bridge_dynamic_spec.rb | 50 ++++++++++++-- spec/defines/network_bridge_spec.rb | 49 ++++++++++++-- spec/defines/network_bridge_static_spec.rb | 73 ++++++++++++++++++-- spec/defines/network_if_bridge_spec.rb | 47 ++++++++++++- spec/defines/network_if_dynamic_spec.rb | 46 +++++++++++-- spec/defines/network_if_promisc_spec.rb | 4 +- spec/defines/network_if_spec.rb | 43 +++++++++++- spec/defines/network_if_static_spec.rb | 74 ++++++++++++++++++--- spec/defines/network_route_spec.rb | 29 ++++++-- spec/defines/network_rule_spec.rb | 10 ++- templates/ifcfg-alias-range.erb | 4 ++ templates/ifcfg-alias.erb | 4 ++ templates/ifcfg-bond.erb | 4 ++ templates/ifcfg-br.erb | 4 ++ templates/ifcfg-eth.erb | 4 ++ 37 files changed, 899 insertions(+), 103 deletions(-) create mode 100644 manifests/service.pp create mode 100644 spec/classes/network_service_spec.rb diff --git a/manifests/alias/range.pp b/manifests/alias/range.pp index 4746d94..ebfb4e7 100644 --- a/manifests/alias/range.pp +++ b/manifests/alias/range.pp @@ -75,6 +75,11 @@ 'absent' => 'absent', default => undef, } + if versioncmp($::operatingsystemrelease, '8') >= 0 { + $nm_controlled = true + } else { + $nm_controlled = false + } file { "ifcfg-${interface}-range${clonenum_start}": ensure => $file_ensure, @@ -88,7 +93,7 @@ if $restart { File["ifcfg-${interface}-range${clonenum_start}"] { - notify => Service['network'], + notify => Class['network::service'], } } diff --git a/manifests/bond/slave.pp b/manifests/bond/slave.pp index 8784584..92a951b 100644 --- a/manifests/bond/slave.pp +++ b/manifests/bond/slave.pp @@ -21,7 +21,7 @@ # # === Requires: # -# Service['network'] +# Class['network::service'] # # === Sample Usage: # @@ -61,6 +61,11 @@ include '::network' $interface = $name + if versioncmp($::operatingsystemrelease, '8') >= 0 { + $nm_controlled = true + } else { + $nm_controlled = false + } file { "ifcfg-${interface}": ensure => 'present', @@ -74,7 +79,7 @@ if $restart { File["ifcfg-${interface}"] { - notify => Service['network'], + notify => Class['network::service'], } } } # define network::bond::slave diff --git a/manifests/bridge.pp b/manifests/bridge.pp index acb2102..b104b44 100644 --- a/manifests/bridge.pp +++ b/manifests/bridge.pp @@ -67,6 +67,11 @@ 'down' => 'no', default => undef, } + if versioncmp($::operatingsystemrelease, '8') >= 0 { + $nm_controlled = true + } else { + $nm_controlled = false + } file { "ifcfg-${interface}": ensure => 'present', @@ -80,7 +85,7 @@ if $restart { File["ifcfg-${interface}"] { - notify => Service['network'], + notify => Class['network::service'], } } } # define network::bridge diff --git a/manifests/bridge/dynamic.pp b/manifests/bridge/dynamic.pp index 729d464..f43c9dc 100644 --- a/manifests/bridge/dynamic.pp +++ b/manifests/bridge/dynamic.pp @@ -68,6 +68,11 @@ 'down' => 'no', default => undef, } + if versioncmp($::operatingsystemrelease, '8') >= 0 { + $nm_controlled = true + } else { + $nm_controlled = false + } file { "ifcfg-${interface}": ensure => 'present', @@ -81,7 +86,7 @@ if $restart { File["ifcfg-${interface}"] { - notify => Service['network'], + notify => Class['network::service'], } } } # define network::bridge::dynamic diff --git a/manifests/bridge/static.pp b/manifests/bridge/static.pp index 95b3a47..ac69995 100644 --- a/manifests/bridge/static.pp +++ b/manifests/bridge/static.pp @@ -112,6 +112,11 @@ 'down' => 'no', default => undef, } + if versioncmp($::operatingsystemrelease, '8') >= 0 { + $nm_controlled = true + } else { + $nm_controlled = false + } file { "ifcfg-${interface}": ensure => 'present', @@ -125,7 +130,7 @@ if $restart { File["ifcfg-${interface}"] { - notify => Service['network'], + notify => Class['network::service'], } } } # define network::bridge::static diff --git a/manifests/global.pp b/manifests/global.pp index 9ff8c67..b12bcd8 100644 --- a/manifests/global.pp +++ b/manifests/global.pp @@ -32,7 +32,7 @@ # # === Requires: # -# Service['network'] +# Class['network::service'] # # === Sample Usage: # @@ -129,7 +129,7 @@ if $restart { File['network.sysconfig'] { - notify => Service['network'], + notify => Class['network::service'], } } } # class global diff --git a/manifests/hiera.pp b/manifests/hiera.pp index 0d35044..4660d09 100644 --- a/manifests/hiera.pp +++ b/manifests/hiera.pp @@ -12,7 +12,7 @@ # # === Requires: # -# Service['network'] +# Class['network::service'] # # === Sample Usage: # diff --git a/manifests/if/promisc.pp b/manifests/if/promisc.pp index 291cdd6..1014653 100644 --- a/manifests/if/promisc.pp +++ b/manifests/if/promisc.pp @@ -19,7 +19,7 @@ # # === Requires: # -# Service['network'] +# Class['network::service'] # # === Sample Usage: # diff --git a/manifests/init.pp b/manifests/init.pp index 6e3798f..04465f6 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -8,7 +8,7 @@ # # === Actions: # -# Defines the network service so that other resources can notify it to restart. +# Fails if not on a RHEL system # # === Sample Usage: # @@ -30,14 +30,7 @@ fail('This network module only supports RedHat-based systems.') } } - - service { 'network': - ensure => 'running', - enable => true, - hasrestart => true, - hasstatus => true, - provider => 'redhat', - } + include network::service } # class network # == Definition: network_if_base @@ -177,6 +170,12 @@ $dns2_real = $dns2 } + if versioncmp($::operatingsystemrelease, '8') >= 0 { + $nm_controlled = true + } else { + $nm_controlled = false + } + if $isalias { $onparent = $ensure ? { 'up' => 'yes', @@ -199,7 +198,7 @@ command => "ip addr flush dev ${interface}", refreshonly => true, subscribe => File["ifcfg-${interface}"], - before => Service['network'], + before => Class['network::service'], path => '/sbin:/usr/sbin', } } @@ -215,7 +214,7 @@ if $restart { File["ifcfg-${interface}"] { - notify => Service['network'], + notify => Class['network::service'], } } } # define network_if_base diff --git a/manifests/route.pp b/manifests/route.pp index cca6421..4c2c527 100644 --- a/manifests/route.pp +++ b/manifests/route.pp @@ -16,7 +16,7 @@ # === Requires: # # File["ifcfg-$name"] -# Service['network'] +# Class['network::service'] # # === Sample Usage: # @@ -62,7 +62,7 @@ $interface = $name if $restart { - $notify = Service['network'] + $notify = Class['network::service'] } else { $notify = undef } diff --git a/manifests/rule.pp b/manifests/rule.pp index bc955f7..78a4276 100644 --- a/manifests/rule.pp +++ b/manifests/rule.pp @@ -14,7 +14,7 @@ # === Requires: # # File["ifcfg-$name"] -# Service['network'] +# Class['network::service'] # # === Sample Usage: # @@ -52,7 +52,7 @@ $interface = $name if $restart { - $notify = Service['network'] + $notify = Class['network::service'] } else { $notify = undef } diff --git a/manifests/service.pp b/manifests/service.pp new file mode 100644 index 0000000..e6ead98 --- /dev/null +++ b/manifests/service.pp @@ -0,0 +1,37 @@ +# == Class: network::service +# +# Restarts the network if notified +# +# === Authors: +# +# Manfred Pusch +# +# === Copyright: +# +# Copyright (C) 2020 Manfred Pusch, unless otherwise noted. +# +class network::service ( + $restart = true, +) { + # Validate our data + validate_bool($restart) + + if $restart { + if versioncmp($::operatingsystemrelease, '8') >= 0 { + exec { 'restart_network': + command => '/usr/bin/nmcli networking off ; /usr/bin/systemctl restart NetworkManager ; /usr/bin/nmcli networking on', + group => 'root', + user => 'root', + refreshonly => true, + } + } else { + service { 'network': + ensure => 'running', + enable => true, + hasrestart => true, + hasstatus => true, + provider => 'redhat', + } + } + } +} # Class: network::service diff --git a/spec/classes/network_global_spec.rb b/spec/classes/network_global_spec.rb index 5231852..bcb0ffb 100644 --- a/spec/classes/network_global_spec.rb +++ b/spec/classes/network_global_spec.rb @@ -32,7 +32,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[network.sysconfig] with correct contents' do verify_contents(catalogue, 'network.sysconfig', [ @@ -43,7 +43,7 @@ ]) end it { should_not contain_exec('hostnamectl set-hostname') } - it { is_expected.to contain_file('network.sysconfig').that_notifies('Service[network]') } + it { is_expected.to contain_file('network.sysconfig').that_notifies('Class[Network::Service]') } end context 'on a supported operatingsystem, default parameters, restart => false' do @@ -73,7 +73,7 @@ ]) end it { should_not contain_exec('hostnamectl set-hostname') } - it { is_expected.to_not contain_file('network.sysconfig').that_notifies('Service[network]') } + it { is_expected.to_not contain_file('network.sysconfig').that_notifies('Class[Network::Service]') } end context 'on a supported operatingsystem, custom parameters, systemd' do diff --git a/spec/classes/network_init_spec.rb b/spec/classes/network_init_spec.rb index c44d416..b07272b 100644 --- a/spec/classes/network_init_spec.rb +++ b/spec/classes/network_init_spec.rb @@ -15,14 +15,12 @@ end context 'on a supported operatingsystem' do - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + }} - it { should contain_service('network').with( - :ensure => 'running', - :enable => true, - :hasrestart => true, - :hasstatus => true - )} + it { is_expected.to compile.with_all_deps } end end diff --git a/spec/classes/network_service_spec.rb b/spec/classes/network_service_spec.rb new file mode 100644 index 0000000..4cc2425 --- /dev/null +++ b/spec/classes/network_service_spec.rb @@ -0,0 +1,32 @@ +#!/usr/bin/env rspec + +require 'spec_helper' + +describe 'network::service', :type => 'class' do + + context 'on RHEL7' do + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + }} + it { should contain_service('network').with( + :ensure => 'running', + :enable => true, + :hasrestart => true, + :hasstatus => true, + )} + end + + context 'on RHEL8' do + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '8.0', + }} + it { should contain_exec('restart_network').with( + :command => '/usr/bin/nmcli networking off ; /usr/bin/systemctl restart NetworkManager ; /usr/bin/nmcli networking on', + :group => 'root', + :user => 'root', + :refreshonly => true, + )} + end +end diff --git a/spec/defines/network_alias_range_spec.rb b/spec/defines/network_alias_range_spec.rb index 3abc951..6c87461 100644 --- a/spec/defines/network_alias_range_spec.rb +++ b/spec/defines/network_alias_range_spec.rb @@ -47,6 +47,42 @@ end + context 'RHEL8 required parameters: ensure => up' do + let(:pre_condition) { "file { 'ifcfg-eth99': }" } + let(:title) { 'eth99' } + let :params do { + :ensure => 'up', + :ipaddress_start => '1.2.3.99', + :ipaddress_end => '1.2.3.200', + :clonenum_start => '3', + } + end + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '8.0', + }} + it { should contain_file('ifcfg-eth99-range3').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-eth99-range3', + :notify => 'Class[Network::Service]' + )} + it 'should contain File[ifcfg-eth99-range3] with required contents' do + verify_contents(catalogue, 'ifcfg-eth99-range3', [ + 'IPADDR_START=1.2.3.99', + 'IPADDR_END=1.2.3.200', + 'CLONENUM_START=3', + 'NO_ALIASROUTING=no', + 'ONPARENT=yes', + 'NM_CONTROLLED=yes', + ]) + end + it { should contain_exec('restart_network') } + it { is_expected.to contain_file('ifcfg-eth99-range3').that_notifies('Class[Network::Service]') } + end + context 'required parameters: ensure => up' do let(:pre_condition) { "file { 'ifcfg-eth99': }" } let(:title) { 'eth99' } @@ -57,14 +93,17 @@ :clonenum_start => '3', } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + }} it { should contain_file('ifcfg-eth99-range3').with( :ensure => 'present', :mode => '0644', :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth99-range3', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth99-range3] with required contents' do verify_contents(catalogue, 'ifcfg-eth99-range3', [ @@ -77,7 +116,7 @@ ]) end it { should contain_service('network') } - it { is_expected.to contain_file('ifcfg-eth99-range3').that_notifies('Service[network]') } + it { is_expected.to contain_file('ifcfg-eth99-range3').that_notifies('Class[Network::Service]') } end context 'required parameters: ensure => up, restart => false' do @@ -91,7 +130,10 @@ :restart => false, } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + }} it { should contain_file('ifcfg-eth99-range3').with( :ensure => 'present', :mode => '0644', @@ -110,7 +152,7 @@ ]) end it { should contain_service('network') } - it { is_expected.to_not contain_file('ifcfg-eth99-range3').that_notifies('Service[network]') } + it { is_expected.to_not contain_file('ifcfg-eth99-range3').that_notifies('Class[Network::Service]') } end context 'required parameters: ensure => down' do @@ -124,14 +166,17 @@ :noaliasrouting => true, } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + }} it { should contain_file('ifcfg-bond7-range9').with( :ensure => 'present', :mode => '0644', :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-bond7-range9', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-bond7-range9] with required contents' do verify_contents(catalogue, 'ifcfg-bond7-range9', [ @@ -156,11 +201,14 @@ :clonenum_start => '9', } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + }} it { should contain_file('ifcfg-bond6-range9').with( :ensure => 'absent', :path => '/etc/sysconfig/network-scripts/ifcfg-bond6-range9', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it { should contain_service('network') } end @@ -179,14 +227,17 @@ :arpcheck => false, } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + }} it { should contain_file('ifcfg-eth8-range9').with( :ensure => 'present', :mode => '0644', :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth8-range9', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth8-range9] with required contents' do verify_contents(catalogue, 'ifcfg-eth8-range9', [ diff --git a/spec/defines/network_alias_spec.rb b/spec/defines/network_alias_spec.rb index b562460..adfad21 100644 --- a/spec/defines/network_alias_spec.rb +++ b/spec/defines/network_alias_spec.rb @@ -38,14 +38,17 @@ :netmask => '255.255.255.0', } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + }} it { should contain_file('ifcfg-bond2:1').with( :ensure => 'present', :mode => '0644', :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-bond2:1', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-bond2:1] with required contents' do verify_contents(catalogue, 'ifcfg-bond2:1', [ @@ -75,14 +78,17 @@ :zone => 'trusted', } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + }} it { should contain_file('ifcfg-bond3:2').with( :ensure => 'present', :mode => '0644', :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-bond3:2', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-bond3:2] with required contents' do verify_contents(catalogue, 'ifcfg-bond3:2', [ @@ -103,4 +109,47 @@ it { should contain_service('network') } end + context 'RHEL8 optional parameters' do + let(:title) { 'bond3:2' } + let :params do { + :ensure => 'down', + :ipaddress => '33.2.3.127', + :netmask => '255.255.0.0', + :gateway => '33.2.3.1', + :noaliasrouting => true, + :userctl => true, + :metric => '10', + :zone => 'trusted', + } + end + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '8.0', + }} + it { should contain_file('ifcfg-bond3:2').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-bond3:2', + :notify => 'Class[Network::Service]' + )} + it 'should contain File[ifcfg-bond3:2] with required contents' do + verify_contents(catalogue, 'ifcfg-bond3:2', [ + 'DEVICE=bond3:2', + 'BOOTPROTO=none', + 'ONPARENT=no', + 'TYPE=Ethernet', + 'IPADDR=33.2.3.127', + 'NETMASK=255.255.0.0', + 'GATEWAY=33.2.3.1', + 'NO_ALIASROUTING=yes', + 'USERCTL=yes', + 'ZONE=trusted', + 'METRIC=10', + 'NM_CONTROLLED=yes', + ]) + end + it { should contain_exec('restart_network') } + end end diff --git a/spec/defines/network_bond_bridge_spec.rb b/spec/defines/network_bond_bridge_spec.rb index 272557d..f888589 100644 --- a/spec/defines/network_bond_bridge_spec.rb +++ b/spec/defines/network_bond_bridge_spec.rb @@ -36,7 +36,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-bond0', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-bond0] with required contents' do verify_contents(catalogue, 'ifcfg-bond0', [ @@ -119,7 +119,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-bond0', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-bond0] with required contents' do verify_contents(catalogue, 'ifcfg-bond0', [ @@ -139,4 +139,45 @@ it { should_not contain_augeas('modprobe.conf_bond0') } end + context 'RHEL8 optional parameters' do + let(:title) { 'bond0' } + let :params do { + :ensure => 'down', + :bridge => 'br6', + :mtu => '9000', + :ethtool_opts => 'speed 1000 duplex full autoneg off', + :bonding_opts => 'mode=active-backup miimon=100', + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '8.0' + } + end + it { should contain_file('ifcfg-bond0').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-bond0', + :notify => 'Class[Network::Service]' + )} + it 'should contain File[ifcfg-bond0] with required contents' do + verify_contents(catalogue, 'ifcfg-bond0', [ + 'DEVICE=bond0', + 'BOOTPROTO=none', + 'ONBOOT=no', + 'HOTPLUG=no', + 'TYPE=Ethernet', + 'MTU=9000', + 'BONDING_OPTS="mode=active-backup miimon=100"', + 'ETHTOOL_OPTS="speed 1000 duplex full autoneg off"', + 'BRIDGE=br6', + 'NM_CONTROLLED=yes', + ]) + end + it { should contain_exec('restart_network') } + it { should_not contain_augeas('modprobe.conf_bond0') } + end end diff --git a/spec/defines/network_bond_dynamic_spec.rb b/spec/defines/network_bond_dynamic_spec.rb index 2b2d2f1..93ed0f7 100644 --- a/spec/defines/network_bond_dynamic_spec.rb +++ b/spec/defines/network_bond_dynamic_spec.rb @@ -34,7 +34,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-bond2', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-bond2] with required contents' do verify_contents(catalogue, 'ifcfg-bond2', [ @@ -118,7 +118,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-bond2', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-bond2] with required contents' do verify_contents(catalogue, 'ifcfg-bond2', [ @@ -140,4 +140,50 @@ it { should_not contain_augeas('modprobe.conf_bond2') } end + context 'RHEL8 optional parameters' do + let(:title) { 'bond2' } + let :params do { + :ensure => 'down', + :mtu => '9000', + :ethtool_opts => 'speed 1000 duplex full autoneg off', + :bonding_opts => 'mode=active-backup arp_interval=60 arp_ip_target=192.168.1.254', + :defroute => 'yes', + :metric => '10', + :zone => 'trusted', + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '8.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', + :notify => 'Class[Network::Service]' + )} + it 'should contain File[ifcfg-bond2] with required contents' do + verify_contents(catalogue, 'ifcfg-bond2', [ + 'DEVICE=bond2', + 'BOOTPROTO=dhcp', + 'ONBOOT=no', + 'HOTPLUG=no', + 'TYPE=Ethernet', + 'MTU=9000', + 'BONDING_OPTS="mode=active-backup arp_interval=60 arp_ip_target=192.168.1.254"', + 'ETHTOOL_OPTS="speed 1000 duplex full autoneg off"', + 'DEFROUTE=yes', + 'ZONE=trusted', + 'METRIC=10', + 'NM_CONTROLLED=yes', + ]) + end + it { should contain_exec('restart_network') } + it { should_not contain_augeas('modprobe.conf_bond2') } + end end diff --git a/spec/defines/network_bond_slave_spec.rb b/spec/defines/network_bond_slave_spec.rb index d8840da..2a99494 100644 --- a/spec/defines/network_bond_slave_spec.rb +++ b/spec/defines/network_bond_slave_spec.rb @@ -36,7 +36,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth1', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth1] with required contents' do verify_contents(catalogue, 'ifcfg-eth1', [ @@ -48,7 +48,7 @@ ]) end it { should contain_service('network') } - it { is_expected.to contain_file('ifcfg-eth1').that_notifies('Service[network]') } + it { is_expected.to contain_file('ifcfg-eth1').that_notifies('Class[Network::Service]') } end context 'required parameters, restart => false' do @@ -62,6 +62,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', } end @@ -83,7 +84,7 @@ ]) end it { should contain_service('network') } - it { is_expected.to_not contain_file('ifcfg-eth1').that_notifies('Service[network]') } + it { is_expected.to_not contain_file('ifcfg-eth1').that_notifies('Class[Network::Service]') } end context 'optional parameters' do @@ -112,7 +113,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth3', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth3] with required contents' do verify_contents(catalogue, 'ifcfg-eth3', [ @@ -131,4 +132,48 @@ it { should contain_service('network') } end + context 'RHEL8 optional parameters' do + let(:pre_condition) { "file { 'ifcfg-bond0': }" } + let(:title) { 'eth3' } + let :params do { + :macaddress => 'ef:ef:ef:ef:ef:ef', + :master => 'bond0', + :ethtool_opts => 'speed 1000 duplex full autoneg off', + :userctl => true, + :bootproto => 'dhcp', + :onboot => 'yes', + + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '8.0', + :macaddress_eth3 => 'fe:fe:fe:aa:aa:aa', + } + end + it { should contain_file('ifcfg-eth3').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-eth3', + :notify => 'Class[Network::Service]' + )} + it 'should contain File[ifcfg-eth3] with required contents' do + verify_contents(catalogue, 'ifcfg-eth3', [ + 'DEVICE=eth3', + 'HWADDR=ef:ef:ef:ef:ef:ef', + 'MASTER=bond0', + 'SLAVE=yes', + 'TYPE=Ethernet', + 'ETHTOOL_OPTS="speed 1000 duplex full autoneg off"', + 'BOOTPROTO=dhcp', + 'ONBOOT=yes', + 'USERCTL=yes', + 'NM_CONTROLLED=yes', + ]) + end + it { should contain_exec('restart_network') } + end end diff --git a/spec/defines/network_bond_spec.rb b/spec/defines/network_bond_spec.rb index b28d4d4..4c1bc9c 100644 --- a/spec/defines/network_bond_spec.rb +++ b/spec/defines/network_bond_spec.rb @@ -34,7 +34,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-bond0', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-bond0] with required contents' do verify_contents(catalogue, 'ifcfg-bond0', [ @@ -115,7 +115,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-bond0', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-bond0] with required contents' do verify_contents(catalogue, 'ifcfg-bond0', [ @@ -135,4 +135,45 @@ it { should_not contain_augeas('modprobe.conf_bond0') } end + context 'RHEL8 optional parameters' do + let(:title) { 'bond0' } + let :params do { + :ensure => 'down', + :mtu => '9000', + :ethtool_opts => 'speed 1000 duplex full autoneg off', + :bonding_opts => 'mode=active-backup miimon=100', + :zone => 'trusted', + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '8.0' + } + end + it { should contain_file('ifcfg-bond0').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-bond0', + :notify => 'Class[Network::Service]' + )} + it 'should contain File[ifcfg-bond0] with required contents' do + verify_contents(catalogue, 'ifcfg-bond0', [ + 'DEVICE=bond0', + 'BOOTPROTO=none', + 'ONBOOT=no', + 'HOTPLUG=no', + 'TYPE=Ethernet', + 'MTU=9000', + 'BONDING_OPTS="mode=active-backup miimon=100"', + 'ETHTOOL_OPTS="speed 1000 duplex full autoneg off"', + 'ZONE=trusted', + 'NM_CONTROLLED=yes', + ]) + end + it { should contain_exec('restart_network') } + it { should_not contain_augeas('modprobe.conf_bond0') } + end end diff --git a/spec/defines/network_bond_static_spec.rb b/spec/defines/network_bond_static_spec.rb index 90f14ef..d093b8c 100644 --- a/spec/defines/network_bond_static_spec.rb +++ b/spec/defines/network_bond_static_spec.rb @@ -65,7 +65,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-bond0', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-bond0] with required contents' do verify_contents(catalogue, 'ifcfg-bond0', [ @@ -163,7 +163,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-bond0', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-bond0] with required contents' do verify_contents(catalogue, 'ifcfg-bond0', [ @@ -197,4 +197,73 @@ it { should_not contain_augeas('modprobe.conf_bond0') } end + context 'optional parameters' do + let(:title) { 'bond0' } + let :params do { + :ensure => 'down', + :ipaddress => '1.2.3.5', + :netmask => '255.255.255.0', + :gateway => '1.2.3.1', + :mtu => '9000', + :ethtool_opts => 'speed 1000 duplex full autoneg off', + :bonding_opts => 'mode=active-backup miimon=100', + :peerdns => true, + :dns1 => '3.4.5.6', + :dns2 => '5.6.7.8', + :ipv6init => true, + :ipv6peerdns => true, + :ipv6address => '123:4567:89ab:cdef:123:4567:89ab:cdef/64', + :ipv6gateway => '123:4567:89ab:cdef:123:4567:89ab:1', + :domain => 'somedomain.com', + :defroute => 'yes', + :metric => '10', + :zone => 'trusted', + :userctl => true, + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '8.0' + } + end + it { should contain_file('ifcfg-bond0').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-bond0', + :notify => 'Class[Network::Service]' + )} + it 'should contain File[ifcfg-bond0] with required contents' do + verify_contents(catalogue, 'ifcfg-bond0', [ + 'DEVICE=bond0', + 'BOOTPROTO=none', + 'ONBOOT=no', + 'HOTPLUG=no', + 'TYPE=Ethernet', + 'IPADDR=1.2.3.5', + 'NETMASK=255.255.255.0', + 'GATEWAY=1.2.3.1', + 'MTU=9000', + 'BONDING_OPTS="mode=active-backup miimon=100"', + 'ETHTOOL_OPTS="speed 1000 duplex full autoneg off"', + 'PEERDNS=yes', + 'DNS1=3.4.5.6', + 'DNS2=5.6.7.8', + 'DOMAIN="somedomain.com"', + 'USERCTL=yes', + 'IPV6INIT=yes', + 'IPV6ADDR=123:4567:89ab:cdef:123:4567:89ab:cdef/64', + 'IPV6_DEFAULTGW=123:4567:89ab:cdef:123:4567:89ab:1', + 'IPV6_PEERDNS=yes', + 'DEFROUTE=yes', + 'ZONE=trusted', + 'METRIC=10', + 'NM_CONTROLLED=yes', + ]) + end + it { should contain_exec('restart_network') } + it { should_not contain_augeas('modprobe.conf_bond0') } + end end diff --git a/spec/defines/network_bridge_dynamic_spec.rb b/spec/defines/network_bridge_dynamic_spec.rb index 77eeec3..91229aa 100644 --- a/spec/defines/network_bridge_dynamic_spec.rb +++ b/spec/defines/network_bridge_dynamic_spec.rb @@ -35,6 +35,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', } end it { should contain_file('ifcfg-br1').with( @@ -43,7 +44,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-br1', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-br1] with required contents' do verify_contents(catalogue, 'ifcfg-br1', [ @@ -58,7 +59,7 @@ ]) end it { should contain_service('network') } - it { is_expected.to contain_file('ifcfg-br1').that_notifies('Service[network]') } + it { is_expected.to contain_file('ifcfg-br1').that_notifies('Class[Network::Service]') } it { should contain_package('bridge-utils') } end @@ -71,6 +72,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', } end it { should contain_file('ifcfg-br1').with( @@ -93,7 +95,7 @@ ]) end it { should contain_service('network') } - it { is_expected.to_not contain_file('ifcfg-br1').that_notifies('Service[network]') } + it { is_expected.to_not contain_file('ifcfg-br1').that_notifies('Class[Network::Service]') } it { should contain_package('bridge-utils') } end @@ -110,6 +112,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', } end it { should contain_file('ifcfg-br1').with( @@ -118,7 +121,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-br1', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-br1] with required contents' do verify_contents(catalogue, 'ifcfg-br1', [ @@ -136,4 +139,43 @@ it { should contain_package('bridge-utils') } end + context 'RHEL8 optional parameters' do + let(:title) { 'br1' } + let :params do { + :ensure => 'down', + :bootproto => 'bootp', + :userctl => true, + :stp => true, + :delay => '1000', + :bridging_opts => 'hello_time=200 priority=65535', + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystemrelease => '8.0', + } + end + it { should contain_file('ifcfg-br1').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-br1', + :notify => 'Class[Network::Service]' + )} + it 'should contain File[ifcfg-br1] with required contents' do + verify_contents(catalogue, 'ifcfg-br1', [ + 'DEVICE=br1', + 'BOOTPROTO=bootp', + 'ONBOOT=no', + 'TYPE=Bridge', + 'DELAY=1000', + 'STP=yes', + 'BRIDGING_OPTS="hello_time=200 priority=65535"', + 'NM_CONTROLLED=yes', + ]) + end + it { should contain_exec('restart_network') } + it { should contain_package('bridge-utils') } + end end diff --git a/spec/defines/network_bridge_spec.rb b/spec/defines/network_bridge_spec.rb index 787be1b..1d9f4a4 100644 --- a/spec/defines/network_bridge_spec.rb +++ b/spec/defines/network_bridge_spec.rb @@ -35,6 +35,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', } end it { should contain_file('ifcfg-br1').with( @@ -43,7 +44,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-br1', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-br1] with required contents' do verify_contents(catalogue, 'ifcfg-br1', [ @@ -58,7 +59,7 @@ ]) end it { should contain_service('network') } - it { is_expected.to contain_file('ifcfg-br1').that_notifies('Service[network]') } + it { is_expected.to contain_file('ifcfg-br1').that_notifies('Class[Network::Service]') } it { should contain_package('bridge-utils') } end @@ -71,6 +72,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', } end it { should contain_file('ifcfg-br1').with( @@ -93,7 +95,7 @@ ]) end it { should contain_service('network') } - it { is_expected.to_not contain_file('ifcfg-br1').that_notifies('Service[network]') } + it { is_expected.to_not contain_file('ifcfg-br1').that_notifies('Class[Network::Service]') } it { should contain_package('bridge-utils') } end @@ -109,6 +111,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', } end it { should contain_file('ifcfg-br1').with( @@ -117,7 +120,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-br1', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-br1] with required contents' do verify_contents(catalogue, 'ifcfg-br1', [ @@ -135,4 +138,42 @@ it { should contain_package('bridge-utils') } end + context 'RHEL8 optional parameters' do + let(:title) { 'br1' } + let :params do { + :ensure => 'down', + :userctl => true, + :stp => true, + :delay => '1000', + :bridging_opts => 'hello_time=200 priority=65535', + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystemrelease => '8.0', + } + end + it { should contain_file('ifcfg-br1').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-br1', + :notify => 'Class[Network::Service]' + )} + it 'should contain File[ifcfg-br1] with required contents' do + verify_contents(catalogue, 'ifcfg-br1', [ + 'DEVICE=br1', + 'BOOTPROTO=none', + 'ONBOOT=no', + 'TYPE=Bridge', + 'DELAY=1000', + 'STP=yes', + 'BRIDGING_OPTS="hello_time=200 priority=65535"', + 'NM_CONTROLLED=yes', + ]) + end + it { should contain_exec('restart_network') } + it { should contain_package('bridge-utils') } + end end diff --git a/spec/defines/network_bridge_static_spec.rb b/spec/defines/network_bridge_static_spec.rb index a8dde12..1affd6b 100644 --- a/spec/defines/network_bridge_static_spec.rb +++ b/spec/defines/network_bridge_static_spec.rb @@ -82,6 +82,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', } end it { should contain_file('ifcfg-br1').with( @@ -90,7 +91,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-br1', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-br1] with required contents' do verify_contents(catalogue, 'ifcfg-br1', [ @@ -105,7 +106,7 @@ ]) end it { should contain_service('network') } - it { is_expected.to contain_file('ifcfg-br1').that_notifies('Service[network]') } + it { is_expected.to contain_file('ifcfg-br1').that_notifies('Class[Network::Service]') } it { should contain_package('bridge-utils') } end @@ -120,6 +121,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', } end it { should contain_file('ifcfg-br1').with( @@ -142,7 +144,7 @@ ]) end it { should contain_service('network') } - it { is_expected.to_not contain_file('ifcfg-br1').that_notifies('Service[network]') } + it { is_expected.to_not contain_file('ifcfg-br1').that_notifies('Class[Network::Service]') } it { should contain_package('bridge-utils') } end @@ -170,6 +172,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', } end it { should contain_file('ifcfg-br1').with( @@ -178,7 +181,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-br1', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-br1] with required contents' do verify_contents(catalogue, 'ifcfg-br1', [ @@ -208,4 +211,66 @@ it { should contain_package('bridge-utils') } end + context 'RHEL8 optional parameters' do + let(:title) { 'br1' } + let :params do { + :ensure => 'down', + :ipaddress => '1.2.3.4', + :netmask => '255.255.255.0', + :gateway => '1.2.3.1', + :ipv6init => true, + :ipv6address => '123:4567:89ab:cdef:123:4567:89ab:cdef/64', + :ipv6gateway => '123:4567:89ab:cdef:123:4567:89ab:1', + :ipv6peerdns => true, + :userctl => true, + :peerdns => true, + :dns1 => '3.4.5.6', + :dns2 => '5.6.7.8', + :domain => 'somedomain.com', + :stp => true, + :delay => '1000', + :bridging_opts => 'hello_time=200 priority=65535', + :scope => 'peer 1.2.3.1', + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystemrelease => '8.0', + } + end + it { should contain_file('ifcfg-br1').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-br1', + :notify => 'Class[Network::Service]' + )} + it 'should contain File[ifcfg-br1] with required contents' do + verify_contents(catalogue, 'ifcfg-br1', [ + 'DEVICE=br1', + 'BOOTPROTO=static', + 'ONBOOT=no', + 'TYPE=Bridge', + 'IPADDR=1.2.3.4', + 'NETMASK=255.255.255.0', + 'GATEWAY=1.2.3.1', + 'IPV6INIT=yes', + 'IPV6ADDR=123:4567:89ab:cdef:123:4567:89ab:cdef/64', + 'IPV6_DEFAULTGW=123:4567:89ab:cdef:123:4567:89ab:1', + 'IPV6_PEERDNS=yes', + 'PEERDNS=yes', + 'DNS1=3.4.5.6', + 'DNS2=5.6.7.8', + 'DOMAIN="somedomain.com"', + 'DELAY=1000', + 'STP=yes', + 'BRIDGING_OPTS="hello_time=200 priority=65535"', + 'SCOPE="peer 1.2.3.1"', + 'NM_CONTROLLED=yes', + ]) + end + it { should contain_exec('restart_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..9b10e34 100644 --- a/spec/defines/network_if_bridge_spec.rb +++ b/spec/defines/network_if_bridge_spec.rb @@ -25,6 +25,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', } end @@ -34,7 +35,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth1', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth1] with required contents' do verify_contents(catalogue, 'ifcfg-eth1', [ @@ -63,6 +64,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', } end @@ -72,7 +74,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth1', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth1] with required contents' do verify_contents(catalogue, 'ifcfg-eth1', [ @@ -91,4 +93,45 @@ it { should contain_service('network') } end + context 'RHEL8 optional parameters' do + let(:title) { 'eth1' } + let :params do { + :ensure => 'down', + :bridge => 'br55', + :mtu => '9000', + :ethtool_opts => 'speed 1000 duplex full autoneg off', + :macaddress => '00:00:00:00:00:00', + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystemrelease => '8.0', + :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 => 'Class[Network::Service]' + )} + it 'should contain File[ifcfg-eth1] with required contents' do + verify_contents(catalogue, 'ifcfg-eth1', [ + 'DEVICE=eth1', + 'BOOTPROTO=none', + 'HWADDR=00:00:00:00:00:00', + 'ONBOOT=no', + 'HOTPLUG=no', + 'TYPE=Ethernet', + 'MTU=9000', + 'ETHTOOL_OPTS="speed 1000 duplex full autoneg off"', + 'BRIDGE=br55', + 'NM_CONTROLLED=yes', + ]) + end + it { should contain_exec('restart_network') } + end + end diff --git a/spec/defines/network_if_dynamic_spec.rb b/spec/defines/network_if_dynamic_spec.rb index 7ff2336..6781934 100644 --- a/spec/defines/network_if_dynamic_spec.rb +++ b/spec/defines/network_if_dynamic_spec.rb @@ -23,6 +23,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', :macaddress_eth99 => 'ff:aa:ff:aa:ff:aa', } end @@ -32,7 +33,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth99', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth99] with required contents' do verify_contents(catalogue, 'ifcfg-eth99', [ @@ -68,6 +69,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', :macaddress_eth99 => 'ff:aa:ff:aa:ff:aa', } end @@ -77,7 +79,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth99', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth99] with required contents' do verify_contents(catalogue, 'ifcfg-eth99', [ @@ -106,6 +108,7 @@ let(:params) {{ :ensure => 'up' }} let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', :macaddress_eth45 => 'bb:cc:bb:cc:bb:cc', } end @@ -115,7 +118,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth45.302', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth45.302] with required contents' do verify_contents(catalogue, 'ifcfg-eth45.302', [ @@ -140,6 +143,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', :macaddress_eth0 => 'bb:cc:bb:cc:bb:cc', } end @@ -149,7 +153,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth0', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth0] with required contents' do verify_contents(catalogue, 'ifcfg-eth0', [ @@ -164,5 +168,37 @@ it { should contain_service('network') } end - + context 'RHEL8 optional parameters - manage_hwaddr' do + let(:title) { 'eth0' } + let :params do { + :ensure => 'up', + :manage_hwaddr => false, + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystemrelease => '8.0', + :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', + :notify => 'Class[Network::Service]' + )} + it 'should contain File[ifcfg-eth0] with required contents' do + verify_contents(catalogue, 'ifcfg-eth0', [ + 'DEVICE=eth0', + 'BOOTPROTO=dhcp', + 'ONBOOT=yes', + 'HOTPLUG=yes', + 'TYPE=Ethernet', + 'NM_CONTROLLED=yes', + ]) + end + it { should contain_exec('restart_network') } + end end diff --git a/spec/defines/network_if_promisc_spec.rb b/spec/defines/network_if_promisc_spec.rb index c4e32f5..d208adb 100644 --- a/spec/defines/network_if_promisc_spec.rb +++ b/spec/defines/network_if_promisc_spec.rb @@ -24,7 +24,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth1', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth1] with required contents' do verify_contents(catalogue, 'ifcfg-eth1', [ @@ -81,7 +81,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth3', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth3] with required contents' do verify_contents(catalogue, 'ifcfg-eth3', [ diff --git a/spec/defines/network_if_spec.rb b/spec/defines/network_if_spec.rb index ea20ced..238d169 100644 --- a/spec/defines/network_if_spec.rb +++ b/spec/defines/network_if_spec.rb @@ -34,7 +34,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth0', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth0] with required contents' do verify_contents(catalogue, 'ifcfg-eth0', [ @@ -71,7 +71,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth0', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth0] with required contents' do verify_contents(catalogue, 'ifcfg-eth0', [ @@ -89,5 +89,44 @@ it { should contain_service('network') } end + context 'RHEL8 optional parameters' do + let(:title) { 'eth0' } + let :params do { + :ensure => 'down', + :mtu => '9000', + :ethtool_opts => 'speed 1000 duplex full autoneg off', + :zone => 'trusted', + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + :operatingsystemrelease => '8.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', + :notify => 'Class[Network::Service]' + )} + it 'should contain File[ifcfg-eth0] with required contents' do + verify_contents(catalogue, 'ifcfg-eth0', [ + 'DEVICE=eth0', + 'BOOTPROTO=none', + 'ONBOOT=no', + 'HOTPLUG=no', + 'TYPE=Ethernet', + 'MTU=9000', + 'ETHTOOL_OPTS="speed 1000 duplex full autoneg off"', + 'ZONE=trusted', + 'NM_CONTROLLED=yes', + ]) + end + it { should contain_exec('restart_network') } + end end diff --git a/spec/defines/network_if_static_spec.rb b/spec/defines/network_if_static_spec.rb index 4409578..00eaf6b 100644 --- a/spec/defines/network_if_static_spec.rb +++ b/spec/defines/network_if_static_spec.rb @@ -75,6 +75,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', } end @@ -84,7 +85,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth1', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth1] with required contents' do verify_contents(catalogue, 'ifcfg-eth1', [ @@ -101,7 +102,7 @@ ]) end it { should contain_service('network') } - it { is_expected.to contain_file('ifcfg-eth1').that_notifies('Service[network]') } + it { is_expected.to contain_file('ifcfg-eth1').that_notifies('Class[Network::Service]') } end context 'no restart' do @@ -115,6 +116,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', } end @@ -140,7 +142,7 @@ ]) end it { should contain_service('network') } - it { is_expected.to_not contain_file('ifcfg-eth1').that_notifies('Service[network]') } + it { is_expected.to_not contain_file('ifcfg-eth1').that_notifies('Class[Network::Service]') } end context 'optional parameters' do @@ -173,6 +175,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', } end @@ -182,7 +185,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth1', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth1] with required contents' do verify_contents(catalogue, 'ifcfg-eth1', [ @@ -229,6 +232,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', :macaddress_eth6 => 'bb:cc:bb:cc:bb:cc', } end @@ -238,7 +242,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth6.203', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth6.203] with required contents' do verify_contents(catalogue, 'ifcfg-eth6.203', [ @@ -267,6 +271,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', :macaddress_eth0 => 'bb:cc:bb:cc:bb:cc', } end @@ -276,7 +281,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth0', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth0] with required contents' do verify_contents(catalogue, 'ifcfg-eth0', [ @@ -304,10 +309,11 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', :macaddress_eth1 => '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]') } + it { should contain_exec('network-flush').with_command('ip addr flush dev eth1').that_comes_before('Class[Network::Service]') } end context 'optional parameters - single ipv6address in array' do @@ -324,6 +330,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', } end @@ -333,7 +340,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth1', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth1] with required contents' do verify_contents(catalogue, 'ifcfg-eth1', [ @@ -370,6 +377,7 @@ end let :facts do { :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', } end @@ -379,7 +387,7 @@ :owner => 'root', :group => 'root', :path => '/etc/sysconfig/network-scripts/ifcfg-eth1', - :notify => 'Service[network]' + :notify => 'Class[Network::Service]' )} it 'should contain File[ifcfg-eth1] with required contents' do verify_contents(catalogue, 'ifcfg-eth1', [ @@ -400,4 +408,52 @@ end it { should contain_service('network') } end + + context 'RHEL8 optional parameters - multiple ipv6addresses' do + let(:title) { 'eth1' } + let :params do { + :ensure => 'up', + :ipaddress => '1.2.3.4', + :netmask => '255.255.255.0', + :ipv6init => true, + :ipv6address => [ + '123:4567:89ab:cdef:123:4567:89ab:cded', + '123:4567:89ab:cdef:123:4567:89ab:cdee', + '123:4567:89ab:cdef:123:4567:89ab:cdef', + ], + } + end + let :facts do { + :osfamily => 'RedHat', + :operatingsystemrelease => '8.0', + :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 => 'Class[Network::Service]' + )} + 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', + 'IPADDR=1.2.3.4', + 'NETMASK=255.255.255.0', + 'PEERDNS=no', + 'IPV6INIT=yes', + 'IPV6ADDR=123:4567:89ab:cdef:123:4567:89ab:cded', + 'IPV6ADDR_SECONDARIES="123:4567:89ab:cdef:123:4567:89ab:cdee 123:4567:89ab:cdef:123:4567:89ab:cdef"', + 'NM_CONTROLLED=yes', + ]) + end + it { should contain_exec('restart_network') } + end end diff --git a/spec/defines/network_route_spec.rb b/spec/defines/network_route_spec.rb index 50d34f2..581614d 100644 --- a/spec/defines/network_route_spec.rb +++ b/spec/defines/network_route_spec.rb @@ -13,7 +13,10 @@ :gateway => [ '192.168.1.2', ], } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + }} it { should contain_file('route-eth1').with( :ensure => 'present', :mode => '0644', @@ -29,7 +32,7 @@ ]) end it { should contain_service('network') } - it { is_expected.to contain_file('route-eth1').that_notifies('Service[network]') } + it { is_expected.to contain_file('route-eth1').that_notifies('Class[Network::Service]') } end context 'singular parameters, restart => false' do @@ -42,7 +45,10 @@ :restart => false, } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + }} it { should contain_file('route-eth1').with( :ensure => 'present', :mode => '0644', @@ -58,7 +64,7 @@ ]) end it { should contain_service('network') } - it { is_expected.to_not contain_file('route-eth1').that_notifies('Service[network]') } + it { is_expected.to_not contain_file('route-eth1').that_notifies('Class[Network::Service]') } end context 'array parameters' do @@ -70,7 +76,10 @@ :gateway => [ '192.168.1.1', '10.0.0.1', ] } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + }} it { should contain_file('route-eth2').with( :ensure => 'present', :mode => '0644', @@ -110,7 +119,10 @@ ] } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + }} it { should contain_file('route-eth0').with( :ensure => 'present', :mode => '0644', @@ -147,7 +159,10 @@ ] } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + }} it { should contain_file('route6-eth0').with( :ensure => 'present', :mode => '0644', diff --git a/spec/defines/network_rule_spec.rb b/spec/defines/network_rule_spec.rb index cfb86d7..edb51d0 100644 --- a/spec/defines/network_rule_spec.rb +++ b/spec/defines/network_rule_spec.rb @@ -22,7 +22,10 @@ ] } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + }} it { should contain_file('rule-eth0').with( :ensure => 'present', :mode => '0644', @@ -58,7 +61,10 @@ ] } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + }} it { should contain_file('rule6-eth0').with( :ensure => 'present', :mode => '0644', diff --git a/templates/ifcfg-alias-range.erb b/templates/ifcfg-alias-range.erb index 018f55e..f805bf9 100644 --- a/templates/ifcfg-alias-range.erb +++ b/templates/ifcfg-alias-range.erb @@ -14,4 +14,8 @@ CLONENUM_START=<%= @clonenum_start %> <% if !@arpcheck %>ARPCHECK=no <% end -%> ONPARENT=<%= @onparent %> +<% if @nm_controlled -%> +NM_CONTROLLED=yes +<% else -%> NM_CONTROLLED=no +<% end -%> diff --git a/templates/ifcfg-alias.erb b/templates/ifcfg-alias.erb index 3961edb..562cd6f 100644 --- a/templates/ifcfg-alias.erb +++ b/templates/ifcfg-alias.erb @@ -22,4 +22,8 @@ TYPE=Ethernet <% end -%> <% if @metric %>METRIC=<%= @metric %> <% end -%> +<% if @nm_controlled -%> +NM_CONTROLLED=yes +<% else -%> NM_CONTROLLED=no +<% end -%> diff --git a/templates/ifcfg-bond.erb b/templates/ifcfg-bond.erb index 3055d47..707a1b3 100644 --- a/templates/ifcfg-bond.erb +++ b/templates/ifcfg-bond.erb @@ -21,4 +21,8 @@ TYPE=Ethernet <% end -%> <% if @userctl %>USERCTL=yes <% end -%> +<% if @nm_controlled -%> +NM_CONTROLLED=yes +<% else -%> NM_CONTROLLED=no +<% end -%> diff --git a/templates/ifcfg-br.erb b/templates/ifcfg-br.erb index dfba2d6..f39498c 100644 --- a/templates/ifcfg-br.erb +++ b/templates/ifcfg-br.erb @@ -38,4 +38,8 @@ DELAY=<%= @delay %> <% end -%> <% if @scope %>SCOPE="<%= @scope %>" <% end -%> +<% if @nm_controlled -%> +NM_CONTROLLED=yes +<% else -%> NM_CONTROLLED=no +<% end -%> diff --git a/templates/ifcfg-eth.erb b/templates/ifcfg-eth.erb index 2f1addb..83bd6b3 100644 --- a/templates/ifcfg-eth.erb +++ b/templates/ifcfg-eth.erb @@ -70,4 +70,8 @@ check_link_down() { <% end -%> <% if !@arpcheck %>ARPCHECK=no <% end -%> +<% if @nm_controlled -%> +NM_CONTROLLED=yes +<% else -%> NM_CONTROLLED=no +<% end -%> From 21a8ad95ed7d70f52b53bad34a7b0e310b37ca8e Mon Sep 17 00:00:00 2001 From: Manfred Pusch Date: Wed, 27 Jan 2021 11:27:39 +0000 Subject: [PATCH 3/3] fixed potential ordering issue --- manifests/init.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index 04465f6..e528777 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -30,7 +30,7 @@ fail('This network module only supports RedHat-based systems.') } } - include network::service + contain network::service } # class network # == Definition: network_if_base