foreman-tasks-core 0.3.2 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/foreman_tasks_core/otp_manager.rb +7 -2
- data/lib/foreman_tasks_core/runner/base.rb +17 -2
- data/lib/foreman_tasks_core/runner/dispatcher.rb +25 -29
- data/lib/foreman_tasks_core/runner/parent.rb +12 -14
- data/lib/foreman_tasks_core/task_launcher/group.rb +2 -1
- data/lib/foreman_tasks_core/ticker.rb +2 -0
- data/lib/foreman_tasks_core/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 774254a2eeb7a396c3035410552edc56882d54a1b96a9a800c726f6db96951b8
|
4
|
+
data.tar.gz: 53221a9224ebd106fe67d5c2d51f681d601eb1c1f40a50b88b05b900644edb13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 186a69b1cae292b820cf97834139ad447b0a8dc75376b2fe9cd1b7c2f70e48b63504e5a2589b2e483cbc7021f18ece002e8995fe80f3892b4b44174a2cbb4999
|
7
|
+
data.tar.gz: 7d9f89140bfe0000b59c42704ed3b5fb16f5645b5bd5ecb95e0aa446c34b93678a575390cdabdd6afe29bf22edfa8f226d3f1810a8f0a928d22f434562abd44c
|
@@ -17,10 +17,15 @@ module ForemanTasksCore
|
|
17
17
|
@password ||= {}
|
18
18
|
end
|
19
19
|
|
20
|
-
def authenticate(hash)
|
20
|
+
def authenticate(hash, expected_user: nil, clear: true)
|
21
21
|
plain = Base64.decode64(hash)
|
22
22
|
username, otp = plain.split(':', 2)
|
23
|
-
|
23
|
+
if expected_user
|
24
|
+
return false unless expected_user == username
|
25
|
+
end
|
26
|
+
password_matches = passwords[username] == otp
|
27
|
+
passwords.delete(username) if clear && password_matches
|
28
|
+
password_matches
|
24
29
|
end
|
25
30
|
|
26
31
|
def tokenize(username, password)
|
@@ -22,6 +22,13 @@ module ForemanTasksCore
|
|
22
22
|
generate_updates
|
23
23
|
end
|
24
24
|
|
25
|
+
# by default, external event just causes the refresh to be triggered: this allows the descendants
|
26
|
+
# of the Base to add custom logic to process the external events.
|
27
|
+
# Similarly as `run_refresh`, it's expected to return updates to be dispatched.
|
28
|
+
def external_event(_event)
|
29
|
+
run_refresh
|
30
|
+
end
|
31
|
+
|
25
32
|
def start
|
26
33
|
raise NotImplementedError
|
27
34
|
end
|
@@ -69,10 +76,18 @@ module ForemanTasksCore
|
|
69
76
|
end
|
70
77
|
|
71
78
|
def generate_updates
|
72
|
-
return
|
79
|
+
return no_update if @continuous_output.empty? && @exit_status.nil?
|
73
80
|
new_data = @continuous_output
|
74
81
|
@continuous_output = ForemanTasksCore::ContinuousOutput.new
|
75
|
-
|
82
|
+
new_update(new_data, @exit_status)
|
83
|
+
end
|
84
|
+
|
85
|
+
def no_update
|
86
|
+
{}
|
87
|
+
end
|
88
|
+
|
89
|
+
def new_update(data, exit_status)
|
90
|
+
{ @suspended_action => Runner::Update.new(data, exit_status) }
|
76
91
|
end
|
77
92
|
|
78
93
|
def initialize_continuous_outputs
|
@@ -37,17 +37,19 @@ module ForemanTasksCore
|
|
37
37
|
|
38
38
|
def refresh_runner
|
39
39
|
@logger.debug("refresh runner #{@runner.id}")
|
40
|
-
|
40
|
+
dispatch_updates(@runner.run_refresh)
|
41
|
+
ensure
|
42
|
+
@refresh_planned = false
|
43
|
+
plan_next_refresh
|
44
|
+
end
|
41
45
|
|
46
|
+
def dispatch_updates(updates)
|
42
47
|
updates.each { |receiver, update| (receiver || @suspended_action) << update }
|
43
48
|
|
44
49
|
# This is a workaround when the runner does not accept the suspended action
|
45
50
|
main_key = updates.keys.any?(&:nil?) ? nil : @suspended_action
|
46
51
|
main_process = updates[main_key]
|
47
52
|
finish if main_process && main_process.exit_status
|
48
|
-
ensure
|
49
|
-
@refresh_planned = false
|
50
|
-
plan_next_refresh
|
51
53
|
end
|
52
54
|
|
53
55
|
def timeout_runner
|
@@ -77,8 +79,8 @@ module ForemanTasksCore
|
|
77
79
|
finish_termination
|
78
80
|
end
|
79
81
|
|
80
|
-
def external_event(
|
81
|
-
|
82
|
+
def external_event(event)
|
83
|
+
dispatch_updates(@runner.external_event(event))
|
82
84
|
end
|
83
85
|
|
84
86
|
private
|
@@ -118,39 +120,33 @@ module ForemanTasksCore
|
|
118
120
|
|
119
121
|
def start(suspended_action, runner)
|
120
122
|
synchronize do
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
return nil
|
132
|
-
end
|
123
|
+
raise "Actor with runner id #{runner.id} already exists" if @runner_actors[runner.id]
|
124
|
+
runner.logger = @logger
|
125
|
+
runner_actor = RunnerActor.spawn("runner-actor-#{runner.id}", self, suspended_action, runner, @clock, @logger)
|
126
|
+
@runner_actors[runner.id] = runner_actor
|
127
|
+
@runner_suspended_actions[runner.id] = suspended_action
|
128
|
+
runner_actor.tell(:start_runner)
|
129
|
+
return runner.id
|
130
|
+
rescue => exception
|
131
|
+
_handle_command_exception(runner.id, exception)
|
132
|
+
return nil
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
136
|
def kill(runner_id)
|
137
137
|
synchronize do
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
_handle_command_exception(runner_id, exception, false)
|
143
|
-
end
|
138
|
+
runner_actor = @runner_actors[runner_id]
|
139
|
+
runner_actor.tell(:kill) if runner_actor
|
140
|
+
rescue => exception
|
141
|
+
_handle_command_exception(runner_id, exception, false)
|
144
142
|
end
|
145
143
|
end
|
146
144
|
|
147
145
|
def finish(runner_id)
|
148
146
|
synchronize do
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
_handle_command_exception(runner_id, exception, false)
|
153
|
-
end
|
147
|
+
_finish(runner_id)
|
148
|
+
rescue => exception
|
149
|
+
_handle_command_exception(runner_id, exception, false)
|
154
150
|
end
|
155
151
|
end
|
156
152
|
|
@@ -10,21 +10,19 @@ module ForemanTasksCore
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def generate_updates
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
13
|
+
base = {}
|
14
|
+
base[@suspended_action] = Runner::Update.new(ForemanTasksCore::ContinuousOutput.new, @exit_status) if @exit_status
|
15
|
+
# Operate on all hosts if the main process ended or only on hosts for which we have updates
|
16
|
+
@outputs.reject { |_, output| @exit_status.nil? && output.empty? }
|
17
|
+
.reduce(base) do |acc, (identifier, output)|
|
18
|
+
@outputs[identifier] = ForemanTasksCore::ContinuousOutput.new # Create a new ContinuousOutput for next round of updates
|
19
|
+
exit_status = @exit_statuses[identifier] || @exit_status if @exit_status
|
20
|
+
acc.merge(host_action(identifier) => Runner::Update.new(output, exit_status))
|
21
|
+
end
|
24
22
|
end
|
25
23
|
|
26
24
|
def initialize_continuous_outputs
|
27
|
-
@outputs =
|
25
|
+
@outputs = @targets.keys.reduce({}) do |acc, target|
|
28
26
|
acc.merge(target => ForemanTasksCore::ContinuousOutput.new)
|
29
27
|
end
|
30
28
|
end
|
@@ -39,8 +37,8 @@ module ForemanTasksCore
|
|
39
37
|
@outputs.each { |_k, output| output.add_output(data, type) }
|
40
38
|
end
|
41
39
|
|
42
|
-
def publish_data(
|
43
|
-
|
40
|
+
def publish_data(_data, _type)
|
41
|
+
true
|
44
42
|
end
|
45
43
|
|
46
44
|
def publish_data_for(identifier, data, type)
|
@@ -40,7 +40,8 @@ module ForemanTasksCore
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def wipe_callback(input)
|
43
|
-
|
43
|
+
callback = input['action_input']['callback']
|
44
|
+
input.merge('action_input' => input['action_input'].merge('callback' => nil, :task_id => callback['task_id']))
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman-tasks-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Nečas
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dynflow
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
version: 1.2.0
|
27
27
|
description: 'Common code used both at Forman and Foreman proxy regarding tasks
|
28
28
|
|
29
|
-
'
|
29
|
+
'
|
30
30
|
email:
|
31
31
|
- inecas@redhat.com
|
32
32
|
executables: []
|
@@ -60,9 +60,10 @@ files:
|
|
60
60
|
- lib/foreman_tasks_core/ticker.rb
|
61
61
|
- lib/foreman_tasks_core/version.rb
|
62
62
|
homepage: https://github.com/theforeman/foreman-tasks
|
63
|
-
licenses:
|
63
|
+
licenses:
|
64
|
+
- GPL-3.0
|
64
65
|
metadata: {}
|
65
|
-
post_install_message:
|
66
|
+
post_install_message:
|
66
67
|
rdoc_options: []
|
67
68
|
require_paths:
|
68
69
|
- lib
|
@@ -77,9 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
78
|
- !ruby/object:Gem::Version
|
78
79
|
version: '0'
|
79
80
|
requirements: []
|
80
|
-
|
81
|
-
|
82
|
-
signing_key:
|
81
|
+
rubygems_version: 3.1.2
|
82
|
+
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: Common code used both at Forman and Foreman proxy regarding tasks
|
85
85
|
test_files: []
|