Skip to content

Commit

Permalink
Fixes #37966 - Rescue Candlepin error during force registration
Browse files Browse the repository at this point in the history
after deleting certs from host. In this situation
Katello tries to update the consumer it just deleted.
  • Loading branch information
jeremylenz committed Oct 31, 2024
1 parent 82d7a2c commit 3f7eae9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/services/katello/registration_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,18 @@ def unregister_host(host, options = {})
end
end

# rubocop:disable Metrics/MethodLength
def register_host(host, consumer_params, content_view_environments, activation_keys = [])
new_host = host.new_record?
unless new_host
host.save!
# Keep the kickstart repository ID so the host's Medium isn't unset
# Important for registering a host during provisioning
unregister_host(host, :unregistering => true, :keep_kickstart_repository => true)
begin
unregister_host(host, :unregistering => true, :keep_kickstart_repository => true)
rescue RestClient::Gone
Rails.logger.debug("Host %s has been removed in preparation for reregistration" % host&.name)
end
host.reload
end

Expand Down Expand Up @@ -194,6 +199,7 @@ def register_host(host, consumer_params, content_view_environments, activation_k
finalize_registration(host)
end
end
# rubocop:enable Metrics/MethodLength

def check_registration_services
ping_results = {}
Expand Down
10 changes: 10 additions & 0 deletions test/services/katello/registration_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ def test_registration_existing_host
::Katello::RegistrationManager.register_host(@host, rhsm_params, [@content_view_environment])
end

def test_force_registration_existing_host
::Host::Managed.any_instance.expects(:update_candlepin_associations).times(1)
::Katello::RegistrationManager.expects(:unregister_host).raises(RestClient::Gone)
::Katello::RegistrationManager.expects(:create_in_candlepin)
::Katello::RegistrationManager.expects(:finalize_registration)
Rails.logger.expects(:debug).with("Host #{@host.name} has been removed in preparation for reregistration")
Rails.logger.expects(:debug).with("ContentFacet: Marking CVEs changed for host #{@host.name}").times(1)
::Katello::RegistrationManager.register_host(@host, rhsm_params, [@content_view_environment])
end

def test_unregister_host
::Host::Managed.any_instance.stubs(:update_candlepin_associations)
@host = FactoryBot.create(:host, :with_content, :with_subscription, :content_view => @content_view,
Expand Down

0 comments on commit 3f7eae9

Please sign in to comment.