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 2154203 - Satellite fails to run Webhook after a successful REX job execution with error "Failed to run hook 'emit_event' for action 'Actions::RemoteExecution::RunHostJob'"
Summary: Satellite fails to run Webhook after a successful REX job execution with erro...
Keywords:
Status: CLOSED MIGRATED
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Hooks and Webhooks
Version: 6.10.7
Hardware: All
OS: All
low
medium
Target Milestone: Unspecified
Assignee: satellite6-bugs
QA Contact: Griffin Sullivan
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-12-16 09:51 UTC by Sayan Das
Modified: 2024-06-06 12:56 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 12:56:38 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker   SAT-25429 0 None Migrated None 2024-06-06 12:56:37 UTC

Description Sayan Das 2022-12-16 09:51:52 UTC
Description of problem:

After creating a webhook and subscribing it to actions.remote_execution.run_host_job_succeeded event, Even though remote execution jobs are running fine on the hosts, The webhook execution fails with the error:
~~~
Failed to run hook 'emit_event' for action 'Actions::RemoteExecution::RunHostJob'
~~~

This happens when the Location assigned with the Webhook Template and the Location of the REX Job, do not match each other. 


Version-Release number of selected component (if applicable):

Satellite 6.10
Satellite 6.11
Satellite 6.12

How reproducible:

Always


Steps to Reproduce:

1. Create any of the affected versions of Satellite with Organization Name "RedHat" and Location "Global"

2. Create a basic ansible role and import it to the Satellite server.

3. Register a system with satellite and ensure that it's associated with "RedHat" org and "Global" location. Assign the ansible role with the host ( imported in step 3).

4. Now be on "RedHat" Organization and "Any Location" context in Satellite UI and 

--> Create a webhook template with the following content, by the name "Show All" and only assign the RedHat organization to it. Don't assign any location.  

<%= payload({
    object: @object
}) %>


--> Create a webhook called "Test Hook" using that "Show All" template, and subscribe it to the "Actions Remote Execution Run Host Job Succeeded" event.

5. While in the "Any Location" context, Go to Hosts --> All Hosts --> Click open the client host --> hit on "Run Ansible Roles" from the dropdown and monitor /var/log/foreman/production.log file

6. Switch to the "Global" location now and repeat Step 5 and monitor /var/log/foreman/production.log file as well.


Actual results:

Step 5:
--> Job and Hook both will be executed successfully.
--> If we open the job from Monitor --> Jobs page, we will see that the Location of the JOB is set to "Any Location".

Step 6:
--> Job runs successfully.
--> Hook fails to run with the following error:
~~~
2022-12-16T14:40:41 [E|dyn|3b8c19bb] Failed to run hook 'emit_event' for action 'Actions::RemoteExecution::RunHostJob'
2022-12-16T14:40:41 [E|dyn|3b8c19bb] undefined method `render' for nil:NilClass (NoMethodError)
 3b8c19bb | /usr/share/gems/gems/foreman_webhooks-2.0.3/app/models/webhook.rb:118:in `rendered_payload'
 3b8c19bb | /usr/share/gems/gems/foreman_webhooks-2.0.3/app/models/webhook.rb:68:in `deliver'
 3b8c19bb | /usr/share/gems/gems/foreman_webhooks-2.0.3/app/models/webhook.rb:46:in `block in deliver'
 3b8c19bb | /usr/share/gems/gems/activerecord-6.0.4.7/lib/active_record/relation/delegation.rb:88:in `each'
 3b8c19bb | /usr/share/gems/gems/foreman_webhooks-2.0.3/app/models/webhook.rb:45:in `deliver'
 3b8c19bb | /usr/share/gems/gems/foreman_webhooks-2.0.3/app/subscribers/foreman_webhooks/event_subscriber.rb:6:in `call'
 3b8c19bb | /usr/share/foreman/app/subscribers/foreman/base_subscriber.rb:6:in `call'
 3b8c19bb | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/notifications/fanout.rb:189:in `finish'
 3b8c19bb | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/notifications/fanout.rb:62:in `block in finish'
 3b8c19bb | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/notifications/fanout.rb:62:in `each'
 3b8c19bb | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/notifications/fanout.rb:62:in `finish'
 3b8c19bb | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/notifications/instrumenter.rb:45:in `finish_with_state'
 3b8c19bb | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/notifications/instrumenter.rb:30:in `instrument'
 3b8c19bb | /usr/share/gems/gems/activesupport-6.0.4.7/lib/active_support/notifications.rb:180:in `instrument'
 3b8c19bb | /usr/share/foreman/lib/foreman/observable.rb:10:in `trigger_hook'
 3b8c19bb | /usr/share/gems/gems/foreman-tasks-5.2.3/app/lib/actions/observable_action.rb:60:in `emit_event'
~~~

--> If we open the related job from Monitor --> Jobs page, we will see that the Location of the JOB is set to "Global".


So the hook fails to run at step 6 since the location context for the job is "Global" but the "Show All" webhook template has no locations assigned ( or wrong location assigned ).

It works on Step 5, as the "Any Location" context of the job, can work with a Webhook template that has no locations assigned ( as expected ).


Expected results:

Rather than showing this misleading error:
~~~
2022-12-16T14:40:41 [E|dyn|3b8c19bb] Failed to run hook 'emit_event' for action 'Actions::RemoteExecution::RunHostJob'
2022-12-16T14:40:41 [E|dyn|3b8c19bb] undefined method `render' for nil:NilClass (NoMethodError)
~~~

Some meaningful message needs to be printed so that users can quickly fix the issue with location or Organization association on their own.


Additional info:

In a Multi-Location environment, There is a possibility of users working in the "Any Location" context and forgetting to assign the right location to Webhook templates. But when they will execute\schedule remote jobs using any playbook\api\hammer they might have specified an Org and Location for the job. So scenarios like that could lead to issues like what is described in this BZ.

Comment 2 Eric Helms 2024-06-06 12:56:38 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.