This bug has been migrated to another issue tracking site. It has been closed here and may no longer be being monitored.

If you would like to get updates for this issue, or to participate in it, you may do so at Red Hat Issue Tracker .
Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2280574 - CV promote fails with undefined method `get_status' for nil:NilClass when deleting a Host in the CV during Finalize phase of the Promote task
Summary: CV promote fails with undefined method `get_status' for nil:NilClass when del...
Keywords:
Status: CLOSED MIGRATED
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Hosts - Content
Version: 6.14.4
Hardware: Unspecified
OS: Unspecified
high
medium
Target Milestone: Unspecified
Assignee: satellite6-bugs
QA Contact: Satellite QE Team
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2024-05-15 08:16 UTC by Pavel Moravec
Modified: 2024-06-06 17:39 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2024-06-06 17:39:17 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker   SAT-25160 0 None Migrated None 2024-06-06 17:39:15 UTC
Red Hat Knowledge Base (Solution) 7070717 0 None None None 2024-05-16 07:33:40 UTC

Description Pavel Moravec 2024-05-15 08:16:28 UTC
Description of problem:
When promoting a CV to a LE (maybe also during other scenarios, not sure now), the task can fail during Finalize step Actions::Katello::ContentView::PromoteToEnvironment .

The reason is in code:

/usr/share/gems/gems/katello-4.9.0.25/app/models/katello/content_view.rb new line 437:

~~~
    def update_host_statuses(environment)
      # update errata applicability counts for all hosts in the CV & LE
      Location.no_taxonomy_scope do
        User.as_anonymous_admin do
          ::Katello::Host::ContentFacet.in_content_views_and_environments(
            content_views: [self],
            lifecycle_environments: [environment]
          ).each do |facet|
            facet.update_applicability_counts
            facet.update_errata_status
          end
        end
      end
    end
~~~

where:
1) ContentFacet list is generated
2) for each facet, applicability is being recalculated
3) some Host for such a facet is deleted
4) the facet for the deleted Host is being recalculated

Then, the 4) fails with backtrace:

 NoMethodError

undefined method `get_status' for nil:NilClass

---
- "/usr/share/gems/gems/katello-4.9.0.25/app/models/katello/host/content_facet.rb:331:in
  `update_errata_status'"
- "/usr/share/gems/gems/katello-4.9.0.25/app/models/katello/content_view.rb:438:in
  `block (3 levels) in update_host_statuses'"
- "/usr/share/gems/gems/activerecord-6.1.7.4/lib/active_record/relation/delegation.rb:88:in
  `each'"
- "/usr/share/gems/gems/activerecord-6.1.7.4/lib/active_record/relation/delegation.rb:88:in
  `each'"
- "/usr/share/gems/gems/katello-4.9.0.25/app/models/katello/content_view.rb:436:in
  `block (2 levels) in update_host_statuses'"
- "/usr/share/foreman/app/models/concerns/foreman/thread_session.rb:108:in `as'"
- "/usr/share/foreman/app/models/concerns/foreman/thread_session.rb:114:in `as_anonymous_admin'"
- "/usr/share/gems/gems/katello-4.9.0.25/app/models/katello/content_view.rb:432:in
  `block in update_host_statuses'"
- "/usr/share/foreman/app/models/taxonomy.rb:73:in `block in no_taxonomy_scope'"
- "/usr/share/foreman/app/models/taxonomy.rb:80:in `block (2 levels) in as_taxonomy'"
- "/usr/share/foreman/app/models/concerns/foreman/thread_session.rb:195:in `as_location'"
- "/usr/share/foreman/app/models/taxonomy.rb:79:in `block in as_taxonomy'"
- "/usr/share/foreman/app/models/concerns/foreman/thread_session.rb:154:in `as_org'"
- "/usr/share/foreman/app/models/taxonomy.rb:78:in `as_taxonomy'"
- "/usr/share/foreman/app/models/taxonomy.rb:72:in `no_taxonomy_scope'"
- "/usr/share/gems/gems/katello-4.9.0.25/app/models/katello/content_view.rb:431:in
  `update_host_statuses'"
- "/usr/share/gems/gems/katello-4.9.0.25/app/lib/actions/katello/content_view/promote_to_environment.rb:49:in
  `finalize'"

Because we call "host.get_status(::Katello::ErrataStatus).refresh!" for a removed Host.


Version-Release number of selected component (if applicable):
Sat 6.14, but applicable to any version, I think


How reproducible:
100%


Steps to Reproduce:
1. Have Satellite with a bigger CV (promoted to non-Library LE) and many Hosts associated to the CV/LE. To populate fake Hosts, you can run below script in a loop:

~~~
domain=YOUR.HOST.DOMAIN
ak=YOUR.ACTIVATION.KEY
org=YOUR.ORGANIZATION

uuid=$(uuidgen)
short=$(hostname -s)

echo "{\"dmi.system.uuid\": \"${uuid}\"}" > /etc/rhsm/facts/uuid.facts
hostnamectl set-hostname ${short}.${uuid%%-*}.${domain}
subscription-manager clean
subscription-manager register --activationkey ${ak} --org ${org}
~~~

(a few hundreds of Hosts is sufficient)

2. Create a new version of the CV and promote it to the LE associated with the Hosts.

3. *During* the promote, regularly delete some Hosts - you must catch the time when Finalize phase is running.

One can mimic 2. even for already promoted CV/LE by running (customize own CV id and LE id):

(within foreman-rake console)

::Katello::ContentView.find(54).update_host_statuses(Katello::KTEnvironment.find(2))

(once you run this, delete a Host)



Actual results:
2. fails in Actions::Katello::ContentView::PromoteToEnvironment step in Finalize phase with above backtrace.

Optionally, foreman-rake mimicking reproducer fails with:

irb(main):138:0> ::Katello::ContentView.find(54).update_host_statuses(Katello::KTEnvironment.find(2))
Traceback (most recent call last):
       16: from lib/tasks/console.rake:5:in `block in <top (required)>'
       15: from (irb):138
       14: from katello (4.9.0.25) app/models/katello/content_view.rb:431:in `update_host_statuses'
       13: from app/models/taxonomy.rb:72:in `no_taxonomy_scope'
       12: from app/models/taxonomy.rb:78:in `as_taxonomy'
       11: from app/models/concerns/foreman/thread_session.rb:154:in `as_org'
       10: from app/models/taxonomy.rb:79:in `block in as_taxonomy'
        9: from app/models/concerns/foreman/thread_session.rb:195:in `as_location'
        8: from app/models/taxonomy.rb:80:in `block (2 levels) in as_taxonomy'
        7: from app/models/taxonomy.rb:73:in `block in no_taxonomy_scope'
        6: from katello (4.9.0.25) app/models/katello/content_view.rb:432:in `block in update_host_statuses'
        5: from app/models/concerns/foreman/thread_session.rb:114:in `as_anonymous_admin'
        4: from app/models/concerns/foreman/thread_session.rb:108:in `as'
        3: from katello (4.9.0.25) app/models/katello/content_view.rb:436:in `block (2 levels) in update_host_statuses'
        2: from katello (4.9.0.25) app/models/katello/content_view.rb:439:in `block (3 levels) in update_host_statuses'
        1: from katello (4.9.0.25) app/models/katello/host/content_facet.rb:331:in `update_errata_status'
NoMethodError (undefined method `get_status' for nil:NilClass)
irb(main):139:0> 


Expected results:
No such exception.


Additional info:
Potential fix: add "if content.host" twice:

    def update_host_statuses(environment)
      # update errata applicability counts for all hosts in the CV & LE
      Location.no_taxonomy_scope do
        User.as_anonymous_admin do
          ::Katello::Host::ContentFacet.in_content_views_and_environments(
            content_views: [self],
            lifecycle_environments: [environment]
          ).each do |facet|
            facet.update_applicability_counts if facet.host   # here it is optional         
            facet.update_errata_status if facet.host          # here it is crucial                              
          end
        end
      end
    end

Comment 2 Eric Helms 2024-06-06 17:39:17 UTC
This BZ has been automatically migrated to the issues.redhat.com Red Hat Issue Tracker. All future work related to this report will be managed there.

Due to differences in account names between systems, some fields were not replicated.  Be sure to add yourself to Jira issue's "Watchers" field to continue receiving updates and add others to the "Need Info From" field to continue requesting information.

To find the migrated issue, look in the "Links" section for a direct link to the new issue location. The issue key will have an icon of 2 footprints next to it, and begin with "SAT-" followed by an integer.  You can also find this issue by visiting https://issues.redhat.com/issues/?jql= and searching the "Bugzilla Bug" field for this BZ's number, e.g. a search like:

"Bugzilla Bug" = 1234567

In the event you have trouble locating or viewing this issue, you can file an issue by sending mail to rh-issues. You can also visit https://access.redhat.com/articles/7032570 for general account information.


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