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 #37471 - Support Zeitwerk loader #10997

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/helpers/katello/katello_url_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Katello
module KatelloUrlHelper
module KatelloURLHelper
unless defined? CONSTANTS_DEFINED
FILEPREFIX = ['file'].freeze
PROTOCOLS = ['http', 'https', 'ftp', 'uln'].freeze
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def plan(repository, smart_proxy)

def run
repository = ::Katello::Repository.find(input[:repository_id])
ForemanTasks.async_task(::Actions::Pulp3::Repository::UpdateCVRepositoryCertGuard, repository, smart_proxy)
ForemanTasks.async_task(::Actions::Pulp3::Repository::UpdateCvRepositoryCertGuard, repository, smart_proxy)
end

def humanized_name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Actions
module Pulp3
module Repository
class UpdateCVRepositoryCertGuard < Pulp3::Abstract
class UpdateCvRepositoryCertGuard < Pulp3::Abstract
def plan(repository, smart_proxy)
root = repository.root
cv_repositories = root.repositories - [root.library_instance]
Expand Down
7 changes: 0 additions & 7 deletions app/lib/katello/api/constraints/activation_key_constraint.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Katello
module Api
module Constraints
class RegisterWithActivationKeyConstraint
def matches?(request)
request.params[:activation_keys]
end
end
end
end
end
2 changes: 0 additions & 2 deletions app/lib/katello/resources/registry.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'katello/util/data'

module Katello
module Resources
require 'rest_client'
Expand Down
2 changes: 1 addition & 1 deletion app/lib/katello/util/cvecf_migrator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Katello
module Util
class CVECFMigrator # used in db/migrate/20220929204746_add_content_view_environment_content_facet.rb
class CvecfMigrator # used in db/migrate/20220929204746_add_content_view_environment_content_facet.rb
def execute!
hosts_with_no_cve = []
hosts_with_missing_cve = []
Expand Down
6 changes: 3 additions & 3 deletions app/lib/katello/util/url_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
#
# ===== Examples
#
# UrlMatcher.match('/foo', ['/', '/foo', '/bar/baz']) #=> ['/foo']
# UrlMatcher.match('/80/07/01', ['/:year/:month/:day']) #=> ['/80/07/01', '80', '07', '01']
# URLMatcher.match('/foo', ['/', '/foo', '/bar/baz']) #=> ['/foo']
# URLMatcher.match('/80/07/01', ['/:year/:month/:day']) #=> ['/80/07/01', '80', '07', '01']
#

require 'pathname'

module Katello
module Util
module UrlMatcher
module URLMatcher
def self.match(path, routes)
path = Path.new(path)
patterns = routes.map { |route| Pattern.new(Array(route).first) }
Expand Down
4 changes: 2 additions & 2 deletions app/lib/katello/validators/katello_url_format_validator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Katello
module Validators
class KatelloUrlFormatValidator < ActiveModel::EachValidator
include KatelloUrlHelper
class KatelloURLFormatValidator < ActiveModel::EachValidator
include KatelloURLHelper

def validate_each(record, attribute, value)
if options[:nil_allowed]
Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/cdn_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CdnConfiguration < Katello::Model
validates :upstream_organization_label, presence: true, if: :network_sync?

validates :url, presence: true, unless: :export_sync?
validates_with Validators::KatelloUrlFormatValidator, attributes: :url, unless: :export_sync?
validates_with Validators::KatelloURLFormatValidator, attributes: :url, unless: :export_sync?
validates_with Validators::KatelloLabelFormatValidator, attributes: :upstream_organization_label, if: proc { upstream_organization_label.present? }
validate :non_redhat_configuration, if: :network_sync?

Expand Down
1 change: 0 additions & 1 deletion app/models/katello/concerns/smart_proxy_extensions.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'proxy_api'
require 'proxy_api/pulp'
require 'proxy_api/pulp_node'
require 'proxy_api/container_gateway'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def run
private

def deliver_failure_notification
::Katello::UINotifications::ContentView::DelelteLatestVersionFailure.deliver!(content_view)
::Katello::UINotifications::ContentView::DeleteLatestVersionFailure.deliver!(content_view)
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions app/models/katello/host/info_provider.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'host_info'

module Katello
module Host
class InfoProvider < ::HostInfo::Provider
Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/root_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class RootRepository < Katello::Model
validates_lengths_from_database :except => [:label]
validates_with Validators::KatelloLabelFormatValidator, :attributes => :label
validates_with Validators::KatelloNameFormatValidator, :attributes => :name
validates_with Validators::KatelloUrlFormatValidator, :attributes => :url,
validates_with Validators::KatelloURLFormatValidator, :attributes => :url,
:nil_allowed => proc { |repo| repo.custom? || repo.organization.cdn_configuration.export_sync? },
:field_name => :url
validates_with Validators::RootRepositoryUniqueAttributeValidator, :attributes => :name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Katello
module UINotifications
module ContentView
class DelelteLatestVersionFailure < ::UINotifications::Base
class DeleteLatestVersionFailure < ::UINotifications::Base
private

def create
Expand Down
8 changes: 8 additions & 0 deletions config/initializers/inflections.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Be sure to restart your server when you modify this file.
Rails.autoloaders.each do |autoloader|
autoloader.inflector.inflect(
'kt_environment' => 'KTEnvironment',
'cdn' => 'CDN'
)
end

# Add new inflection rules using the following format
# (all these examples are active by default):
Expand All @@ -9,4 +15,6 @@
# inflect.uncountable %w(fish sheep)

inflect.singular 'bases', 'base'

inflect.acronym 'SCA' # Simple Content Access
end
2 changes: 0 additions & 2 deletions config/routes/api/registry.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'katello/api/mapper_extensions'

class ActionDispatch::Routing::Mapper
include Katello::Routing::MapperExtensions
end
Expand Down
5 changes: 1 addition & 4 deletions config/routes/api/rhsm.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'katello/api/constraints/activation_key_constraint'
require 'katello/api/mapper_extensions'

class ActionDispatch::Routing::Mapper
include Katello::Routing::MapperExtensions
end
Expand All @@ -11,7 +8,7 @@ class ActionDispatch::Routing::Mapper

scope :path => :rhsm, :module => :rhsm, :as => :rhsm do
# subscription-manager support
scope :constraints => Katello::RegisterWithActivationKeyConstraint.new do
scope :constraints => Katello::Api::Constraints::RegisterWithActivationKeyConstraint.new do
match '/consumers' => 'candlepin_proxies#consumer_activate', :via => :post
end
match '/consumers' => 'candlepin_proxies#consumer_create', :via => :post
Expand Down
3 changes: 0 additions & 3 deletions config/routes/api/v2.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'katello/api/constraints/activation_key_constraint'
require 'katello/api/mapper_extensions'

class ActionDispatch::Routing::Mapper
include Katello::Routing::MapperExtensions
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20140716211853_repo_rename_feed_to_url.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class RepoRenameFeedToUrl < ActiveRecord::Migration[4.2]
class RepoRenameFeedToURL < ActiveRecord::Migration[4.2]
def up
rename_column :katello_repositories, :feed, :url
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddDockerContainerRegistryUrlToProviders < ActiveRecord::Migration[4.2]
class AddDockerContainerRegistryURLToProviders < ActiveRecord::Migration[4.2]
def up
add_column :katello_providers, :docker_registry_url, :string, :limit => 255
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20150224083608_remove_docker_registry_url.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class RemoveDockerRegistryUrl < ActiveRecord::Migration[4.2]
class RemoveDockerRegistryURL < ActiveRecord::Migration[4.2]
def up
remove_column :katello_providers, :docker_registry_url
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddAuthUrlTokenToRootRepositories < ActiveRecord::Migration[6.0]
class AddAuthURLTokenToRootRepositories < ActiveRecord::Migration[6.0]
def change
add_column :katello_root_repositories, :ansible_collection_auth_url, :text
add_column :katello_root_repositories, :ansible_collection_auth_token, :text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def up
t.references :content_view_environment, :null => false, :index => false, :foreign_key => { :to_table => 'katello_content_view_environments' }
t.references :content_facet, :null => false, :index => false, :foreign_key => { :to_table => 'katello_content_facets' }
end
::Katello::Util::CVECFMigrator.new.execute!
::Katello::Util::CvecfMigrator.new.execute!
FakeContentFacet.all.each do |content_facet|
cve_id = ::Katello::KTEnvironment.find(content_facet.lifecycle_environment_id)
.content_view_environments
Expand Down
22 changes: 12 additions & 10 deletions lib/katello/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ class Engine < ::Rails::Engine

# make sure the Katello plugin is initialized before `after_initialize`
# hook so that the resumed Dynflow tasks can rely on everything ready.
initializer 'katello.register_plugin', :before => :finisher_hook, :after => 'foreman_remote_execution.register_plugin' do
::Foreman::AccessControl::Permission.prepend ::Katello::Concerns::PermissionExtensions
require 'katello/plugin'
initializer 'katello.register_plugin', :before => :finisher_hook, :after => 'foreman_remote_execution.register_plugin' do |app|
app.reloader.to_prepare do
::Foreman::AccessControl::Permission.prepend ::Katello::Concerns::PermissionExtensions
require 'katello/plugin'

# extend builtin permissions from core with new actions
require 'katello/permissions'
# extend builtin permissions from core with new actions
require 'katello/permissions'
end
end

initializer "katello.set_dynflow_middlewares", :before => :finisher_hook do |_app|
Expand Down Expand Up @@ -185,11 +187,11 @@ class Engine < ::Rails::Engine
# We need to explicitly load this files because Foreman has
# similar strucuture and if the Foreman files are loaded first,
# autoloading doesn't work.
require_dependency "#{Katello::Engine.root}/app/lib/katello/api/v2/rendering"
require_dependency "#{Katello::Engine.root}/app/controllers/katello/api/api_controller"
require_dependency "#{Katello::Engine.root}/app/controllers/katello/api/v2/api_controller"
require_dependency "#{Katello::Engine.root}/app/services/katello/proxy_status/pulp"
require_dependency "#{Katello::Engine.root}/app/services/katello/proxy_status/pulp_node"
# require_dependency "#{Katello::Engine.root}/app/lib/katello/api/v2/rendering"
# require_dependency "#{Katello::Engine.root}/app/controllers/katello/api/api_controller"
# require_dependency "#{Katello::Engine.root}/app/controllers/katello/api/v2/api_controller"
# require_dependency "#{Katello::Engine.root}/app/services/katello/proxy_status/pulp"
# require_dependency "#{Katello::Engine.root}/app/services/katello/proxy_status/pulp_node"

#Api controller extensions
::Api::V2::HostsController.include Katello::Concerns::Api::V2::HostsControllerExtensions
Expand Down
3 changes: 1 addition & 2 deletions lib/katello/plugin.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
require 'katello/permission_creator'
require 'katello/repository_types'
require 'katello/host_status_manager'
# rubocop:disable Metrics/BlockLength

Foreman::Plugin.register :katello do
requires_foreman '>= 3.11'
requires_foreman '>= 3.13'
register_gettext

sub_menu :top_menu, :content_menu, :caption => N_('Content'),
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/katello_url_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'katello_test_helper'

module Katello
describe KatelloUrlHelper do
describe KatelloURLHelper do
describe "Valid https? Urls" do
it "should validate clean http urls" do
assert kurl_valid?('http://www.hugheshoney.com')
Expand Down
12 changes: 6 additions & 6 deletions spec/lib/url_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@
require 'katello/util/url_matcher'

module Katello
describe Util::UrlMatcher do
describe Util::URLMatcher do
it "should accept empty string and array" do
m = Util::UrlMatcher.match('', [])
m = Util::URLMatcher.match('', [])
value(m[0]).must_be_nil
value(m.size).must_equal(1)
end

it "should not match different paths" do
m = Util::UrlMatcher.match('/asdf', ['/abcd'])
m = Util::URLMatcher.match('/asdf', ['/abcd'])
value(m[0]).must_be_nil
value(m.size).must_equal(1)
end

it "should accept /" do
m = Util::UrlMatcher.match('/', ['/'])
m = Util::URLMatcher.match('/', ['/'])
value(m[0]).must_match('/')
value(m.size).must_equal(1)
end

it "should accept /x/y/z" do
m = Util::UrlMatcher.match('/80/01/15', ['/:year/:month/:day'])
m = Util::URLMatcher.match('/80/01/15', ['/:year/:month/:day'])
value(m[0]).must_match('/:year/:month/:day')
value(m[1]).must_match('80')
value(m[2]).must_match('01')
value(m[3]).must_match('15')
end

it "should match first always" do
m = Util::UrlMatcher.match('/80/01/15', ['/:a/:b/:c', '/:year/:month/:day'])
m = Util::URLMatcher.match('/80/01/15', ['/:a/:b/:c', '/:year/:month/:day'])
value(m[0]).must_match('/:a/:b/:c')
value(m[1]).must_match('80')
value(m[2]).must_match('01')
Expand Down
48 changes: 48 additions & 0 deletions test/models/association_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,58 @@ def ignorable_foreign_keys
}
end

# After we enabled eager loading in tests for Zeitwerk, Katello::Model.subclasses call started to return
# more models than we tested before. We need to ignore some of them to avoid false positives.
# Ideally this list should not exist. TODO: go over these models and ensure that they don't need the tests below
# or fix them.
def self.ignorable_models
[
"Katello::AlternateContentSourceProduct",
"Katello::CapsuleLifecycleEnvironment",
"Katello::ComplianceReason",
"Katello::ContentFacetApplicableDeb",
"Katello::ContentFacetApplicableRpm",
"Katello::ContentFacetRepository",
"Katello::ContentMigrationProgress",
"Katello::ContentViewDebFilterRule",
"Katello::ContentViewVersionComponent",
"Katello::DockerManifestListManifest",
"Katello::DockerMetaTag",
"Katello::EnvironmentPrior",
"Katello::ErratumBugzilla",
"Katello::Event",
"Katello::HostInstalledDeb",
"Katello::HostInstalledPackage",
"Katello::HostQueueElement",
"Katello::HostTracer",
"Katello::InstalledPackage",
"Katello::InstalledProduct",
"Katello::KeyHostCollection",
"Katello::ModuleStreamErratumPackage",
"Katello::ModuleStreamRpm",
"Katello::PoolActivationKey",
"Katello::Pulp3::ContentGuard",
"Katello::Pulp3::DistributionReference",
"Katello::Pulp3::RepositoryReference",
"Katello::RepositoryContentViewFilter",
"Katello::RepositoryDockerManifestList",
"Katello::RepositoryDockerMetaTag",
"Katello::RepositoryDockerTag",
"Katello::RepositoryFileUnit",
"Katello::RepositoryGenericContentUnit",
"Katello::SmartProxyAlternateContentSource",
"Katello::SmartProxySyncHistory",
"Katello::SubscriptionFacetActivationKey",
"Katello::SubscriptionFacetInstalledProduct",
"Katello::SubscriptionFacetPurposeAddon"
]
end

Katello::Model.subclasses.each do |model|
next unless model.table_name&.starts_with?('katello_')
next if model.ancestors.include? Facets::Base
next if model.ancestors.include? Facets::HostgroupFacet
next if self.ignorable_models.include?(model.to_s)

describe model do
model.reflect_on_all_associations(:belongs_to).each do |association|
Expand Down
4 changes: 2 additions & 2 deletions test/models/katello/alternate_content_source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ def test_http_proxy
def test_custom_uln_base_url
@yum_acs.base_url = 'uln://uln-repo'
error = assert_raises(ActiveRecord::RecordInvalid) { @yum_acs.save! }
assert_match 'Validation failed: Base url uln://uln-repo is not a valid path', error.message
assert_match 'Validation failed: Base URL uln://uln-repo is not a valid path', error.message
end

def test_custom_missing_base_url
@yum_acs.base_url = nil
error = assert_raises(ActiveRecord::RecordInvalid) { @yum_acs.save! }
assert_match "Base url can\'t be blank", error.message
assert_match "Base URL can\'t be blank", error.message
end

def test_custom_missing_verify_ssl
Expand Down
Loading