diff --git a/app/models/katello/host/content_facet.rb b/app/models/katello/host/content_facet.rb index a2566c45bc7..b670ccd35bd 100644 --- a/app/models/katello/host/content_facet.rb +++ b/app/models/katello/host/content_facet.rb @@ -15,6 +15,16 @@ class ContentFacet < Katello::Model ALL_TRACER_PACKAGE_NAMES = [ "python-#{HOST_TOOLS_TRACER_PACKAGE_NAME}", "python3-#{HOST_TOOLS_TRACER_PACKAGE_NAME}", HOST_TOOLS_TRACER_PACKAGE_NAME ].freeze + BOOTC_FIELD_FACT_NAMES = [ + "bootc.booted.image", + "bootc.booted.digest", + "bootc.staged.image", + "bootc.staged.digest", + "bootc.rollback.image", + "bootc.rollback.digest", + "bootc.available.image", + "bootc.available.digest" + ].freeze belongs_to :kickstart_repository, :class_name => "::Katello::Repository", :inverse_of => :kickstart_content_facets belongs_to :content_source, :class_name => "::SmartProxy", :inverse_of => :content_facets @@ -308,6 +318,21 @@ def self.with_non_installable_errata(errata, hosts = nil) Katello::Host::ContentFacet.where(id: non_installable_errata) end + def self.populate_fields_from_facts(host, parser, _type, _source_proxy) + return unless host.content_facet.present? + facet = host.content_facet || host.build_content_facet + attrs_to_add = {} + BOOTC_FIELD_FACT_NAMES.each do |fact_name| + fact_value = parser.facts[fact_name] + next if fact_value.blank? + field_name = fact_name.gsub(".", "_") + + attrs_to_add[field_name] = fact_value + end + facet.assign_attributes(attrs_to_add) + facet.save unless facet.new_record? + end + def self.with_applicable_errata(errata) self.joins(:applicable_errata).where("#{Katello::Erratum.table_name}.id" => errata) end diff --git a/app/models/katello/host/subscription_facet.rb b/app/models/katello/host/subscription_facet.rb index 4341e318ab4..44c20f3d0de 100644 --- a/app/models/katello/host/subscription_facet.rb +++ b/app/models/katello/host/subscription_facet.rb @@ -302,10 +302,11 @@ def self.populate_fields_from_facts(host, parser, _type, _source_proxy) return unless host.subscription_facet || has_convert2rhel # Add in custom convert2rhel fact if system was converted using convert2rhel through Katello # We want the value nil unless the custom fact is present otherwise we get a 0 in the database which if debugging - # might make you think it was converted2rhel but not with satellite, that is why I have the tenary below. + # might make you think it was converted2rhel but not with satellite, that is why I have the ternary below. facet = host.subscription_facet || host.build_subscription_facet facet.attributes = { convert2rhel_through_foreman: has_convert2rhel ? ::Foreman::Cast.to_bool(parser.facts['conversions.env.CONVERT2RHEL_THROUGH_FOREMAN']) : nil, + }.compact facet.save unless facet.new_record? end