Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37966 - Rescue Candlepin error during force registration #11199

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading