/
sync.rb
95 lines (82 loc) · 4.65 KB
/
sync.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# rubocop:disable HandleExceptions
module Actions
module Katello
module Repository
class Sync < Actions::EntryAction
include Helpers::Presenter
middleware.use Actions::Middleware::KeepCurrentUser
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
# clear yum metadata if validate_contents is on (to avoid metadata corruption issues)
plan_action(Pulp::Repository::RemoveYumMetadataFile, :pulp_id => repo.pulp_id) if validate_contents
sync_args = {:pulp_id => repo.pulp_id, :task_id => pulp_sync_task_id, :source_url => source_url, :options => pulp_sync_options}
output = plan_action(Pulp::Repository::Sync, sync_args).output
contents_changed = skip_metadata_check || output[:contents_changed]
plan_action(Katello::Repository::IndexContent, :id => repo.id, :contents_changed => contents_changed, :full_index => skip_metadata_check)
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, :pulp_id => repo.pulp_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]))
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
Helpers::Presenter::Delegated.new(self, planned_actions(Pulp::Repository::Sync))
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