Skip to content

Commit

Permalink
Fixes #37994 - populate bootc fields from facts
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Nov 7, 2024
1 parent 12b5a3d commit b8377e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 25 additions & 0 deletions app/models/katello/host/content_facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Check failure on line 26 in app/models/katello/host/content_facet.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Style/TrailingCommaInArrayLiteral: Put a comma after the last item of a multiline array.
].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
Expand Down Expand Up @@ -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?

Check failure on line 322 in app/models/katello/host/content_facet.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Rails/Blank: Use `if host.content_facet.blank?` instead of `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(".", "_")

Check failure on line 328 in app/models/katello/host/content_facet.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Performance/StringReplacement: Use `tr` instead of `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
Expand Down
3 changes: 2 additions & 1 deletion app/models/katello/host/subscription_facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b8377e3

Please sign in to comment.