@@ -125,11 +125,9 @@ def joined_hostnames(hosts)
125
125
# * organization_destroy: destroy some data associated with host, but
126
126
# leave items alone that will be removed later as part of org destroy
127
127
# * unregistering: unregister the host but don't destroy it
128
- # * keep_kickstart_repository: ensure the KS repo ID is not set to nil
129
128
def unregister_host ( host , options = { } )
130
129
organization_destroy = options . fetch ( :organization_destroy , false )
131
130
unregistering = options . fetch ( :unregistering , false )
132
- keep_kickstart_repository = options . fetch ( :keep_kickstart_repository , false )
133
131
134
132
# if the first operation fails, just raise the error since there's nothing to clean up yet.
135
133
candlepin_consumer_destroy ( host . subscription_facet . uuid ) if !organization_destroy && host . subscription_facet . try ( :uuid )
@@ -140,11 +138,7 @@ def unregister_host(host, options = {})
140
138
host . subscription_facet . try ( :destroy! )
141
139
142
140
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 )
148
142
elsif organization_destroy
149
143
host . content_facet . try ( :destroy! )
150
144
remove_host_artifacts ( host , clear_content_facet : false )
@@ -159,10 +153,11 @@ def register_host(host, consumer_params, content_view_environments, activation_k
159
153
new_host = host . new_record?
160
154
unless new_host
161
155
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
164
159
begin
165
- unregister_host ( host , :unregistering => true , :keep_kickstart_repository => true )
160
+ unregister_host ( host , :unregistering => true )
166
161
rescue RestClient ::Gone
167
162
Rails . logger . debug ( "Host %s has been removed in preparation for reregistration" % host &.name )
168
163
end
@@ -319,23 +314,21 @@ def populate_subscription_facet(host, activation_keys, consumer_params, uuid)
319
314
subscription_facet
320
315
end
321
316
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 } "
324
319
if host . content_facet && clear_content_facet
325
320
host . content_facet . bound_repositories = [ ]
326
321
host . content_facet . applicable_errata = [ ]
327
322
host . content_facet . uuid = nil
328
323
329
324
# 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 ]
334
326
# Clear provisioning information if setting is disabled
335
327
host . content_facet . content_view_environments = [ ]
336
328
host . content_facet . kickstart_repository_id = nil
337
329
host . content_facet . content_source = ::SmartProxy . pulp_primary
338
330
end
331
+ # If setting is enabled, keep current values (CVEs, kickstart_repository_id, content_source)
339
332
340
333
host . content_facet . save!
341
334
Rails . logger . debug "remove_host_artifacts: marking CVEs unchanged to prevent backend update"
0 commit comments