-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #36310 - Migrate off ContentViews generated for repository export #11112
Fixes #36310 - Migrate off ContentViews generated for repository export #11112
Conversation
87201fe
to
fac3e6e
Compare
My understanding of c33da7a is that multi-CV assignment is possible for Hosts but NOT for Activation Keys -- a Host performs multi-CV registration using multiple Activation Keys, never via a single Activation Key with multiple CVs assigned to it. In addition to the fact that Activation Keys may have only a single CV assigned, validations already prevent CVs generated for repository export from being associated with AKs. Based on these facts, I've removed the (harmless, but also unnecessary) Activation Key portion of the migration logic. |
The test failures in the RPM build pipeline are unrelated to this change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting the following error on a stream install:
2024-08-27T15:28:59 [E|kat|dba292f5] NameError: undefined local variable or method `cve' for #<Katello::Api::Rhsm::CandlepinProxiesController:0x000055cfe8863c70>
dba292f5 | /usr/share/gems/gems/katello-4.14.0.pre.master/app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb:421:in `block in update_environments_from_facts'
dba292f5 | /usr/share/gems/gems/katello-4.14.0.pre.master/app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb:419:in `map'
dba292f5 | /usr/share/gems/gems/katello-4.14.0.pre.master/app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb:419:in `update_environments_from_facts'
dba292f5 | /usr/share/gems/gems/katello-4.14.0.pre.master/app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb:271:in `facts'
dba292f5 | /usr/share/gems/gems/actionpack-6.1.7.8/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
Ensures no Hosts remain on ContentViews generated for repository export. If doing so would leave the Host a valid ContentView, the Default Organization View is assigned to it. Also implements additional filtering in the candlepin proxies controller, and several additional tests.
fac3e6e
to
c87acda
Compare
Thanks for the review @chris1984 Huh, I didn't change that in my prior update so I should have hit that issue before. Maybe the test coverage for the Anyway, I just needed to set |
Hey @chris1984 thanks for the initial review. Do you have some time to take a fresh look? |
Will get to it this week :) wrapping up a few last minute 6.16 things |
no worries... thanks! |
@parthaa did you still want to look at this one, since you did ISS |
Nice work. LGTM |
@@ -211,7 +211,16 @@ def enabled_repos | |||
|
|||
#api :POST, "/environments/:environment_id/consumers", N_("Register a consumer in environment") | |||
def consumer_create | |||
host = Katello::RegistrationManager.process_registration(rhsm_params, find_content_view_environments) | |||
content_view_environments = find_content_view_environments | |||
if content_view_environments.any? { |cve| cve.content_view.generated_for_repository_export? } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont think this is necessary because of https://github.com/Katello/katello/blob/master/app/models/katello/host/content_facet.rb#L47 that checks for .generated_for_repository_export?
Would recommend the following patch for diff --git a/db/migrate/20240815080259_migrate_off_generated_content_views.rb b/db/migrate/20240815080259_migrate_off_generated_content_views.rb
index 9df225aeb4..6e542787fc 100644
--- a/db/migrate/20240815080259_migrate_off_generated_content_views.rb
+++ b/db/migrate/20240815080259_migrate_off_generated_content_views.rb
@@ -1,4 +1,8 @@
class MigrateOffGeneratedContentViews < ActiveRecord::Migration[6.1]
+ class FakeCVECF < ApplicationRecord
+ self.table_name = 'katello_content_view_environment_content_facets'
+ end
+
def up
say_with_time "Migrating hosts off generated content views" do
migrate_hosts
@@ -13,25 +17,28 @@ class MigrateOffGeneratedContentViews < ActiveRecord::Migration[6.1]
def migrate_hosts
say_with_time "Migrating hosts..." do
- generated_content_views = Katello::ContentView.where(generated_for: 'repository_export')
-
- facets = Katello::Host::ContentFacet.joins(:content_view_environments)
- facets = facets.where(katello_content_view_environments: { content_view_id: generated_content_views })
- facets.find_each do |content_facet|
- offending_cves = content_facet.content_view_environments.select { |cve| generated_content_views.include?(cve.content_view) }
- valid_cves = content_facet.content_view_environments - offending_cves
+ generated_content_views = Katello::ContentView.generated_for_repository
+ facets = Katello::Host::ContentFacet.joins(:content_view_environments).
+ where(content_view_environments: { content_view: generated_content_views })
+ facets.all.each do |content_facet|
+ valid_cves = content_facet.content_view_environments.where.not(content_view: generated_content_views)
if valid_cves.empty?
- default_view = Katello::ContentView.find_by(name: "Default Organization View", organization: content_facet.host.organization)
- if default_view
- default_cve = default_view.content_view_environments.find_by(lifecycle_environment: content_facet.lifecycle_environments.first)
- content_facet.update!(content_view_environments: [default_cve])
+ organization = content_facet.host.organization
+ default_cve = organization.content_view_environments.find_by(lifecycle_environment: organization.library,
+ content_view: organization.default_content_view)
+ if default_cve
+ FakeCVECF.where(content_facet_id: content_facet).delete_all
+ FakeCVECF.create!(content_facet_id: content_facet.id,
+ content_view_environment_id: default_cve.id)
say "Replaced all content views with Default Organization View for host #{content_facet.host.name}", true
else
say "No Default Organization View found for host #{content_facet.host.name}. Skipping.", true
end
else
- content_facet.update!(content_view_environments: valid_cves)
+ FakeCVECF.where(content_facet_id: content_facet).
+ where.not(content_view_environment_id: valid_cves).
+ delete_all
say "Removed offending content views for host #{content_facet.host.name}", true
end
end |
Ensures no Hosts remain on ContentViews generated for repository export. If doing so would leave the Host without a valid ContentView, the Default Organization View is assigned to it.
Also implements additional filtering in the candlepin proxies controller, and several additional tests.
What considerations are taken in implementing this pull request?
At least some validation was already done with c33da7a
What are the testing steps for this pull request?
Export a Content View
Try assigning some hosts to the content view created for export
Apply patch
Run migration