Skip to content

Commit

Permalink
Fixes #36840 - Clear content source when unregistering host (#10797)
Browse files Browse the repository at this point in the history
* Fixes #36840 - Clear content source when unregistering host
  Also correctly display the content source
  on host details page (previously it was showing the
  Registered Through smart proxy mislabeled as content source)
* Refs #36840 - add test
  • Loading branch information
jeremylenz authored Nov 15, 2023
1 parent 17c731a commit c045d9b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/services/katello/registration_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ def remove_host_artifacts(host, clear_content_facet: true)
host.content_facet.applicable_errata = []
host.content_facet.uuid = nil
host.content_facet.content_view_environments = []
host.content_facet.content_source = ::SmartProxy.pulp_primary
host.content_facet.save!
Rails.logger.debug "remove_host_artifacts: marking CVEs unchanged to prevent backend update"
host.content_facet.mark_cves_unchanged
Expand Down
13 changes: 13 additions & 0 deletions test/services/katello/registration_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,19 @@ def test_unregister_host_rhsm_facts
assert_empty @host.rhsm_fact_values
end

def test_unregister_host_resets_content_source
@host = FactoryBot.create(:host, :with_content, :with_subscription, :content_view => @content_view,
:lifecycle_environment => @library, :organization => @content_view.organization)
pulp3_proxy = FactoryBot.create(:smart_proxy, :with_pulp3)
@host.content_facet.update(:content_source_id => pulp3_proxy.id)
::Katello::Resources::Candlepin::Consumer.expects(:destroy)

::Katello::RegistrationManager.unregister_host(@host, unregistering: true)

refute_nil @host.content_facet.content_source
assert_equal ::SmartProxy.pulp_primary, @host.content_facet.content_source
end

def test_destroy_host_not_found
@host = FactoryBot.create(:host, :with_content, :with_subscription, :content_view => @content_view,
:lifecycle_environment => @library, :organization => @content_view.organization)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ const RegistrationCard = ({ isExpandedGlobal, hostDetails }) => {
const subscriptionFacetAttributes
= propsToCamelCase(hostDetails?.subscription_facet_attributes || {});
const {
registeredAt, registeredThrough, activationKeys, user,
registeredAt, activationKeys, user,
}
= subscriptionFacetAttributes;
const contentFacetAttributes
= propsToCamelCase(hostDetails?.content_facet_attributes || {});
const { contentSourceName } = contentFacetAttributes;
const login = user?.login;
if (!registeredAt) return null;
return (
Expand All @@ -78,7 +81,7 @@ const RegistrationCard = ({ isExpandedGlobal, hostDetails }) => {
</DescriptionListGroup>
<DescriptionListGroup>
<DescriptionListTerm>{__('Content source')}</DescriptionListTerm>
<DescriptionListDescription>{registeredThrough}</DescriptionListDescription>
<DescriptionListDescription>{contentSourceName}</DescriptionListDescription>
</DescriptionListGroup>
</DescriptionList>
</CardTemplate>
Expand All @@ -99,6 +102,9 @@ RegistrationCard.propTypes = {
name: PropTypes.string,
})),
}),
content_facet_attributes: PropTypes.shape({
content_source_name: PropTypes.string,
}),
}),
};

Expand Down

0 comments on commit c045d9b

Please sign in to comment.