Skip to content

Commit

Permalink
Refs #37696 - Don't run sub facet fact parser on non registered hosts
Browse files Browse the repository at this point in the history
* When a host that is not registered with subscription manager tries to update facts we get an error "Content host must be unregistered before performing this action"

This change causes the fact parser to skip if the host does not have a subscription facet, also changing the db column from int4 to boolean
  • Loading branch information
chris1984 committed Aug 15, 2024
1 parent 4bd1489 commit e8508db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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 @@ -298,11 +298,12 @@ def backend_update_needed?
end

def self.populate_fields_from_facts(host, parser, _type, _source_proxy)
return unless host.subscription_facet # skip method if the host is not a registered host
has_convert2rhel = parser.facts.key?('conversions.env.CONVERT2RHEL_THROUGH_FOREMAN')
# 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.
facet = host.subscription_facet || host.build_subscription_facet
facet = host.subscription_facet
facet.attributes = {
convert2rhel_through_foreman: has_convert2rhel ? ::Foreman::Cast.to_bool(parser.facts['conversions.env.CONVERT2RHEL_THROUGH_FOREMAN']) : nil
}.compact
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20240815215102_change_convert2_rhel_to_boolean.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ChangeConvert2RhelToBoolean < ActiveRecord::Migration[6.1]
def up
change_column :katello_subscription_facets, :convert2rhel_through_foreman, :boolean, using: 'convert2rhel_through_foreman::boolean'
end

def down
change_column :katello_subscription_facets, :convert2rhel_through_foreman, :integer, using: 'convert2rhel_through_foreman::integer'
end
end

0 comments on commit e8508db

Please sign in to comment.