Skip to content

Conversation

parthaa
Copy link
Contributor

@parthaa parthaa commented Aug 14, 2025

Introduces new option to retain build_profile information on unregistration

What are the changes introduced in this pull request?

A configurable option retain_build_profile_upon_unregistration to allow users to choose whether provisioning information like CV/LCE/KS/media is retained or cleared upon host unregistration.

Considerations taken when implementing this change?

Katello typically cleared the content view environment information of a host on unregistration. However some customers want to preserve content view environments and KS repository ids so that they have these options available when build is set to false (see the redmine for more info).

What are the testing steps for this pull request?

Checkout the PR

  1. Administrations -> Settings -> Content
  2. See the new option for the retaining build profile
Screenshot_20250814_161205

Now play with the settings register and unregister a host couple of times

For retain_build_profile_upon_unregistration = no

> Host.last.content_facet.content_view_environments
=> []

For retain_build_profile_upon_unregistration = yes

> Host.last.content_facet.content_view_environments
=> [#<Katello::ContentViewEnvironment:0x00007f7058d96348
  id: 1,
  name: "Library",
  label: "Library",
  cp_id: "1a94200bf624d5f2ffca3adfd351c6ae",
  content_view_id: 1,
  created_at: Wed, 04 Jun 2025 19:40:45.887069000 UTC +00:00,
  updated_at: Wed, 04 Jun 2025 19:40:45.887069000 UTC +00:00,
  environment_id: 1,
  content_view_version_id: 1>]

Summary by Sourcery

Introduce a new setting to conditionally retain provisioning information when unregistering hosts and update the unregistration process accordingly.

New Features:

  • Add retain_build_profile_upon_unregistration boolean setting to control retention of build profile data on host unregistration

Enhancements:

  • Modify RegistrationManager#remove_host_artifacts to clear or preserve Content View environments and kickstart repository based on the new setting

Tests:

  • Add tests to verify build profile data is cleared when the setting is disabled
  • Add tests to verify build profile data is retained when the setting is enabled
  • Add test to ensure kickstart repository is preserved when using the keep_kickstart_repository flag with the setting enabled

Copy link

sourcery-ai bot commented Aug 14, 2025

Reviewer's Guide

Adds a new boolean setting to control whether provisioning data is cleared on host unregistration, updates the unregistration logic to respect this setting, and provides tests covering both retention and clearing scenarios.

Sequence diagram for host unregistration with build profile retention setting

sequenceDiagram
  actor User
  participant Host
  participant ContentFacet
  participant Setting
  User->>Host: Unregister host
  Host->>Setting: Check retain_build_profile_upon_unregistration
  alt Retention enabled
    Host->>ContentFacet: Retain provisioning info (CV/LCE/KS/media)
  else Retention disabled
    Host->>ContentFacet: Clear provisioning info (CV/LCE/KS/media)
  end
  ContentFacet->>ContentFacet: Save changes
Loading

Class diagram for changes to Host content_facet on unregistration

classDiagram
  class Host {
    +content_facet: ContentFacet
  }
  class ContentFacet {
    +bound_repositories: Array
    +applicable_errata: Array
    +uuid: String
    +content_view_environments: Array
    +kickstart_repository_id: Integer
    +content_source: SmartProxy
    +mark_cves_unchanged()
    +save!()
  }
  Host --> ContentFacet
  ContentFacet --> SmartProxy

  class Setting {
    +retain_build_profile_upon_unregistration: Boolean
  }
Loading

File-Level Changes

Change Details Files
Introduce retain_build_profile_upon_unregistration setting
  • Define new plugin setting with type boolean and default false
  • Provide full_name and description for UI display
lib/katello/plugin.rb
Conditionally clear or retain build profile in unregistration logic
  • Wrap content_view_environments and kickstart_repository_id assignments in a Setting check
  • Retain kickstart_repository_id when setting enabled or when keep_kickstart_repository flag is passed
  • Remove unconditional assignment of kickstart_repository_id
app/services/katello/registration_manager.rb
Add tests for new unregistration behavior
  • Test that build profile is cleared when setting is false
  • Test that build profile is retained when setting is true
  • Test that kickstart repository is retained when flag is passed with setting enabled
test/services/katello/registration_manager_test.rb

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `test/services/katello/registration_manager_test.rb:360` </location>
<code_context>
+      def test_unregister_host_retains_build_profile_when_setting_enabled
</code_context>

<issue_to_address>
Missing assertion for media retention/clearing as described in the setting.

Please add assertions to check that media is retained or cleared as specified by the setting, ensuring the test fully covers the described behavior.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@parthaa parthaa force-pushed the partially-build branch 2 times, most recently from 96405fe to 210fae2 Compare August 14, 2025 21:13
Copy link
Member

@jeremylenz jeremylenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thought.. Now that there's a setting that controls all build info (CV/LCE, KS repo, content source), this might be a good time to refactor the keep_kickstart_repository stuff above, in this same file. I'm thinking we don't need to pass that around as much any more. Worth some investigation.

@parthaa
Copy link
Contributor Author

parthaa commented Aug 15, 2025

One thought.. Now that there's a setting that controls all build info (CV/LCE, KS repo, content source), this might be a good time to refactor the keep_kickstart_repository stuff above, in this same file. I'm thinking we don't need to pass that around as much any more. Worth some investigation.

I ve added a commit. Let me know if this looks better. I ve tried to remove the keep_kickstart_repository option

@jeremylenz
Copy link
Member

Yes I like this better. 👍 cc @ianballou as well

@ianballou
Copy link
Member

I recommend we run some provisioning PRT test against this. I just want to make sure there's no worry about having that Medium missing from Host error pop up again. It's a regression that popped up one of the last times we touched this code.

Introduces new option to retain build_profile information on
unregistration

Removing unnecessary keep_kickstart_repository

Verify content sources
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants