-
Notifications
You must be signed in to change notification settings - Fork 293
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 #11144
Open
parthaa
wants to merge
1
commit into
Katello:master
Choose a base branch
from
parthaa:migrate-hosts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
db/migrate/20240815080259_migrate_off_generated_content_views.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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 | ||
end | ||
end | ||
|
||
def down | ||
say "This migration cannot be reversed", true | ||
end | ||
|
||
private | ||
|
||
def migrate_hosts | ||
say_with_time "Migrating hosts..." do | ||
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? | ||
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 | ||
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 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -107,6 +107,16 @@ def setup | |||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
test "should not allow generated content view to be associated with activation key" do | ||||||||||||||||||||||||||||||||||||||||
generated_cv = FactoryBot.create(:katello_content_view, :generated_for => :repository_export, :organization => @dev_view.organization) | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
exception = assert_raises(ActiveRecord::RecordInvalid) do | ||||||||||||||||||||||||||||||||||||||||
@dev_key.update!(content_view: generated_cv) | ||||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
assert_match(/Generated content views cannot be assigned to hosts or activation keys/, exception.message) | ||||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||||
Comment on lines
+110
to
+118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Something along these lines looks necessary due to the changes in 746bda7#diff-d7dd2b8980210ef5f81a8ac4d2bfd2384210cf326a1b165a5b6869b0c661a241 |
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
def test_search_name | ||||||||||||||||||||||||||||||||||||||||
activation_keys = ActivationKey.search_for("name = \"#{@dev_staging_view_key.name}\"") | ||||||||||||||||||||||||||||||||||||||||
assert_includes activation_keys, @dev_staging_view_key | ||||||||||||||||||||||||||||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think it should be
find_content_view_environments
(see L#321 below)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.
Moved it back. I don't see this path being called from subman but may be some one who is curl posting to this URL directly will be calling this.
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.
Hmm, still the same issue:
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.
To clarify, this is what it was originally before my PR:
My PR had:
And yours had:
So I wasn't suggesting that you need to reinstate my version of the change, just that you never FULLY reverted it to the original
That said, it seems the current issue in the tests is occurring regardless. I'm not sure what is the cause
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.
can you share the stack trace for this.
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.
I kicked off a re-run in CI of the failed tests to be sure:
It looks like the test needs to try updating
convent_view_environments
instead