Skip to content

Commit

Permalink
Add stricter types for onboot/hotplug/bonding parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
runejuhl committed Aug 12, 2019
1 parent 9ec41a3 commit 538fa91
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 70 deletions.
50 changes: 26 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ network_config { 'eth0':
ensure => 'present',
family => 'inet',
method => 'dhcp',
onboot => 'true',
hotplug => 'true',
onboot => true,
hotplug => true,
options => {'pre-up' => 'sleep 2'},
}
network_config { 'lo':
ensure => 'present',
family => 'inet',
method => 'loopback',
onboot => 'true',
onboot => true,
}
network_config { 'eth1':
Expand All @@ -38,7 +38,7 @@ network_config { 'eth1':
ipaddress => '169.254.0.1',
method => 'static',
netmask => '255.255.0.0',
onboot => 'true',
onboot => true,
}
```

Expand Down Expand Up @@ -82,26 +82,28 @@ network_route { 'default':

Create resources on the fly with the `puppet resource` command:

root@debian-6:~# puppet resource network_config eth1 ensure=present family=inet method=static ipaddress=169.254.0.1 netmask=255.255.0.0
notice: /Network_config[eth1]/ensure: created
network_config { 'eth1':
ensure => 'present',
family => 'inet',
ipaddress => '169.254.0.1',
method => 'static',
netmask => '255.255.0.0',
onboot => 'true',
}

# puppet resource network_route 23.23.42.0 ensure=present netmask=255.255.255.0 interface=eth0 gateway=192.168.1.1
notice: /Network_route[23.23.42.0]/ensure: created
network_route { '23.23.42.0':
ensure => 'present',
gateway => '192.168.1.1',
interface => 'eth0',
netmask => '255.255.255.0',
options => 'table 200',
}
```
root@debian-6:~# puppet resource network_config eth1 ensure=present family=inet method=static ipaddress=169.254.0.1 netmask=255.255.0.0
notice: /Network_config[eth1]/ensure: created
network_config { 'eth1':
ensure => 'present',
family => 'inet',
ipaddress => '169.254.0.1',
method => 'static',
netmask => '255.255.0.0',
onboot => true,
}
# puppet resource network_route 23.23.42.0 ensure=present netmask=255.255.255.0 interface=eth0 gateway=192.168.1.1
notice: /Network_route[23.23.42.0]/ensure: created
network_route { '23.23.42.0':
ensure => 'present',
gateway => '192.168.1.1',
interface => 'eth0',
netmask => '255.255.255.0',
options => 'table 200',
}
```

## Dependencies

Expand Down
36 changes: 18 additions & 18 deletions manifests/bond.pp
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,25 @@
#
define network::bond(
$slaves,
$ensure = present,
$ipaddress = undef,
$netmask = undef,
$method = undef,
$family = undef,
$onboot = undef,
$hotplug = undef,
$lacp_rate = undef,
$mtu = undef,
$options = undef,
$slave_options = undef,
$ensure = present,
$ipaddress = undef,
$netmask = undef,
$method = undef,
$family = undef,
Optional[Boolean] $onboot = undef,
Optional[Boolean] $hotplug = undef,
$lacp_rate = undef,
Network::MTU $mtu = undef,
$options = undef,
$slave_options = undef,

$mode = 'active-backup',
$miimon = '100',
$downdelay = '200',
$updelay = '200',
$primary = $slaves[0],
$primary_reselect = 'always',
$xmit_hash_policy = 'layer2',
$mode = 'active-backup',
Network::PositiveInteger $miimon = 100,
Network::PositiveInteger $downdelay = 200,
Network::PositiveInteger $updelay = 200,
$primary = $slaves[0],
$primary_reselect = 'always',
$xmit_hash_policy = 'layer2',
) {

require network::bond::setup
Expand Down
26 changes: 13 additions & 13 deletions spec/defines/bond/debian_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
'slaves' => %w[eth0 eth1],

'mode' => 'active-backup',
'miimon' => '100',
'downdelay' => '200',
'updelay' => '200',
'miimon' => 100,
'downdelay' => 200,
'updelay' => 200,
'lacp_rate' => 'slow',
'primary' => 'eth0',
'primary_reselect' => 'always',
Expand All @@ -37,9 +37,9 @@
'options' => {
'bond-slaves' => 'eth0 eth1',
'bond-mode' => 'active-backup',
'bond-miimon' => '100',
'bond-downdelay' => '200',
'bond-updelay' => '200',
'bond-miimon' => 100,
'bond-downdelay' => 200,
'bond-updelay' => 200,
'bond-lacp-rate' => 'slow',
'bond-primary' => 'eth0',
'bond-primary-reselect' => 'always',
Expand All @@ -59,12 +59,12 @@
'mtu' => 1550,
'options' => { 'bond-future-option' => 'yes' },
'slave_options' => { 'slave-future-option' => 'no' },
'hotplug' => 'false',
'hotplug' => false,

'mode' => 'balance-rr',
'miimon' => '50',
'downdelay' => '100',
'updelay' => '100',
'miimon' => 50,
'downdelay' => 100,
'updelay' => 100,
'lacp_rate' => 'fast',
'xmit_hash_policy' => 'layer3+4'
}
Expand All @@ -85,9 +85,9 @@
'options' => {
'bond-slaves' => 'eth0 eth1 eth2',
'bond-mode' => 'balance-rr',
'bond-miimon' => '50',
'bond-downdelay' => '100',
'bond-updelay' => '100',
'bond-miimon' => 50,
'bond-downdelay' => 100,
'bond-updelay' => 100,
'bond-lacp-rate' => 'fast',
'bond-xmit-hash-policy' => 'layer3+4',
'bond-future-option' => 'yes',
Expand Down
16 changes: 8 additions & 8 deletions spec/defines/bond/redhat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
'slaves' => %w[eth0 eth1],

'mode' => 'active-backup',
'miimon' => '100',
'downdelay' => '200',
'updelay' => '200',
'miimon' => 100,
'downdelay' => 200,
'updelay' => 200,
'lacp_rate' => 'slow',
'primary' => 'eth0',
'primary_reselect' => 'always',
Expand Down Expand Up @@ -58,12 +58,12 @@
'mtu' => '1550',
'options' => { 'NM_CONTROLLED' => 'yes' },
'slave_options' => { 'NM_CONTROLLED' => 'no' },
'hotplug' => 'false',
'hotplug' => false,

'mode' => 'balance-rr',
'miimon' => '50',
'downdelay' => '100',
'updelay' => '100',
'miimon' => 50,
'downdelay' => 100,
'updelay' => 100,
'lacp_rate' => 'fast',
'xmit_hash_policy' => 'layer3+4'
}
Expand All @@ -89,7 +89,7 @@
'ipaddress' => '10.20.2.1',
'netmask' => '255.255.255.192',
'hotplug' => false,
'mtu' => '1550',
'mtu' => 1550,
'options' => {
'BONDING_OPTS' => 'mode=balance-rr miimon=50 downdelay=100 updelay=100 lacp_rate=fast xmit_hash_policy=layer3+4',
'NM_CONTROLLED' => 'yes'
Expand Down
6 changes: 3 additions & 3 deletions spec/defines/bond_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
'slave_options' => { 'NM_CONTROLLED' => 'no' },

'mode' => 'active-backup',
'miimon' => '100',
'downdelay' => '200',
'updelay' => '200',
'miimon' => 100,
'downdelay' => 200,
'updelay' => 200,
'lacp_rate' => 'slow',
'primary' => 'eth0',
'primary_reselect' => 'always',
Expand Down
10 changes: 6 additions & 4 deletions templates/bond/opts-redhat.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<%= %w[mode miimon downdelay updelay lacp_rate primary primary_reselect xmit_hash_policy].reject {
|option| scope.lookupvar(option).nil? || scope.lookupvar(option) == :undef || scope.lookupvar(option) == :absent || scope.lookupvar(option).empty? }.map {
|key| "#{key}=#{scope.lookupvar(key)}"
}.join(' ') -%>
<%= %w[mode miimon downdelay updelay lacp_rate primary primary_reselect xmit_hash_policy].reject { |option|
v = scope.lookupvar(option)
v.nil? || v == :undef || v == :absent || ( (v === Enumerable || v.is_a?(String) ) && v.empty?)
}.map { |key|
"#{key}=#{scope.lookupvar(key)}"
}.join(' ') -%>
1 change: 1 addition & 0 deletions types/mtu.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Network::MTU = Network::PositiveInteger
1 change: 1 addition & 0 deletions types/positiveinteger.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Network::PositiveInteger = Integer[1,default]

0 comments on commit 538fa91

Please sign in to comment.