Project

General

Profile

Bug #29719

Hostgroup facets with inheritable attributes cause errors on hostgroups without instances of the facet

Added by Alexander Olofsson 7 months ago. Updated 7 months ago.

Status:
Closed
Priority:
Normal
Category:
Host groups
Target version:
-
Difficulty:
Triaged:
No
Bugzilla link:
Fixed in Releases:
Found in Releases:

Description

When a hostgroup facet has been registered, along with a host facet and inheritable attributes, then any attempts to select a hostgroup that has no instance of said hostgroup facet errors out with a NoMethodError.

The stacktrace in question;

  from app/models/concerns/facets/hostgroup_extensions.rb:25:in `inherited_facet_attributes'
  from app/models/concerns/facets/base.rb:45:in `inherited_attributes'
  from app/models/concerns/facets/base_host_extensions.rb:18:in `block in apply_facet_attributes'
  from app/models/concerns/facets/base_host_extensions.rb:16:in `map'
  from app/models/concerns/facets/base_host_extensions.rb:16:in `apply_facet_attributes'
  from app/models/host/managed.rb:557:in `apply_inherited_attributes'
  from app/models/host/managed.rb:70:in `initialize'
  from active_record/inheritance.rb:66:in `new'
  from active_record/inheritance.rb:66:in `new'
  from app/models/concerns/foreman/sti.rb:19:in `new'
  from app/models/host.rb:15:in `method_missing'
  from app/controllers/hosts_controller.rb:661:in `refresh_host'
  from app/controllers/hosts_controller.rb:586:in `process_hostgroup'
  from action_controller/metal/basic_implicit_render.rb:6:in `send_action'

I looked through the call trace and it seems like there's nothing that actually checks if the hostgroup has an instance of the facet before attempting to read inherited attributes from it.

Associated revisions

Revision 709e5fd0 (diff)
Added by Alexander "Ananace" Olofsson 7 months ago

Fixes #29719 - Hostgroup facet inheritance error (#7642)

  • Fixes #29719 - Hostgroup facet inheritance error

As the method for Hostgroup#inherited_facet_attributes - and methods
that call it - include no checks for if a hostgroup includes an
instance of the requested facet before trying to read attributes from
it, this can lead to a NoMethodError here.

Wrapping it in a safe accessor and a fallback to an empty hash means
that such calls will no longer error, and will still read attributes
correctly from the ancestry as well.

  • Fixes #29719 - Add test against inheritance error

History

#1 Updated by The Foreman Bot 7 months ago

  • Assignee set to Alexander Olofsson
  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/7642 added

#2 Updated by The Foreman Bot 7 months ago

  • Fixed in Releases 2.2.0 added

#3 Updated by Anonymous 7 months ago

  • Status changed from Ready For Testing to Closed

#4 Updated by Tomer Brisker 7 months ago

  • Fixed in Releases 2.1.0 added
  • Fixed in Releases deleted (2.2.0)

#5 Updated by Amit Upadhye 7 months ago

  • Category set to Host groups

Also available in: Atom PDF