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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c036a816a81a10ce427600ce920c1aa98c59bb2c317dcba1662f906941d00e0
4
- data.tar.gz: 3e74db375442e42f0ad7e7f5887d1cd5ab79b311d86c1389f24fb5d168146a70
3
+ metadata.gz: 774254a2eeb7a396c3035410552edc56882d54a1b96a9a800c726f6db96951b8
4
+ data.tar.gz: 53221a9224ebd106fe67d5c2d51f681d601eb1c1f40a50b88b05b900644edb13
5
5
  SHA512:
6
- metadata.gz: 7c68ff530abb93733509feb1201d74c7588b1edc3e90c6caf2fd54fce11aedeb760595c2ce3fcf8f208fe5eafbc7bca00aecec08ee4b28d0b1e438c6b81938d1
7
- data.tar.gz: f1e5baa029323687099e055874464d1710ddbcc8488207fcb64bdc5f5682ff90311c8db6fbf5ce6eb372a4d9eb821df51ac26a5e151bbc6d4551983a896e6f82
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
- drop_otp(username, otp)
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 {} if @continuous_output.empty? && @exit_status.nil?
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
- { @suspended_action => Runner::Update.new(new_data, @exit_status) }
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
- updates = @runner.run_refresh
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(_event)
81
- refresh_runner
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
- begin
122
- raise "Actor with runner id #{runner.id} already exists" if @runner_actors[runner.id]
123
- runner.logger = @logger
124
- runner_actor = RunnerActor.spawn("runner-actor-#{runner.id}", self, suspended_action, runner, @clock, @logger)
125
- @runner_actors[runner.id] = runner_actor
126
- @runner_suspended_actions[runner.id] = suspended_action
127
- runner_actor.tell(:start_runner)
128
- return runner.id
129
- rescue => exception
130
- _handle_command_exception(runner.id, exception)
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
- begin
139
- runner_actor = @runner_actors[runner_id]
140
- runner_actor.tell(:kill) if runner_actor
141
- rescue => exception
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
- begin
150
- _finish(runner_id)
151
- rescue => exception
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
- @outputs.reduce({}) do |acc, (key, value)|
14
- if value.empty? && @exit_status.nil?
15
- acc
16
- else
17
- identifier = key
18
- @outputs[identifier] = ForemanTasksCore::ContinuousOutput.new
19
- key = host_action(identifier) unless identifier == @suspended_action
20
- exit_status = @exit_statuses[identifier] || @exit_status if @exit_status
21
- acc.merge(key => Runner::Update.new(value, exit_status))
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 = ([@suspended_action] + @targets.keys).reduce({}) do |acc, target|
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(data, type)
43
- @outputs[@suspended_action].add_output(data, type)
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
- input.merge('action_input' => input['action_input'].merge('callback' => nil))
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
@@ -1,3 +1,5 @@
1
+ require 'dynflow'
2
+
1
3
  module ForemanTasksCore
2
4
  class Ticker < ::Dynflow::Actor
3
5
  attr_reader :clock
@@ -1,3 +1,3 @@
1
1
  module ForemanTasksCore
2
- VERSION = '0.3.2'.freeze
2
+ VERSION = '0.3.6'.freeze
3
3
  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.2
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: 2019-04-09 00:00:00.000000000 Z
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
- rubyforge_project:
81
- rubygems_version: 2.7.6
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: []