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 #37852 - Support Rails 7.0 #11155

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ofedoren
Copy link
Contributor

@ofedoren ofedoren commented Sep 20, 2024

What are the changes introduced in this pull request?

We're updating Rails version in Foreman: theforeman/foreman#10299 (please visit it first if you have any questions/suggestions, there are many comments regarding the changes)

This PR tries to make Katello Rails 7 friendly (compatible).

Considerations taken when implementing this change?

  1. Mostly removing deprecated usage of #<< for ActiveModel::Errors objects
  2. Just a heads up regarding https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#digest-class-for-activesupport-digest-changing-to-sha256. How it affects this plugin is more or less here: Fixes #37825 - Upgrade Rails to 7.0 theforeman/foreman#10299 (comment)

What are the testing steps for this pull request?

Ensuring CI is green.

If you really want some 🍪, test some workflows live.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

I see lots of changes around the error handling and I think that's already Rails 6.1 compatible. Perhaps something that we can already merge to reduce the size of this PR?

@@ -63,7 +63,7 @@ def setup

@validator.validate(@content_facet)

assert_empty @content_facet.errors.values
assert_empty @content_facet.errors.map { |error| error.message }
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert_empty @content_facet.errors.map { |error| error.message }
assert_empty @content_facet.errors.map(&:message)

@chris1984
Copy link
Member

@SatelliteQE/TeamPhoenix

@Satellite-QE
Copy link

PRT Result

Build Number: 9132
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman --team Phoenix-content --external-logging
Test Result: = 6 skipped, 3973 deselected, 5492 warnings, 1490 errors in 4906.50s (1:21:46) =

@Satellite-QE
Copy link

PRT Result

Build Number: 9133
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman --team Phoenix-subscriptions --external-logging
Test Result: ======= 4779 deselected, 5492 warnings, 690 errors in 4923.46s (1:22:03) =======

@ekohl
Copy link
Member

ekohl commented Oct 24, 2024

@chris1984 I doubt PRT is going to be of any use. You need updated Foreman and Rails and we haven't packaged that.

@ofedoren ofedoren force-pushed the feat-37852-support-rails-7 branch 3 times, most recently from b26b87d to 1f31c0f Compare November 7, 2024 14:27
@ofedoren
Copy link
Contributor Author

ofedoren commented Nov 7, 2024

The test failure is unrelated to this PR, it for some reason wasn't caught by GHA for theforeman/foreman_remote_execution#913

Fixed in theforeman/foreman_remote_execution#925

@@ -6,7 +6,7 @@ def self.array_with_indifferent_access(variable)
end

def self.hexdigest(string)
defined?(ActiveSupport::Digest) ? ActiveSupport::Digest.hexdigest(string) : Digest::MD5.hexdigest(string)
defined?(ActiveSupport::Digest) ? OpenSSL::Digest::SHA1.hexdigest(string)[0...32] : Digest::MD5.hexdigest(string)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This forces SHA1 for hexdigest since it was default in Rails < 7. This makes sure Katello behaves the same way and the tests are green.

I'd ask maintainers to check the needed changes for this plugin to support SHA256. Afterwards this line can be switched back (until Rails upgrades the default to SHA512).

Copy link
Member

Choose a reason for hiding this comment

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

@parthaa said in https://community.theforeman.org/t/rails-7-upgrade/37771/27 that the actual value doesn't matter, as long as it's consistent.

I wonder if the old code was ever used. rails/rails@82822a3 introduced ActiveSupport::Digest and was introduced in Rails 5.2 (by a former Foreman developer). Perhaps a PR to replace it al with direct calls to ActiveSupport::Digest.hexdigest() is a better approach.

Having said that, I find it interesting that the class itself still defaults to md5: https://github.com/rails/rails/blob/4df235f7c0149ac7be86580d41a74a7785cb9bb9/activesupport/lib/active_support/digest.rb#L9

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So should I just revert the changes back and simply update IDs in VCR tests?

Copy link
Member

Choose a reason for hiding this comment

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

Since the IDs just need to be random numbers, I think it's fine to use the new SHA 256 default. I was going to suggest continuing to use SHA1 like suggested here so the VCR recordings could be avoided, but that's already done, so I think we're all good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just thought if it will break stuff for upgrading users:

  • IDs are generated or rather mapped (for the same input A -> the same output B)
  • These IDs are stored somewhere
  • Newer hashing class will create for the same input A -> the same output, but different C
  • The stored B can't be referenced by A, since hashed version is C.

But if mapping goes only before storing and then the app using only stored values (without any further #hexdigest calls on A to reference stored value) then yeah, it should be safe. We just would need to update tests whenever new default comes from Rails.

Copy link
Member

Choose a reason for hiding this comment

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

I haven't found anywhere where we actually try to regenerate and look up any IDs that get created via hexdigest. Rather, we work with the value that's stored in the database.

katello.gemspec Outdated
@@ -63,7 +63,7 @@ Gem::Specification.new do |gem|

# UI
gem.add_dependency "deface", '>= 1.0.2', '< 2.0.0'
gem.add_dependency "angular-rails-templates", "~> 1.1.0"
gem.add_dependency "angular-rails-templates", "~> 1.2.0"
Copy link
Member

Choose a reason for hiding this comment

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

I split this off into #11222.

@ekohl
Copy link
Member

ekohl commented Nov 20, 2024

I see you split off #11226 into a separate PR, which is great. Are you also planning to split of the removal of require statements? I'd think that's also compatible with our current Zeitwerk and that only scopes this PR to the digest changes.

@@ -27,7 +27,7 @@ jobs:
plugin: katello
postgresql_container: ghcr.io/theforeman/postgresql-evr
test_existing_database: false
foreman_version: develop # set to the Foreman release branch after branching :)
foreman_version: refs/pull/10299/head # set to the Foreman release branch after branching :)
Copy link
Member

Choose a reason for hiding this comment

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

Comment reminder to revert this back to develop before merging.

@ekohl
Copy link
Member

ekohl commented Nov 20, 2024

When I locally rebase this I see there are some changes remaining where the template parameter to respond_for_show and respond_for_index is changed into full_template. Why is that change needed?

@parthaa
Copy link
Contributor

parthaa commented Nov 20, 2024

When I locally rebase this I see there are some changes remaining where the template parameter to respond_for_show and respond_for_index is changed into full_template. Why is that change needed?

hmm seems connected to

diff --git a/app/lib/katello/api/v2/rendering.rb b/app/lib/katello/api/v2/rendering.rb
index 653e41a76e..a987e9ebde 100644
--- a/app/lib/katello/api/v2/rendering.rb
+++ b/app/lib/katello/api/v2/rendering.rb
@@ -41,8 +41,9 @@ module Katello
         def respond_with_template(action, resource_name, options = {}, &_block)
           yield if block_given?
           status = options[:status] || 200
+          template = options[:full_template] || "katello/api/v2/#{resource_name}/#{action}"

-          render :template => "katello/api/v2/#{resource_name}/#{action}",
+          render :template => template,
                  :status => status,
                  :locals => options.slice(:object_name, :root_name, :locals),
                  :layout => "katello/api/v2/layouts/#{options[:layout]}"

Guessing relative paths dont work with zeitwerk ?

-      respond_for_show(:resource => host, :template => '../../../api/v2/hosts/show')
+      respond_for_show(:resource => host, :full_template => 'katello/api/v2/hosts/show')

@ofedoren
Copy link
Contributor Author

ofedoren commented Nov 21, 2024

@ekohl, @parthaa, without this change it just stops working on Rails 7. Not sure why, but this change was safe, straightforward and compatible for other places. It just seemed easier to fix it like that than digging to find what change in Rails caused that :/

Copy link
Member

@ianballou ianballou left a comment

Choose a reason for hiding this comment

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

This is looking fine to me, I tested it a bit with theforeman/foreman#10299.
Just don't forget to change the foreman version back to develop for testing!

@ofedoren
Copy link
Contributor Author

Sorry for pushing after approval. I've just rebased both Foreman PR and this one, just to ensure it's still green, so I can drop the last commit to make it ready for merge.

@ofedoren
Copy link
Contributor Author

PR is green after rebase, thus dropped the last commit.

Screenshot_20241126_142427

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants