Skip to content

Commit

Permalink
Ensure boolean properties munged
Browse files Browse the repository at this point in the history
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
  • Loading branch information
treydock committed Oct 21, 2024
1 parent 3a1251c commit 8434e45
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions lib/puppet/provider/network_config/redhat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ def self.munge(pairs)
# For all of the remaining values, blindly toss them into the options hash.
props[:options] = pairs

%w[onboot hotplug].each do |bool_property|
props[bool_property] = (props[bool_property] == 'yes') if props[bool_property]
%i[onboot hotplug].each do |bool_property|
props[bool_property] = (props[bool_property] == 'yes') unless props[bool_property].nil?
end

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

%w[onboot hotplug].each do |bool_property|
if props[bool_property]
%i[onboot hotplug].each do |bool_property|
unless props[bool_property].nil?
props[bool_property] = (props[bool_property] == true ? 'yes' : 'no')
end
end
Expand Down
30 changes: 15 additions & 15 deletions spec/unit/provider/network_config/redhat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def fixture_data(file)
describe 'the onboot property' do
let(:data) { described_class.parse_file('eth0', fixture_data('eth0-dhcp'))[0] }

it { expect(data[:onboot]).to eq('yes') }
it { expect(data[:onboot]).to be(true) }
end

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

it { expect(data[:hotplug]).to eq('yes') }
it { expect(data[:hotplug]).to be(true) }
end

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

it { expect(data[:hotplug]).to eq('no') }
it { expect(data[:hotplug]).to be(false) }
end
end

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

its(:onboot) { is_expected.to eq('yes') }
its(:onboot) { is_expected.to be(true) }
its(:mtu) { is_expected.to eq('1500') }

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

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

its(:onboot) { is_expected.to eq('yes') }
its(:onboot) { is_expected.to be(true) }
its(:mtu) { is_expected.to eq('1500') }
its(:mode) { is_expected.to eq(:raw) }

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

its(:onboot) { is_expected.to eq('yes') }
its(:onboot) { is_expected.to be(true) }
its(:mtu) { is_expected.to eq('1500') }
its(:mode) { is_expected.to eq(:raw) }

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

its(:onboot) { is_expected.to eq('yes') }
its(:onboot) { is_expected.to be(true) }
its(:mtu) { is_expected.to eq('1500') }
its(:mode) { is_expected.to eq(:raw) }

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

its(:onboot) { is_expected.to eq('yes') }
its(:onboot) { is_expected.to be(true) }
its(:mtu) { is_expected.to eq('1500') }
its(:mode) { is_expected.to eq(:raw) }

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

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

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

its(:onboot) { is_expected.to eq('yes') }
its(:onboot) { is_expected.to be(true) }
its(:method) { is_expected.to eq('static') }
its(:mtu) { is_expected.to eq('9000') }
its(:mode) { is_expected.to eq(:vlan) }
Expand Down Expand Up @@ -380,7 +380,7 @@ def fixture_data(file)
instance_double('eth0_provider',
name: 'eth0',
ensure: :present,
onboot: 'yes',
onboot: true,
hotplug: true,
family: 'inet',
method: 'none',
Expand All @@ -395,7 +395,7 @@ def fixture_data(file)
instance_double('eth0_1_provider',
name: 'eth0.1',
ensure: :present,
onboot: 'yes',
onboot: true,
hotplug: true,
family: 'inet',
method: 'none',
Expand Down Expand Up @@ -424,7 +424,7 @@ def fixture_data(file)
let(:lo_provider) do
instance_double('lo_provider',
name: 'lo',
onboot: 'yes',
onboot: true,
hotplug: true,
family: 'inet',
method: 'loopback',
Expand Down

0 comments on commit 8434e45

Please sign in to comment.