Skip to content
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

Ensure boolean properties munged #335

Merged
merged 1 commit into from
Oct 21, 2024
Merged
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
8 changes: 4 additions & 4 deletions lib/puppet/provider/network_config/redhat.rb
Original file line number Diff line number Diff line change
@@ -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]
@@ -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
30 changes: 15 additions & 15 deletions spec/unit/provider/network_config/redhat_spec.rb
Original file line number Diff line number Diff line change
@@ -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
@@ -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

@@ -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
@@ -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') }
@@ -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) }

@@ -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) }

@@ -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) }

@@ -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) }

@@ -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) }
@@ -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) }
@@ -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) }
@@ -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',
@@ -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',
@@ -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',

Unchanged files with check annotations Beta

{

Check warning on line 1 in metadata.json

GitHub Actions / Puppet / Static validations

Skipping EOL operating system RedHat 7

Check warning on line 1 in metadata.json

GitHub Actions / Puppet / Static validations

Skipping EOL operating system CentOS 7

Check warning on line 1 in metadata.json

GitHub Actions / Puppet / Static validations

Skipping EOL operating system CentOS 8

Check warning on line 1 in metadata.json

GitHub Actions / Puppet / Static validations

Skipping EOL operating system Debian 10
"name": "puppet-network",
"version": "2.0.1-rc0",
"author": "Vox Pupuli",
expect(Puppet::Type.type(:network_config).propertybyname(:options).required_features).to include(:provider_options)
end
it 'is a descendant of the KeyValue property' do

Check warning on line 68 in spec/unit/type/network_config_spec.rb

GitHub Actions / Puppet / 8 (Ruby 3.2)

Puppet::Type::Network_config when validating the attribute options is a descendant of the KeyValue property Failure/Error: expect(Puppet::Type.type(:network_config).propertybyname(:options).ancestors).to include(Puppet::Property::Ensure) expected [Puppet::Type::Network_config::Options, Puppet::Property, Puppet::Parameter, Puppet::Util::Logging, P...acts, FastGettext::Translation, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject] to include Puppet::Property::Ensure Diff: @@ -1,12 +1,23 @@ -[Puppet::Property::Ensure] +[Puppet::Type::Network_config::Options, + Puppet::Property, + Puppet::Parameter, + Puppet::Util::Logging, + Puppet::Util::Errors, + Puppet::Util, + Object, + RspecPuppetFacts, + FastGettext::Translation, + JSON::Ext::Generator::GeneratorMethods::Object, + Kernel, + BasicObject]

Check warning on line 68 in spec/unit/type/network_config_spec.rb

GitHub Actions / Puppet / 7 (Ruby 2.7)

Puppet::Type::Network_config when validating the attribute options is a descendant of the KeyValue property Failure/Error: expect(Puppet::Type.type(:network_config).propertybyname(:options).ancestors).to include(Puppet::Property::Ensure) expected [Puppet::Type::Network_config::Options, Puppet::Property, Puppet::Parameter, Puppet::Util::Logging, P...ator::GeneratorMethods::Object, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject] to include Puppet::Property::Ensure Diff: @@ -1,13 +1,25 @@ -[Puppet::Property::Ensure] +[Puppet::Type::Network_config::Options, + Puppet::Property, + Puppet::Parameter, + Puppet::Util::Logging, + Puppet::Util::Errors, + Puppet::Util, + Object, + RspecPuppetFacts, + FastGettext::Translation, + PSON::Pure::Generator::GeneratorMethods::Object, + JSON::Ext::Generator::GeneratorMethods::Object, + Kernel, + BasicObject]
pending 'on conversion to specific type'
expect(Puppet::Type.type(:network_config).propertybyname(:options).ancestors).to include(Puppet::Property::Ensure)
end
expect { Puppet::Type.type(:network_config).new(name: 'yay', family: :inet, ipaddress: address4) }.not_to raise_error
end
it 'fails when passed an IPv6 address' do

Check warning on line 85 in spec/unit/type/network_config_spec.rb

GitHub Actions / Puppet / 8 (Ruby 3.2)

Puppet::Type::Network_config when validating the attribute value ipaddress using the inet family fails when passed an IPv6 address Failure/Error: expect { Puppet::Type.type(:network_config).new(name: 'yay', family: :inet, ipaddress: address6) }.to raise_error(%r{not a valid ipv4 address}) expected Exception with message matching /not a valid ipv4 address/ but nothing was raised

Check warning on line 85 in spec/unit/type/network_config_spec.rb

GitHub Actions / Puppet / 7 (Ruby 2.7)

Puppet::Type::Network_config when validating the attribute value ipaddress using the inet family fails when passed an IPv6 address Failure/Error: expect { Puppet::Type.type(:network_config).new(name: 'yay', family: :inet, ipaddress: address6) }.to raise_error(%r{not a valid ipv4 address}) expected Exception with message matching /not a valid ipv4 address/ but nothing was raised
pending('Not yet implemented')
expect { Puppet::Type.type(:network_config).new(name: 'yay', family: :inet, ipaddress: address6) }.to raise_error(%r{not a valid ipv4 address})
end
expect { Puppet::Type.type(:network_config).new(name: 'yay', family: :inet6, ipaddress: address6) }.not_to raise_error
end
it 'fails when passed an IPv4 address' do

Check warning on line 96 in spec/unit/type/network_config_spec.rb

GitHub Actions / Puppet / 8 (Ruby 3.2)

Puppet::Type::Network_config when validating the attribute value ipaddress using the inet6 family fails when passed an IPv4 address Failure/Error: expect { Puppet::Type.type(:network_config).new(name: 'yay', family: :inet6, ipaddress: address4) }.to raise_error(%r{not a valid ipv6 address}) expected Exception with message matching /not a valid ipv6 address/ but nothing was raised

Check warning on line 96 in spec/unit/type/network_config_spec.rb

GitHub Actions / Puppet / 7 (Ruby 2.7)

Puppet::Type::Network_config when validating the attribute value ipaddress using the inet6 family fails when passed an IPv4 address Failure/Error: expect { Puppet::Type.type(:network_config).new(name: 'yay', family: :inet6, ipaddress: address4) }.to raise_error(%r{not a valid ipv6 address}) expected Exception with message matching /not a valid ipv6 address/ but nothing was raised
pending('Not yet implemented')
expect { Puppet::Type.type(:network_config).new(name: 'yay', family: :inet6, ipaddress: address4) }.to raise_error(%r{not a valid ipv6 address})
end