Skip to content

Fixes #38862 - Switch to subscription facet for uuids#11569

Merged
sjha4 merged 1 commit into
Katello:masterfrom
sjha4:sp_sync_nil_facet_uuid
Nov 20, 2025
Merged

Fixes #38862 - Switch to subscription facet for uuids#11569
sjha4 merged 1 commit into
Katello:masterfrom
sjha4:sp_sync_nil_facet_uuid

Conversation

@sjha4
Copy link
Copy Markdown
Member

@sjha4 sjha4 commented Nov 17, 2025

What are the changes introduced in this pull request?

  1. Switch to using subscription facet UUID for hosts through smart_proxy.content_facets. Content facet UUID can be cleared out in certain workflows but subscription_facet is not and is the source of truth.
  2. Handle case where subscription_facet uuid is nil regardless for edge case.
  3. Add some error handling by logging error properly for API calls during container_gateway calls.

Considerations taken when implementing this change?

subscription_facets is a method to grab the sub facets instead of a relation on smart_proxy to avoid extra relations and dependencies. Something a test failure raised as a flag with claude.

What are the testing steps for this pull request?

Register a host via a smart proxy.
Do something like:
cf = smart_proxy.content_facets.first
cf.uuid = nil
cf.save!

Try a smart proxy sync. You'll see an error :

Last sync failed: ERF12-0457 [ProxyAPI::ProxyException]: Unable to update hosts ([RestClient::InternalServerError]: 500 Internal Server Error) for proxy https://centos9-proxy-devel-stable.sajha.example.com:9090/container_gateway/update_hosts

With this change, you should be able to correctly sync even with nil content_facet uuid.
For completeness, you can also set subscription facet uuid to nil and try a sync. The sync will still succeed and nil UUID will be correctly ignored.

Summary by Sourcery

Use subscription_facet UUID as the source of truth for container gateway host and repository updates, gracefully skip missing UUIDs, and add error handling and logging.

Bug Fixes:

  • Skip hosts with nil subscription_facet UUID to prevent container gateway sync failures

Enhancements:

  • Use subscription_facet UUID instead of content_facet UUID for container gateway operations
  • Introduce subscription_facets scope to retrieve applicable host facets
  • Add error handling and logging for container gateway API calls

Tests:

  • Add tests for syncing container gateway hosts using subscription_facet UUIDs and skipping nil values
  • Add tests for update_host_repositories handling hosts with and without subscription_facet UUIDs

Copy link
Copy Markdown
Contributor

@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/models/concerns/smart_proxy_extensions_test.rb:438` </location>
<code_context>
         SmartProxy.joins(:smart_proxy_alternate_content_sources).where('katello_smart_proxy_alternate_content_sources.smart_proxy_id' => self.id)
       end

+      def subscription_facets
</code_context>

<issue_to_address>
**suggestion (testing):** Tests do not cover error handling/logging for API failures in sync_container_gateway.

Please add tests that simulate exceptions in these API calls and verify that error logging occurs as expected.
</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.

@@ -436,6 +436,108 @@ def test_sync_container_gateway
capsule_content.smart_proxy.expects(:container_gateway_users).returns(::User.where(login: 'secret_admin'))
capsule_content.smart_proxy.sync_container_gateway
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Tests do not cover error handling/logging for API failures in sync_container_gateway.

Please add tests that simulate exceptions in these API calls and verify that error logging occurs as expected.

Copy link
Copy Markdown
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.

just a few nits 😇

Comment thread app/models/katello/concerns/smart_proxy_extensions.rb Outdated
Comment thread app/models/katello/concerns/smart_proxy_extensions.rb Outdated
Comment thread app/models/katello/concerns/smart_proxy_extensions.rb
host_repo_map = { hosts: [] }
content_facets.each do |facet|
subscription_facets.each do |facet|
next if facet.uuid.blank?
repositories = ::Katello::Repository.readable_docker_catalog(facet.host)
host_repo_map[:hosts] << { facet.uuid => build_repo_list(repositories) }
end
ProxyAPI::ContainerGateway.new(url: self.url).host_repository_mapping(host_repo_map)
end

def update_host_repositories(host)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Funnily enough I don't think this method is called anywhere. Can it be removed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

@ianballou ianballou left a comment

Choose a reason for hiding this comment

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

This seems to be working well, I made a content facet UUID nil and I was still able to run sync_container_gateway. Tested quickly with a cert-using host.

Comment on lines +271 to +272
facets ||= subscription_facets
hosts = facets.select { |facet| facet.uuid.present? }.map do |facet|
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
facets ||= subscription_facets
hosts = facets.select { |facet| facet.uuid.present? }.map do |facet|
facets ||= subscription_facets.where.not(uuid: nil)
hosts = facets.map do |facet|

Gets rid of a block going to a block.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated to move this to subscription_facets function directly..So both callers can rely on the filter being there.

Comment thread app/models/katello/concerns/smart_proxy_extensions.rb
Copy link
Copy Markdown
Member

@ianballou ianballou left a comment

Choose a reason for hiding this comment

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

Works for me!

@sjha4 sjha4 merged commit a4c5da2 into Katello:master Nov 20, 2025
22 checks passed
zjhuntin pushed a commit to zjhuntin/katello that referenced this pull request Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants