foreman_rh_cloud 5.0.32 → 5.0.35
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/api/v2/rh_cloud/cloud_request_controller.rb +83 -0
- data/app/controllers/foreman_inventory_upload/uploads_controller.rb +7 -0
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +13 -2
- data/app/controllers/insights_cloud/hits_controller.rb +8 -1
- data/app/models/setting/rh_cloud.rb +2 -1
- data/app/services/foreman_rh_cloud/cloud_connector.rb +1 -1
- data/app/services/foreman_rh_cloud/cloud_presence.rb +124 -0
- data/app/services/foreman_rh_cloud/cloud_request.rb +8 -1
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +16 -5
- data/app/services/foreman_rh_cloud/hit_remediations_retriever.rb +67 -0
- data/app/services/foreman_rh_cloud/remediations_retriever.rb +16 -45
- data/app/services/foreman_rh_cloud/template_renderer_helper.rb +13 -1
- data/app/services/foreman_rh_cloud/url_remediations_retriever.rb +37 -0
- data/app/views/job_templates/cloud_connector.erb +30 -0
- data/app/views/job_templates/rh_cloud_download_playbook.erb +26 -0
- data/config/routes.rb +2 -0
- data/lib/foreman_rh_cloud/engine.rb +33 -12
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/foreman_rh_cloud.rb +4 -0
- data/lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb +193 -0
- data/lib/insights_cloud/async/insights_scheduled_sync.rb +4 -0
- data/lib/insights_cloud/generators/playbook_progress_generator.rb +49 -0
- data/lib/tasks/insights.rake +13 -0
- data/package.json +1 -1
- data/test/controllers/insights_cloud/api/cloud_request_controller_test.rb +78 -0
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +16 -0
- data/test/jobs/connector_playbook_execution_reporter_task_test.rb +207 -0
- data/test/unit/playbook_progress_generator_test.rb +75 -0
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +13 -8
- data/test/unit/services/foreman_rh_cloud/{remediations_retriever_test.rb → hit_remediations_retriever_test.rb} +3 -3
- data/test/unit/services/foreman_rh_cloud/url_remediations_retriever_test.rb +27 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +6 -11
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js +22 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationActions.js +6 -1
- data/webpack/InsightsHostDetailsTab/InsightsTotalRiskChart.js +3 -2
- metadata +20 -4
@@ -0,0 +1,207 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'test_plugin_helper'
|
3
|
+
require 'foreman_tasks/test_helpers'
|
4
|
+
require "#{ForemanTasks::Engine.root}/test/support/dummy_dynflow_action"
|
5
|
+
|
6
|
+
class ConnectorPlaybookExecutionReporterTaskTest < ActiveSupport::TestCase
|
7
|
+
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
8
|
+
|
9
|
+
# override default send behavior for the test
|
10
|
+
class TestConnectorPlaybookExecutionReporterTask < InsightsCloud::Async::ConnectorPlaybookExecutionReporterTask
|
11
|
+
def send_report(report)
|
12
|
+
output[:saved_reports] = (output[:saved_reports] || []) << report
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
setup do
|
17
|
+
feature = RemoteExecutionFeature.register(
|
18
|
+
:rh_cloud_connector_run_playbook,
|
19
|
+
N_('Run RH Cloud playbook'),
|
20
|
+
description: N_('Run playbook genrated by Red Hat remediations app'),
|
21
|
+
host_action_button: false,
|
22
|
+
provided_inputs: ['playbook_url', 'report_url', 'correlation_id', 'report_interval']
|
23
|
+
)
|
24
|
+
|
25
|
+
puts "REX Register: #{feature.id}"
|
26
|
+
|
27
|
+
@job_invocation = generate_job_invocation
|
28
|
+
|
29
|
+
# reset connector feature ID cache
|
30
|
+
TestConnectorPlaybookExecutionReporterTask.instance_variable_set(:@connector_feature_id, nil)
|
31
|
+
|
32
|
+
puts RemoteExecutionFeature.all.to_a
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'It reports finish playbook messages' do
|
36
|
+
TestConnectorPlaybookExecutionReporterTask.any_instance.stubs(:done?).returns(true)
|
37
|
+
|
38
|
+
actual = ForemanTasks.sync_task(TestConnectorPlaybookExecutionReporterTask, @job_invocation)
|
39
|
+
|
40
|
+
actual_report = actual.output[:saved_reports].first.to_s
|
41
|
+
|
42
|
+
assert_equal 1, actual.output[:saved_reports].size
|
43
|
+
assert_not_nil actual_report
|
44
|
+
actual_jsonl = read_jsonl(actual_report)
|
45
|
+
|
46
|
+
assert_not_nil actual_report_finished = actual_jsonl.find { |l| l['type'] == 'playbook_run_completed' }
|
47
|
+
assert_equal 'TEST_CORRELATION', actual_report_finished['correlation_id']
|
48
|
+
assert_equal 'success', actual_report_finished['status']
|
49
|
+
|
50
|
+
assert_not_nil actual_host_finished = actual_jsonl.find { |l| l['type'] == 'playbook_run_finished' && l['host'] == @host1.insights.uuid }
|
51
|
+
assert_equal 'TEST_CORRELATION', actual_host_finished['correlation_id']
|
52
|
+
assert_equal 'success', actual_host_finished['status']
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'It reports single progress message for done host' do
|
56
|
+
TestConnectorPlaybookExecutionReporterTask.any_instance.stubs(:done?).returns(false, true)
|
57
|
+
|
58
|
+
actual = ForemanTasks.sync_task(TestConnectorPlaybookExecutionReporterTask, @job_invocation)
|
59
|
+
|
60
|
+
actual_report = actual.output[:saved_reports].first.to_s
|
61
|
+
|
62
|
+
assert_equal 1, actual.output[:saved_reports].size
|
63
|
+
assert_not_nil actual_report
|
64
|
+
actual_jsonl = read_jsonl(actual_report)
|
65
|
+
|
66
|
+
actual_host_updates = actual_jsonl
|
67
|
+
.select { |l| l['type'] == 'playbook_run_update' && l['host'] == @host1.insights.uuid }
|
68
|
+
assert_equal 1, actual_host_updates.size
|
69
|
+
assert_equal 0, actual_host_updates.first['sequence']
|
70
|
+
end
|
71
|
+
|
72
|
+
test 'It reports two progress messages for in progress host' do
|
73
|
+
TestConnectorPlaybookExecutionReporterTask.any_instance.stubs(:done?).returns(false, false, true)
|
74
|
+
|
75
|
+
host1_task = @job_invocation.template_invocations.joins(:host).where(hosts: {name: @host1.name}).first.run_host_job_task
|
76
|
+
host1_task.state = 'running'
|
77
|
+
host1_task.save!
|
78
|
+
|
79
|
+
actual = ForemanTasks.sync_task(TestConnectorPlaybookExecutionReporterTask, @job_invocation)
|
80
|
+
|
81
|
+
assert_equal 2, actual.output[:saved_reports].size
|
82
|
+
|
83
|
+
first_report = actual.output[:saved_reports].first.to_s
|
84
|
+
actual_jsonl = read_jsonl(first_report)
|
85
|
+
|
86
|
+
actual_host_updates = actual_jsonl
|
87
|
+
.select { |l| l['type'] == 'playbook_run_update' && l['host'] == @host1.insights.uuid }
|
88
|
+
assert_equal 1, actual_host_updates.size
|
89
|
+
assert_equal 0, actual_host_updates.first['sequence']
|
90
|
+
|
91
|
+
actual_host_updates = actual_jsonl
|
92
|
+
.select { |l| l['type'] == 'playbook_run_update' && l['host'] == @host2.insights.uuid }
|
93
|
+
assert_equal 1, actual_host_updates.size
|
94
|
+
assert_equal 0, actual_host_updates.first['sequence']
|
95
|
+
|
96
|
+
second_report = actual.output[:saved_reports].last.to_s
|
97
|
+
actual_jsonl = read_jsonl(second_report)
|
98
|
+
|
99
|
+
actual_host_updates = actual_jsonl
|
100
|
+
.select { |l| l['type'] == 'playbook_run_update' && l['host'] == @host1.insights.uuid }
|
101
|
+
assert_equal 1, actual_host_updates.size
|
102
|
+
assert_equal 1, actual_host_updates.first['sequence']
|
103
|
+
|
104
|
+
actual_host_updates = actual_jsonl
|
105
|
+
.select { |l| l['type'] == 'playbook_run_update' && l['host'] == @host2.insights.uuid }
|
106
|
+
assert_equal 0, actual_host_updates.size
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def generate_job_invocation
|
112
|
+
job_template = FactoryBot.build(
|
113
|
+
:job_template,
|
114
|
+
:template => 'BLEH'
|
115
|
+
)
|
116
|
+
feature = RemoteExecutionFeature.feature!(:rh_cloud_connector_run_playbook).id
|
117
|
+
|
118
|
+
puts "Generated feature: #{feature}"
|
119
|
+
|
120
|
+
job_invocation = FactoryBot.create(
|
121
|
+
:job_invocation,
|
122
|
+
remote_execution_feature_id: feature,
|
123
|
+
task_id: FactoryBot.create(:dynflow_task).id
|
124
|
+
)
|
125
|
+
|
126
|
+
job_template.template_inputs << playbook_url_input = FactoryBot.build(:template_input,
|
127
|
+
:name => 'playbook_url',
|
128
|
+
:input_type => 'user',
|
129
|
+
:required => true)
|
130
|
+
job_template.template_inputs << report_url_input = FactoryBot.build(:template_input,
|
131
|
+
:name => 'report_url',
|
132
|
+
:input_type => 'user',
|
133
|
+
:required => true)
|
134
|
+
job_template.template_inputs << correlation_id_input = FactoryBot.build(:template_input,
|
135
|
+
:name => 'correlation_id',
|
136
|
+
:input_type => 'user',
|
137
|
+
:required => true)
|
138
|
+
job_template.template_inputs << report_interval_input = FactoryBot.build(:template_input,
|
139
|
+
:name => 'report_interval',
|
140
|
+
:input_type => 'user',
|
141
|
+
:required => true)
|
142
|
+
|
143
|
+
template_invocation = FactoryBot.build(:template_invocation,
|
144
|
+
:template => job_template,
|
145
|
+
:job_invocation => job_invocation
|
146
|
+
)
|
147
|
+
|
148
|
+
template_invocation.input_values << FactoryBot.create(
|
149
|
+
:template_invocation_input_value,
|
150
|
+
:template_invocation => template_invocation,
|
151
|
+
:template_input => playbook_url_input,
|
152
|
+
:value => 'http://example.com/TEST_PLAYBOOK'
|
153
|
+
)
|
154
|
+
template_invocation.input_values << FactoryBot.create(
|
155
|
+
:template_invocation_input_value,
|
156
|
+
:template_invocation => template_invocation,
|
157
|
+
:template_input => report_url_input,
|
158
|
+
:value => 'http://example.com/TEST_REPORT'
|
159
|
+
)
|
160
|
+
template_invocation.input_values << FactoryBot.create(
|
161
|
+
:template_invocation_input_value,
|
162
|
+
:template_invocation => template_invocation,
|
163
|
+
:template_input => correlation_id_input,
|
164
|
+
:value => 'TEST_CORRELATION'
|
165
|
+
)
|
166
|
+
template_invocation.input_values << FactoryBot.create(
|
167
|
+
:template_invocation_input_value,
|
168
|
+
:template_invocation => template_invocation,
|
169
|
+
:template_input => report_interval_input,
|
170
|
+
:value => '1'
|
171
|
+
)
|
172
|
+
|
173
|
+
@host1 = FactoryBot.create(:host, :with_insights_hits, name: 'host1')
|
174
|
+
@host1.insights.uuid = 'TEST_UUID1'
|
175
|
+
@host1.insights.save!
|
176
|
+
@host2 = FactoryBot.create(:host, :with_insights_hits, name: 'host2')
|
177
|
+
@host2.insights.uuid = 'TEST_UUID2'
|
178
|
+
@host2.insights.save!
|
179
|
+
|
180
|
+
targeting = FactoryBot.create(:targeting, hosts: [@host1, @host2])
|
181
|
+
job_invocation.targeting = targeting
|
182
|
+
job_invocation.save!
|
183
|
+
|
184
|
+
job_invocation.template_invocations << FactoryBot.create(
|
185
|
+
:template_invocation,
|
186
|
+
run_host_job_task: FactoryBot.create(:dynflow_task),
|
187
|
+
host_id: @host1.id
|
188
|
+
)
|
189
|
+
job_invocation.template_invocations << FactoryBot.create(
|
190
|
+
:template_invocation,
|
191
|
+
run_host_job_task: FactoryBot.create(:dynflow_task),
|
192
|
+
host_id: @host2.id
|
193
|
+
)
|
194
|
+
|
195
|
+
fake_output = (1..5).map do |i|
|
196
|
+
{ 'timestamp' => (Time.now - (5 - i)).to_f, 'output' => "#{i}\n" }
|
197
|
+
end
|
198
|
+
Support::DummyDynflowAction.any_instance.stubs(:live_output).returns(fake_output)
|
199
|
+
Support::DummyDynflowAction.any_instance.stubs(:exit_status).returns(0)
|
200
|
+
|
201
|
+
job_invocation
|
202
|
+
end
|
203
|
+
|
204
|
+
def read_jsonl(jsonl)
|
205
|
+
jsonl.lines.map { |l| JSON.parse(l) }
|
206
|
+
end
|
207
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class PlaybookProgressGeneratorTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@correlation_id = 'CORRELATION_ID'
|
6
|
+
@generator = InsightsCloud::Generators::PlaybookProgressGenerator.new(@correlation_id)
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'Outputs host progress message' do
|
10
|
+
@generator.host_progress_message('test_host', 'test_output', 0)
|
11
|
+
|
12
|
+
actual = @generator.generate
|
13
|
+
actual_message = JSON.parse(actual)
|
14
|
+
|
15
|
+
assert_equal "playbook_run_update", actual_message["type"]
|
16
|
+
assert_equal 3, actual_message["version"]
|
17
|
+
assert_equal @correlation_id, actual_message["correlation_id"]
|
18
|
+
assert_equal 0, actual_message["sequence"]
|
19
|
+
assert_equal 'test_host', actual_message["host"]
|
20
|
+
assert_equal 'test_output', actual_message["console"]
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'Outputs host finished with error message' do
|
24
|
+
@generator.host_finished_message('test_host', 100)
|
25
|
+
|
26
|
+
actual = @generator.generate
|
27
|
+
actual_message = JSON.parse(actual)
|
28
|
+
|
29
|
+
assert_equal "playbook_run_finished", actual_message["type"]
|
30
|
+
assert_equal 3, actual_message["version"]
|
31
|
+
assert_equal @correlation_id, actual_message["correlation_id"]
|
32
|
+
assert_equal 'test_host', actual_message["host"]
|
33
|
+
assert_equal 'failure', actual_message["status"]
|
34
|
+
assert_equal 0, actual_message["connection_code"]
|
35
|
+
assert_equal 100, actual_message["execution_code"]
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'Outputs host finished successfully message' do
|
39
|
+
@generator.host_finished_message('test_host', 0)
|
40
|
+
|
41
|
+
actual = @generator.generate
|
42
|
+
actual_message = JSON.parse(actual)
|
43
|
+
|
44
|
+
assert_equal "playbook_run_finished", actual_message["type"]
|
45
|
+
assert_equal 3, actual_message["version"]
|
46
|
+
assert_equal @correlation_id, actual_message["correlation_id"]
|
47
|
+
assert_equal 'test_host', actual_message["host"]
|
48
|
+
assert_equal 'success', actual_message["status"]
|
49
|
+
assert_equal 0, actual_message["connection_code"]
|
50
|
+
assert_equal 0, actual_message["execution_code"]
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'Outputs job finished message' do
|
54
|
+
@generator.job_finished_message
|
55
|
+
|
56
|
+
actual = @generator.generate
|
57
|
+
actual_message = JSON.parse(actual)
|
58
|
+
|
59
|
+
assert_equal "playbook_run_completed", actual_message["type"]
|
60
|
+
assert_equal 3, actual_message["version"]
|
61
|
+
assert_equal @correlation_id, actual_message["correlation_id"]
|
62
|
+
assert_equal "success", actual_message["status"]
|
63
|
+
end
|
64
|
+
|
65
|
+
test 'Outputs a valid JSONL format' do
|
66
|
+
@generator.host_finished_message('test_host1', 0)
|
67
|
+
@generator.host_finished_message('test_host2', 0)
|
68
|
+
|
69
|
+
actual = @generator.generate.lines
|
70
|
+
actual_message1 = JSON.parse(actual[0])
|
71
|
+
assert_equal 'test_host1', actual_message1['host']
|
72
|
+
actual_message2 = JSON.parse(actual[1])
|
73
|
+
assert_equal 'test_host2', actual_message2['host']
|
74
|
+
end
|
75
|
+
end
|
@@ -6,18 +6,23 @@ class CloudRequestForwarderTest < ActiveSupport::TestCase
|
|
6
6
|
|
7
7
|
setup do
|
8
8
|
@forwarder = ::ForemanRhCloud::CloudRequestForwarder.new
|
9
|
+
|
10
|
+
ForemanRhCloud.stubs(:base_url).returns('https://cloud.example.com')
|
11
|
+
ForemanRhCloud.stubs(:cert_base_url).returns('https://cert.cloud.example.com')
|
12
|
+
ForemanRhCloud.stubs(:legacy_insights_url).returns('https://cert-api.access.example.com')
|
13
|
+
ForemanRhCloud.stubs(:authentication_url).returns('https://sso.example.com/auth/realms/redhat-external/protocol/openid-connect/token')
|
9
14
|
end
|
10
15
|
|
11
16
|
test 'should prepare correct cloud url' do
|
12
17
|
paths = {
|
13
|
-
"/redhat_access/r/insights/platform/module-update-router/v1/channel?module=insights-core" => "https://cert.cloud.
|
14
|
-
"/redhat_access/r/insights/v1/static/release/insights-core.egg" => "https://cert-api.access.
|
15
|
-
"/redhat_access/r/insights/v1/static/uploader.v2.json" => "https://cert-api.access.
|
16
|
-
"/redhat_access/r/insights/v1/static/uploader.v2.json.asc" => "https://cert-api.access.
|
17
|
-
"/redhat_access/r/insights/platform/inventory/v1/hosts" => "https://cert.cloud.
|
18
|
-
"/redhat_access/r/insights/platform/ingress/v1/upload" => "https://cert.cloud.
|
19
|
-
"/redhat_access/r/insights/uploads/67200803-132b-474b-a6f9-37be74185df4" => "https://cert-api.access.
|
20
|
-
"/redhat_access/r/insights/" => "https://cert.cloud.
|
18
|
+
"/redhat_access/r/insights/platform/module-update-router/v1/channel?module=insights-core" => "https://cert.cloud.example.com/api/module-update-router/v1/channel?module=insights-core",
|
19
|
+
"/redhat_access/r/insights/v1/static/release/insights-core.egg" => "https://cert-api.access.example.com/r/insights/v1/static/release/insights-core.egg",
|
20
|
+
"/redhat_access/r/insights/v1/static/uploader.v2.json" => "https://cert-api.access.example.com/r/insights/v1/static/uploader.v2.json",
|
21
|
+
"/redhat_access/r/insights/v1/static/uploader.v2.json.asc" => "https://cert-api.access.example.com/r/insights/v1/static/uploader.v2.json.asc",
|
22
|
+
"/redhat_access/r/insights/platform/inventory/v1/hosts" => "https://cert.cloud.example.com/api/inventory/v1/hosts",
|
23
|
+
"/redhat_access/r/insights/platform/ingress/v1/upload" => "https://cert.cloud.example.com/api/ingress/v1/upload",
|
24
|
+
"/redhat_access/r/insights/uploads/67200803-132b-474b-a6f9-37be74185df4" => "https://cert-api.access.example.com/r/insights/uploads/67200803-132b-474b-a6f9-37be74185df4",
|
25
|
+
"/redhat_access/r/insights/" => "https://cert.cloud.example.com/api/apicast-tests/ping",
|
21
26
|
}
|
22
27
|
|
23
28
|
paths.each do |key, value|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_plugin_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class HitRemediationsRetrieverTest < ActiveSupport::TestCase
|
4
4
|
setup do
|
5
5
|
@host1 = FactoryBot.create(:host)
|
6
6
|
@host2 = FactoryBot.create(:host)
|
@@ -16,7 +16,7 @@ class RemediationsRetrieverTest < ActiveSupport::TestCase
|
|
16
16
|
host2_hit1 = FactoryBot.create(:insights_hit, rule_id: rule1.rule_id, host_id: @host2.id)
|
17
17
|
|
18
18
|
pairs = [{'hit_id' => host1_hit1.id, 'resolution_id' => rule1_remediation1.id}, {'hit_id' => host2_hit1.id, 'resolution_id' => rule1_remediation1.id}]
|
19
|
-
retriever = ForemanRhCloud::
|
19
|
+
retriever = ForemanRhCloud::HitRemediationsRetriever.new(pairs)
|
20
20
|
|
21
21
|
actual_request = retriever.send(:playbook_request)
|
22
22
|
|
@@ -39,7 +39,7 @@ class RemediationsRetrieverTest < ActiveSupport::TestCase
|
|
39
39
|
host2_hit1 = FactoryBot.create(:insights_hit, rule_id: rule1.rule_id, host_id: @host2.id)
|
40
40
|
|
41
41
|
pairs = [{'hit_id' => host1_hit1.id, 'resolution_id' => rule1_remediation1.id}, {'hit_id' => host2_hit1.id, 'resolution_id' => rule1_remediation2.id}]
|
42
|
-
retriever = ForemanRhCloud::
|
42
|
+
retriever = ForemanRhCloud::HitRemediationsRetriever.new(pairs)
|
43
43
|
|
44
44
|
actual_request = retriever.send(:playbook_request)
|
45
45
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class UrlRemediationsRetrieverTest < ActiveSupport::TestCase
|
4
|
+
test 'Calls the given url' do
|
5
|
+
Setting[:rh_cloud_token] = 'TEST_TOKEN'
|
6
|
+
retreiver = ForemanRhCloud::UrlRemediationsRetriever.new(
|
7
|
+
url: 'http://test.example.com',
|
8
|
+
payload: 'TEST_PAYLOAD',
|
9
|
+
headers: {
|
10
|
+
custom1: 'TEST_HEADER',
|
11
|
+
}
|
12
|
+
)
|
13
|
+
|
14
|
+
response = mock('response')
|
15
|
+
response.stubs(:body).returns('TEST_RESPONSE')
|
16
|
+
retreiver.expects(:execute_cloud_request).with do |params|
|
17
|
+
params[:method] == :get &&
|
18
|
+
params[:url] == 'http://test.example.com' &&
|
19
|
+
params[:headers][:custom1] == 'TEST_HEADER' &&
|
20
|
+
params[:payload] == "\"TEST_PAYLOAD\""
|
21
|
+
end.returns(response)
|
22
|
+
|
23
|
+
actual = retreiver.create_playbook
|
24
|
+
|
25
|
+
assert_equal 'TEST_RESPONSE', actual
|
26
|
+
end
|
27
|
+
end
|
@@ -8,8 +8,11 @@ import {
|
|
8
8
|
INSIGHTS_SET_SELECTED_IDS,
|
9
9
|
INSIGHTS_SET_SELECT_ALL_ALERT,
|
10
10
|
INSIGHTS_SET_SELECT_ALL,
|
11
|
-
NEW_HOST_PATH,
|
12
11
|
} from './InsightsTableConstants';
|
12
|
+
import {
|
13
|
+
getServerQueryForHostname,
|
14
|
+
isNewHostPage,
|
15
|
+
} from './InsightsTableHelpers';
|
13
16
|
|
14
17
|
export const fetchInsights = (queryParams = {}) => (dispatch, getState) => {
|
15
18
|
const state = getState();
|
@@ -34,13 +37,7 @@ export const fetchInsights = (queryParams = {}) => (dispatch, getState) => {
|
|
34
37
|
dispatch(setSelectAllAlert(false));
|
35
38
|
}
|
36
39
|
|
37
|
-
|
38
|
-
if (isNewHostPage(uri)) {
|
39
|
-
const hostname = uri.pathname().split('/new/hosts/')[1];
|
40
|
-
const hostQuery = `hostname = ${hostname}`;
|
41
|
-
const q = query?.trim();
|
42
|
-
search = q ? `${hostQuery} AND (${q})` : hostQuery;
|
43
|
-
}
|
40
|
+
const search = getServerQueryForHostname(query);
|
44
41
|
|
45
42
|
return dispatch(
|
46
43
|
get({
|
@@ -151,11 +148,9 @@ const setSelectAllUrl = selectAllValue => dispatch => {
|
|
151
148
|
|
152
149
|
const updateUrl = (uri, dispatch) => {
|
153
150
|
const nextUrlParams = { search: uri.search() };
|
154
|
-
if (isNewHostPage(
|
151
|
+
if (isNewHostPage()) {
|
155
152
|
// we need to keep the hash so the insights tab will remain selected in the new host details page.
|
156
153
|
nextUrlParams.hash = '/Insights';
|
157
154
|
}
|
158
155
|
dispatch(push(nextUrlParams));
|
159
156
|
};
|
160
|
-
|
161
|
-
const isNewHostPage = uri => uri.pathname().includes(NEW_HOST_PATH);
|
@@ -1,4 +1,7 @@
|
|
1
1
|
/* eslint-disable camelcase */
|
2
|
+
import URI from 'urijs';
|
3
|
+
import { NEW_HOST_PATH } from './InsightsTableConstants';
|
4
|
+
|
2
5
|
export const modifySelectedRows = (
|
3
6
|
hits,
|
4
7
|
selectedIds,
|
@@ -54,3 +57,22 @@ export const getPerPageOptions = (urlPerPage, appPerPage) => {
|
|
54
57
|
const options = [...initialValues].sort((a, b) => a - b);
|
55
58
|
return options.map(value => ({ title: value.toString(), value }));
|
56
59
|
};
|
60
|
+
|
61
|
+
export const isNewHostPage = () => {
|
62
|
+
const uri = new URI();
|
63
|
+
const pathname = uri.pathname();
|
64
|
+
const isIncluded = pathname.includes(NEW_HOST_PATH);
|
65
|
+
return isIncluded ? pathname.split('/new/hosts/')[1] : false; // return hostname or false
|
66
|
+
};
|
67
|
+
|
68
|
+
// return query or specific hostname with query if it's in the new host page.
|
69
|
+
export const getServerQueryForHostname = query => {
|
70
|
+
const isNewHost = isNewHostPage();
|
71
|
+
let serverQuery = query;
|
72
|
+
if (isNewHost) {
|
73
|
+
const hostQuery = `hostname = ${isNewHost}`;
|
74
|
+
const q = query?.trim();
|
75
|
+
serverQuery = q ? `${hostQuery} AND (${q})` : hostQuery;
|
76
|
+
}
|
77
|
+
return serverQuery;
|
78
|
+
};
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { get } from 'foremanReact/redux/API';
|
2
|
+
import { getServerQueryForHostname } from '../InsightsTable/InsightsTableHelpers';
|
2
3
|
import {
|
3
4
|
REMEDIATIONS_API_KEY,
|
4
5
|
REMEDIATIONS_PATH,
|
@@ -8,5 +9,9 @@ export const fetchRemediations = ({ selectedIds, isAllSelected, query }) =>
|
|
8
9
|
get({
|
9
10
|
key: REMEDIATIONS_API_KEY,
|
10
11
|
url: REMEDIATIONS_PATH,
|
11
|
-
params: {
|
12
|
+
params: {
|
13
|
+
ids: Object.keys(selectedIds),
|
14
|
+
isAllSelected,
|
15
|
+
query: getServerQueryForHostname(query),
|
16
|
+
},
|
12
17
|
});
|
@@ -19,10 +19,11 @@ const InsightsTotalRiskCard = ({ hostDetails: { id } }) => {
|
|
19
19
|
const dispatch = useDispatch();
|
20
20
|
const API_KEY = `HOST_${id}_RECOMMENDATIONS`;
|
21
21
|
const API_OPTIONS = useMemo(() => ({ key: API_KEY }), [API_KEY]);
|
22
|
+
const url = id && insightsCloudUrl(`hits/${id}`); // This will keep the API call from being triggered if there's no host id.
|
22
23
|
const {
|
23
24
|
status = STATUS.PENDING,
|
24
25
|
response: { hits = [] },
|
25
|
-
} = useAPI('get',
|
26
|
+
} = useAPI('get', url, API_OPTIONS);
|
26
27
|
|
27
28
|
useEffect(() => {
|
28
29
|
if (status === STATUS.RESOLVED) {
|
@@ -116,7 +117,7 @@ const InsightsTotalRiskCard = ({ hostDetails: { id } }) => {
|
|
116
117
|
|
117
118
|
return (
|
118
119
|
<CardTemplate
|
119
|
-
header={__('Total
|
120
|
+
header={__('Total risks')}
|
120
121
|
dropdownItems={[
|
121
122
|
<DropdownItem
|
122
123
|
key="insights-tab"
|
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: 5.0.
|
4
|
+
version: 5.0.35
|
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: 2022-
|
11
|
+
date: 2022-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: katello
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- LICENSE
|
133
133
|
- README.md
|
134
134
|
- Rakefile
|
135
|
+
- app/controllers/api/v2/rh_cloud/cloud_request_controller.rb
|
135
136
|
- app/controllers/api/v2/rh_cloud/inventory_controller.rb
|
136
137
|
- app/controllers/concerns/insights_cloud/candlepin_cache.rb
|
137
138
|
- app/controllers/concerns/insights_cloud/client_authentication.rb
|
@@ -166,12 +167,17 @@ files:
|
|
166
167
|
- app/services/foreman_rh_cloud/cloud_auth.rb
|
167
168
|
- app/services/foreman_rh_cloud/cloud_connector.rb
|
168
169
|
- app/services/foreman_rh_cloud/cloud_ping_service.rb
|
170
|
+
- app/services/foreman_rh_cloud/cloud_presence.rb
|
169
171
|
- app/services/foreman_rh_cloud/cloud_request.rb
|
170
172
|
- app/services/foreman_rh_cloud/cloud_request_forwarder.rb
|
173
|
+
- app/services/foreman_rh_cloud/hit_remediations_retriever.rb
|
171
174
|
- app/services/foreman_rh_cloud/insights_status_cleaner.rb
|
172
175
|
- app/services/foreman_rh_cloud/remediations_retriever.rb
|
173
176
|
- app/services/foreman_rh_cloud/template_renderer_helper.rb
|
177
|
+
- app/services/foreman_rh_cloud/url_remediations_retriever.rb
|
174
178
|
- app/views/hosts/_insights_tab.html.erb
|
179
|
+
- app/views/job_templates/cloud_connector.erb
|
180
|
+
- app/views/job_templates/rh_cloud_download_playbook.erb
|
175
181
|
- app/views/job_templates/rh_cloud_remediations.erb
|
176
182
|
- app/views/layouts/foreman_rh_cloud/application.html.erb
|
177
183
|
- config/Gemfile.lock.gh_test
|
@@ -215,6 +221,7 @@ files:
|
|
215
221
|
- lib/foreman_rh_cloud/engine.rb
|
216
222
|
- lib/foreman_rh_cloud/version.rb
|
217
223
|
- lib/insights_cloud.rb
|
224
|
+
- lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb
|
218
225
|
- lib/insights_cloud/async/insights_client_status_aging.rb
|
219
226
|
- lib/insights_cloud/async/insights_full_sync.rb
|
220
227
|
- lib/insights_cloud/async/insights_generate_notifications.rb
|
@@ -222,6 +229,7 @@ files:
|
|
222
229
|
- lib/insights_cloud/async/insights_rules_sync.rb
|
223
230
|
- lib/insights_cloud/async/insights_scheduled_sync.rb
|
224
231
|
- lib/insights_cloud/async/rules_result.rb
|
232
|
+
- lib/insights_cloud/generators/playbook_progress_generator.rb
|
225
233
|
- lib/inventory_sync/async/host_result.rb
|
226
234
|
- lib/inventory_sync/async/inventory_full_sync.rb
|
227
235
|
- lib/inventory_sync/async/inventory_hosts_sync.rb
|
@@ -237,6 +245,7 @@ files:
|
|
237
245
|
- locale/gemspec.rb
|
238
246
|
- package.json
|
239
247
|
- test/controllers/accounts_controller_test.rb
|
248
|
+
- test/controllers/insights_cloud/api/cloud_request_controller_test.rb
|
240
249
|
- test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb
|
241
250
|
- test/controllers/insights_sync/settings_controller_test.rb
|
242
251
|
- test/controllers/inventory_upload/api/inventory_controller_test.rb
|
@@ -246,6 +255,7 @@ files:
|
|
246
255
|
- test/controllers/uploads_settings_controller_test.rb
|
247
256
|
- test/factories/insights_factories.rb
|
248
257
|
- test/factories/inventory_upload_factories.rb
|
258
|
+
- test/jobs/connector_playbook_execution_reporter_task_test.rb
|
249
259
|
- test/jobs/insights_client_status_aging_test.rb
|
250
260
|
- test/jobs/insights_full_sync_test.rb
|
251
261
|
- test/jobs/insights_resolutions_sync_test.rb
|
@@ -262,14 +272,16 @@ files:
|
|
262
272
|
- test/unit/foreman_rh_cloud_self_host_test.rb
|
263
273
|
- test/unit/insights_facet_test.rb
|
264
274
|
- test/unit/metadata_generator_test.rb
|
275
|
+
- test/unit/playbook_progress_generator_test.rb
|
265
276
|
- test/unit/rh_cloud_http_proxy_test.rb
|
266
277
|
- test/unit/rh_cloud_permissions_test.rb
|
267
278
|
- test/unit/services/foreman_rh_cloud/branch_info_test.rb
|
268
279
|
- test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb
|
269
280
|
- test/unit/services/foreman_rh_cloud/cloud_status_service_test.rb
|
281
|
+
- test/unit/services/foreman_rh_cloud/hit_remediations_retriever_test.rb
|
270
282
|
- test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb
|
271
|
-
- test/unit/services/foreman_rh_cloud/remediations_retriever_test.rb
|
272
283
|
- test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb
|
284
|
+
- test/unit/services/foreman_rh_cloud/url_remediations_retriever_test.rb
|
273
285
|
- test/unit/shell_process_job_test.rb
|
274
286
|
- test/unit/slice_generator_test.rb
|
275
287
|
- test/unit/tags_generator_test.rb
|
@@ -672,6 +684,7 @@ specification_version: 4
|
|
672
684
|
summary: Summary of ForemanRhCloud.
|
673
685
|
test_files:
|
674
686
|
- test/controllers/accounts_controller_test.rb
|
687
|
+
- test/controllers/insights_cloud/api/cloud_request_controller_test.rb
|
675
688
|
- test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb
|
676
689
|
- test/controllers/insights_sync/settings_controller_test.rb
|
677
690
|
- test/controllers/inventory_upload/api/inventory_controller_test.rb
|
@@ -681,6 +694,7 @@ test_files:
|
|
681
694
|
- test/controllers/uploads_settings_controller_test.rb
|
682
695
|
- test/factories/insights_factories.rb
|
683
696
|
- test/factories/inventory_upload_factories.rb
|
697
|
+
- test/jobs/connector_playbook_execution_reporter_task_test.rb
|
684
698
|
- test/jobs/insights_client_status_aging_test.rb
|
685
699
|
- test/jobs/insights_full_sync_test.rb
|
686
700
|
- test/jobs/insights_resolutions_sync_test.rb
|
@@ -697,14 +711,16 @@ test_files:
|
|
697
711
|
- test/unit/foreman_rh_cloud_self_host_test.rb
|
698
712
|
- test/unit/insights_facet_test.rb
|
699
713
|
- test/unit/metadata_generator_test.rb
|
714
|
+
- test/unit/playbook_progress_generator_test.rb
|
700
715
|
- test/unit/rh_cloud_http_proxy_test.rb
|
701
716
|
- test/unit/rh_cloud_permissions_test.rb
|
702
717
|
- test/unit/services/foreman_rh_cloud/branch_info_test.rb
|
703
718
|
- test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb
|
704
719
|
- test/unit/services/foreman_rh_cloud/cloud_status_service_test.rb
|
720
|
+
- test/unit/services/foreman_rh_cloud/hit_remediations_retriever_test.rb
|
705
721
|
- test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb
|
706
|
-
- test/unit/services/foreman_rh_cloud/remediations_retriever_test.rb
|
707
722
|
- test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb
|
723
|
+
- test/unit/services/foreman_rh_cloud/url_remediations_retriever_test.rb
|
708
724
|
- test/unit/shell_process_job_test.rb
|
709
725
|
- test/unit/slice_generator_test.rb
|
710
726
|
- test/unit/tags_generator_test.rb
|