Skip to content

Commit 6e35a04

Browse files
Allow HWADDR to be disabled
1 parent ced4e4e commit 6e35a04

File tree

6 files changed

+117
-54
lines changed

6 files changed

+117
-54
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ Normal interface - static (minimal):
5454
netmask => '255.255.255.128',
5555
}
5656

57+
Normal interface - static (minimal without HWADDR in ifcfg-file):
58+
59+
network::if::static { 'eth0':
60+
ensure => 'up',
61+
ipaddress => '1.2.3.248',
62+
netmask => '255.255.255.128',
63+
manage_hwaddr => false,
64+
}
65+
5766
Normal interface - static:
5867

5968
network::if::static { 'eth1':

manifests/if/static.pp

+40-36
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@
44
#
55
# === Parameters:
66
#
7-
# $ensure - required - up|down
8-
# $ipaddress - required
9-
# $netmask - required
10-
# $gateway - optional
11-
# $ipv6address - optional
12-
# $ipv6init - optional - defaults to false
13-
# $ipv6gateway - optional
14-
# $macaddress - optional - defaults to macaddress_$title
15-
# $ipv6autoconf - optional - defaults to false
16-
# $userctl - optional - defaults to false
17-
# $mtu - optional
18-
# $ethtool_opts - optional
19-
# $peerdns - optional
20-
# $ipv6peerdns - optional - defaults to false
21-
# $dns1 - optional
22-
# $dns2 - optional
23-
# $domain - optional
7+
# $ensure - required - up|down
8+
# $ipaddress - required
9+
# $netmask - required
10+
# $gateway - optional
11+
# $ipv6address - optional
12+
# $ipv6init - optional - defaults to false
13+
# $ipv6gateway - optional
14+
# $macaddress - optional - defaults to macaddress_$title
15+
# $manage_hwaddr - optional - defaults to true
16+
# $ipv6autoconf - optional - defaults to false
17+
# $userctl - optional - defaults to false
18+
# $mtu - optional
19+
# $ethtool_opts - optional
20+
# $peerdns - optional
21+
# $ipv6peerdns - optional - defaults to false
22+
# $dns1 - optional
23+
# $dns2 - optional
24+
# $domain - optional
2425
#
2526
# === Actions:
2627
#
@@ -56,6 +57,7 @@
5657
$ipv6init = false,
5758
$ipv6gateway = undef,
5859
$macaddress = undef,
60+
$manage_hwaddr = true,
5961
$ipv6autoconf = false,
6062
$userctl = false,
6163
$mtu = undef,
@@ -86,26 +88,28 @@
8688
validate_bool($ipv6autoconf)
8789
validate_bool($peerdns)
8890
validate_bool($ipv6peerdns)
91+
validate_bool($manage_hwaddr)
8992

9093
network_if_base { $title:
91-
ensure => $ensure,
92-
ipv6init => $ipv6init,
93-
ipaddress => $ipaddress,
94-
ipv6address => $ipv6address,
95-
netmask => $netmask,
96-
gateway => $gateway,
97-
ipv6gateway => $ipv6gateway,
98-
ipv6autoconf => $ipv6autoconf,
99-
macaddress => $macaddy,
100-
bootproto => 'none',
101-
userctl => $userctl,
102-
mtu => $mtu,
103-
ethtool_opts => $ethtool_opts,
104-
peerdns => $peerdns,
105-
ipv6peerdns => $ipv6peerdns,
106-
dns1 => $dns1,
107-
dns2 => $dns2,
108-
domain => $domain,
109-
linkdelay => $linkdelay,
94+
ensure => $ensure,
95+
ipv6init => $ipv6init,
96+
ipaddress => $ipaddress,
97+
ipv6address => $ipv6address,
98+
netmask => $netmask,
99+
gateway => $gateway,
100+
ipv6gateway => $ipv6gateway,
101+
ipv6autoconf => $ipv6autoconf,
102+
macaddress => $macaddy,
103+
manage_hwaddr => $manage_hwaddr,
104+
bootproto => 'none',
105+
userctl => $userctl,
106+
mtu => $mtu,
107+
ethtool_opts => $ethtool_opts,
108+
peerdns => $peerdns,
109+
ipv6peerdns => $ipv6peerdns,
110+
dns1 => $dns1,
111+
dns2 => $dns2,
112+
domain => $domain,
113+
linkdelay => $linkdelay,
110114
}
111115
} # define network::if::static

manifests/init.pp

+20-17
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,24 @@
4949
#
5050
# === Parameters:
5151
#
52-
# $ensure - required - up|down
53-
# $ipaddress - required
54-
# $netmask - required
55-
# $macaddress - required
56-
# $gateway - optional
57-
# $bootproto - optional
58-
# $userctl - optional - defaults to false
59-
# $mtu - optional
60-
# $dhcp_hostname - optional
61-
# $ethtool_opts - optional
62-
# $bonding_opts - optional
63-
# $isalias - optional
64-
# $peerdns - optional
65-
# $dns1 - optional
66-
# $dns2 - optional
67-
# $domain - optional
68-
# $bridge - optional
52+
# $ensure - required - up|down
53+
# $ipaddress - required
54+
# $netmask - required
55+
# $macaddress - required
56+
# $manage_hwaddr - optional - defaults to true
57+
# $gateway - optional
58+
# $bootproto - optional
59+
# $userctl - optional - defaults to false
60+
# $mtu - optional
61+
# $dhcp_hostname - optional
62+
# $ethtool_opts - optional
63+
# $bonding_opts - optional
64+
# $isalias - optional
65+
# $peerdns - optional
66+
# $dns1 - optional
67+
# $dns2 - optional
68+
# $domain - optional
69+
# $bridge - optional
6970
#
7071
# === Actions:
7172
#
@@ -97,6 +98,7 @@
9798
$ipaddress,
9899
$netmask,
99100
$macaddress,
101+
$manage_hwaddr = true,
100102
$gateway = undef,
101103
$ipv6address = undef,
102104
$ipv6gateway = undef,
@@ -124,6 +126,7 @@
124126
validate_bool($ipv6init)
125127
validate_bool($ipv6autoconf)
126128
validate_bool($ipv6peerdns)
129+
validate_bool($manage_hwaddr)
127130
# Validate our regular expressions
128131
$states = [ '^up$', '^down$' ]
129132
validate_re($ensure, $states, '$ensure must be either "up" or "down".')

spec/classes/network_global_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@
113113
end
114114
end
115115

116+
context 'manage_hwaddr = foo' do
117+
let(:params) {{ :manage_hwaddr => 'foo' }}
118+
119+
it 'should fail' do
120+
expect {
121+
should raise_error(Puppet::Error, /$manage_hwaddr is not a boolean. It looks to be a String./)
122+
}
123+
end
124+
end
125+
116126
end
117127

118128
context 'on a supported operatingsystem, custom parameters' do

spec/defines/network_if_static_spec.rb

+37
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,41 @@
173173
it { should contain_service('network') }
174174
end
175175

176+
context 'optional parameters - manage_hwaddr' do
177+
let(:title) { 'eth0' }
178+
let :params do {
179+
:ensure => 'up',
180+
:ipaddress => '1.2.3.4',
181+
:netmask => '255.255.255.0',
182+
:manage_hwaddr => false,
183+
}
184+
end
185+
let :facts do {
186+
:osfamily => 'RedHat',
187+
:macaddress_eth0 => 'bb:cc:bb:cc:bb:cc',
188+
}
189+
end
190+
it { should contain_file('ifcfg-eth0').with(
191+
:ensure => 'present',
192+
:mode => '0644',
193+
:owner => 'root',
194+
:group => 'root',
195+
:path => '/etc/sysconfig/network-scripts/ifcfg-eth0',
196+
:notify => 'Service[network]'
197+
)}
198+
it 'should contain File[ifcfg-eth0] with required contents' do
199+
verify_contents(catalogue, 'ifcfg-eth0', [
200+
'DEVICE=eth0',
201+
'BOOTPROTO=none',
202+
'ONBOOT=yes',
203+
'HOTPLUG=yes',
204+
'TYPE=Ethernet',
205+
'IPADDR=1.2.3.4',
206+
'NETMASK=255.255.255.0',
207+
'NM_CONTROLLED=no',
208+
])
209+
end
210+
it { should contain_service('network') }
211+
end
212+
176213
end

templates/ifcfg-eth.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
###
44
DEVICE=<%= @interface %>
55
BOOTPROTO=<%= @bootproto %>
6-
<% if @macaddress %>HWADDR=<%= @macaddress %>
6+
<% if @manage_hwaddr and @macaddress %>HWADDR=<%= @macaddress %>
77
<% end -%>
88
ONBOOT=<%= @onboot %>
99
HOTPLUG=<%= @onboot %>

0 commit comments

Comments
 (0)