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 #37145 - Ruby 3 support #10861

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ jobs:
plugin: katello
postgresql_container: ghcr.io/theforeman/postgresql-evr
test_existing_database: false
foreman_version: 'test-dyn'
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ AllCops:
- '**/*.rb'
- app/views/**/*.rabl
- '**/*.rake'
TargetRubyVersion: 2.5
TargetRubyVersion: 2.7

Metrics/MethodLength:
Description: 'Avoid methods longer than 30 lines of code.'
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/katello/capsule_content/sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def plan(smart_proxy, options = {})
if smart_proxy.has_feature?(SmartProxy::PULP3_FEATURE)
plan_action(Actions::Pulp3::ContentGuard::Refresh, smart_proxy)
end
plan_action(SyncCapsule, smart_proxy, refresh_options)
plan_action(SyncCapsule, smart_proxy, **refresh_options)
end
plan_self(smart_proxy_id: smart_proxy.id)
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/katello/capsule_content/sync_capsule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def plan(smart_proxy, options = {})
options[:repository_ids_list] = repos.pluck(:id)
end
if smart_proxy.has_feature?(SmartProxy::PULP3_FEATURE)
plan_action(Actions::Pulp3::Orchestration::Repository::RefreshRepos, smart_proxy, options)
plan_action(Actions::Pulp3::Orchestration::Repository::RefreshRepos, smart_proxy, **options)
end

repos.in_groups_of(Setting[:foreman_proxy_content_batch_size], false) do |repo_batch|
Expand Down
4 changes: 2 additions & 2 deletions app/lib/actions/katello/content_view/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Publish < Actions::EntryAction
def plan(content_view, description = "", options = {importing: false, syncable: false}) # rubocop:disable Metrics/PerceivedComplexity
action_subject(content_view)

content_view.check_ready_to_publish!(options.slice(:importing, :syncable))
content_view.check_ready_to_publish!(**options.slice(:importing, :syncable))
unless options[:importing] || options[:syncable]
::Katello::Util::CandlepinRepositoryChecker.check_repositories_for_publish!(content_view)
end
Expand Down Expand Up @@ -57,7 +57,7 @@ def plan(content_view, description = "", options = {importing: false, syncable:
separated_repo_map = separated_repo_mapping(repository_mapping, content_view.solve_dependencies)

if options[:importing]
handle_import(version, options.slice(:path, :metadata))
handle_import(version, **options.slice(:path, :metadata))
elsif separated_repo_map[:pulp3_yum_multicopy].keys.flatten.present?
plan_action(Repository::MultiCloneToVersion, separated_repo_map[:pulp3_yum_multicopy], version)
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/katello/content_view/remove.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def plan(content_view, options)
concurrence do
all_cv_envs.each do |cv_env|
if cv_env.hosts.any? || cv_env.activation_keys.any?
plan_action(ContentViewEnvironment::ReassignObjects, cv_env, options)
plan_action(ContentViewEnvironment::ReassignObjects, cv_env, **options)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/katello/content_view_version/destroy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def plan(version, options = {})
repos.each do |repo|
repo_options = options.clone
repo_options[:docker_cleanup] = false
plan_action(Repository::Destroy, repo, repo_options)
plan_action(Repository::Destroy, repo, **repo_options)
docker_cleanup ||= repo.docker?
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/katello/content_view_version/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def plan(options)
action_subject(options.fetch(:content_view_version))

sequence do
export_output = plan_action(::Actions::Pulp3::Orchestration::ContentViewVersion::Export, options).output
export_output = plan_action(::Actions::Pulp3::Orchestration::ContentViewVersion::Export, **options).output

plan_self(export_history_id: export_output[:export_history_id],
exported_file_checksum: export_output[:exported_file_checksum],
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/katello/product/destroy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def plan_content_destruction(product, skip_environment_update)
def plan_repo_destruction(product, options)
product.repositories.in_default_view.each do |repo|
repo_options = options.clone
plan_action(Katello::Repository::Destroy, repo, repo_options.merge(destroy_content: false))
plan_action(Katello::Repository::Destroy, repo, **repo_options.merge(destroy_content: false))
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/lib/actions/katello/repository/bulk_metadata_generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module Repository
class BulkMetadataGenerate < Actions::Base
def plan(repos, options = {})
sequence do
plan_action(::Actions::BulkAction, ::Actions::Katello::Repository::MetadataGenerate, repos.in_default_view, options) if repos.in_default_view.any?
plan_action(::Actions::BulkAction, ::Actions::Katello::Repository::MetadataGenerate, repos.archived, options) if repos.archived.any?
plan_action(::Actions::BulkAction, ::Actions::Katello::Repository::MetadataGenerate, repos.in_published_environments, options) if repos.in_published_environments.any?
plan_action(::Actions::BulkAction, ::Actions::Katello::Repository::MetadataGenerate, repos.in_default_view, **options) if repos.in_default_view.any?
plan_action(::Actions::BulkAction, ::Actions::Katello::Repository::MetadataGenerate, repos.archived, **options) if repos.archived.any?
plan_action(::Actions::BulkAction, ::Actions::Katello::Repository::MetadataGenerate, repos.in_published_environments, **options) if repos.in_published_environments.any?
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/lib/actions/katello/repository/clone_contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def plan(source_repositories, new_repository, options)

index_options = {id: new_repository.id, force_index: true}
index_options[:source_repository_id] = source_repositories.first.id if source_repositories.count == 1 && filters.empty? && rpm_filenames.nil?
plan_action(Katello::Repository::IndexContent, index_options)
plan_action(Katello::Repository::IndexContent, **index_options)
end
end

Expand All @@ -38,7 +38,7 @@ def metadata_generate(source_repositories, new_repository, filters, rpm_filename
metadata_options[:source_repository] = source_repositories.first
end

plan_action(Katello::Repository::MetadataGenerate, new_repository, metadata_options)
plan_action(Katello::Repository::MetadataGenerate, new_repository, **metadata_options)
unless source_repositories.first.saved_checksum_type == new_repository.saved_checksum_type
plan_self(:source_checksum_type => source_repositories.first.saved_checksum_type,
:target_repo_id => new_repository.id)
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/katello/repository/import_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def plan(repository, uploads, options = {})
action_class = ::Actions::Pulp3::Orchestration::Repository::ImportUpload
end

import_upload = plan_action(action_class, repository, SmartProxy.pulp_primary, import_upload_args)
import_upload = plan_action(action_class, repository, SmartProxy.pulp_primary, **import_upload_args)
plan_action(FinishUpload, repository, :import_upload_task => import_upload.output,
generate_metadata: false, content_type: options[:content_type])
import_upload.output
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/katello/repository/multi_clone_contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def metadata_generate(source_repositories, new_repository, filters, matching_con
metadata_options[:source_repository] = source_repositories.first
end

plan_action(Katello::Repository::MetadataGenerate, new_repository, metadata_options)
plan_action(Katello::Repository::MetadataGenerate, new_repository, **metadata_options)
unless source_repositories.first.saved_checksum_type == new_repository.saved_checksum_type
plan_self(:source_checksum_type => source_repositories.first.saved_checksum_type,
:target_repo_id => new_repository.id)
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/katello/repository/remove_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def plan(repository, content_units, options = {})
repository.clear_smart_proxy_sync_histories
pulp_action = plan_action(
Pulp3::Orchestration::Repository::RemoveUnits,
repository, SmartProxy.pulp_primary, remove_content_args)
repository, SmartProxy.pulp_primary, **remove_content_args)
return if pulp_action.error
plan_self(:content_unit_class => content_units.first.class.name, :content_unit_ids => content_unit_ids)
plan_action(CapsuleSync, repository) if sync_capsule
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/katello/repository/sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def plan(repo, options = {})
sync_action = plan_action(Actions::Pulp3::Orchestration::Repository::Sync,
repo,
SmartProxy.pulp_primary,
pulp_sync_options)
**pulp_sync_options)
output = sync_action.output

plan_action(Katello::Repository::IndexContent, :id => repo.id, :force_index => skip_metadata_check)
Expand Down
11 changes: 6 additions & 5 deletions app/lib/actions/middleware/backend_services_check.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Actions
module Middleware
class BackendServicesCheck < Dynflow::Middleware
def plan(*args)
def plan(*args, **kwargs)
if Setting[:check_services_before_actions]
#To prevent the ping from happening multiple times, keep track on the initial entry action
#If capsule_id is passed as in args from an action, Katello::Ping checks the pulp server on the capsule
Expand All @@ -10,7 +10,7 @@ def plan(*args)
to_check = services - parent.input[:services_checked]

if to_check.any?
result = User.as_anonymous_admin { ::Katello::Ping.ping(services: to_check, capsule_id: capsule_id(args))[:services] }
result = User.as_anonymous_admin { ::Katello::Ping.ping(services: to_check, capsule_id: capsule_id(args, kwargs))[:services] }

to_check.each do |service|
if result[service][:status] != ::Katello::Ping::OK_RETURN_CODE
Expand All @@ -20,13 +20,14 @@ def plan(*args)
parent.input[:services_checked].concat(to_check)
end
end
pass(*args)
pass(*args, **kwargs)
end

protected

def capsule_id(args)
capsule_id = nil
def capsule_id(args, kwargs)
capsule_id = kwargs[:capsule_id] || kwargs[:smart_proxy_id]
return capsule_id if capsule_id
args.each do |arg|
if arg.is_a? SmartProxy
capsule_id = arg.id
Expand Down
4 changes: 2 additions & 2 deletions app/lib/actions/middleware/remote_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module Middleware
# wraps the plan/run/finalize methods to include the info about the user
# that triggered the action.
class RemoteAction < Dynflow::Middleware
def plan(*args)
def plan(*args, **kwargs)
fail "No current user is set. Please set User.current to perform a remote action" if User.current.nil?
pass(*args).tap do
pass(*args, **kwargs).tap do
action.input[:remote_user] = User.remote_user
action.input[:remote_cp_user] = User.remote_user
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/pulp3/capsule_content/sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def plan(repository, smart_proxy, options = {})
sequence do
sync_task = plan_self(:repository_id => repository.id, :smart_proxy_id => smart_proxy.id, :options => options)
options[:sync_task_output] = sync_task.output[:pulp_tasks]
plan_action(GenerateMetadata, repository, smart_proxy, options)
plan_action(GenerateMetadata, repository, smart_proxy, **options)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Delete < Pulp3::Abstract
def plan(smart_proxy_acs, options = {})
sequence do
plan_action(Actions::Pulp3::AlternateContentSource::Delete, smart_proxy_acs)
plan_action(Actions::Pulp3::AlternateContentSource::DeleteRemote, smart_proxy_acs, options)
plan_action(Actions::Pulp3::AlternateContentSource::DeleteRemote, smart_proxy_acs, **options)
plan_self(smart_proxy_id: smart_proxy_acs.smart_proxy_id, smart_proxy_acs_id: smart_proxy_acs.id)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def plan(repository, smart_proxy, options = {})
if options[:source_repository] && publication_content_type
plan_self(source_repository_id: options[:source_repository].id, target_repository_id: repository.id, smart_proxy_id: smart_proxy.id)
elsif publication_content_type && (force_publication || repository.publication_href.nil? || !repository.using_mirrored_metadata?)
plan_action(Actions::Pulp3::Repository::CreatePublication, repository, smart_proxy, options)
plan_action(Actions::Pulp3::Repository::CreatePublication, repository, smart_proxy, **options)
elsif !publication_content_type
plan_self(target_repository_id: repository.id, contents_changed: options[:contents_changed], skip_publication: true)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def plan(repository, smart_proxy, args)
smart_proxy,
args).output
plan_self(:commit_output => tag_manifest_output[:pulp_tasks])
plan_action(Pulp3::Repository::SaveVersion, repository, {force_fetch_version: true, tasks: tag_manifest_output[:pulp_tasks]})
plan_action(Pulp3::Repository::SaveVersion, repository, force_fetch_version: true, tasks: tag_manifest_output[:pulp_tasks])
else
if content_unit_href
artifact_output = { :content_unit_href => content_unit_href }
Expand All @@ -33,7 +33,7 @@ def plan(repository, smart_proxy, args)
repository,
smart_proxy,
commit_output[:pulp_tasks],
args.dig(:unit_type_id), args).output
args.dig(:unit_type_id), **args).output
end

plan_self(:commit_output => commit_output[:pulp_tasks], :artifact_output => artifact_output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class RemoveUnits < Pulp3::Abstract

def plan(repository, smart_proxy, options)
sequence do
action_output = plan_action(Actions::Pulp3::Repository::RemoveUnits, repository, smart_proxy, options).output
action_output = plan_action(Actions::Pulp3::Repository::RemoveUnits, repository, smart_proxy, **options).output
plan_action(Pulp3::Repository::SaveVersion, repository, tasks: action_output[:pulp_tasks])
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/lib/actions/pulp3/orchestration/repository/sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module Orchestration
module Repository
class Sync < Pulp3::Abstract
include Actions::Helpers::OutputPropagator
def plan(repository, smart_proxy, options)
def plan(repository, smart_proxy, **options)
sequence do
plan_action(Actions::Pulp3::Repository::RefreshRemote, repository, smart_proxy)
action_output = plan_action(Actions::Pulp3::Repository::Sync, repository, smart_proxy, options).output
action_output = plan_action(Actions::Pulp3::Repository::Sync, repository, smart_proxy, **options).output

force_fetch_version = true if options[:optimize] == false
version_output = plan_action(Pulp3::Repository::SaveVersion, repository, tasks: action_output[:pulp_tasks], :force_fetch_version => force_fetch_version).output
Expand Down
12 changes: 6 additions & 6 deletions app/lib/katello/lazy_accessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ def changed_remote_attributes=(val)
@changed_remote_attributes = val
end

def save(*)
if (status = super)
def save(...)
if (status = super(...))
changed_remote_attributes.clear
end
status
end

def save!(*)
super.tap do
def save!(...)
super(...).tap do
changed_remote_attributes.clear
end
end

def reload(*)
super.tap do
def reload(...)
super(...).tap do
changed_remote_attributes.clear
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/services/katello/pulp3/content_view_version/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class Export
FORMATS = [SYNCABLE, IMPORTABLE].freeze

attr_reader :smart_proxy, :content_view_version, :destination_server, :from_content_view_version, :repository, :base_path
def self.create(options)
def self.create(**options)
if options.delete(:format) == SYNCABLE
SyncableFormatExport.new(options)
SyncableFormatExport.new(**options)
else
self.new(options)
self.new(**options)
end
end

Expand Down
2 changes: 2 additions & 0 deletions gemfile.d/test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
group :test do
gem "vcr", "~> 6.1"
gem 'theforeman-rubocop', '~> 0.0.6', require: false
# TODO: Remove it, just to test the changes.
gem 'foreman-tasks', git: 'https://github.com/ofedoren/foreman-tasks.git', branch: 'feat-37103-kwargs-compat'
end
9 changes: 6 additions & 3 deletions katello.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
gem.homepage = "http://www.katello.org"
gem.summary = "Content and Subscription Management plugin for Foreman"
gem.description = "Katello adds Content and Subscription Management to Foreman. For this it relies on Candlepin and Pulp."
gem.required_ruby_version = '~> 2.5'
gem.required_ruby_version = '>= 2.7', '< 3.1'

gem.files = Dir["{app,webpack,vendor,lib,db,ca,config,locale}/**/*"] +
Dir['LICENSE.txt', 'README.md', 'package.json']
Expand All @@ -33,9 +33,9 @@ Gem::Specification.new do |gem|
gem.add_dependency "rest-client"

gem.add_dependency "rabl"
gem.add_dependency "foreman-tasks", ">= 5.0"
gem.add_dependency "foreman-tasks"
gem.add_dependency "foreman_remote_execution", ">= 7.1.0"
gem.add_dependency "dynflow", ">= 1.6.1"
gem.add_dependency "dynflow"
gem.add_dependency "activerecord-import"
gem.add_dependency "stomp"
gem.add_dependency "scoped_search", ">= 4.1.9"
Expand All @@ -49,6 +49,9 @@ Gem::Specification.new do |gem|

# Pulp
gem.add_dependency "anemone"
# required by anemone: https://github.com/chriskite/anemone/blob/next/lib/anemone/page.rb#L3
# webrick is no longer a part of Ruby's stdlib: https://bugs.ruby-lang.org/issues/17303
gem.add_dependency "webrick"

#pulp3
gem.add_dependency "pulpcore_client", ">= 3.39.0", "< 3.40.0"
Expand Down
2 changes: 1 addition & 1 deletion test/actions/katello/activation_key_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CreateTest < TestBase

plan_action action, activation_key, service_level: 'Self-support'

assert_action_planned_with(action, ::Actions::Candlepin::ActivationKey::Create, candlepin_input)
assert_action_planned_with(action, ::Actions::Candlepin::ActivationKey::Create, **candlepin_input)
end

it 'raises error when validation fails' do
Expand Down
2 changes: 1 addition & 1 deletion test/actions/katello/content_view_version/destroy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DestroyTest < ActiveSupport::TestCase
plan_action(action, @version, options)

@version.repositories.each do |repo|
assert_action_planned_with(action, Actions::Katello::Repository::Destroy, repo, options)
assert_action_planned_with(action, Actions::Katello::Repository::Destroy, repo, **options)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/actions/katello/organization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class ManifestImportTest < TestBase
::Actions::Candlepin::Owner::ImportProducts,
organization_id: organization.id
)
assert_action_planned_with(action, ::Actions::Katello::Repository::RefreshRepository) do |args|
assert_action_planned_with(action, ::Actions::Katello::Repository::RefreshRepository) do |*args|
assert args.first.library_instance?
end
end
Expand Down Expand Up @@ -298,7 +298,7 @@ class ManifestDeleteTest < TestBase
::Actions::Candlepin::Owner::DestroyImports,
label: organization.label
)
assert_action_planned_with(action, ::Actions::Katello::Repository::RefreshRepository) do |args|
assert_action_planned_with(action, ::Actions::Katello::Repository::RefreshRepository) do |*args|
assert args.first.library_instance?
end
end
Expand Down
Loading
Loading