Skip to content

Commit 5c4173d

Browse files
committed
Ensure boolean properties munged
The props hash is using symbol keys so the previous behavior was never actually munging and unmunging those boolean values BEFORE: ONBOOT=true AFTER: ONBOOT=yes
1 parent 3a1251c commit 5c4173d

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

lib/puppet/provider/network_config/redhat.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ def self.munge(pairs)
170170
# For all of the remaining values, blindly toss them into the options hash.
171171
props[:options] = pairs
172172

173-
%w[onboot hotplug].each do |bool_property|
174-
props[bool_property] = (props[bool_property] == 'yes') if props[bool_property]
173+
%i[onboot hotplug].each do |bool_property|
174+
props[bool_property] = (props[bool_property] == 'yes') unless props[bool_property].nil?
175175
end
176176

177177
props[:method] = 'static' unless %w[bootp dhcp].include? props[:method]
@@ -214,8 +214,8 @@ def self.format_file(filename, providers)
214214
def self.unmunge(props)
215215
pairs = {}
216216

217-
%w[onboot hotplug].each do |bool_property|
218-
if props[bool_property]
217+
%i[onboot hotplug].each do |bool_property|
218+
unless props[bool_property].nil?
219219
props[bool_property] = (props[bool_property] == true ? 'yes' : 'no')
220220
end
221221
end

spec/unit/provider/network_config/redhat_spec.rb

+15-15
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def fixture_data(file)
5959
describe 'the onboot property' do
6060
let(:data) { described_class.parse_file('eth0', fixture_data('eth0-dhcp'))[0] }
6161

62-
it { expect(data[:onboot]).to eq('yes') }
62+
it { expect(data[:onboot]).to eq(true) }
6363
end
6464

6565
describe 'the method property' do
@@ -80,13 +80,13 @@ def fixture_data(file)
8080
describe 'when true' do
8181
let(:data) { described_class.parse_file('eth0', fixture_data('eth0-hotplug'))[0] }
8282

83-
it { expect(data[:hotplug]).to eq('yes') }
83+
it { expect(data[:hotplug]).to eq(true) }
8484
end
8585

8686
describe 'when false' do
8787
let(:data) { described_class.parse_file('eth0', fixture_data('eth0-nohotplug'))[0] }
8888

89-
it { expect(data[:hotplug]).to eq('no') }
89+
it { expect(data[:hotplug]).to eq(false) }
9090
end
9191
end
9292

@@ -120,7 +120,7 @@ def fixture_data(file)
120120
describe 'bond0' do
121121
subject { described_class.instances.find { |i| i.name == 'bond0' } }
122122

123-
its(:onboot) { is_expected.to eq('yes') }
123+
its(:onboot) { is_expected.to eq(true) }
124124
its(:mtu) { is_expected.to eq('1500') }
125125

126126
its(:options) do
@@ -133,7 +133,7 @@ def fixture_data(file)
133133
describe 'bond1' do
134134
subject { described_class.instances.find { |i| i.name == 'bond1' } }
135135

136-
its(:onboot) { is_expected.to eq('yes') }
136+
its(:onboot) { is_expected.to eq(true) }
137137
its(:ipaddress) { is_expected.to eq('172.20.1.9') }
138138
its(:netmask) { is_expected.to eq('255.255.255.0') }
139139
its(:mtu) { is_expected.to eq('1500') }
@@ -148,7 +148,7 @@ def fixture_data(file)
148148
describe 'eth0' do
149149
subject { described_class.instances.find { |i| i.name == 'eth0' } }
150150

151-
its(:onboot) { is_expected.to eq('yes') }
151+
its(:onboot) { is_expected.to eq(true) }
152152
its(:mtu) { is_expected.to eq('1500') }
153153
its(:mode) { is_expected.to eq(:raw) }
154154

@@ -164,7 +164,7 @@ def fixture_data(file)
164164
describe 'eth1' do
165165
subject { described_class.instances.find { |i| i.name == 'eth1' } }
166166

167-
its(:onboot) { is_expected.to eq('yes') }
167+
its(:onboot) { is_expected.to eq(true) }
168168
its(:mtu) { is_expected.to eq('1500') }
169169
its(:mode) { is_expected.to eq(:raw) }
170170

@@ -180,7 +180,7 @@ def fixture_data(file)
180180
describe 'eth2' do
181181
subject { described_class.instances.find { |i| i.name == 'eth2' } }
182182

183-
its(:onboot) { is_expected.to eq('yes') }
183+
its(:onboot) { is_expected.to eq(true) }
184184
its(:mtu) { is_expected.to eq('1500') }
185185
its(:mode) { is_expected.to eq(:raw) }
186186

@@ -196,7 +196,7 @@ def fixture_data(file)
196196
describe 'eth3' do
197197
subject { described_class.instances.find { |i| i.name == 'eth3' } }
198198

199-
its(:onboot) { is_expected.to eq('yes') }
199+
its(:onboot) { is_expected.to eq(true) }
200200
its(:mtu) { is_expected.to eq('1500') }
201201
its(:mode) { is_expected.to eq(:raw) }
202202

@@ -316,7 +316,7 @@ def fixture_data(file)
316316
describe 'eth0.0' do
317317
subject { described_class.instances.find { |i| i.name == 'eth0.0' } }
318318

319-
its(:onboot) { is_expected.to eq('yes') }
319+
its(:onboot) { is_expected.to eq(true) }
320320
its(:method) { is_expected.to eq('static') }
321321
its(:mtu) { is_expected.to eq('9000') }
322322
its(:mode) { is_expected.to eq(:vlan) }
@@ -334,7 +334,7 @@ def fixture_data(file)
334334
describe 'eth0.1' do
335335
subject { described_class.instances.find { |i| i.name == 'eth0.1' } }
336336

337-
its(:onboot) { is_expected.to eq('yes') }
337+
its(:onboot) { is_expected.to eq(true) }
338338
its(:method) { is_expected.to eq('static') }
339339
its(:mtu) { is_expected.to eq('9000') }
340340
its(:mode) { is_expected.to eq(:vlan) }
@@ -352,7 +352,7 @@ def fixture_data(file)
352352
describe 'eth0.4095' do
353353
subject { described_class.instances.find { |i| i.name == 'eth0.4095' } }
354354

355-
its(:onboot) { is_expected.to eq('yes') }
355+
its(:onboot) { is_expected.to eq(true) }
356356
its(:method) { is_expected.to eq('static') }
357357
its(:mtu) { is_expected.to eq('9000') }
358358
its(:mode) { is_expected.to eq(:vlan) }
@@ -380,7 +380,7 @@ def fixture_data(file)
380380
instance_double('eth0_provider',
381381
name: 'eth0',
382382
ensure: :present,
383-
onboot: 'yes',
383+
onboot: true,
384384
hotplug: true,
385385
family: 'inet',
386386
method: 'none',
@@ -395,7 +395,7 @@ def fixture_data(file)
395395
instance_double('eth0_1_provider',
396396
name: 'eth0.1',
397397
ensure: :present,
398-
onboot: 'yes',
398+
onboot: true,
399399
hotplug: true,
400400
family: 'inet',
401401
method: 'none',
@@ -424,7 +424,7 @@ def fixture_data(file)
424424
let(:lo_provider) do
425425
instance_double('lo_provider',
426426
name: 'lo',
427-
onboot: 'yes',
427+
onboot: true,
428428
hotplug: true,
429429
family: 'inet',
430430
method: 'loopback',

0 commit comments

Comments
 (0)