Skip to content

Commit c59b27e

Browse files
committed
Removing unnecessary keep_kickstart_repository
1 parent 210fae2 commit c59b27e

File tree

2 files changed

+9
-35
lines changed

2 files changed

+9
-35
lines changed

app/services/katello/registration_manager.rb

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,9 @@ def joined_hostnames(hosts)
125125
# * organization_destroy: destroy some data associated with host, but
126126
# leave items alone that will be removed later as part of org destroy
127127
# * unregistering: unregister the host but don't destroy it
128-
# * keep_kickstart_repository: ensure the KS repo ID is not set to nil
129128
def unregister_host(host, options = {})
130129
organization_destroy = options.fetch(:organization_destroy, false)
131130
unregistering = options.fetch(:unregistering, false)
132-
keep_kickstart_repository = options.fetch(:keep_kickstart_repository, false)
133131

134132
# if the first operation fails, just raise the error since there's nothing to clean up yet.
135133
candlepin_consumer_destroy(host.subscription_facet.uuid) if !organization_destroy && host.subscription_facet.try(:uuid)
@@ -140,11 +138,7 @@ def unregister_host(host, options = {})
140138
host.subscription_facet.try(:destroy!)
141139

142140
if unregistering
143-
if keep_kickstart_repository
144-
remove_host_artifacts(host, kickstart_repository_id: host&.content_facet&.kickstart_repository_id)
145-
else
146-
remove_host_artifacts(host)
147-
end
141+
remove_host_artifacts(host)
148142
elsif organization_destroy
149143
host.content_facet.try(:destroy!)
150144
remove_host_artifacts(host, clear_content_facet: false)
@@ -159,10 +153,11 @@ def register_host(host, consumer_params, content_view_environments, activation_k
159153
new_host = host.new_record?
160154
unless new_host
161155
host.save!
162-
# Keep the kickstart repository ID so the host's Medium isn't unset
163-
# Important for registering a host during provisioning
156+
# Unregister the host before re-registering
157+
# The retain_build_profile_upon_unregistration setting controls whether
158+
# provisioning information (including kickstart repository) is preserved
164159
begin
165-
unregister_host(host, :unregistering => true, :keep_kickstart_repository => true)
160+
unregister_host(host, :unregistering => true)
166161
rescue RestClient::Gone
167162
Rails.logger.debug("Host %s has been removed in preparation for reregistration" % host&.name)
168163
end
@@ -319,23 +314,21 @@ def populate_subscription_facet(host, activation_keys, consumer_params, uuid)
319314
subscription_facet
320315
end
321316

322-
def remove_host_artifacts(host, clear_content_facet: true, kickstart_repository_id: nil)
323-
Rails.logger.debug "Host ID: #{host.id}, clear_content_facet: #{clear_content_facet}, kickstart_repository_id: #{kickstart_repository_id}"
317+
def remove_host_artifacts(host, clear_content_facet: true)
318+
Rails.logger.debug "Host ID: #{host.id}, clear_content_facet: #{clear_content_facet}"
324319
if host.content_facet && clear_content_facet
325320
host.content_facet.bound_repositories = []
326321
host.content_facet.applicable_errata = []
327322
host.content_facet.uuid = nil
328323

329324
# Clear or retain provisioning information based on setting
330-
if Setting[:retain_build_profile_upon_unregistration]
331-
# Retain current kickstart_repository_id if setting is enabled
332-
host.content_facet.kickstart_repository_id = kickstart_repository_id if kickstart_repository_id
333-
else
325+
unless Setting[:retain_build_profile_upon_unregistration]
334326
# Clear provisioning information if setting is disabled
335327
host.content_facet.content_view_environments = []
336328
host.content_facet.kickstart_repository_id = nil
337329
host.content_facet.content_source = ::SmartProxy.pulp_primary
338330
end
331+
# If setting is enabled, keep current values (CVEs, kickstart_repository_id, content_source)
339332

340333
host.content_facet.save!
341334
Rails.logger.debug "remove_host_artifacts: marking CVEs unchanged to prevent backend update"

test/services/katello/registration_manager_test.rb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -377,25 +377,6 @@ def test_unregister_host_retains_build_profile_when_setting_enabled
377377
assert_nil @host.content_facet.uuid
378378
end
379379

380-
def test_unregister_host_retains_kickstart_repository_when_keep_kickstart_repository_and_setting_enabled
381-
::Host::Managed.any_instance.stubs(:update_candlepin_associations)
382-
@host = FactoryBot.create(:host, :with_content, :with_subscription, :content_view => @content_view,
383-
:lifecycle_environment => @library, :organization => @content_view.organization)
384-
kickstart_repo = katello_repositories(:fedora_17_x86_64)
385-
@host.content_facet.update(:kickstart_repository_id => kickstart_repo.id)
386-
387-
original_cves = @host.content_facet.content_view_environments.dup
388-
389-
Setting[:retain_build_profile_upon_unregistration] = true
390-
::Katello::Resources::Candlepin::Consumer.expects(:destroy)
391-
392-
::Katello::RegistrationManager.unregister_host(@host, unregistering: true, keep_kickstart_repository: true)
393-
394-
# Verify provisioning information is retained
395-
assert_equal original_cves, @host.content_facet.content_view_environments
396-
assert_equal kickstart_repo.id, @host.content_facet.kickstart_repository_id
397-
end
398-
399380
def test_destroy_host_not_found
400381
@host = FactoryBot.create(:host, :with_content, :with_subscription, :content_view => @content_view,
401382
:lifecycle_environment => @library, :organization => @content_view.organization)

0 commit comments

Comments
 (0)