# rubocop:disable HandleExceptions module Actions module Katello module Repository class Sync < Actions::EntryAction include Helpers::Presenter include Actions::Katello::PulpSelector middleware.use Actions::Middleware::ExecuteIfContentsChanged input_format do param :id, Integer param :sync_result, Hash end # @param repo # @param pulp_sync_task_id in case the sync was triggered outside # of Katello and we just need to finish the rest of the orchestration # rubocop:disable MethodLength # rubocop:disable CyclomaticComplexity def plan(repo, _pulp_sync_task_id = nil, options = {}) action_subject(repo) source_url = options.fetch(:source_url, nil) incremental = options.fetch(:incremental, false) validate_contents = options.fetch(:validate_contents, false) skip_metadata_check = options.fetch(:skip_metadata_check, false) || validate_contents generate_applicability = repo.yum? pulp_sync_options = {} pulp_sync_options[:download_policy] = ::Runcible::Models::YumImporter::DOWNLOAD_ON_DEMAND if validate_contents pulp_sync_options[:force_full] = true if skip_metadata_check pulp_sync_options[:remove_missing] = false if incremental fail ::Katello::Errors::InvalidActionOptionError, _("Unable to sync repo. This repository does not have a feed url.") if repo.url.blank? && source_url.blank? fail ::Katello::Errors::InvalidActionOptionError, _("Cannot validate contents on non-yum repositories.") if validate_contents && !repo.yum? fail ::Katello::Errors::InvalidActionOptionError, _("Cannot skip metadata check on non-yum repositories.") if skip_metadata_check && !repo.yum? sequence do plan_action(Pulp::Repository::RemoveUnits, :repo_id => repo.id, :content_unit_type => ::Katello::YumMetadataFile::CONTENT_TYPE) if validate_contents sync_args = {:smart_proxy_id => SmartProxy.pulp_master.id, :repo_id => repo.id, :source_url => source_url, :options => pulp_sync_options} sync_action = plan_pulp_action([Actions::Pulp::Orchestration::Repository::Sync, Actions::Pulp3::Orchestration::Repository::Sync], repo, SmartProxy.pulp_master, sync_args) output = sync_action.output contents_changed = skip_metadata_check || output[:contents_changed] plan_action(Katello::Repository::IndexContent, :id => repo.id, :contents_changed => contents_changed) plan_action(Katello::Foreman::ContentUpdate, repo.environment, repo.content_view, repo) plan_action(Katello::Repository::FetchPxeFiles, :id => repo.id) plan_action(Katello::Repository::CorrectChecksum, repo) concurrence do plan_action(Pulp::Repository::Download, :pulp_id => repo.pulp_id, :options => {:verify_all_units => true}) if validate_contents plan_action(Katello::Repository::MetadataGenerate, repo, :force => true) if skip_metadata_check plan_action(Katello::Repository::ErrataMail, repo, nil, contents_changed) plan_action(Pulp::Repository::RegenerateApplicability, :repository_id => repo.id, :contents_changed => contents_changed) if generate_applicability end plan_self(:id => repo.id, :sync_result => output, :skip_metadata_check => skip_metadata_check, :validate_contents => validate_contents, :contents_changed => contents_changed) plan_action(Katello::Repository::ImportApplicability, :repo_id => repo.id, :contents_changed => contents_changed) if generate_applicability plan_action(Katello::Repository::SyncHook, :id => repo.id) end end def run ForemanTasks.async_task(Repository::CapsuleSync, ::Katello::Repository.find(input[:id])) if Setting[:foreman_proxy_content_auto_sync] rescue ::Katello::Errors::CapsuleCannotBeReached # skip any capsules that cannot be connected to end def humanized_name if input && input[:validate_contents] _("Synchronize: Validate Content") elsif input && input[:skip_metadata_check] _("Synchronize: Skip Metadata Check") else _("Synchronize") end end def presenter found = all_planned_actions(Pulp::Repository::Sync) found = all_planned_actions(Pulp3::Repository::Sync) if found.empty? Helpers::Presenter::Delegated.new(self, found) end def pulp_task_id pulp_action = planned_actions(Pulp::Repository::Sync).first if (pulp_task = Array(pulp_action.external_task).first) pulp_task.fetch(:task_id) end end def rescue_strategy Dynflow::Action::Rescue::Skip end end end end end