From 4a4173906482d69a253a0ca0c3c5871ef05e42b6 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 15 Aug 2024 17:57:44 -0400 Subject: [PATCH] Refs #37696 - Don't run sub facet fact parser on non registered hosts * Changed the int4 column on convert2rhel_through_foreman from init4 to boolean * Return out of the fact parser method for hosts that are not registered such as foreman/satellite instance, so we don't error when those systems upload facts * Got rid of build_subscription_facet because the hosts that come from convert2rhel already are registered and have a subscription facet, so no need to build one which also breaks hosts that are not registered through subscription-manager If for some reason we hit an edge case where we don't get the convert2rhel fact the first time during registration , we will get it when the client checks in again ~ 4 hours. Talking with Shim and Jeremy this seems like a fine approach since the systems rhsmcertd will send us the filtered fact again, which is more than enough time before rh_cloud would send off it's report to console.redhat.com --- app/models/katello/host/subscription_facet.rb | 3 ++- .../20240815215102_change_convert2_rhel_to_boolean.rb | 9 +++++++++ test/models/host/subscription_facet_test.rb | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20240815215102_change_convert2_rhel_to_boolean.rb diff --git a/app/models/katello/host/subscription_facet.rb b/app/models/katello/host/subscription_facet.rb index a9cf4d30697..f058fb1fa12 100644 --- a/app/models/katello/host/subscription_facet.rb +++ b/app/models/katello/host/subscription_facet.rb @@ -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 diff --git a/db/migrate/20240815215102_change_convert2_rhel_to_boolean.rb b/db/migrate/20240815215102_change_convert2_rhel_to_boolean.rb new file mode 100644 index 00000000000..b9d1fff723d --- /dev/null +++ b/db/migrate/20240815215102_change_convert2_rhel_to_boolean.rb @@ -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 diff --git a/test/models/host/subscription_facet_test.rb b/test/models/host/subscription_facet_test.rb index a169706fba9..b01b08e69f6 100644 --- a/test/models/host/subscription_facet_test.rb +++ b/test/models/host/subscription_facet_test.rb @@ -43,7 +43,7 @@ def test_search_role def test_convert2rhel_through_foreman_on_host subscription_facet.update(convert2rhel_through_foreman: 1) - assert_equal 1, host.subscription_facet.convert2rhel_through_foreman + assert true, host.subscription_facet.convert2rhel_through_foreman assert_includes ::Host.search_for("convert2rhel_through_foreman = 1"), host end