Skip to content

Commit ccb54b1

Browse files
Allow HWADDR to be disabled
1 parent a8b3180 commit ccb54b1

File tree

8 files changed

+148
-39
lines changed

8 files changed

+148
-39
lines changed

README.md

+16
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':
@@ -75,6 +84,13 @@ Normal interface - dhcp (minimal):
7584
ensure => 'up',
7685
}
7786

87+
Normal interface - dhcp (minimal without HWADDR in ifcfg-file):
88+
89+
network::if::dynamic { 'eth2':
90+
ensure => 'up',
91+
manage_hwaddr => false,
92+
}
93+
7894
Normal interface - dhcp:
7995

8096
network::if::dynamic { 'eth3':

manifests/if/dynamic.pp

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#
77
# $ensure - required - up|down
88
# $macaddress - optional - defaults to macaddress_$title
9+
# $manage_hwaddr - optional - defaults to true
910
# $bootproto - optional - defaults to "dhcp"
1011
# $userctl - optional - defaults to false
1112
# $mtu - optional
@@ -43,6 +44,7 @@
4344
define network::if::dynamic (
4445
$ensure,
4546
$macaddress = undef,
47+
$manage_hwaddr = true,
4648
$bootproto = 'dhcp',
4749
$userctl = false,
4850
$mtu = undef,
@@ -66,13 +68,15 @@
6668
# Validate booleans
6769
validate_bool($userctl)
6870
validate_bool($peerdns)
71+
validate_bool($manage_hwaddr)
6972

7073
network_if_base { $title:
7174
ensure => $ensure,
7275
ipaddress => '',
7376
netmask => '',
7477
gateway => '',
7578
macaddress => $macaddy,
79+
manage_hwaddr => $manage_hwaddr,
7680
bootproto => $bootproto,
7781
userctl => $userctl,
7882
mtu => $mtu,

manifests/if/static.pp

+42-38
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,25 @@
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
24-
# $scope - 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+
# $manage_hwaddr - optional - defaults to true
15+
# $macaddress - optional - defaults to macaddress_$title
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
25+
# $scope - optional
2526
#
2627
# === Actions:
2728
#
@@ -57,6 +58,7 @@
5758
$ipv6init = false,
5859
$ipv6gateway = undef,
5960
$macaddress = undef,
61+
$manage_hwaddr = true,
6062
$ipv6autoconf = false,
6163
$userctl = false,
6264
$mtu = undef,
@@ -88,27 +90,29 @@
8890
validate_bool($ipv6autoconf)
8991
validate_bool($peerdns)
9092
validate_bool($ipv6peerdns)
93+
validate_bool($manage_hwaddr)
9194

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

manifests/init.pp

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
# $ipaddress - required
5454
# $netmask - required
5555
# $macaddress - required
56+
# $manage_hwaddr - optional - defaults to true
5657
# $gateway - optional
5758
# $bootproto - optional
5859
# $userctl - optional - defaults to false
@@ -99,6 +100,7 @@
99100
$ipaddress,
100101
$netmask,
101102
$macaddress,
103+
$manage_hwaddr = true,
102104
$gateway = undef,
103105
$ipv6address = undef,
104106
$ipv6gateway = undef,
@@ -130,6 +132,7 @@
130132
validate_bool($ipv6autoconf)
131133
validate_bool($ipv6peerdns)
132134
validate_bool($check_link_down)
135+
validate_bool($manage_hwaddr)
133136
# Validate our regular expressions
134137
$states = [ '^up$', '^down$' ]
135138
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_dynamic_spec.rb

+34
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,38 @@
125125
it { should contain_service('network') }
126126
end
127127

128+
context 'optional parameters - manage_hwaddr' do
129+
let(:title) { 'eth0' }
130+
let :params do {
131+
:ensure => 'up',
132+
:manage_hwaddr => false,
133+
}
134+
end
135+
let :facts do {
136+
:osfamily => 'RedHat',
137+
:macaddress_eth0 => 'bb:cc:bb:cc:bb:cc',
138+
}
139+
end
140+
it { should contain_file('ifcfg-eth0').with(
141+
:ensure => 'present',
142+
:mode => '0644',
143+
:owner => 'root',
144+
:group => 'root',
145+
:path => '/etc/sysconfig/network-scripts/ifcfg-eth0',
146+
:notify => 'Service[network]'
147+
)}
148+
it 'should contain File[ifcfg-eth0] with required contents' do
149+
verify_contents(catalogue, 'ifcfg-eth0', [
150+
'DEVICE=eth0',
151+
'BOOTPROTO=none',
152+
'ONBOOT=yes',
153+
'HOTPLUG=yes',
154+
'TYPE=Ethernet',
155+
'NM_CONTROLLED=no',
156+
])
157+
end
158+
it { should contain_service('network') }
159+
end
160+
161+
128162
end

spec/defines/network_if_static_spec.rb

+37
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,41 @@
175175
it { should contain_service('network') }
176176
end
177177

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

templates/ifcfg-eth.erb

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
###
44
DEVICE=<%= @interface %>
55
BOOTPROTO=<%= @bootproto %>
6-
<% if @macaddress and @macaddress != '' %>HWADDR=<%= @macaddress %>
6+
<% if @manage_hwaddr and @macaddress and @macaddress != '' -%>
7+
HWADDR=<%= @macaddress %>
78
<% end -%>
89
ONBOOT=<%= @onboot %>
910
HOTPLUG=<%= @onboot %>

0 commit comments

Comments
 (0)