Skip to content
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 #37795 - set multiple Content Views via a single Activation key #11135

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

parthaa
Copy link
Contributor

@parthaa parthaa commented Sep 6, 2024

What are the changes introduced in this pull request?

  • Can add multiple content view environments to Activation Keys.
  • Can have a host register to multiple content view environments via Activation Key
  • Can have a host register to a composite of Activation Keys
  • API bindings to see information about the content view environments
  • API bindings to set the content view environments
  • Adds Content View Environment Activation Keys mapping table to manage multiple CVEs for an AK.

Considerations taken when implementing this change?

The approach largely mirrors what we did for content facets except 2 important changes

  • If you have the multi cv setting on and you specified multiple activation key on host registration, the CVEs of each individual activation key will get added. If you have the setting off, the behavior will be the same as status quo - only the cve of the last activation key will be added.
  • Prior to migration if you have an activation key where only the lce environment was set and content view was blank, the migrator will ignore creating CVEs for those environments. The Activation Key will be associated to no content view environment (this could be useful if you are creating activation keys with system purpose attributes.)

What are the testing steps for this pull request?

  1. Create a few activation keys
  2. Check out the PR and run the migration
  3. Verify things migrated correctly.
  4. You should then be able to use hammer activation-key create --name=foo --organization-id=1 --content-view-environments='env_label1/cv_label1,env_label2/cv_label2'
  5. You can verify activation key foo has 2 content view environments on rails console
  6. Try registering a host to to this activation key via global registration.
  7. You should notice repositories from env1/cv1 and env2/cv2 in the redhat repos file.
  8. Try testing things like deleting content views and have it reassigned to something else etc.

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.

thanks @parthaa!

Some initial code comments

Also tested a bit and found that when I use the Angular page to edit syspurpose values on an AK, multiple CVEs are overwritten. This does not happen with the new React AK page.

app/models/katello/activation_key.rb Show resolved Hide resolved
app/services/katello/registration_manager.rb Outdated Show resolved Hide resolved
app/services/katello/registration_manager.rb Show resolved Hide resolved
@parthaa parthaa changed the title [WIP]Fixes #37795 - set multiple Content Views via a single Activation key Fixes #37795 - set multiple Content Views via a single Activation key Sep 9, 2024
self.table_name = 'katello_activation_keys'
end

class CVEAKMigrator # used in db/migrate/20220929204746_add_content_view_environment_content_facet.rb
Copy link
Member

Choose a reason for hiding this comment

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

As discussed please change the logic here so that

if the AK doesn't have CV or LCE, don't add it. (AKs aren't required to have cv/lce.)
if the AK has only CV, add it as Default LCE and that CV (and add a warning in the docs)
if the AK has only LCE, add it as Default LCE / Default Org View
if the AK has both, great, add that CVE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be addressed in the latest commit

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those CVEs should be part of the aks_with_no_cve + aks_with_missing_cve list. Seems to be ok to me? I am I missing something?

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.

Did some more testing

Global Reg with multiple AKs works as expected:

  1. Multiple AKs' CVEs are combined
  2. Ordering of CVEs is preserved between multiple AKs

Available Releases works as expected (Release version dropdown on AK details shows release versions from the AK's repositories)

app/models/katello/content_view_environment.rb Outdated Show resolved Hide resolved
app/models/katello/activation_key.rb Outdated Show resolved Hide resolved
app/models/katello/content_view_environment.rb Outdated Show resolved Hide resolved
app/services/katello/registration_manager.rb Outdated Show resolved Hide resolved
app/views/katello/api/v2/activation_keys/base.json.rabl Outdated Show resolved Hide resolved
app/lib/katello/util/cveak_migrator.rb Outdated Show resolved Hide resolved
app/lib/katello/util/cveak_migrator.rb Outdated Show resolved Hide resolved
self.table_name = 'katello_activation_keys'
end

class CVEAKMigrator # used in db/migrate/20220929204746_add_content_view_environment_content_facet.rb

This comment was marked as resolved.

app/lib/katello/util/cveak_migrator.rb Outdated Show resolved Hide resolved
@jeremylenz
Copy link
Member

I guess the only one I don't see covered is

if the AK has only CV, add it as Default LCE and that CV (and add a warning in the docs)

Right now it would get Library/Default Org View.

@jeremylenz
Copy link
Member

  1. need to rebase now that Zeitwerk is merged
  2. In config/initializers/inflections.rb, need to add
'cveak_migrator' => 'CVEAKMigrator',

in the first section

@jeremylenz
Copy link
Member

jeremylenz commented Sep 12, 2024

Ruby test failures related, should be easy fixes
React test failures unrelated, due to jsx-eslint/eslint-plugin-react#3819

add_foreign_key "katello_activation_keys", "katello_environments",
:name => "katello_activation_keys_environment_id", :column => "environment_id"

::Katello::ActivationKey.reset_column_information
Copy link
Member

@jeremylenz jeremylenz Sep 12, 2024

Choose a reason for hiding this comment

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

== 20240730163043 AddContentViewEnvironmentActivationKey: reverting ===========
-- add_column(:katello_activation_keys, :content_view_id, :integer, {:index=>true})
   -> 0.0010s
-- add_column(:katello_activation_keys, :environment_id, :integer, {:index=>true})
   -> 0.0004s
-- add_foreign_key("katello_activation_keys", "katello_content_views", {:name=>"katello_activation_keys_content_view_id", :column=>"content_view_id"})
   -> 0.0011s
-- add_foreign_key("katello_activation_keys", "katello_environments", {:name=>"katello_activation_keys_environment_id", :column=>"environment_id"})
   -> 0.0010s
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedColumn: ERROR:  column "priority" does not exist
LINE 1: ...ontent_view_environment_activation_keys" ORDER BY "priority"...

I got this when trying to run the down migration. Seems it happens at about this point. The down migration erasing the "priority" column has already run at this point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

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.

Let's take it for a real spin now!

🚀

@parthaa parthaa merged commit 746bda7 into Katello:master Sep 12, 2024
27 checks passed
@parthaa parthaa deleted the ak-multi-env branch September 12, 2024 19:15
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.

2 participants