Bug 2196540
| Summary: | "Host-Registered Content Hosts" Report gives error while generating - undefined method `nvra' for nil:NilClass | |||
|---|---|---|---|---|
| Product: | Red Hat Satellite | Reporter: | vivek singh <vivsingh> | |
| Component: | Reporting | Assignee: | Samir Jha <sajha> | |
| Status: | CLOSED ERRATA | QA Contact: | Lucy Fu <lufu> | |
| Severity: | high | Docs Contact: | ||
| Priority: | high | |||
| Version: | 6.13.0 | CC: | ahumbe, iballou, lufu, pcreech, sajha, saydas | |
| Target Milestone: | 6.14.0 | Keywords: | EasyFix, Regression, Triaged | |
| Target Release: | Unused | |||
| Hardware: | Unspecified | |||
| OS: | Unspecified | |||
| Whiteboard: | ||||
| Fixed In Version: | Doc Type: | If docs needed, set a value | ||
| Doc Text: | Story Points: | --- | ||
| Clone Of: | ||||
| : | 2218660 (view as bug list) | Environment: | ||
| Last Closed: | 2023-11-08 14:19:23 UTC | Type: | Bug | |
| Regression: | --- | Mount Type: | --- | |
| Documentation: | --- | CRM: | ||
| Verified Versions: | Category: | --- | ||
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | ||
| Cloudforms Team: | --- | Target Upstream Version: | ||
| Embargoed: | ||||
|
Description
vivek singh
2023-05-09 12:43:05 UTC
Analysis:
Old code: ( 6.12 and before )
def host_latest_applicable_rpm_version(host, package)
host.applicable_rpms.where(name: package).order(:version_sortable).limit(1).pluck(:nvra).first
end
New Code: ( > = 6.13 )
def host_latest_applicable_rpm_version(host, package)
::Katello::Rpm.latest(host.applicable_rpms.where(name: package)).first.nvra
end
Test of new code:
irb(main):004:0> host = Host.second
=> #<Host::Managed id: 2, name: "dhcp130-139.example.com", last_compile: "2023-05-09 09:35:24.000000000 +0000", last_rep...
irb(main):007:0> package = 'kernel'
=> "kernel"
irb(main):008:0> ::Katello::Rpm.latest(host.applicable_rpms.where(name: package)).first.nvra
Traceback (most recent call last):
2: from lib/tasks/console.rake:5:in `block in <top (required)>'
1: from (irb):8
NoMethodError (undefined method `nvra' for nil:NilClass)
irb(main):009:0> ::Katello::Rpm.latest(host.applicable_rpms.where(name: package)).first
=> nil
irb(main):011:0> ::Katello::Rpm.latest(host.applicable_rpms.where(name: package)).first.try(:nvra)
=> nil
Basically, If the host.applicable_rpms have no results or host.applicable_rpms.where(name: package)).first have no results, we run into this and if we use the try method , that helps to get past the issue
So following, fixes the issue:
diff --git a/app/lib/katello/concerns/base_template_scope_extensions.rb b/app/lib/katello/concerns/base_template_scope_extensions.rb
index 873c7bf..6cfe8f8 100644
--- a/app/lib/katello/concerns/base_template_scope_extensions.rb
@@ -161,7 +161,7 @@ module Katello
returns String, desc: 'Package version'
end
def host_latest_applicable_rpm_version(host, package)
- ::Katello::Rpm.latest(host.applicable_rpms.where(name: package)).first.nvra
+ ::Katello::Rpm.latest(host.applicable_rpms.where(name: package)).first.try(:nvra)
end
apipie :method, 'Loads Pool objects' do
I am guessing this also fixes the issue instead of what I tried in Coment 1 https://github.com/Katello/katello/pull/10497/files#diff-97789298ab25018d9ce64de6b68fa6cfcc0b066e351c4156ebd5d70176022281R182-R186 def host_latest_applicable_rpm_version(host, package) return [] if host.content_facet.nil? applicable = ::Katello::Rpm.latest(host.applicable_rpms.where(name: package)) applicable.present? ? applicable.first.nvra : [] end This change is scheduled to be part of Satellite 6.14 along with the inclusion Installable ERRATA template But perhaps we should consider this or part of the fix for 6.13.z or else many customers could end up hitting this issue when a host would not have any applicable rpms CC'ing Ian from the Katello team We can use the same code from the "Installable ERRATA template" RFE but we'll need something that only applies to the 6.13 / Katello 4.7 branches. To complete this issue I'd recommend making a Katello 4.7 issue upstream and then create the PR against the Katello 4.7 branch only. That should ensure that, next time there's a Katello 4.8 release, it'll be marked as a cherry-pick. Created redmine issue https://projects.theforeman.org/issues/36486 from this bug Moving this bug to POST for triage into Satellite since the upstream issue https://projects.theforeman.org/issues/36486 has been resolved. 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 (Important: Satellite 6.14 security and bug fix update), 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-2023:6818 |