Fixes #38862 - Switch to subscription facet for uuids#11569
Conversation
There was a problem hiding this comment.
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>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 | |||
There was a problem hiding this comment.
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.
35fb928 to
a59c3a3
Compare
| 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) |
There was a problem hiding this comment.
Funnily enough I don't think this method is called anywhere. Can it be removed?
ianballou
left a comment
There was a problem hiding this comment.
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.
| facets ||= subscription_facets | ||
| hosts = facets.select { |facet| facet.uuid.present? }.map do |facet| |
There was a problem hiding this comment.
| 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.
There was a problem hiding this comment.
Updated to move this to subscription_facets function directly..So both callers can rely on the filter being there.
a59c3a3 to
798fd9d
Compare
What are the changes introduced in this pull request?
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 :
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:
Enhancements:
Tests: