Bug #16063

Autoprovisioning fails with Katello plugin installed

Added by Lukas Zapletal 11 months ago. Updated 8 months ago.

Status:Closed
Priority:Urgent
Assigned To:Lukas Zapletal
Category:Content Views
Target version:Foreman - Team Daniel - iteration 3
Difficulty: Pull request:https://github.com/Katello/katello/pull/6401
Bugzilla link:1364544
Story points-
Velocity based estimate-
ReleaseKatello 3.2.0Release relationshipAuto

Description

Autoprovisioning uses Host.becomes method to convert Discovered host to Managed which skips creating of any facets registered with Host::Managed. Method set_hostgroup_defaults is called, but Katello only sets ContentFacet flags when it's present:

      def set_hostgroup_defaults_with_katello_attributes
        if hostgroup.present?
          if content_facet.present?
            self.content_facet.kickstart_repository_id ||= hostgroup.inherited_kickstart_repository_id
          end
          assign_hostgroup_attributes(%w(content_source_id content_view_id lifecycle_environment_id))
        end
        set_hostgroup_defaults_without_katello_attributes
      end

ContentFacet cannot be created until hostgroup is associated, because it requires some (most) attributes to be present. Therefore it can't be created during discovery stage. It can be built as empty using build_content_facet during provisioning phase as well, because of required attributes. The only way is to build/create it explicitly reading all required attributes from hostgroup. Something like:

host.build_content_facet(
:kickstart_repository_id => rule.hostgroup.inherited_kickstart_repository_id,
:content_source_id => rule.hostgroup.content_source_id,
:content_view_id => rule.hostgroup.content_view_id,
:lifecycle_environment_id => rule.hostgroup.lifecycle_environment_id)

But Rails immediately stores ContentFacet model in the database since Host::Discovered is already saved (this is an undocumented behavior of ActiveRecord). Also this creates dependency between Discovery and Katello plugins.

We need to find a way to solve this.


Related issues

Related to Discovery - Bug #9784: Autoprovisioning via hostgroup does not populate all para... Closed 03/16/2015
Related to Foreman - Refactor #16987: Explicit building of facets Closed 10/18/2016
Related to Foreman - Refactor #14699: Katello needs foreman's os_selected method to submit all ... Closed 04/18/2016

Associated revisions

Revision 0d1d7c14
Added by Lukas Zapletal 8 months ago

Fixes #16063 - content facet builds when not present

History

#1 Updated by Lukas Zapletal 11 months ago

  • Bugzilla link set to 1364544

Questions for Katello folks:

Are the presence validators necessary? It would be much easier for auto-provisioning if the content_facet could be created as empty during discovery phase, because creating it during becomes is tricky. Rails will force storing new record in database if the associated object - host::discovered - was already stored. This could lead to multiple facets created (on errors for example).

Why you set the content_facet attributes only when it's present. Isn't expected it will always be present? I can't think of Host::Managed that has no ContentFacet (except this particular issue). If this was just defensive coding, fine. I am just curious.

And finally - for now I could force creating ContentFacet during discovery, but this creates indirect dependence between Discovery and Katello plugins. We need to find a way how to define this kind of dependence. Perhaps to introduce some kind of inter-plugin DSL to define own settings. Discovery could create a list of facets that should be created when a host is discovered.

#2 Updated by Lukas Zapletal 11 months ago

  • Assigned To set to Lukas Zapletal
  • Priority changed from Normal to Urgent
  • Target version set to Team Daniel - iteration 2

#3 Updated by Lukas Zapletal 10 months ago

  • Related to Bug #9784: Autoprovisioning via hostgroup does not populate all parameters via WebUI or API added

#4 Updated by Justin Sherrill 10 months ago

Hey Lzap,

The reason for this check is that the content facet requires a content_view_id and lifecycle_environment_id to be set:

https://github.com/Katello/katello/blob/master/app/models/katello/host/content_facet.rb#L17-L18

In this instance if it does not exist we likely could create that new fact from those values on the hostgroup assuming they exist there.

#5 Updated by Lukas Zapletal 10 months ago

How about creating a dummy CV and LE and associate Content Facet during discovery phase with these resources?

#6 Updated by Lukas Zapletal 10 months ago

Justin had this idea of adding a lambda/proc in the facet registration, so that a hostgroup could be passed in, and a facet returned. Discovery could just loop through all registered facets and .save! any returned objects.

At the moment, Rails will save the record the moment build_content_facet method is returned, but that should not be huge issue.

#7 Updated by Shimon Shtein 10 months ago

Would it be enough if I extend Host::Managed#apply_inherited_attributes to query facets too? so each time #apply_inherited_attributes is called, facets framework will query each registered facet to add it information to the attributes set. In our case, we the framework will query ContentFacet.apply_inherited_attributes that will return:

{ content_facet_attributes => { :content_view => hostgroup_content_view, :lifecycle_environment => hostgroup_lifecycle_environment } }

This will be merged with the main attributes and a host will be created/updated with content facet present and valid.

#8 Updated by Daniel Lobato Garcia 9 months ago

  • Target version changed from Team Daniel - iteration 2 to Team Daniel - iteration 3

#9 Updated by Lukas Zapletal 8 months ago

#10 Updated by The Foreman Bot 8 months ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/Katello/katello/pull/6401 added

#11 Updated by Lukas Zapletal 8 months ago

  • Project changed from Discovery to Katello
  • Category changed from Discovery plugin to Content Views

#12 Updated by Eric Helms 8 months ago

  • Release set to Katello 3.2.0

#13 Updated by Lukas Zapletal 8 months ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#14 Updated by Lukas Zapletal 2 months ago

  • Related to Refactor #14699: Katello needs foreman's os_selected method to submit all form data added

Also available in: Atom PDF