Skip to content

Allow HWADDR to be disabled #69

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

Merged
merged 1 commit into from
Mar 10, 2016
Merged
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ Normal interface - static (minimal):
netmask => '255.255.255.128',
}

Normal interface - static (minimal without HWADDR in ifcfg-file):

network::if::static { 'eth0':
ensure => 'up',
ipaddress => '1.2.3.248',
netmask => '255.255.255.128',
manage_hwaddr => false,
}

Normal interface - static:

network::if::static { 'eth1':
Expand All @@ -75,6 +84,13 @@ Normal interface - dhcp (minimal):
ensure => 'up',
}

Normal interface - dhcp (minimal without HWADDR in ifcfg-file):

network::if::dynamic { 'eth2':
ensure => 'up',
manage_hwaddr => false,
}

Normal interface - dhcp:

network::if::dynamic { 'eth3':
Expand Down
4 changes: 4 additions & 0 deletions manifests/if/dynamic.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#
# $ensure - required - up|down
# $macaddress - optional - defaults to macaddress_$title
# $manage_hwaddr - optional - defaults to true
# $bootproto - optional - defaults to "dhcp"
# $userctl - optional - defaults to false
# $mtu - optional
Expand Down Expand Up @@ -43,6 +44,7 @@
define network::if::dynamic (
$ensure,
$macaddress = undef,
$manage_hwaddr = true,
$bootproto = 'dhcp',
$userctl = false,
$mtu = undef,
Expand All @@ -66,13 +68,15 @@
# Validate booleans
validate_bool($userctl)
validate_bool($peerdns)
validate_bool($manage_hwaddr)

network_if_base { $title:
ensure => $ensure,
ipaddress => '',
netmask => '',
gateway => '',
macaddress => $macaddy,
manage_hwaddr => $manage_hwaddr,
bootproto => $bootproto,
userctl => $userctl,
mtu => $mtu,
Expand Down
80 changes: 42 additions & 38 deletions manifests/if/static.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@
#
# === Parameters:
#
# $ensure - required - up|down
# $ipaddress - required
# $netmask - required
# $gateway - optional
# $ipv6address - optional
# $ipv6init - optional - defaults to false
# $ipv6gateway - optional
# $macaddress - optional - defaults to macaddress_$title
# $ipv6autoconf - optional - defaults to false
# $userctl - optional - defaults to false
# $mtu - optional
# $ethtool_opts - optional
# $peerdns - optional
# $ipv6peerdns - optional - defaults to false
# $dns1 - optional
# $dns2 - optional
# $domain - optional
# $scope - optional
# $ensure - required - up|down
# $ipaddress - required
# $netmask - required
# $gateway - optional
# $ipv6address - optional
# $ipv6init - optional - defaults to false
# $ipv6gateway - optional
# $manage_hwaddr - optional - defaults to true
# $macaddress - optional - defaults to macaddress_$title
# $ipv6autoconf - optional - defaults to false
# $userctl - optional - defaults to false
# $mtu - optional
# $ethtool_opts - optional
# $peerdns - optional
# $ipv6peerdns - optional - defaults to false
# $dns1 - optional
# $dns2 - optional
# $domain - optional
# $scope - optional
#
# === Actions:
#
Expand Down Expand Up @@ -57,6 +58,7 @@
$ipv6init = false,
$ipv6gateway = undef,
$macaddress = undef,
$manage_hwaddr = true,
$ipv6autoconf = false,
$userctl = false,
$mtu = undef,
Expand Down Expand Up @@ -88,27 +90,29 @@
validate_bool($ipv6autoconf)
validate_bool($peerdns)
validate_bool($ipv6peerdns)
validate_bool($manage_hwaddr)

network_if_base { $title:
ensure => $ensure,
ipv6init => $ipv6init,
ipaddress => $ipaddress,
ipv6address => $ipv6address,
netmask => $netmask,
gateway => $gateway,
ipv6gateway => $ipv6gateway,
ipv6autoconf => $ipv6autoconf,
macaddress => $macaddy,
bootproto => 'none',
userctl => $userctl,
mtu => $mtu,
ethtool_opts => $ethtool_opts,
peerdns => $peerdns,
ipv6peerdns => $ipv6peerdns,
dns1 => $dns1,
dns2 => $dns2,
domain => $domain,
linkdelay => $linkdelay,
scope => $scope,
ensure => $ensure,
ipv6init => $ipv6init,
ipaddress => $ipaddress,
ipv6address => $ipv6address,
netmask => $netmask,
gateway => $gateway,
ipv6gateway => $ipv6gateway,
ipv6autoconf => $ipv6autoconf,
macaddress => $macaddy,
manage_hwaddr => $manage_hwaddr,
bootproto => 'none',
userctl => $userctl,
mtu => $mtu,
ethtool_opts => $ethtool_opts,
peerdns => $peerdns,
ipv6peerdns => $ipv6peerdns,
dns1 => $dns1,
dns2 => $dns2,
domain => $domain,
linkdelay => $linkdelay,
scope => $scope,
}
} # define network::if::static
3 changes: 3 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
# $ipaddress - required
# $netmask - required
# $macaddress - required
# $manage_hwaddr - optional - defaults to true
# $gateway - optional
# $bootproto - optional
# $userctl - optional - defaults to false
Expand Down Expand Up @@ -99,6 +100,7 @@
$ipaddress,
$netmask,
$macaddress,
$manage_hwaddr = true,
$gateway = undef,
$ipv6address = undef,
$ipv6gateway = undef,
Expand Down Expand Up @@ -130,6 +132,7 @@
validate_bool($ipv6autoconf)
validate_bool($ipv6peerdns)
validate_bool($check_link_down)
validate_bool($manage_hwaddr)
# Validate our regular expressions
$states = [ '^up$', '^down$' ]
validate_re($ensure, $states, '$ensure must be either "up" or "down".')
Expand Down
10 changes: 10 additions & 0 deletions spec/classes/network_global_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@
end
end

context 'manage_hwaddr = foo' do
let(:params) {{ :manage_hwaddr => 'foo' }}

it 'should fail' do
expect {
should raise_error(Puppet::Error, /$manage_hwaddr is not a boolean. It looks to be a String./)
}
end
end

end

context 'on a supported operatingsystem, custom parameters' do
Expand Down
34 changes: 34 additions & 0 deletions spec/defines/network_if_dynamic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,38 @@
it { should contain_service('network') }
end

context 'optional parameters - manage_hwaddr' do
let(:title) { 'eth0' }
let :params do {
:ensure => 'up',
:manage_hwaddr => false,
}
end
let :facts do {
:osfamily => 'RedHat',
:macaddress_eth0 => 'bb:cc:bb:cc:bb:cc',
}
end
it { should contain_file('ifcfg-eth0').with(
:ensure => 'present',
:mode => '0644',
:owner => 'root',
:group => 'root',
:path => '/etc/sysconfig/network-scripts/ifcfg-eth0',
:notify => 'Service[network]'
)}
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=no',
])
end
it { should contain_service('network') }
end


end
37 changes: 37 additions & 0 deletions spec/defines/network_if_static_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,41 @@
it { should contain_service('network') }
end

context 'optional parameters - manage_hwaddr' do
let(:title) { 'eth0' }
let :params do {
:ensure => 'up',
:ipaddress => '1.2.3.4',
:netmask => '255.255.255.0',
:manage_hwaddr => false,
}
end
let :facts do {
:osfamily => 'RedHat',
:macaddress_eth0 => 'bb:cc:bb:cc:bb:cc',
}
end
it { should contain_file('ifcfg-eth0').with(
:ensure => 'present',
:mode => '0644',
:owner => 'root',
:group => 'root',
:path => '/etc/sysconfig/network-scripts/ifcfg-eth0',
:notify => 'Service[network]'
)}
it 'should contain File[ifcfg-eth0] with required contents' do
verify_contents(catalogue, 'ifcfg-eth0', [
'DEVICE=eth0',
'BOOTPROTO=none',
'ONBOOT=yes',
'HOTPLUG=yes',
'TYPE=Ethernet',
'IPADDR=1.2.3.4',
'NETMASK=255.255.255.0',
'NM_CONTROLLED=no',
])
end
it { should contain_service('network') }
end

end
3 changes: 2 additions & 1 deletion templates/ifcfg-eth.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
###
DEVICE=<%= @interface %>
BOOTPROTO=<%= @bootproto %>
<% if @macaddress and @macaddress != '' %>HWADDR=<%= @macaddress %>
<% if @manage_hwaddr and @macaddress and @macaddress != '' -%>
HWADDR=<%= @macaddress %>
<% end -%>
ONBOOT=<%= @onboot %>
HOTPLUG=<%= @onboot %>
Expand Down