foreman_rh_cloud 5.0.38 → 5.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/api/v2/rh_cloud/cloud_request_controller.rb +11 -5
- data/app/controllers/insights_cloud/settings_controller.rb +14 -0
- data/config/routes.rb +2 -0
- data/lib/foreman_rh_cloud/engine.rb +5 -1
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb +3 -1
- data/lib/insights_cloud/generators/playbook_progress_generator.rb +2 -2
- data/lib/insights_cloud.rb +4 -0
- data/package.json +1 -1
- data/test/controllers/insights_cloud/api/cloud_request_controller_test.rb +27 -0
- data/test/controllers/insights_sync/settings_controller_test.rb +17 -0
- data/test/unit/playbook_progress_generator_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ee0416cdf8e5d2ed1315759fe70b9d5328754afbf676cecff442f20f835cde2c
|
|
4
|
+
data.tar.gz: c32a6486106d8dd395860f2ba956ef06980e8e8115a55b1f8731e3d7db440ffb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1afe5ccd1f0704428ac26ff319491e737e04acd28cc8bfc2e2e77acba7195657ecd89a078aadc3e892f5953680d2da9113f52562847cf9839b28c2d9e4507f9c
|
|
7
|
+
data.tar.gz: 6e78ebbbd8a9e833aadb15b95673fe57f99a60daab0ca3c48d1829dfd055e7f7744c0189e63b51077d03c2dd5d0084d95ecf87a745796afc2965dc016bef2132
|
|
@@ -27,16 +27,18 @@ module Api::V2::RhCloud
|
|
|
27
27
|
private
|
|
28
28
|
|
|
29
29
|
def metadata
|
|
30
|
-
params['metadata']
|
|
30
|
+
params['Metadata'] || params['metadata']
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def content
|
|
34
|
+
content = params['Content'] || params['content']
|
|
35
|
+
|
|
34
36
|
# the content received as base 64 of the string in double quotes
|
|
35
|
-
Base64.decode64(
|
|
37
|
+
Base64.decode64(content).tr('"', '')
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
def directive
|
|
39
|
-
params['directive']
|
|
41
|
+
params['Directive'] || params['directive']
|
|
40
42
|
end
|
|
41
43
|
|
|
42
44
|
def handle_run_playbook_request
|
|
@@ -44,9 +46,13 @@ module Api::V2::RhCloud
|
|
|
44
46
|
logger.error("Reporting URL is not valid: #{metadata['return_url']}") && return unless valid_url?(metadata['return_url'])
|
|
45
47
|
|
|
46
48
|
hosts = metadata['hosts'].split(',')
|
|
47
|
-
host_ids = host_ids(hosts)
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
# select hosts from the metadata list that are not disabled by the parameter.
|
|
51
|
+
host_ids = Host.search_for("not params.#{InsightsCloud.enable_cloud_remediations_param} = f")
|
|
52
|
+
.where(id: host_ids(hosts))
|
|
53
|
+
.pluck(:id)
|
|
54
|
+
|
|
55
|
+
logger.warn("Some hosts were not found/ignored. Looked for: #{hosts}, found ids: #{host_ids}") unless host_ids.length == hosts.length
|
|
50
56
|
|
|
51
57
|
logger.error("sat_org_id is not present in the metadata") && return unless metadata['sat_org_id']
|
|
52
58
|
org_id = metadata['sat_org_id'].to_i
|
|
@@ -9,6 +9,20 @@ module InsightsCloud
|
|
|
9
9
|
render_setting(:insightsSyncEnabled, :allow_auto_insights_sync)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
def set_org_parameter
|
|
13
|
+
parameter = params.require(:parameter)
|
|
14
|
+
new_value = ActiveModel::Type::Boolean.new.cast(params.require(:value))
|
|
15
|
+
org_id = params.require(:organization_id)
|
|
16
|
+
|
|
17
|
+
organization = Organization.authorized.find(org_id)
|
|
18
|
+
|
|
19
|
+
org_param = organization.organization_parameters.find_or_create_by(name: parameter) do |org_param|
|
|
20
|
+
org_param.name = parameter
|
|
21
|
+
end
|
|
22
|
+
org_param.value = new_value
|
|
23
|
+
org_param.save!
|
|
24
|
+
end
|
|
25
|
+
|
|
12
26
|
private
|
|
13
27
|
|
|
14
28
|
def render_setting(node_name, setting)
|
data/config/routes.rb
CHANGED
|
@@ -25,6 +25,8 @@ Rails.application.routes.draw do
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
match 'hits/:host_id', to: 'hits#show', via: :get
|
|
28
|
+
|
|
29
|
+
post ':organization_id/parameter', to: 'settings#set_org_parameter', constraints: { organization_id: %r{[^\/]+} }
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
namespace :foreman_rh_cloud do
|
|
@@ -83,9 +83,13 @@ module ForemanRhCloud
|
|
|
83
83
|
:dispatch_cloud_requests,
|
|
84
84
|
'api/v2/rh_cloud/cloud_request': [:update]
|
|
85
85
|
)
|
|
86
|
+
permission(
|
|
87
|
+
:control_organization_insights,
|
|
88
|
+
'insights_cloud/settings': [:set_org_parameter]
|
|
89
|
+
)
|
|
86
90
|
end
|
|
87
91
|
|
|
88
|
-
plugin_permissions = [:view_foreman_rh_cloud, :generate_foreman_rh_cloud, :view_insights_hits, :dispatch_cloud_requests]
|
|
92
|
+
plugin_permissions = [:view_foreman_rh_cloud, :generate_foreman_rh_cloud, :view_insights_hits, :dispatch_cloud_requests, :control_organization_insights]
|
|
89
93
|
|
|
90
94
|
role 'ForemanRhCloud', plugin_permissions, 'Role granting permissions to view the hosts inventory,
|
|
91
95
|
generate a report, upload it to the cloud and download it locally'
|
|
@@ -137,6 +137,7 @@ module InsightsCloud
|
|
|
137
137
|
|
|
138
138
|
def report_job_progress(invocation_status)
|
|
139
139
|
generator = InsightsCloud::Generators::PlaybookProgressGenerator.new(correlation_id)
|
|
140
|
+
all_hosts_success = true
|
|
140
141
|
|
|
141
142
|
invocation_status.each do |host_name, status|
|
|
142
143
|
# skip host if the host already reported that it's finished
|
|
@@ -151,9 +152,10 @@ module InsightsCloud
|
|
|
151
152
|
if status['state'] == 'stopped'
|
|
152
153
|
generator.host_finished_message(host_name, status['exit_status'])
|
|
153
154
|
status['report_done'] = true
|
|
155
|
+
all_hosts_success &&= status['exit_status'] == 0
|
|
154
156
|
end
|
|
155
157
|
end
|
|
156
|
-
generator.job_finished_message if done?(invocation_status)
|
|
158
|
+
generator.job_finished_message(all_hosts_success) if done?(invocation_status)
|
|
157
159
|
|
|
158
160
|
send_report(generator.generate)
|
|
159
161
|
end
|
|
@@ -30,12 +30,12 @@ module InsightsCloud
|
|
|
30
30
|
}
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
def job_finished_message
|
|
33
|
+
def job_finished_message(success)
|
|
34
34
|
@messages << {
|
|
35
35
|
"type": "playbook_run_completed",
|
|
36
36
|
"version": 3,
|
|
37
37
|
"correlation_id": correlation_id,
|
|
38
|
-
"status":
|
|
38
|
+
"status": success ? 'success' : 'failure',
|
|
39
39
|
}
|
|
40
40
|
end
|
|
41
41
|
|
data/lib/insights_cloud.rb
CHANGED
data/package.json
CHANGED
|
@@ -40,6 +40,33 @@ module InsightsCloud::Api
|
|
|
40
40
|
assert_response :success
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
+
test 'Starts playbook run for correct directive with capitalized keys' do
|
|
44
|
+
host1 = FactoryBot.create(:host, :with_insights_hits)
|
|
45
|
+
host1.insights.uuid = 'TEST_UUID1'
|
|
46
|
+
host1.insights.save!
|
|
47
|
+
host2 = FactoryBot.create(:host, :with_insights_hits)
|
|
48
|
+
host2.insights.uuid = 'TEST_UUID2'
|
|
49
|
+
host2.insights.save!
|
|
50
|
+
|
|
51
|
+
mock_composer = mock('composer')
|
|
52
|
+
::JobInvocationComposer.expects(:for_feature).with do |feature, host_ids, params|
|
|
53
|
+
feature == :rh_cloud_connector_run_playbook &&
|
|
54
|
+
host_ids.first == host1.id &&
|
|
55
|
+
host_ids.last == host2.id
|
|
56
|
+
end.returns(mock_composer)
|
|
57
|
+
mock_composer.expects(:trigger!)
|
|
58
|
+
mock_composer.expects(:job_invocation)
|
|
59
|
+
|
|
60
|
+
params = run_playbook_request
|
|
61
|
+
params['Directive'] = params.delete('directive')
|
|
62
|
+
params['Metadata'] = params.delete('metadata')
|
|
63
|
+
params['Content'] = params.delete('content')
|
|
64
|
+
|
|
65
|
+
post :update, params: run_playbook_request
|
|
66
|
+
|
|
67
|
+
assert_response :success
|
|
68
|
+
end
|
|
69
|
+
|
|
43
70
|
private
|
|
44
71
|
|
|
45
72
|
def run_playbook_request
|
|
@@ -27,4 +27,21 @@ class SettingsControllerTest < ActionController::TestCase
|
|
|
27
27
|
assert_equal true, actual['insightsSyncEnabled']
|
|
28
28
|
assert_equal true, Setting[:allow_auto_insights_sync]
|
|
29
29
|
end
|
|
30
|
+
|
|
31
|
+
test 'Should update an organization parameter' do
|
|
32
|
+
FactoryBot.create(:common_parameter, name: InsightsCloud.enable_cloud_remediations_param, value: false)
|
|
33
|
+
host = FactoryBot.create(:host)
|
|
34
|
+
|
|
35
|
+
# make sure the parameter is there
|
|
36
|
+
assert_equal false, host.host_params[InsightsCloud.enable_cloud_remediations_param]
|
|
37
|
+
|
|
38
|
+
post :set_org_parameter, params: { parameter: InsightsCloud.enable_cloud_remediations_param, value: true, organization_id: host.organization.id }, session: set_session_user
|
|
39
|
+
|
|
40
|
+
# needed for properly access host_params
|
|
41
|
+
User.as_anonymous_admin do
|
|
42
|
+
# refresh the host record
|
|
43
|
+
host = Host.find(host.id)
|
|
44
|
+
assert_equal true, host.host_params[InsightsCloud.enable_cloud_remediations_param]
|
|
45
|
+
end
|
|
46
|
+
end
|
|
30
47
|
end
|
|
@@ -51,7 +51,7 @@ class PlaybookProgressGeneratorTest < ActiveSupport::TestCase
|
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
test 'Outputs job finished message' do
|
|
54
|
-
@generator.job_finished_message
|
|
54
|
+
@generator.job_finished_message(true)
|
|
55
55
|
|
|
56
56
|
actual = @generator.generate
|
|
57
57
|
actual_message = JSON.parse(actual)
|
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.39
|
|
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-06-
|
|
11
|
+
date: 2022-06-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: katello
|