Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stricter types for onboot/hotplug/bonding parameters #257

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion lib/puppet/provider/network_config/interfaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def self.parse_file(_filename, contents)
case key # rubocop:disable Metrics/BlockNesting
when 'address' then Instance[name].ipaddress = val
when 'netmask' then Instance[name].netmask = val
when 'mtu' then Instance[name].mtu = val
when 'mtu' then Instance[name].mtu = val.to_i
else Instance[name].options[key] << val
end
end
Expand Down
13 changes: 3 additions & 10 deletions lib/puppet/type/network_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,8 @@
desc 'The Maximum Transmission Unit size to use for the interface'
validate do |value|
# reject floating point and negative integers
# XXX this lets 1500.0 pass
if value.is_a? Numeric
unless value.integer?
raise ArgumentError, "#{value} is not a valid mtu (must be a positive integer)"
end
else
unless value =~ %r{^\d+$}
raise ArgumentError, "#{value} is not a valid mtu (must be a positive integer)"
end
unless value.is_a?(Numeric) && value.integer?
raise ArgumentError, "#{value} is not a valid mtu (must be a positive integer)"
end

# Intel 82598 & 82599 chips support MTUs up to 16110; is there any
Expand All @@ -106,7 +99,7 @@
# is 42 with a 802.1q header and 46 without.
min_mtu = 42
max_mtu = 65_536
unless (min_mtu..max_mtu).cover?(value.to_i)
unless min_mtu <= value && value <= max_mtu
raise ArgumentError, "#{value} is not in the valid mtu range (#{min_mtu} .. #{max_mtu})"
end
end
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
14 changes: 7 additions & 7 deletions spec/unit/provider/network_config/interfaces_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def fixture_data(file)
ipaddress: '192.168.0.2',
netmask: '255.255.255.0',
onboot: true,
mtu: '1500',
mtu: 1500,
options: {
'broadcast' => '192.168.0.255',
'gateway' => '192.168.0.1'
Expand Down Expand Up @@ -118,7 +118,7 @@ def fixture_data(file)
ipaddress: '192.168.0.2',
netmask: '255.255.255.0',
onboot: true,
mtu: '1500',
mtu: 1500,
options: {
'broadcast' => '192.168.0.255',
'gateway' => '192.168.0.1'
Expand All @@ -129,7 +129,7 @@ def fixture_data(file)
ipaddress: '172.16.0.2',
netmask: '255.255.255.0',
onboot: true,
mtu: '1500',
mtu: 1500,
mode: :vlan,
options: {
'broadcast' => '172.16.0.255',
Expand Down Expand Up @@ -164,7 +164,7 @@ def fixture_data(file)
method: 'static',
ipaddress: '169.254.0.1',
netmask: '255.255.0.0',
mtu: '1500',
mtu: 1500,
mode: nil,
options: nil)
end
Expand All @@ -179,7 +179,7 @@ def fixture_data(file)
method: 'static',
ipaddress: '169.254.0.1',
netmask: '255.255.0.0',
mtu: '1500',
mtu: 1500,
mode: :vlan,
options: {
'vlan-raw-device' => 'eth1'
Expand Down Expand Up @@ -226,7 +226,7 @@ def fixture_data(file)
method: 'static',
ipaddress: '169.254.0.1',
netmask: '255.255.0.0',
mtu: '576',
mtu: 576,
mode: nil,
options: {
'pre-up' => '/bin/touch /tmp/eth1-up',
Expand All @@ -246,7 +246,7 @@ def fixture_data(file)
method: 'loopback',
ipaddress: nil,
netmask: nil,
mtu: '65536',
mtu: 65_536,
mode: nil,
options: nil)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/provider/network_config/redhat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def fixture_data(file)
method: 'none',
ipaddress: '169.254.0.1',
netmask: '255.255.255.0',
mtu: '1500',
mtu: 1500,
mode: :vlan,
options: { 'NM_CONTROLLED' => 'no', 'USERCTL' => 'no' })
end
Expand Down Expand Up @@ -460,7 +460,7 @@ def fixture_data(file)
ipaddress: '172.20.1.9',
netmask: '255.255.255.0',
method: 'static',
mtu: '1500',
mtu: 1500,
mode: nil,
options: {
'BONDING_OPTS' => %(mode=4 miimon=100 xmit_hash_policy=layer3+4)
Expand Down
Loading