Katello: Configuration rebuild failed for: Content_Host_Status and Refresh_Content_Host_Status

Problem:

When I attempt to rebuild a hosts configuration via hammer (or via the web UI) I get the following error:

Configuration rebuild failed for: Content_Host_Status and Refresh_Content_Host_Status.

Expected outcome:

The host configuration is rebuilt without error.

Foreman and Proxy versions:
foreman-3.3.0-1.el7.noarch
foreman-proxy-3.3.0-1.el7.noarch

Foreman and Proxy plugin versions:
katello-4.5.0-0.1.rc2.el7.noarch

Distribution and version:
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.9.2009 (Core)
Release: 7.9.2009
Codename: Cor

Other relevant data:
This problem seems to have been around since around the time I upgraded to 3.2/4.4, but I had not needed to rebuild host configs much so it flew under the radar. I had working around it by just running “hammer host rebuild-config --only DNS,DHCP,TFTP”.

Hi,
just stumbled over that myself.

Apparently, this was introduced by this PR in katello-3.17: https://github.com/Katello/katello/pull/8773

@Partha_Aji does that mean this is works as designed?

Statuses are supposed to be reset to UNKNOWN on build.

Guessing it’s the update! here that’s failing: https://github.com/parthaa/katello/blob/94c6901cfc49b054d4ee0689eee6cda45884a456/app/models/katello/concerns/host_managed_extensions.rb#L91

I’m not convinced throwing an error is the best way to deal with it. I would want more info about the error-- do you have the backtrace?

There is no backtrace available as it doesn’t crash. It only fails with:

Configuration rebuild failed for: Content_Host_Status and Refresh_Content_Host_Status.

If you run hammer host rebuild-config --only Content_Host_Status --id 4 it will fail, too.

It fails here:

Actually. I think its a interface issue. The register_rebuild method expects, that in the end a method is called, which returns a queue element. In case, e.g. self.changes.key?('build') is false, it does not get such a queue.

To fix this, I tested this successfully:

      def refresh_content_host_status
        if content_facet&.present?
          self.host_statuses.where(type: ::Katello::HostStatusManager::STATUSES.map(&:name)).each do |status|
            status.refresh!
          end
        end
        refresh_global_status
      end

      def queue_refresh_content_host_status
        if !new_record? && !build && self.changes.key?('build')
          queue.create(id: "refresh_content_host_status_#{id}", name: _("Refresh Content Host Statuses for %s") % self,
            priority: 300, action: [self, :refresh_content_host_status])
        else
          queue.create(id: "refresh_content_host_status_#{id}", name: _("Skip: Refresh Content Host Statuses for %s") % self,
            priority: 300, action: [nil])
        end
      end

      def reset_katello_status
        self.host_statuses.where(type: ::Katello::HostStatusManager::STATUSES.map(&:name)).each do |status|
          status.update!(:status => status.class.const_get(:UNKNOWN))
        end
        self.host_statuses.reload
        true
      end

      def queue_reset_content_host_status
        if should_reset_content_host_status?
          logger.debug "Scheduling host status cleanup"
          queue.create(id: "reset_content_host_status_#{id}", name: _("Mark Content Host Statuses as Unknown for %s") % self,
            priority: 200, action: [self, :reset_katello_status])
        else
          queue.create(id: "reset_content_host_status_#{id}", name: _("Skip: Mark Content Host Statuses as Unknown for %s") % self,
            priority: 200, action: [nil])
        end
      end

Yes, its not nice to create a queue element which runs “nil”. It doesn’t throw an error but I’m not sure if it has other drawbacks or can be solved better.

Fix: Fixes #36996 - fix methods called by rebuild_config by m-bucher · Pull Request #10828 · Katello/katello · GitHub