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 #38147 - correctly find org on FakeActivationKey #11280

Merged
merged 1 commit into from
Jan 24, 2025

Conversation

jeremylenz
Copy link
Member

@jeremylenz jeremylenz commented Jan 17, 2025

What are the changes introduced in this pull request?

In CVEAKMigrator we create FakeActivationKeys and then try to use the .organization method on them, which results in an error

2025-01-14 20:23:33 [INFO  ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: undefined method `organization' for #<Katello::Util::FakeActivationKey id: 8, name: "Red Hat
Enterprise Linux", description: nil, organization_id: 1, environment_id: 4, created_at: "2023-08-22 21:10:28.552603000 +0000", updated_at: "2023-08-22 21:27:43.731203000 +0000", user_id: 5, max_hosts: nil, content_view_id: nil, cp

https://community.theforeman.org/t/issue-when-upgrading-to-3-13-and-the-fix/42026

This should prevent that error.

Considerations taken when implementing this change?

I suppose it's possible the organization referenced by the AK could have disappeared, and this won't fix that.

What are the testing steps for this pull request?

not really sure. I guess you'd have to down-migrate to before AK MultiCV
Then make sure you have at least one AK with a CV ID and LCE ID that does NOT correspond to a real ContentViewEnvironment (e.g. that content view has not been promoted to that lifecycle environment)

Then try CVEAKMigrator.new.execute! in the console and make sure that codepath runs.

Alternatively, what I did to reproduce is, in the console

class FakeActivationKey < ApplicationRecord
    self.table_name = 'katello_activation_keys'
end

> FakeActivationKey.all.first.organization
NoMethodError: undefined method `organization' for #<FakeActivationKey id: 1, name: "ak1", description: nil, organization_id: 1, created_at: "2025-01-13 14:38:29.042717000 +0000", updated_at: "2025-01-13 14:38:29.309252000 +0000", user_id: 4, max_hosts: nil, cp_id: "4028fae3945ff2a80194601a138b0005", release_version: nil, unlimited_hosts: true, auto_attach: true, purpose_role: nil, purpose_usage: nil>

@parthaa
Copy link
Contributor

parthaa commented Jan 23, 2025

I am ok with your approach. Would you say this would be better though

class FakeActivationKey < ApplicationRecord
    self.table_name = 'katello_activation_keys'
    belongs_to :organization
end

Copy link
Contributor

@parthaa parthaa left a comment

Choose a reason for hiding this comment

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

APJ

@jeremylenz jeremylenz merged commit b594562 into Katello:master Jan 24, 2025
19 checks passed
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