foreman_rh_cloud 8.0.48 → 8.0.49

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: e5aaa9176ddc41ce5b0d3877b0f84d4da1e7646095d9552c0b4e2c268d6cff2b
4
- data.tar.gz: 323a006184c5e0f989ef81ac8a010a2e493eb8cd69dc35b93ecb30a2e807dcec
3
+ metadata.gz: 0cedd47c0a845f1b043329ed3c2487bb781d7807667e8c1608c0f7204f0734ff
4
+ data.tar.gz: 3ac8c4184db82abea338841e9783181acfdb5c75dd9ee2bca4bf2dcc401ef5a0
5
5
  SHA512:
6
- metadata.gz: 4758b21705294f7bc5628878fbcf101e081f7a662426fb50501ad9909b09d7c33959ec316e3b790f248587a0ba85933782c5822c70fe9ec434ab57f070b0b0ca
7
- data.tar.gz: e67bebbc9e8d478fa32778037d1fd4172b8633ff0c845bda2fa554c9e51cc74f94eca21ded5b9c7826a0622aa2842908e5abf70f1ffe2472fdecb6c6cf2f7d11
6
+ metadata.gz: b5e70d7b496792133a6d32ae8daeb2016b884eed3167936f0bd60e45146a36ee57201f61136c8440d4a992b7a7e7cc60a0cfca8ae9f703431ebc0f58fb44507a
7
+ data.tar.gz: 15c2c3df4d42ba65f84aabcb5875534a3e07f5dd1e684ed21574c5d5103639ee9fda51e62f45c53b52ffba92ca9e16b04a1eb3b40894c850921e78fc0e959ef3
@@ -147,7 +147,7 @@ module ForemanInventoryUpload
147
147
  @stream.array_field('installed_packages') do
148
148
  first = true
149
149
  host.installed_packages.each do |package|
150
- @stream.raw("#{first ? '' : ', '}#{@stream.stringify_value(package.nvra)}")
150
+ @stream.raw("#{first ? '' : ', '}#{@stream.stringify_value(package.nvrea)}")
151
151
  first = false
152
152
  end
153
153
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '8.0.48'.freeze
2
+ VERSION = '8.0.49'.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)
@@ -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": "8.0.48",
3
+ "version": "8.0.49",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -27,6 +27,7 @@
27
27
  "@theforeman/test": ">= 10.1.1",
28
28
  "@theforeman/eslint-plugin-foreman": ">= 10.1.1",
29
29
  "babel-eslint": "~10.0.0",
30
+ "cosmiconfig-typescript-loader": "~4.3.0",
30
31
  "eslint": "~6.7.2",
31
32
  "eslint-plugin-spellcheck": "~0.0.17",
32
33
  "jed": "~1.1.1",
@@ -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,9 @@ 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, @job_invocation.finished?
47
+ assert_equal 'stopped', @job_invocation.sub_task_for_host(Host.where(name: 'host1').first)['state']
48
+
42
49
  assert_not_nil actual_report_finished = actual_jsonl.find { |l| l['type'] == 'playbook_run_completed' }
43
50
  assert_equal 'TEST_CORRELATION', actual_report_finished['correlation_id']
44
51
  assert_equal 'success', actual_report_finished['status']
@@ -49,57 +56,121 @@ class ConnectorPlaybookExecutionReporterTaskTest < ActiveSupport::TestCase
49
56
  end
50
57
 
51
58
  test 'It reports single progress message for done host' do
52
- TestConnectorPlaybookExecutionReporterTask.any_instance.stubs(:done?).returns(false, true)
59
+ class ArrangeTestHost < InsightsCloud::Async::ConnectorPlaybookExecutionReporterTask
60
+ def send_report(report)
61
+ host1_task = @job_invocation.sub_task_for_host(Host.where(name: 'host1').first)
62
+ host1_task.state = 'stopped'
63
+ host1_task.save!
64
+
65
+ output[:saved_reports] = (output[:saved_reports] || []) << report
66
+ end
67
+ end
53
68
 
54
- actual = ForemanTasks.sync_task(TestConnectorPlaybookExecutionReporterTask, @job_invocation)
69
+ ArrangeTestHost.instance_variable_set(:@connector_feature_id, nil)
70
+ host1_task = @job_invocation.sub_task_for_host(Host.where(name: 'host1').first)
71
+ host1_task.state = 'running'
72
+ host1_task.save!
55
73
 
56
- actual_report = actual.output[:saved_reports].first.to_s
74
+ ArrangeTestHost.any_instance.stubs(:job_finished?).returns(false, true)
57
75
 
58
- assert_equal 1, actual.output[:saved_reports].size
59
- assert_not_nil actual_report
60
- actual_jsonl = read_jsonl(actual_report)
76
+ actual = ForemanTasks.sync_task(ArrangeTestHost, @job_invocation)
77
+
78
+ actual_report1 = actual.output[:saved_reports].first.to_s
79
+ actual_report2 = actual.output[:saved_reports].second.to_s
80
+
81
+ assert_equal 2, actual.output[:saved_reports].size
82
+ assert_not_nil actual_report1
83
+ assert_not_nil actual_report2
84
+
85
+ actual_json1 = read_jsonl(actual_report1)
86
+ actual_json2 = read_jsonl(actual_report2)
87
+
88
+ assert_equal 'stopped', @job_invocation.sub_task_for_host(Host.where(name: 'host1').first)['state']
61
89
 
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']
90
+ assert_not_nil actual_report_updated = actual_json1.find { |l| l['type'] == 'playbook_run_update' && l['host'] == 'TEST_UUID1' }
91
+ assert_equal 'TEST_CORRELATION', actual_report_updated['correlation_id']
92
+ assert_equal 'TEST_UUID1', actual_report_updated['host']
93
+ assert_equal 0, actual_report_updated['sequence']
94
+ assert_equal 6, actual_report_updated.size
95
+
96
+ assert_not_nil actual_report_updated = actual_json2.find { |l| l['type'] == 'playbook_run_update' && l['host'] == 'TEST_UUID1' }
97
+ assert_equal 'TEST_CORRELATION', actual_report_updated['correlation_id']
98
+ assert_equal 'TEST_UUID1', actual_report_updated['host']
99
+ assert_equal 1, actual_report_updated['sequence']
100
+ assert_equal 6, actual_report_updated.size
101
+
102
+ assert_not_nil actual_host_finished = actual_json2.find { |l| l['type'] == 'playbook_run_finished' && l['host'] == 'TEST_UUID1' }
103
+ assert_equal 'TEST_CORRELATION', actual_host_finished['correlation_id']
104
+ assert_equal 'TEST_UUID1', actual_host_finished['host']
105
+ assert_equal 'success', actual_host_finished['status']
106
+ assert_equal 7, actual_host_finished.size
107
+
108
+ assert_not_nil actual_report_finished = actual_json2.find { |l| l['type'] == 'playbook_run_completed' }
109
+ assert_equal 'TEST_CORRELATION', actual_report_finished['correlation_id']
110
+ assert_equal 'success', actual_report_finished['status']
111
+ assert_equal 4, actual_report_finished.size
66
112
  end
67
113
 
68
114
  test 'It reports two progress messages for in progress host' do
69
- TestConnectorPlaybookExecutionReporterTask.any_instance.stubs(:done?).returns(false, false, true)
115
+ class ArrangeTestHostTwo < InsightsCloud::Async::ConnectorPlaybookExecutionReporterTask
116
+ def send_report(report)
117
+ iteration_number = output[:iteration_number].to_i
118
+
119
+ if iteration_number == 1
120
+ host1_task = job_invocation.sub_task_for_host(Host.where(name: 'host1').first)
121
+ host1_task.state = 'stopped'
122
+ host1_task.save!
123
+ end
124
+
125
+ output[:iteration_number] = iteration_number + 1
126
+ output[:saved_reports] = (output[:saved_reports] || []) << report
127
+ end
128
+ end
70
129
 
71
- host1_task = @job_invocation.template_invocations.joins(:host).where(hosts: {name: @host1.name}).first.run_host_job_task
130
+ ArrangeTestHostTwo.instance_variable_set(:@connector_feature_id, nil)
131
+ host1_task = @job_invocation.sub_task_for_host(Host.where(name: 'host1').first)
72
132
  host1_task.state = 'running'
73
133
  host1_task.save!
74
134
 
75
- actual = ForemanTasks.sync_task(TestConnectorPlaybookExecutionReporterTask, @job_invocation)
135
+ ArrangeTestHostTwo.any_instance.stubs(:job_finished?).returns(false, false, true)
76
136
 
77
- assert_equal 2, actual.output[:saved_reports].size
137
+ actual = ForemanTasks.sync_task(ArrangeTestHostTwo, @job_invocation)
78
138
 
79
- first_report = actual.output[:saved_reports].first.to_s
80
- actual_jsonl = read_jsonl(first_report)
139
+ actual_report1 = actual.output[:saved_reports].first.to_s
140
+ actual_report2 = actual.output[:saved_reports].second.to_s
141
+ actual_report3 = actual.output[:saved_reports].third.to_s
81
142
 
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']
143
+ assert_equal 3, actual.output[:saved_reports].size
144
+ assert_not_nil actual_report1
145
+ assert_not_nil actual_report2
146
+ assert_not_nil actual_report3
86
147
 
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']
148
+ actual_json1 = read_jsonl(actual_report1)
149
+ actual_json2 = read_jsonl(actual_report2)
150
+ actual_json3 = read_jsonl(actual_report3)
91
151
 
92
- second_report = actual.output[:saved_reports].last.to_s
93
- actual_jsonl = read_jsonl(second_report)
152
+ assert_not_nil actual_report_updated = actual_json1.find { |l| l['type'] == 'playbook_run_update' && l['host'] == 'TEST_UUID1' }
153
+ assert_equal 'TEST_CORRELATION', actual_report_updated['correlation_id']
154
+ assert_equal 'TEST_UUID1', actual_report_updated['host']
155
+ assert_equal 0, actual_report_updated['sequence']
156
+ assert_equal 6, actual_report_updated.size
94
157
 
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']
158
+ assert_not_nil actual_report_updated = actual_json2.find { |l| l['type'] == 'playbook_run_update' && l['host'] == 'TEST_UUID1' }
159
+ assert_equal 'TEST_CORRELATION', actual_report_updated['correlation_id']
160
+ assert_equal 'TEST_UUID1', actual_report_updated['host']
161
+ assert_equal 1, actual_report_updated['sequence']
162
+ assert_equal 6, actual_report_updated.size
99
163
 
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
164
+ assert_not_nil actual_host_finished = actual_json3.find { |l| l['type'] == 'playbook_run_finished' && l['host'] == 'TEST_UUID1' }
165
+ assert_equal 'TEST_CORRELATION', actual_host_finished['correlation_id']
166
+ assert_equal 'TEST_UUID1', actual_host_finished['host']
167
+ assert_equal 'success', actual_host_finished['status']
168
+ assert_equal 7, actual_host_finished.size
169
+
170
+ assert_not_nil actual_report_finished = actual_json3.find { |l| l['type'] == 'playbook_run_completed' }
171
+ assert_equal 'TEST_CORRELATION', actual_report_finished['correlation_id']
172
+ assert_equal 'success', actual_report_finished['status']
173
+ assert_equal 4, actual_report_finished.size
103
174
  end
104
175
 
105
176
  private
@@ -164,10 +235,12 @@ class ConnectorPlaybookExecutionReporterTaskTest < ActiveSupport::TestCase
164
235
  :value => '1'
165
236
  )
166
237
 
167
- @host1 = FactoryBot.create(:host, :with_insights_hits, name: 'host1')
238
+ @host1 = FactoryBot.create(:host, :with_insights_hits)
239
+ @host1.name = 'host1' # overriding name since there is an issue with Factorybot and setting the name correctly, same for 2nd host
168
240
  @host1.insights.uuid = 'TEST_UUID1'
169
241
  @host1.insights.save!
170
- @host2 = FactoryBot.create(:host, :with_insights_hits, name: 'host2')
242
+ @host2 = FactoryBot.create(:host, :with_insights_hits)
243
+ @host2.name = 'host2'
171
244
  @host2.insights.uuid = 'TEST_UUID2'
172
245
  @host2.insights.save!
173
246
 
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: 8.0.48
4
+ version: 8.0.49
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Red Hat Cloud team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-02 00:00:00.000000000 Z
11
+ date: 2023-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katello