Bug 2048913 - "foreman-maintain health check --label check-hotfix-installed" fails with error "undefined method `[]' for nil:NilClass"
Summary: "foreman-maintain health check --label check-hotfix-installed" fails with err...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Satellite Maintain
Version: 6.11.0
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: 6.11.0
Assignee: Evgeni Golov
QA Contact: sganar
URL:
Whiteboard:
Depends On:
Blocks: 1693733 2052506
TreeView+ depends on / blocked
 
Reported: 2022-02-01 07:42 UTC by sganar
Modified: 2022-07-05 14:33 UTC (History)
7 users (show)

Fixed In Version: rubygem-foreman_maintain-1.0.3
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-07-05 14:32:43 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 34393 0 Normal New "foreman-maintain health check --label check-hotfix-installed" fails with error "undefined method `[]' for nil:NilClass"... 2022-02-04 11:26:12 UTC
Red Hat Product Errata RHSA-2022:5498 0 None None None 2022-07-05 14:33:00 UTC

Description sganar 2022-02-01 07:42:05 UTC
Description of problem:

"foreman-maintain health check --label check-hotfix-installed" is failing with error "undefined method `[]' for nil:NilClass"

Version-Release number of selected component (if applicable):
Satellite 7.0 Rhel 8.5

How reproducible:
Always

Steps to Reproduce:
1. Have a fresh Satellite on RHEL 8.5
2. Run foreman-maintain health check --label check-hotfix-installed
3.

Actual results:
check fails with error "undefined method `[]' for nil:NilClass"

Expected results:
check should pass

Additional info:

Comment 3 Evgeni Golov 2022-02-04 11:24:31 UTC
Thanks!

Can you please try the following patch?

diff --git definitions/checks/check_hotfix_installed.rb definitions/checks/check_hotfix_installed.rb
index 3f025fc..1873540 100644
--- definitions/checks/check_hotfix_installed.rb
+++ definitions/checks/check_hotfix_installed.rb
@@ -46,7 +46,7 @@ class Checks::CheckHotfixInstalled < ForemanMaintain::Check
   def installed_packages
     packages = []
     repoquery_cmd = execute!('which repoquery')
-    IO.popen([repoquery_cmd, '-a', '--installed', '--qf', '%{ui_from_repo} %{nvra}']) do |io|
+    IO.popen([repoquery_cmd, '-a', '--installed', '--qf', '%{ui_from_repo} %{name}-%{evr}.%{arch}']) do |io|
       io.each do |line|
         repo, pkg = line.chomp.split
         packages << pkg if /satellite|rhscl/ =~ repo[1..-1].downcase


/usr/share/gems/gems/foreman_maintain-1.0.1/definitions/checks/check_hotfix_installed.rb is the file in question on your install

Comment 4 Evgeni Golov 2022-02-04 11:26:11 UTC
Created redmine issue https://projects.theforeman.org/issues/34393 from this bug

Comment 6 Evgeni Golov 2022-02-04 12:32:07 UTC
Thanks, after talking with Amit, this needs a bit more safeguarding:

diff --git a/definitions/checks/check_hotfix_installed.rb b/definitions/checks/check_hotfix_installed.rb
index 3f025fcd..8d9cb471 100644
--- a/definitions/checks/check_hotfix_installed.rb
+++ b/definitions/checks/check_hotfix_installed.rb
@@ -46,9 +46,11 @@ def modified_files(package)
   def installed_packages
     packages = []
     repoquery_cmd = execute!('which repoquery')
-    IO.popen([repoquery_cmd, '-a', '--installed', '--qf', '%{ui_from_repo} %{nvra}']) do |io|
+    query_format = '%{ui_from_repo} %{name}-%{evr}.%{arch}'
+    IO.popen([repoquery_cmd, '-a', '--installed', '--qf', query_format]) do |io|
       io.each do |line|
         repo, pkg = line.chomp.split
+        next if repo.nil? || pkg.nil?
         packages << pkg if /satellite|rhscl/ =~ repo[1..-1].downcase
       end
     end


(the next if part is new, the other is just differently formatted compared to the version I posted above)

Comment 7 sganar 2022-02-04 12:47:35 UTC
That worked! 

# foreman-maintain health check --label check-hotfix-installed
Running preparation steps required to run the next scenarios
================================================================================
Check whether system has any non Red Hat repositories (e.g.: EPEL) enabled: 
- Checking repositories enabled on the system                         [OK]      
--------------------------------------------------------------------------------


Running ForemanMaintain::Scenario::FilteredScenario
================================================================================
Check to verify if any hotfix installed on system: 
- Checking for presence of hotfix(es). It may take some time to verify.         
                                                                      [OK]
--------------------------------------------------------------------------------

Comment 8 Evgeni Golov 2022-02-04 12:51:28 UTC
Awesome, thanks for the quick feedback!

Comment 9 Bryan Kearney 2022-02-05 02:18:58 UTC
Upstream bug assigned to egolov

Comment 10 Bryan Kearney 2022-02-05 02:19:00 UTC
Upstream bug assigned to egolov

Comment 11 sganar 2022-02-14 11:17:37 UTC
Verified.

Tested on Satellite 7.0 Snap 9.0 RHEL 8.5

Steps followed: 
1. Have a fresh Satellite on RHEL 8.5
2. Run foreman-maintain health check --label check-hotfix-installed

Observation: 
health check passes without any error as expected.

Comment 15 errata-xmlrpc 2022-07-05 14:32:43 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: Satellite 6.11 Release), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2022:5498


Note You need to log in before you can comment on or make changes to this bug.