Skip to content

Commit

Permalink
Correct rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanlcarlson committed Sep 10, 2024
1 parent aa40f65 commit d651c3f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 30 deletions.
19 changes: 8 additions & 11 deletions lib/facter/ipmi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def parse_ipmitool_output(ipmitool_output)

def add_ipmi_fact(name, value)
fact_names = []
if not fact_names.include?("ipmi_#{name}") then
fact_names.push("ipmi_#{name}")
end
fact_names.push("ipmi_#{name}") unless fact_names.include?("ipmi_#{name}")
fact_names.push("ipmi#{@channel_nr}_#{name}")
fact_names.each do |n|
Facter.add(n) do
Expand All @@ -87,7 +85,7 @@ def add_ipmi_fact(name, value)
confine kernel: 'Linux'
setcode do
ipmi_hash = {}
if Facter::Util::Resolution.which('ipmitool') then
if Facter::Util::Resolution.which('ipmitool')
(1..11).each do |channel_nr|
lan_channel_hash = {}
ipmitool_output = Facter::Util::Resolution.exec("ipmitool lan print #{channel_nr} 2>&1")
Expand All @@ -105,13 +103,12 @@ def add_ipmi_fact(name, value)
lan_channel_hash['gateway'] = Regexp.last_match(1)
end
end
if not lan_channel_hash.empty?() then
lan_channel_hash['channel'] = channel_nr
if not ipmi_hash.key?('default') then
ipmi_hash['default'] = lan_channel_hash
end
ipmi_hash[channel_nr] = lan_channel_hash
end

next if lan_channel_hash.empty?

lan_channel_hash['channel'] = channel_nr
ipmi_hash['default'] = lan_channel_hash unless ipmi_hash.key?('default')
ipmi_hash[channel_nr] = lan_channel_hash
end
end
ipmi_hash
Expand Down
14 changes: 8 additions & 6 deletions spec/classes/ipmi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
describe 'ipmi', type: :class do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) { facts.merge(
{
:ipmitool_mc_info => { :IPMI_Puppet_Service_Recommend => 'running' },
:ipmi => { :default => { :channel => 1}}
}
) }
let(:facts) do
facts.merge(
{
ipmitool_mc_info: { IPMI_Puppet_Service_Recommend: 'running' },
ipmi: { default: { channel: 1 } }
}
)
end

case facts[:os]['family']
when 'RedHat'
Expand Down
14 changes: 8 additions & 6 deletions spec/defines/ipmi_network_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
describe 'ipmi::network', type: :define do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) let(:facts) { facts.merge(
{
:ipmitool_mc_info => { :IPMI_Puppet_Service_Recommend => 'running' },
:ipmi => { :default => { :channel => 1}}
}
) }
let(:facts) do
facts.merge(
{
ipmitool_mc_info: { IPMI_Puppet_Service_Recommend: 'running' },
ipmi: { default: { channel: 1 } }
}
)
end
let(:title) { 'example' }

describe 'when deploying as dhcp with minimal params' do
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/ipmi_snmp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

},
ipmitool_mc_info: { IPMI_Puppet_Service_Recommend: 'running' },
ipmi: { default:{ channel: 1}},
ipmi: { default: { channel: 1 } },
}
end

Expand Down
14 changes: 8 additions & 6 deletions spec/defines/ipmi_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
describe 'ipmi::user', type: :define do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) { facts.merge(
{
:ipmitool_mc_info => { :IPMI_Puppet_Service_Recommend => 'running' },
:ipmi => { :default => { :channel => 1}}
}
) }
let(:facts) do
facts.merge(
{
ipmitool_mc_info: { IPMI_Puppet_Service_Recommend: 'running' },
ipmi: { default: { channel: 1 } }
}
)
end
let(:title) { 'newuser' }

context 'when deploying with password param' do
Expand Down

0 comments on commit d651c3f

Please sign in to comment.