Bug 1397033

Summary: Invalid constant in hooks directory crashes the Rails application
Product: Red Hat Satellite Reporter: Stefan Nemeth <snemeth>
Component: Hooks and WebhooksAssignee: Lukas Zapletal <lzap>
Status: CLOSED ERRATA QA Contact: Sebastian Gräßl <sgraessl>
Severity: low Docs Contact:
Priority: low    
Version: 6.2.4CC: bbuckingham, ehelms, jcallaha, lzap, mhulan, sgraessl
Target Milestone: UnspecifiedKeywords: EasyFix, 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: Environment:
Last Closed: 2018-02-21 16:51:07 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:

Description Stefan Nemeth 2016-11-21 12:48:07 UTC
Created attachment 1222382 [details]
rb error.

Description of problem:

When creating a hook in /usr/share/foreman/config/hooks with name, which does not match correct hook object and event 
#foreman-rake hooks:objects
#foreman-rake hooks:events[$object]

webui crashes with

Web application could not be started

uninitialized constant Test (NameError)

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

How reproducible:
100%

Steps to Reproduce:
1. create directory structure with non existing hook in /usr/share/foreman/config/hooks/

for example 
/usr/share/foreman/config/hooks/test/test/hook.sh

cat hook.sh
!#/bin/bash
logger "testing hooks"

2. restart apace 
#systemctl restart httpd


Actual results:
see attachment. Webui crashes. 

Also executing any foreman-rake command fails

foreman-rake katello:reindex
rake aborted!
NameError: uninitialized constant Test
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_hooks-0.3.11/lib/foreman_hooks.rb:90:in `load_missing_constant_with_hooks'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/inflector/methods.rb:238:in `const_get'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/inflector/methods.rb:238:in `block in constantize'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/inflector/methods.rb:236:in `each'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/inflector/methods.rb:236:in `inject'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/inflector/methods.rb:236:in `constantize'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_hooks-0.3.11/lib/foreman_hooks/engine.rb:6:in `block (2 levels) in <class:Engine>'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_hooks-0.3.11/lib/foreman_hooks/engine.rb:6:in `each'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_hooks-0.3.11/lib/foreman_hooks/engine.rb:6:in `block in <class:Engine>'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:438:in `instance_exec'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:438:in `block in make_lambda'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:184:in `call'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:184:in `block in simple'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:185:in `call'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:185:in `block in simple'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:185:in `call'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:185:in `block in simple'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:185:in `call'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:185:in `block in simple'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:185:in `call'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:185:in `block in simple'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:185:in `call'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:185:in `block in simple'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:185:in `call'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:185:in `block in simple'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:86:in `call'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activesupport-4.1.5/lib/active_support/callbacks.rb:86:in `run_callbacks'
/opt/rh/rh-ror41/root/usr/share/gems/gems/actionpack-4.1.5/lib/action_dispatch/middleware/reloader.rb:83:in `prepare!'
/opt/rh/rh-ror41/root/usr/share/gems/gems/actionpack-4.1.5/lib/action_dispatch/middleware/reloader.rb:55:in `prepare!'
/opt/rh/rh-ror41/root/usr/share/gems/gems/railties-4.1.5/lib/rails/application/finisher.rb:52:in `block in <module:Finisher>'
/opt/rh/rh-ror41/root/usr/share/gems/gems/railties-4.1.5/lib/rails/initializable.rb:30:in `instance_exec'
/opt/rh/rh-ror41/root/usr/share/gems/gems/railties-4.1.5/lib/rails/initializable.rb:30:in `run'
/opt/rh/rh-ror41/root/usr/share/gems/gems/railties-4.1.5/lib/rails/initializable.rb:55:in `block in run_initializers'
/opt/rh/rh-ror41/root/usr/share/gems/gems/railties-4.1.5/lib/rails/initializable.rb:54:in `run_initializers'
/opt/rh/rh-ror41/root/usr/share/gems/gems/railties-4.1.5/lib/rails/application.rb:300:in `initialize!'
/opt/rh/rh-ror41/root/usr/share/gems/gems/railties-4.1.5/lib/rails/railtie.rb:194:in `public_send'
/opt/rh/rh-ror41/root/usr/share/gems/gems/railties-4.1.5/lib/rails/railtie.rb:194:in `method_missing'
/usr/share/foreman/config/environment.rb:5:in `<top (required)>'
/opt/rh/rh-ror41/root/usr/share/gems/gems/polyglot-0.3.4/lib/polyglot.rb:65:in `require'
/opt/rh/rh-ror41/root/usr/share/gems/gems/railties-4.1.5/lib/rails/application.rb:276:in `require_environment!'
/opt/rh/rh-ror41/root/usr/share/gems/gems/railties-4.1.5/lib/rails/application.rb:379:in `block in run_tasks_blocks'
Tasks: TOP => katello:reindex => environment


Expected results:

Throw warning or error to log, ignore the incorrect hooks. 
Additional info:

Comment 4 Lukas Zapletal 2016-11-23 09:03:33 UTC
This was fixed in upstream recently, this will not be part of 6.3. I don't think this is worth backporting, will be fixed in 6.4.

commit fb9dd1d4b3f085dfc896e95dfa2093a4fc318cce
Refs: v0.3.12-3-gfb9dd1d
Author:     Dominic Cleal <dominic>
AuthorDate: Wed Oct 19 14:39:58 2016 +0100
Commit:     Dominic Cleal <dominic>
CommitDate: Wed Oct 19 14:40:28 2016 +0100


Brad, I would like to schedule this for 6.4 for QA, I don't see Target Version yet. Can you create one? Or what is the correct process? I am setting the flag at least.

Thanks for report.

Comment 6 Brad Buckingham 2016-11-24 01:31:24 UTC
Stefan, Lukas, thanks for the feedback.

Lukas, we do not currently use Target Version.  At this time, we are using the sat-6.4.0 flag for those fixes that we are planning to include in the next release.  I will move the bugzilla to POST to reflect that the fix is upstream as well.

Comment 8 Sebastian Gräßl 2017-08-23 08:49:14 UTC
Verified on Satellite-6.3 Snap 12.

A hook created as described does not crash the UI and foreman-rake tasks are working as expected.

Comment 9 Satellite Program 2018-02-21 16:51:07 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, 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-2018:0336