Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Lint: RuboCop and style checks
name: Lint

on:
pull_request:
push:
branches: [main, master]

jobs:
rubocop:
runs-on: ubuntu-latest
continue-on-error: true # Allow to fail - report as warning only
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true
- name: Run RuboCop
run: bundle exec rubocop
10 changes: 5 additions & 5 deletions lib/rubyipmi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def self.connect(user, pass, host, provider = 'any', opts = {:driver => 'lan20',
opts[:timeout] ||= 'default'

if opts[:privilege] && !supported_privilege_type?(opts[:privilege])
logger.error("Invalid privilege type :#{opts[:privilege]}, must be one of: #{PRIV_TYPES.join("\n")}") if logger
logger&.error("Invalid privilege type :#{opts[:privilege]}, must be one of: #{PRIV_TYPES.join("\n")}")
raise "Invalid privilege type :#{opts[:privilege]}, must be one of: #{PRIV_TYPES.join("\n")}"
end

Expand All @@ -119,7 +119,7 @@ def self.connect(user, pass, host, provider = 'any', opts = {:driver => 'lan20',
# Support multiple drivers
# Note: these are just generic names of drivers that need to be specified for each provider
unless valid_drivers.include?(opts[:driver])
logger.debug("You must specify a valid driver: #{valid_drivers.join(',')}") if logger
logger&.debug("You must specify a valid driver: #{valid_drivers.join(',')}")
raise "You must specify a valid driver: #{valid_drivers.join(',')}"
end

Expand All @@ -130,12 +130,12 @@ def self.connect(user, pass, host, provider = 'any', opts = {:driver => 'lan20',
elsif provider == "ipmitool"
Rubyipmi::Ipmitool::Connection.new(user, pass, host, opts)
else
logger.error("Incorrect provider given, must use one of #{valid_providers.join(', ')}") if logger
logger&.error("Incorrect provider given, must use one of #{valid_providers.join(', ')}")
raise "Incorrect provider given, must use one of #{valid_providers.join(', ')}"
end
else
# Can't find the provider command line tool, maybe try other provider?
logger.error("The IPMI provider: #{provider} is not installed") if logger
logger&.error("The IPMI provider: #{provider} is not installed")
raise "The IPMI provider: #{provider} is not installed"
end
end
Expand Down Expand Up @@ -167,7 +167,7 @@ def self.is_provider_installed?(provider)
when "ipmitool"
cmdpath = locate_command('ipmitool')
else
logger.error("Invalid BMC provider type #{provider}") if logger
logger&.error("Invalid BMC provider type #{provider}")
false
end
# return false if command was not found
Expand Down
10 changes: 5 additions & 5 deletions lib/rubyipmi/commands/basecommand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def locate_command(commandname)
def runcmd
@success = false
@success = run
logger.debug(@lastcall.inspect) unless @lastcall.nil? if logger
logger.debug(@result) unless @result.nil? if logger
logger&.debug(@lastcall.inspect) unless @lastcall.nil?
logger&.debug(@result) unless @result.nil?
@success
end

Expand All @@ -63,7 +63,7 @@ def run
@cmd = locate_command(@cmdname)
setpass
@result = nil
logger.debug(makecommand) if logger
logger&.debug(makecommand)
begin
command = makecommand
@lastcall = command
Expand All @@ -76,7 +76,7 @@ def run
retrycount = retrycount.next
retry
else
logger.error("Exhausted all auto fixes, cannot determine what the problem is") if logger
logger&.error("Exhausted all auto fixes, cannot determine what the problem is")
raise "Exhausted all auto fixes, cannot determine what the problem is"
end
ensure
Expand All @@ -96,7 +96,7 @@ def find_fix(result)
fix = ErrorCodes.search(result)
@options.merge_notify!(fix)
rescue
Rubyipmi.logger.debug("Could not find fix for error code: \n#{result}") if logger
logger&.debug("Could not find fix for error code: \n#{result}")
raise "Could not find fix for error code: \n#{result}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubyipmi/freeipmi/commands/bmcdevice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def reset(type = 'cold')
key = "#{type}-reset"
command(key)
else
logger.error("reset type: #{type} is not a valid choice, use warm or cold") if logger
logger&.error("reset type: #{type} is not a valid choice, use warm or cold")
raise "reset type: #{type} is not a valid choice, use warm or cold"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubyipmi/freeipmi/commands/chassis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def bootdevice(device, reboot = false, persistent = false)
bootstatus = config.bootdevice(device, persistent)
power.cycle if reboot && bootstatus
else
logger.error("Device with name: #{device} is not a valid boot device for host #{options['hostname']}") if logger
logger&.error("Device with name: #{device} is not a valid boot device for host #{options['hostname']}")
raise "Device with name: #{device} is not a valid boot device for host #{options['hostname']}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubyipmi/ipmitool/commands/bmc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def reset(type = 'cold')
@options.delete_notify("cmdargs")
return value
else
logger.error("reset type: #{type} is not a valid choice, use warm or cold") if logger
logger&.error("reset type: #{type} is not a valid choice, use warm or cold")
raise "reset type: #{type} is not a valid choice, use warm or cold"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubyipmi/ipmitool/commands/chassis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def bootdevice(device, reboot = false, persistent = false)
bootstatus = config.bootdevice(device, persistent)
power.cycle if reboot && status
else
logger.debug("Device with name: #{device} is not a valid boot device for host #{options['hostname']}") if logger
logger&.debug("Device with name: #{device} is not a valid boot device for host #{options['hostname']}")
raise "Device with name: #{device} is not a valid boot device for host #{options['hostname']}"
end
bootstatus
Expand Down
Loading