Skip to content

Commit

Permalink
Mirror puppet-module-mofed nm_controlled behavior (#33)
Browse files Browse the repository at this point in the history
* Making nm_controlled a variable.

* Committing nm_controlled fixes per puppet-mofed module.

* Adding additional items from mofed puppet module.
  • Loading branch information
pedmon committed Aug 22, 2022
1 parent a2f9bed commit 0ae5e5c
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 19 deletions.
9 changes: 9 additions & 0 deletions REFERENCE.md
Expand Up @@ -284,6 +284,7 @@ The following parameters are available in the `infiniband::interface` defined ty
* [`gateway`](#gateway)
* [`ensure`](#ensure)
* [`enable`](#enable)
* [`nm_controlled`](#nm_controlled)
* [`connected_mode`](#connected_mode)
* [`mtu`](#mtu)
* [`bonding`](#bonding)
Expand Down Expand Up @@ -330,6 +331,14 @@ Sets if the infiniband::interface should be enabled at boot.

Default value: ``true``

##### <a name="nm_controlled"></a>`nm_controlled`

Data type: `Optional[Variant[Boolean, Enum['yes','no']]]`

Value for nm_controlled on interface

Default value: ``undef``

##### <a name="connected_mode"></a>`connected_mode`

Data type: `Enum['yes', 'no']`
Expand Down
31 changes: 20 additions & 11 deletions manifests/interface.pp
Expand Up @@ -19,6 +19,8 @@
# Sets if the infiniband::interface should be present or absent.
# @param enable
# Sets if the infiniband::interface should be enabled at boot.
# @param nm_controlled
# Value for nm_controlled on interface
# @param connected_mode
# The CONNECTED_MODE value for the infiniband interface.
# @param mtu
Expand All @@ -33,14 +35,15 @@
define infiniband::interface (
Stdlib::Compat::Ip_address $ipaddr,
Stdlib::Compat::Ip_address $netmask,
Optional[Stdlib::Compat::Ip_address] $gateway = undef,
Enum['present', 'absent'] $ensure = 'present',
Boolean $enable = true,
Enum['yes', 'no'] $connected_mode = 'yes',
Optional[Integer] $mtu = undef,
Boolean $bonding = false,
Array[String] $bonding_slaves = [],
String $bonding_opts = 'mode=active-backup miimon=100',
Optional[Stdlib::Compat::Ip_address] $gateway = undef,
Enum['present', 'absent'] $ensure = 'present',
Boolean $enable = true,
Enum['yes', 'no'] $connected_mode = 'yes',
Optional[Variant[Boolean, Enum['yes','no']]] $nm_controlled = undef,
Optional[Integer] $mtu = undef,
Boolean $bonding = false,
Array[String] $bonding_slaves = [],
String $bonding_opts = 'mode=active-backup miimon=100',
) {

$onboot = $enable ? {
Expand All @@ -55,6 +58,12 @@
'CONNECTED_MODE' => $connected_mode,
}

if $::osfamily == 'RedHat' and versioncmp($::operatingsystemmajrelease, '8') >= 0 {
$_nm_controlled = pick($nm_controlled, false)
} else {
$_nm_controlled = pick($nm_controlled, 'no')
}

if $bonding {
if empty($bonding_slaves) {
fail("No slave interfaces given for bonding interface ${name}")
Expand All @@ -69,7 +78,7 @@
type => 'InfiniBand',
master => $name,
slave => 'yes',
nm_controlled => 'no',
nm_controlled => $_nm_controlled,
mtu => $mtu,
options_extra_redhat => $options_extra_redhat,
}
Expand All @@ -86,7 +95,7 @@
gateway => $gateway,
bonding_master => 'yes',
bonding_opts => $bonding_opts,
nm_controlled => 'no',
nm_controlled => $_nm_controlled,
mtu => $mtu,
}

Expand All @@ -99,7 +108,7 @@
ipaddress => $ipaddr,
netmask => $netmask,
gateway => $gateway,
nm_controlled => 'no',
nm_controlled => $_nm_controlled,
mtu => $mtu,
options_extra_redhat => $options_extra_redhat,
}
Expand Down
24 changes: 16 additions & 8 deletions spec/defines/infiniband_interface_spec.rb
Expand Up @@ -23,6 +23,14 @@
default_params
end

let :fixture_suffix do
if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'].to_i >= 8
'-no_nm_controlled'
else
''
end
end

it { is_expected.to contain_class('network') }

it do
Expand All @@ -34,7 +42,7 @@

it do
is_expected.to contain_file('/etc/sysconfig/network-scripts/ifcfg-ib0') \
.with_content(my_fixture_read('ifcfg-ib0_with_connected_mode'))
.with_content(my_fixture_read("ifcfg-ib0_with_connected_mode#{fixture_suffix}"))
end

context 'ensure => absent' do
Expand All @@ -50,31 +58,31 @@
default_params.merge(enable: false)
end

it { is_expected.to contain_file('/etc/sysconfig/network-scripts/ifcfg-ib0').with_content(my_fixture_read('ifcfg-ib0_with_onboot_no')) }
it { is_expected.to contain_file('/etc/sysconfig/network-scripts/ifcfg-ib0').with_content(my_fixture_read("ifcfg-ib0_with_onboot_no#{fixture_suffix}")) }
end

context 'connected_mode => no' do
let :params do
default_params.merge(connected_mode: 'no')
end

it { is_expected.to contain_file('/etc/sysconfig/network-scripts/ifcfg-ib0').with_content(my_fixture_read('ifcfg-ib0_without_connected_mode')) }
it { is_expected.to contain_file('/etc/sysconfig/network-scripts/ifcfg-ib0').with_content(my_fixture_read("ifcfg-ib0_without_connected_mode#{fixture_suffix}")) }
end

context 'mtu => 65520' do
let :params do
default_params.merge(mtu: 65_520)
end

it { is_expected.to contain_file('/etc/sysconfig/network-scripts/ifcfg-ib0'). with_content(my_fixture_read('ifcfg-ib0_with_mtu')) }
it { is_expected.to contain_file('/etc/sysconfig/network-scripts/ifcfg-ib0'). with_content(my_fixture_read("ifcfg-ib0_with_mtu#{fixture_suffix}")) }
end

context 'gateway => 192.168.1.254' do
let :params do
default_params.merge(gateway: '192.168.1.254')
end

it { is_expected.to contain_file('/etc/sysconfig/network-scripts/ifcfg-ib0').with_content(my_fixture_read('ifcfg-ib0_with_gateway')) }
it { is_expected.to contain_file('/etc/sysconfig/network-scripts/ifcfg-ib0').with_content(my_fixture_read("ifcfg-ib0_with_gateway#{fixture_suffix}")) }
end

context 'bonding => true' do
Expand All @@ -96,9 +104,9 @@
end

it {
is_expected.to contain_file('/etc/sysconfig/network-scripts/ifcfg-ib0').with_content(my_fixture_read('ifcfg-bond-slave-ib0'))
is_expected.to contain_file('/etc/sysconfig/network-scripts/ifcfg-ib1').with_content(my_fixture_read('ifcfg-bond-slave-ib1'))
is_expected.to contain_file('/etc/sysconfig/network-scripts/ifcfg-ibbond0').with_content(my_fixture_read('ifcfg-bond-master-ibbond0'))
is_expected.to contain_file('/etc/sysconfig/network-scripts/ifcfg-ib0').with_content(my_fixture_read("ifcfg-bond-slave-ib0#{fixture_suffix}"))
is_expected.to contain_file('/etc/sysconfig/network-scripts/ifcfg-ib1').with_content(my_fixture_read("ifcfg-bond-slave-ib1#{fixture_suffix}"))
is_expected.to contain_file('/etc/sysconfig/network-scripts/ifcfg-ibbond0').with_content(my_fixture_read("ifcfg-bond-master-ibbond0#{fixture_suffix}"))
}
end

Expand Down
@@ -0,0 +1,13 @@
# File Managed by Puppet
DEVICE="ibbond0"
BOOTPROTO="none"
ONBOOT="yes"
TYPE="Bond"
USERCTL="no"
PEERDNS="no"
PEERNTP="no"
IPADDR="192.168.1.1"
NETMASK="255.255.255.0"
BONDING_MASTER="yes"
BONDING_OPTS="mode=active-backup miimon=100"
MTU="65520"
@@ -0,0 +1,12 @@
# File Managed by Puppet
DEVICE="ib0"
BOOTPROTO="none"
ONBOOT="yes"
TYPE="InfiniBand"
USERCTL="no"
PEERDNS="no"
PEERNTP="no"
MASTER="ibbond0"
SLAVE="yes"
MTU="65520"
CONNECTED_MODE="yes"
@@ -0,0 +1,12 @@
# File Managed by Puppet
DEVICE="ib1"
BOOTPROTO="none"
ONBOOT="yes"
TYPE="InfiniBand"
USERCTL="no"
PEERDNS="no"
PEERNTP="no"
MASTER="ibbond0"
SLAVE="yes"
MTU="65520"
CONNECTED_MODE="yes"
@@ -0,0 +1,11 @@
# File Managed by Puppet
DEVICE="ib0"
BOOTPROTO="none"
ONBOOT="yes"
TYPE="InfiniBand"
USERCTL="no"
PEERDNS="no"
PEERNTP="no"
IPADDR="192.168.1.1"
NETMASK="255.255.255.0"
CONNECTED_MODE="yes"
@@ -0,0 +1,12 @@
# File Managed by Puppet
DEVICE="ib0"
BOOTPROTO="none"
ONBOOT="yes"
TYPE="InfiniBand"
USERCTL="no"
PEERDNS="no"
PEERNTP="no"
IPADDR="192.168.1.1"
NETMASK="255.255.255.0"
GATEWAY="192.168.1.254"
CONNECTED_MODE="yes"
@@ -0,0 +1,12 @@
# File Managed by Puppet
DEVICE="ib0"
BOOTPROTO="none"
ONBOOT="yes"
TYPE="InfiniBand"
USERCTL="no"
PEERDNS="no"
PEERNTP="no"
IPADDR="192.168.1.1"
NETMASK="255.255.255.0"
MTU="65520"
CONNECTED_MODE="yes"
@@ -0,0 +1,11 @@
# File Managed by Puppet
DEVICE="ib0"
BOOTPROTO="none"
ONBOOT="no"
TYPE="InfiniBand"
USERCTL="no"
PEERDNS="no"
PEERNTP="no"
IPADDR="192.168.1.1"
NETMASK="255.255.255.0"
CONNECTED_MODE="yes"
@@ -0,0 +1,11 @@
# File Managed by Puppet
DEVICE="ib0"
BOOTPROTO="none"
ONBOOT="yes"
TYPE="InfiniBand"
USERCTL="no"
PEERDNS="no"
PEERNTP="no"
IPADDR="192.168.1.1"
NETMASK="255.255.255.0"
CONNECTED_MODE="no"

0 comments on commit 0ae5e5c

Please sign in to comment.