Bug #16063
closedAutoprovisioning fails with Katello plugin installed
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.