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 057b8f0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/services/katello/registration_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ def register_host(host, consumer_params, content_view_environments, activation_k
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
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 057b8f0

Please sign in to comment.