foreman_rh_cloud 7.0.46 → 7.0.47

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: 1383b077fcadc72b19517f0ed1173aec5ac958a207e8b04a6119e91b75b062c0
4
- data.tar.gz: 98783f069cfd8cbc89e2a295b0433437ec3d88b168ccef7c2b7c42b851d07929
3
+ metadata.gz: c5493c69d3f1918da42b12dfc523e6bf387203e1d1cdd057d6bea1e401caeef6
4
+ data.tar.gz: 7413d1788622b27285da6a7257928b57b79bb6de8660ca9f966edcbb4cc7ee00
5
5
  SHA512:
6
- metadata.gz: 711977116c1b74dfd5b528bf7298df5f9c5da3dda6f63a788ed4ea8f82e76b62139d5d4417b4af19ca3e564e0764d99cc38ca30a496b1f78fd170829fef11017
7
- data.tar.gz: 78f1a3584c4eea9f64d49cf4be866cd41074e04264c860d22332205124c312c62372cde26435e1e4bfe7303a7574754cbab3f49e3f1c3a31a6abe65c4363890c
6
+ metadata.gz: bf2220d31d2bc0b41291560ea0f25a8a88c33d73e281915ebe4534bf0a2fbd80be8f815776b38eade95366e92824179519decf91062f607a60c396e03a0387e2
7
+ data.tar.gz: 9d16b6f204bc3585e00b012e0fa47132ae4209fbaa85015c8db99ebce79aac167fa85374423366b2ff4ecd2cb725a20d7a5d52b61873f525b37ea7094e23fc7f
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '7.0.46'.freeze
2
+ VERSION = '7.0.47'.freeze
3
3
  end
@@ -43,7 +43,17 @@ module InsightsCloud
43
43
  end
44
44
 
45
45
  def done?(current_status = invocation_status)
46
- job_invocation.finished? || current_status.map { |_host_id, task_status| task_status['report_done'] }.all?
46
+ ActiveModel::Type::Boolean.new.cast(current_status[:task_state][:task_done_reported])
47
+ end
48
+
49
+ def job_finished?
50
+ job_invocation.finished?
51
+ end
52
+
53
+ def all_hosts_finished?(current_status)
54
+ current_status[:hosts_state].values.all? do |status|
55
+ ActiveModel::Type::Boolean.new.cast(status['report_done'] == true)
56
+ end
47
57
  end
48
58
 
49
59
  # noop, we don't want to do anything when the polling task starts
@@ -95,7 +105,11 @@ module InsightsCloud
95
105
  end
96
106
 
97
107
  def host_status(host)
98
- external_task&.dig('invocation_status', host)
108
+ external_task&.dig('invocation_status', :hosts_state, host)
109
+ end
110
+
111
+ def task_done_state
112
+ ActiveModel::Type::Boolean.new.cast(external_task&.dig('invocation_status', :task_state, :task_done_reported))
99
113
  end
100
114
 
101
115
  def sequence(host)
@@ -111,13 +125,15 @@ module InsightsCloud
111
125
  end
112
126
 
113
127
  def invocation_status
114
- Hash[job_invocation.targeting.hosts.map do |host|
128
+ hosts_state = Hash[job_invocation.targeting.hosts.map do |host|
115
129
  next unless host.insights&.uuid
116
130
  [
117
131
  host.insights.uuid,
118
132
  task_status(job_invocation.sub_task_for_host(host), host.insights.uuid),
119
133
  ]
120
134
  end.compact]
135
+
136
+ {task_state: {task_done_reported: task_done_state}, hosts_state: hosts_state}
121
137
  end
122
138
 
123
139
  def task_status(host_task, host_name)
@@ -128,7 +144,7 @@ module InsightsCloud
128
144
  {
129
145
  'state' => host_task.state,
130
146
  'output' => host_task.main_action.live_output.map { |line| line['output'] }.join("\n"),
131
- 'exit_status' => host_task.main_action.exit_status,
147
+ 'exit_status' => ActiveModel::Type::Integer.new.cast(host_task.main_action.exit_status),
132
148
  'sequence' => sequence(host_name),
133
149
  'report_done' => host_done?(host_name),
134
150
  }
@@ -138,9 +154,9 @@ module InsightsCloud
138
154
  generator = InsightsCloud::Generators::PlaybookProgressGenerator.new(correlation_id)
139
155
  all_hosts_success = true
140
156
 
141
- invocation_status.each do |host_name, status|
157
+ invocation_status[:hosts_state].each do |host_name, status|
142
158
  # skip host if the host already reported that it's finished
143
- next if status['report_done']
159
+ next if ActiveModel::Type::Boolean.new.cast(status['report_done'])
144
160
 
145
161
  unless status['state'] == 'unknown'
146
162
  sequence = status['sequence']
@@ -154,7 +170,11 @@ module InsightsCloud
154
170
  all_hosts_success &&= status['exit_status'] == 0
155
171
  end
156
172
  end
157
- generator.job_finished_message(all_hosts_success) if done?(invocation_status)
173
+
174
+ if (job_finished? || all_hosts_finished?(invocation_status))
175
+ generator.job_finished_message(all_hosts_success)
176
+ invocation_status[:task_state][:task_done_reported] = true
177
+ end
158
178
 
159
179
  send_report(generator.generate)
160
180
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "7.0.46",
3
+ "version": "7.0.47",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -29,7 +29,11 @@ class ConnectorPlaybookExecutionReporterTaskTest < ActiveSupport::TestCase
29
29
  end
30
30
 
31
31
  test 'It reports finish playbook messages' do
32
- TestConnectorPlaybookExecutionReporterTask.any_instance.stubs(:done?).returns(true)
32
+ host1_task = @job_invocation.sub_task_for_host(Host.where(name: 'host1').first)
33
+ host1_task.state = 'stopped'
34
+ host1_task.save!
35
+
36
+ TestConnectorPlaybookExecutionReporterTask.any_instance.stubs(:job_finished?).returns(true)
33
37
 
34
38
  actual = ForemanTasks.sync_task(TestConnectorPlaybookExecutionReporterTask, @job_invocation)
35
39
 
@@ -39,6 +43,13 @@ class ConnectorPlaybookExecutionReporterTaskTest < ActiveSupport::TestCase
39
43
  assert_not_nil actual_report
40
44
  actual_jsonl = read_jsonl(actual_report)
41
45
 
46
+ assert_equal true, actual.output['task']['invocation_status']['task_state']['task_done_reported']
47
+ assert_equal 0, actual.output['task']['invocation_status']['hosts_state']['TEST_UUID1']['exit_status']
48
+ assert_equal 0, actual.output['task']['invocation_status']['hosts_state']['TEST_UUID2']['exit_status']
49
+
50
+ assert_equal true, @job_invocation.finished?
51
+ assert_equal 'stopped', @job_invocation.sub_task_for_host(Host.where(name: 'host1').first)['state']
52
+
42
53
  assert_not_nil actual_report_finished = actual_jsonl.find { |l| l['type'] == 'playbook_run_completed' }
43
54
  assert_equal 'TEST_CORRELATION', actual_report_finished['correlation_id']
44
55
  assert_equal 'success', actual_report_finished['status']
@@ -49,57 +60,127 @@ class ConnectorPlaybookExecutionReporterTaskTest < ActiveSupport::TestCase
49
60
  end
50
61
 
51
62
  test 'It reports single progress message for done host' do
52
- TestConnectorPlaybookExecutionReporterTask.any_instance.stubs(:done?).returns(false, true)
63
+ class ArrangeTestHost < InsightsCloud::Async::ConnectorPlaybookExecutionReporterTask
64
+ def send_report(report)
65
+ host1_task = @job_invocation.sub_task_for_host(Host.where(name: 'host1').first)
66
+ host1_task.state = 'stopped'
67
+ host1_task.save!
68
+
69
+ output[:saved_reports] = (output[:saved_reports] || []) << report
70
+ end
71
+ end
53
72
 
54
- actual = ForemanTasks.sync_task(TestConnectorPlaybookExecutionReporterTask, @job_invocation)
73
+ ArrangeTestHost.instance_variable_set(:@connector_feature_id, nil)
74
+ host1_task = @job_invocation.sub_task_for_host(Host.where(name: 'host1').first)
75
+ host1_task.state = 'running'
76
+ host1_task.save!
55
77
 
56
- actual_report = actual.output[:saved_reports].first.to_s
78
+ ArrangeTestHost.any_instance.stubs(:job_finished?).returns(false, true)
57
79
 
58
- assert_equal 1, actual.output[:saved_reports].size
59
- assert_not_nil actual_report
60
- actual_jsonl = read_jsonl(actual_report)
80
+ actual = ForemanTasks.sync_task(ArrangeTestHost, @job_invocation)
81
+
82
+ actual_report1 = actual.output[:saved_reports].first.to_s
83
+ actual_report2 = actual.output[:saved_reports].second.to_s
84
+
85
+ assert_equal 2, actual.output[:saved_reports].size
86
+ assert_not_nil actual_report1
87
+ assert_not_nil actual_report2
88
+
89
+ actual_json1 = read_jsonl(actual_report1)
90
+ actual_json2 = read_jsonl(actual_report2)
91
+
92
+ assert_equal true, actual.output['task']['invocation_status']['task_state']['task_done_reported']
93
+ assert_equal 0, actual.output['task']['invocation_status']['hosts_state']['TEST_UUID1']['exit_status']
61
94
 
62
- actual_host_updates = actual_jsonl
63
- .select { |l| l['type'] == 'playbook_run_update' && l['host'] == @host1.insights.uuid }
64
- assert_equal 1, actual_host_updates.size
65
- assert_equal 0, actual_host_updates.first['sequence']
95
+ assert_equal 'stopped', @job_invocation.sub_task_for_host(Host.where(name: 'host1').first)['state']
96
+
97
+ assert_not_nil actual_report_updated = actual_json1.find { |l| l['type'] == 'playbook_run_update' && l['host'] == 'TEST_UUID1' }
98
+ assert_equal 'TEST_CORRELATION', actual_report_updated['correlation_id']
99
+ assert_equal 'TEST_UUID1', actual_report_updated['host']
100
+ assert_equal 0, actual_report_updated['sequence']
101
+ assert_equal 6, actual_report_updated.size
102
+
103
+ assert_not_nil actual_report_updated = actual_json2.find { |l| l['type'] == 'playbook_run_update' && l['host'] == 'TEST_UUID1' }
104
+ assert_equal 'TEST_CORRELATION', actual_report_updated['correlation_id']
105
+ assert_equal 'TEST_UUID1', actual_report_updated['host']
106
+ assert_equal 1, actual_report_updated['sequence']
107
+ assert_equal 6, actual_report_updated.size
108
+
109
+ assert_not_nil actual_host_finished = actual_json2.find { |l| l['type'] == 'playbook_run_finished' && l['host'] == 'TEST_UUID1' }
110
+ assert_equal 'TEST_CORRELATION', actual_host_finished['correlation_id']
111
+ assert_equal 'TEST_UUID1', actual_host_finished['host']
112
+ assert_equal 'success', actual_host_finished['status']
113
+ assert_equal 7, actual_host_finished.size
114
+
115
+ assert_not_nil actual_report_finished = actual_json2.find { |l| l['type'] == 'playbook_run_completed' }
116
+ assert_equal 'TEST_CORRELATION', actual_report_finished['correlation_id']
117
+ assert_equal 'success', actual_report_finished['status']
118
+ assert_equal 4, actual_report_finished.size
66
119
  end
67
120
 
68
121
  test 'It reports two progress messages for in progress host' do
69
- TestConnectorPlaybookExecutionReporterTask.any_instance.stubs(:done?).returns(false, false, true)
122
+ class ArrangeTestHostTwo < InsightsCloud::Async::ConnectorPlaybookExecutionReporterTask
123
+ def send_report(report)
124
+ iteration_number = output[:iteration_number].to_i
125
+
126
+ if iteration_number == 1
127
+ host1_task = job_invocation.sub_task_for_host(Host.where(name: 'host1').first)
128
+ host1_task.state = 'stopped'
129
+ host1_task.save!
130
+ end
131
+
132
+ output[:iteration_number] = iteration_number + 1
133
+ output[:saved_reports] = (output[:saved_reports] || []) << report
134
+ end
135
+ end
70
136
 
71
- host1_task = @job_invocation.template_invocations.joins(:host).where(hosts: {name: @host1.name}).first.run_host_job_task
137
+ ArrangeTestHostTwo.instance_variable_set(:@connector_feature_id, nil)
138
+ host1_task = @job_invocation.sub_task_for_host(Host.where(name: 'host1').first)
72
139
  host1_task.state = 'running'
73
140
  host1_task.save!
74
141
 
75
- actual = ForemanTasks.sync_task(TestConnectorPlaybookExecutionReporterTask, @job_invocation)
142
+ ArrangeTestHostTwo.any_instance.stubs(:job_finished?).returns(false, false, true)
76
143
 
77
- assert_equal 2, actual.output[:saved_reports].size
144
+ actual = ForemanTasks.sync_task(ArrangeTestHostTwo, @job_invocation)
145
+
146
+ actual_report1 = actual.output[:saved_reports].first.to_s
147
+ actual_report2 = actual.output[:saved_reports].second.to_s
148
+ actual_report3 = actual.output[:saved_reports].third.to_s
149
+
150
+ assert_equal 3, actual.output[:saved_reports].size
151
+ assert_not_nil actual_report1
152
+ assert_not_nil actual_report2
153
+ assert_not_nil actual_report3
78
154
 
79
- first_report = actual.output[:saved_reports].first.to_s
80
- actual_jsonl = read_jsonl(first_report)
155
+ actual_json1 = read_jsonl(actual_report1)
156
+ actual_json2 = read_jsonl(actual_report2)
157
+ actual_json3 = read_jsonl(actual_report3)
81
158
 
82
- actual_host_updates = actual_jsonl
83
- .select { |l| l['type'] == 'playbook_run_update' && l['host'] == @host1.insights.uuid }
84
- assert_equal 1, actual_host_updates.size
85
- assert_equal 0, actual_host_updates.first['sequence']
159
+ assert_equal true, actual.output['task']['invocation_status']['task_state']['task_done_reported']
160
+ assert_equal 0, actual.output['task']['invocation_status']['hosts_state']['TEST_UUID1']['exit_status']
86
161
 
87
- actual_host_updates = actual_jsonl
88
- .select { |l| l['type'] == 'playbook_run_update' && l['host'] == @host2.insights.uuid }
89
- assert_equal 1, actual_host_updates.size
90
- assert_equal 0, actual_host_updates.first['sequence']
162
+ assert_not_nil actual_report_updated = actual_json1.find { |l| l['type'] == 'playbook_run_update' && l['host'] == 'TEST_UUID1' }
163
+ assert_equal 'TEST_CORRELATION', actual_report_updated['correlation_id']
164
+ assert_equal 'TEST_UUID1', actual_report_updated['host']
165
+ assert_equal 0, actual_report_updated['sequence']
166
+ assert_equal 6, actual_report_updated.size
91
167
 
92
- second_report = actual.output[:saved_reports].last.to_s
93
- actual_jsonl = read_jsonl(second_report)
168
+ assert_not_nil actual_report_updated = actual_json2.find { |l| l['type'] == 'playbook_run_update' && l['host'] == 'TEST_UUID1' }
169
+ assert_equal 'TEST_CORRELATION', actual_report_updated['correlation_id']
170
+ assert_equal 'TEST_UUID1', actual_report_updated['host']
171
+ assert_equal 1, actual_report_updated['sequence']
172
+ assert_equal 6, actual_report_updated.size
94
173
 
95
- actual_host_updates = actual_jsonl
96
- .select { |l| l['type'] == 'playbook_run_update' && l['host'] == @host1.insights.uuid }
97
- assert_equal 1, actual_host_updates.size
98
- assert_equal 1, actual_host_updates.first['sequence']
174
+ assert_not_nil actual_host_finished = actual_json3.find { |l| l['type'] == 'playbook_run_finished' && l['host'] == 'TEST_UUID1' }
175
+ assert_equal 'TEST_CORRELATION', actual_host_finished['correlation_id']
176
+ assert_equal 'TEST_UUID1', actual_host_finished['host']
177
+ assert_equal 'success', actual_host_finished['status']
178
+ assert_equal 7, actual_host_finished.size
99
179
 
100
- actual_host_updates = actual_jsonl
101
- .select { |l| l['type'] == 'playbook_run_update' && l['host'] == @host2.insights.uuid }
102
- assert_equal 0, actual_host_updates.size
180
+ assert_not_nil actual_report_finished = actual_json3.find { |l| l['type'] == 'playbook_run_completed' }
181
+ assert_equal 'TEST_CORRELATION', actual_report_finished['correlation_id']
182
+ assert_equal 'success', actual_report_finished['status']
183
+ assert_equal 4, actual_report_finished.size
103
184
  end
104
185
 
105
186
  private
@@ -164,10 +245,12 @@ class ConnectorPlaybookExecutionReporterTaskTest < ActiveSupport::TestCase
164
245
  :value => '1'
165
246
  )
166
247
 
167
- @host1 = FactoryBot.create(:host, :with_insights_hits, name: 'host1')
248
+ @host1 = FactoryBot.create(:host, :with_insights_hits)
249
+ @host1.name = 'host1' # overriding name since there is an issue with Factorybot and setting the name correctly, same for 2nd host
168
250
  @host1.insights.uuid = 'TEST_UUID1'
169
251
  @host1.insights.save!
170
- @host2 = FactoryBot.create(:host, :with_insights_hits, name: 'host2')
252
+ @host2 = FactoryBot.create(:host, :with_insights_hits)
253
+ @host2.name = 'host2'
171
254
  @host2.insights.uuid = 'TEST_UUID2'
172
255
  @host2.insights.save!
173
256
 
@@ -190,7 +273,7 @@ class ConnectorPlaybookExecutionReporterTaskTest < ActiveSupport::TestCase
190
273
  { 'timestamp' => (Time.now - (5 - i)).to_f, 'output' => "#{i}\n" }
191
274
  end
192
275
  Support::DummyDynflowAction.any_instance.stubs(:live_output).returns(fake_output)
193
- Support::DummyDynflowAction.any_instance.stubs(:exit_status).returns(0)
276
+ Support::DummyDynflowAction.any_instance.stubs(:exit_status).returns("0")
194
277
 
195
278
  job_invocation
196
279
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_rh_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.46
4
+ version: 7.0.47
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Red Hat Cloud team
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-12 00:00:00.000000000 Z
11
+ date: 2023-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katello
@@ -650,7 +650,7 @@ homepage: https://github.com/theforeman/foreman_rh_cloud
650
650
  licenses:
651
651
  - GPL-3.0
652
652
  metadata: {}
653
- post_install_message:
653
+ post_install_message:
654
654
  rdoc_options: []
655
655
  require_paths:
656
656
  - lib
@@ -665,8 +665,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
665
665
  - !ruby/object:Gem::Version
666
666
  version: '0'
667
667
  requirements: []
668
- rubygems_version: 3.3.26
669
- signing_key:
668
+ rubygems_version: 3.3.5
669
+ signing_key:
670
670
  specification_version: 4
671
671
  summary: Summary of ForemanRhCloud.
672
672
  test_files: