foreman_rh_cloud 14.4.0 → 14.6.0
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 +1 -0
- data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +11 -5
- data/app/controllers/foreman_inventory_upload/accounts_controller.rb +0 -1
- data/app/controllers/foreman_inventory_upload/uploads_controller.rb +0 -11
- data/app/controllers/foreman_inventory_upload/uploads_settings_controller.rb +0 -8
- data/app/services/foreman_rh_cloud/cert_auth.rb +2 -1
- data/app/services/foreman_rh_cloud/cloud_presence.rb +23 -0
- data/app/services/foreman_rh_cloud/cloud_request.rb +2 -1
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +9 -5
- data/config/routes.rb +1 -3
- data/lib/foreman_rh_cloud/engine.rb +1 -6
- data/lib/foreman_rh_cloud/plugin.rb +4 -2
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/foreman_rh_cloud.rb +16 -0
- data/lib/insights_cloud/async/cloud_connector_announce_task.rb +76 -19
- data/package.json +1 -1
- data/test/controllers/inventory_upload/api/inventory_controller_test.rb +10 -8
- data/test/jobs/cloud_connector_announce_task_test.rb +116 -106
- data/test/unit/foreman_rh_cloud_iop_metadata_test.rb +27 -0
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +28 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/integrations.test.js +4 -12
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/__tests__/Toast.test.js +62 -61
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTableActions.test.js +2 -2
- data/webpack/InsightsCloudSync/__tests__/InsightsCloudSyncActions.test.js +7 -5
- data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabIntegration.test.js +69 -8
- data/webpack/InsightsVulnerabilityActionsBar/__tests__/InsightsVulnerabilityActionsBar.test.js +1 -5
- data/webpack/test_setup.js +1 -0
- metadata +2 -8
- data/app/services/foreman_rh_cloud/cloud_connector.rb +0 -74
- data/webpack/__mocks__/foremanReact/Root/Context/ForemanContext.js +0 -6
- data/webpack/__mocks__/foremanReact/common/I18n.js +0 -6
- data/webpack/__mocks__/foremanReact/common/helpers.js +0 -14
- data/webpack/__mocks__/foremanReact/constants.js +0 -24
- data/webpack/__mocks__/foremanReact/redux/API/APISelectors.js +0 -24
- data/webpack/__mocks__/foremanReact/redux/API/index.js +0 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6c5686d5268a4028cc883b95daa1948748a56a41cb54495668a4170cd1fcaab9
|
|
4
|
+
data.tar.gz: 533e44e09c87944392c120d57cc34e9244fbe3cf176dddb6c8d7ab7334ce4f92
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ca9d76abf073cb2f31f74822d45c40d18f6f735f2d6251d67c3ebae1bec9d26c33fe6c9098e8bb6f1b21f922003eaecbfe0da7249111e28ea4cd0f04e0d25138
|
|
7
|
+
data.tar.gz: cbe8078e2ef86cde32ad7feef2c0dd19850de71cefec7aa61939d71605d749e0ad18225492c160b5f5d57ba15bea691f0af0a5978e5300979e4858bc959b0e72
|
|
@@ -7,7 +7,7 @@ module Api
|
|
|
7
7
|
include InventoryUpload::TaskActions
|
|
8
8
|
include ForemanRhCloud::IopSmartProxyAccess
|
|
9
9
|
|
|
10
|
-
before_action :require_non_iop_smart_proxy, only: [:
|
|
10
|
+
before_action :require_non_iop_smart_proxy, only: [:announce_to_sources]
|
|
11
11
|
|
|
12
12
|
api :GET, "/organizations/:organization_id/rh_cloud/report", N_("Download latest report")
|
|
13
13
|
param :organization_id, Integer, required: true, desc: N_("Set the current organization context for the request")
|
|
@@ -70,10 +70,16 @@ module Api
|
|
|
70
70
|
render json: { message: error.message }, status: :bad_request
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
-
api :POST, "/rh_cloud/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
api :POST, "/rh_cloud/announce_to_sources", N_("Schedule a task to register in Red Hat Sources for cloud connector")
|
|
74
|
+
param :instance_id, String, required: true, desc: N_("RHC instance ID to register with Red Hat Sources")
|
|
75
|
+
def announce_to_sources
|
|
76
|
+
Setting[:rhc_instance_id] = params[:instance_id]
|
|
77
|
+
|
|
78
|
+
task = ForemanTasks.async_task(InsightsCloud::Async::CloudConnectorAnnounceTask, true)
|
|
79
|
+
|
|
80
|
+
render json: {
|
|
81
|
+
task: task,
|
|
82
|
+
}, status: :accepted
|
|
77
83
|
end
|
|
78
84
|
end
|
|
79
85
|
end
|
|
@@ -1,22 +1,11 @@
|
|
|
1
1
|
module ForemanInventoryUpload
|
|
2
2
|
class UploadsController < ::ApplicationController
|
|
3
3
|
include InventoryUpload::ReportActions
|
|
4
|
-
include ForemanRhCloud::IopSmartProxyAccess
|
|
5
|
-
|
|
6
|
-
before_action :require_non_iop_smart_proxy, only: [:enable_cloud_connector]
|
|
7
4
|
|
|
8
5
|
def download_file
|
|
9
6
|
filename, file = report_file(params[:organization_id])
|
|
10
7
|
|
|
11
8
|
send_file file, disposition: 'attachment', filename: filename
|
|
12
9
|
end
|
|
13
|
-
|
|
14
|
-
def enable_cloud_connector
|
|
15
|
-
# Set the autoupload to true, since it's required by the feature.
|
|
16
|
-
Setting[:allow_auto_inventory_upload] = true
|
|
17
|
-
|
|
18
|
-
cloud_connector = ForemanRhCloud::CloudConnector.new
|
|
19
|
-
render json: cloud_connector.install.to_json
|
|
20
|
-
end
|
|
21
10
|
end
|
|
22
11
|
end
|
|
@@ -9,7 +9,6 @@ module ForemanInventoryUpload
|
|
|
9
9
|
ipsObfuscationEnabled: Setting[:obfuscate_inventory_ips],
|
|
10
10
|
excludePackagesEnabled: Setting[:exclude_installed_packages],
|
|
11
11
|
allowAutoInsightsMismatchDelete: Setting[:allow_auto_insights_mismatch_delete],
|
|
12
|
-
CloudConnectorStatus: ForemanInventoryUpload::UploadsSettingsController.cloud_connector_status,
|
|
13
12
|
lastSyncTask: last_successful_inventory_sync_task,
|
|
14
13
|
}, status: :ok
|
|
15
14
|
end
|
|
@@ -19,13 +18,6 @@ module ForemanInventoryUpload
|
|
|
19
18
|
index
|
|
20
19
|
end
|
|
21
20
|
|
|
22
|
-
def self.cloud_connector_status
|
|
23
|
-
cloud_connector = ForemanRhCloud::CloudConnector.new
|
|
24
|
-
job = cloud_connector&.latest_job
|
|
25
|
-
return nil unless job
|
|
26
|
-
{ id: job.id, task: ForemanTasks::Task.where(:id => job.task_id).first }
|
|
27
|
-
end
|
|
28
|
-
|
|
29
21
|
def last_successful_inventory_sync_task
|
|
30
22
|
task = ForemanTasks::Task.where(label: 'InventorySync::Async::InventoryFullSync', result: 'success')
|
|
31
23
|
.reorder('ended_at desc').first
|
|
@@ -11,8 +11,9 @@ module ForemanRhCloud
|
|
|
11
11
|
|
|
12
12
|
def execute_cloud_request(params)
|
|
13
13
|
organization = params.delete(:organization)
|
|
14
|
+
force_cloud = params[:force_cloud]
|
|
14
15
|
# Cache the value of with_iop_smart_proxy? to avoid multiple calls to the database
|
|
15
|
-
with_iop_smart_proxy = ForemanRhCloud.with_iop_smart_proxy?
|
|
16
|
+
with_iop_smart_proxy = ForemanRhCloud.with_iop_smart_proxy? && !force_cloud
|
|
16
17
|
certs = with_iop_smart_proxy ? foreman_certificate : candlepin_id_cert(organization)
|
|
17
18
|
default_params = {
|
|
18
19
|
ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
|
|
@@ -74,6 +74,9 @@ module ForemanRhCloud
|
|
|
74
74
|
|
|
75
75
|
def register_rhc_instance
|
|
76
76
|
raise Foreman::Exception.new('rhc_instance_id is empty, cannot register RHC to the cloud') if Setting[:rhc_instance_id].empty?
|
|
77
|
+
|
|
78
|
+
return :already_registered if rhc_connection_exists?
|
|
79
|
+
|
|
77
80
|
source_id = satellite_instance_source || create_satellite_instance_source
|
|
78
81
|
|
|
79
82
|
create_response = JSON.parse(
|
|
@@ -95,6 +98,22 @@ module ForemanRhCloud
|
|
|
95
98
|
@satellite_instance_source = create_response['id']
|
|
96
99
|
end
|
|
97
100
|
|
|
101
|
+
def rhc_connection_exists?
|
|
102
|
+
response = JSON.parse(
|
|
103
|
+
execute_cloud_request(
|
|
104
|
+
method: :get,
|
|
105
|
+
url: rhc_connection_url,
|
|
106
|
+
headers: {
|
|
107
|
+
content_type: :json,
|
|
108
|
+
},
|
|
109
|
+
ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
|
|
110
|
+
ssl_client_key: OpenSSL::PKey.read(certs[:key])
|
|
111
|
+
)
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
response['data']&.any?
|
|
115
|
+
end
|
|
116
|
+
|
|
98
117
|
private
|
|
99
118
|
|
|
100
119
|
def sources_url(path)
|
|
@@ -113,6 +132,10 @@ module ForemanRhCloud
|
|
|
113
132
|
sources_url('/sources')
|
|
114
133
|
end
|
|
115
134
|
|
|
135
|
+
def rhc_connection_url
|
|
136
|
+
sources_url("/rhc_connections?filter[rhc_id]=#{Setting[:rhc_instance_id]}")
|
|
137
|
+
end
|
|
138
|
+
|
|
116
139
|
def create_rhc_connections_url
|
|
117
140
|
sources_url('/rhc_connections')
|
|
118
141
|
end
|
|
@@ -3,12 +3,13 @@ module ForemanRhCloud
|
|
|
3
3
|
extend ActiveSupport::Concern
|
|
4
4
|
|
|
5
5
|
def execute_cloud_request(params)
|
|
6
|
+
force_cloud = params.delete(:force_cloud)
|
|
6
7
|
final_params = {
|
|
7
8
|
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
|
8
9
|
proxy: ForemanRhCloud.transformed_http_proxy_string,
|
|
9
10
|
}.deep_merge(params)
|
|
10
11
|
|
|
11
|
-
if ForemanRhCloud.with_iop_smart_proxy?
|
|
12
|
+
if ForemanRhCloud.with_iop_smart_proxy? && !force_cloud
|
|
12
13
|
final_params[:ssl_ca_file] ||= ForemanRhCloud.ca_cert
|
|
13
14
|
end
|
|
14
15
|
|
|
@@ -36,8 +36,9 @@ module ForemanRhCloud
|
|
|
36
36
|
}
|
|
37
37
|
requested_url = original_request.original_fullpath.end_with?('/') ? original_request.path + '/' : original_request.path
|
|
38
38
|
params = path_params(requested_url)
|
|
39
|
+
force_cloud = params[:force_cloud]
|
|
39
40
|
|
|
40
|
-
if ForemanRhCloud.with_iop_smart_proxy?
|
|
41
|
+
if ForemanRhCloud.with_iop_smart_proxy? && !force_cloud
|
|
41
42
|
params[:ssl_ca_file] = ForemanRhCloud.ca_cert
|
|
42
43
|
end
|
|
43
44
|
|
|
@@ -70,10 +71,13 @@ module ForemanRhCloud
|
|
|
70
71
|
|
|
71
72
|
def path_params(request_path)
|
|
72
73
|
case request_path
|
|
73
|
-
when
|
|
74
|
+
when lightspeed_cla?
|
|
75
|
+
force_cloud = ForemanRhCloud.with_iop_smart_proxy? && Setting[:force_cla_connection]
|
|
74
76
|
{
|
|
75
|
-
url: ForemanRhCloud.
|
|
76
|
-
|
|
77
|
+
url: ForemanRhCloud.cloud_cert_base_url + request_path,
|
|
78
|
+
force_cloud: force_cloud,
|
|
79
|
+
proxy: (force_cloud ? ForemanRhCloud.transformed_cloud_http_proxy_string : nil),
|
|
80
|
+
}.compact
|
|
77
81
|
when platform_request?
|
|
78
82
|
{
|
|
79
83
|
url: ForemanRhCloud.cert_base_url + request_path.sub('/redhat_access/r/insights/platform', '/api'),
|
|
@@ -104,7 +108,7 @@ module ForemanRhCloud
|
|
|
104
108
|
"for=\"_#{host.subscription_facet.uuid}\""
|
|
105
109
|
end
|
|
106
110
|
|
|
107
|
-
def
|
|
111
|
+
def lightspeed_cla?
|
|
108
112
|
->(request_path) { request_path.include? '/lightspeed' }
|
|
109
113
|
end
|
|
110
114
|
|
data/config/routes.rb
CHANGED
|
@@ -7,8 +7,6 @@ Rails.application.routes.draw do
|
|
|
7
7
|
get 'settings', to: 'uploads_settings#index'
|
|
8
8
|
post 'setting', to: 'uploads_settings#set_advanced_setting'
|
|
9
9
|
|
|
10
|
-
post 'cloud_connector', to: 'uploads#enable_cloud_connector'
|
|
11
|
-
|
|
12
10
|
resources :tasks, only: [:create, :show]
|
|
13
11
|
|
|
14
12
|
get 'status', to: 'cloud_status#index'
|
|
@@ -72,7 +70,7 @@ Rails.application.routes.draw do
|
|
|
72
70
|
end
|
|
73
71
|
|
|
74
72
|
namespace 'rh_cloud' do
|
|
75
|
-
post '
|
|
73
|
+
post 'announce_to_sources', to: 'inventory#announce_to_sources'
|
|
76
74
|
post 'cloud_request', to: 'cloud_request#update'
|
|
77
75
|
get 'advisor_engine_config', to: 'advisor_engine_config#show'
|
|
78
76
|
|
|
@@ -61,6 +61,7 @@ module ForemanRhCloud
|
|
|
61
61
|
ForemanRhCloud::Engine.register_scheduled_task(InventorySync::Async::InventoryScheduledSync, '0 0 * * *')
|
|
62
62
|
ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsScheduledSync, '0 0 * * *')
|
|
63
63
|
ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsClientStatusAging, '0 0 * * *')
|
|
64
|
+
ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::CloudConnectorAnnounceTask, '0 0 * * *')
|
|
64
65
|
end
|
|
65
66
|
end
|
|
66
67
|
rescue ActiveRecord::NoDatabaseError
|
|
@@ -80,12 +81,6 @@ module ForemanRhCloud
|
|
|
80
81
|
host_action_button: false,
|
|
81
82
|
provided_inputs: ['playbook_url', 'report_url', 'correlation_id', 'report_interval']
|
|
82
83
|
)
|
|
83
|
-
RemoteExecutionFeature.register(
|
|
84
|
-
:ansible_configure_cloud_connector,
|
|
85
|
-
N_('Configure Cloud Connector on given hosts'),
|
|
86
|
-
:description => N_('Configure Cloud Connector on given hosts'),
|
|
87
|
-
:proxy_selector_override => ::RemoteExecutionProxySelector::INTERNAL_PROXY
|
|
88
|
-
)
|
|
89
84
|
end
|
|
90
85
|
|
|
91
86
|
# Ideally this code belongs to an initializer. The problem is that Katello controllers are not initialized completely until after the end of the to_prepare blocks
|
|
@@ -22,6 +22,7 @@ module ForemanRhCloud
|
|
|
22
22
|
setting('include_parameter_tags', type: :boolean, description: N_('Should import include parameter tags from Foreman? Ignored when using local Insights.'), default: false, full_name: N_('Include parameters in insights-client reports'))
|
|
23
23
|
setting('rhc_instance_id', type: :string, description: N_('RHC daemon id. Ignored when using local Insights.'), default: nil, full_name: N_('ID of the RHC(Yggdrasil) daemon'))
|
|
24
24
|
setting('insights_minimal_data_collection', type: :boolean, default: false, full_name: N_('Minimal data collection'), description: N_('Only include the minimum required data in inventory reports for uploading to Red Hat cloud. When this is true, installed packages are excluded from the report regardless of the exclude_installed_packages setting, and host names and IPv4 addresses are excluded from the report regardless of obfuscation settings. Ignored when using local Insights.'))
|
|
25
|
+
setting('force_cla_connection', type: :boolean, default: false, full_name: N_('Force RHEL Lightspeed CLA connection'), description: N_('Forward requests to Lightspeed CLA even when in IoP mode. Ignored when IoP mode is off.'))
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
|
|
@@ -31,8 +32,7 @@ module ForemanRhCloud
|
|
|
31
32
|
:generate_foreman_rh_cloud,
|
|
32
33
|
'foreman_inventory_upload/reports': [:generate],
|
|
33
34
|
'foreman_inventory_upload/tasks': [:create],
|
|
34
|
-
'api/v2/rh_cloud/inventory': [:get_hosts, :remove_hosts, :sync_inventory_status, :download_file, :generate_report, :
|
|
35
|
-
'foreman_inventory_upload/uploads': [:enable_cloud_connector],
|
|
35
|
+
'api/v2/rh_cloud/inventory': [:get_hosts, :remove_hosts, :sync_inventory_status, :download_file, :generate_report, :announce_to_sources],
|
|
36
36
|
'foreman_inventory_upload/uploads_settings': [:set_advanced_setting],
|
|
37
37
|
'foreman_inventory_upload/missing_hosts': [:remove_hosts],
|
|
38
38
|
'insights_cloud/settings': [:update],
|
|
@@ -123,6 +123,8 @@ module ForemanRhCloud
|
|
|
123
123
|
role 'ForemanRhCloud Read Only', read_only_permissions, 'Role granting read-only permissions to view
|
|
124
124
|
Insights Compliance, Vulnerability, Advisor, and host inventory'
|
|
125
125
|
|
|
126
|
+
role 'Cloud Connector', [:dispatch_cloud_requests], 'Role granting permission to dispatch cloud connector requests'
|
|
127
|
+
|
|
126
128
|
add_permissions_to_default_roles Role::ORG_ADMIN => plugin_permissions,
|
|
127
129
|
Role::MANAGER => plugin_permissions,
|
|
128
130
|
Role::SYSTEM_ADMIN => plugin_permissions
|
data/lib/foreman_rh_cloud.rb
CHANGED
|
@@ -21,6 +21,14 @@ module ForemanRhCloud
|
|
|
21
21
|
env_or_on_premise_url('SATELLITE_CERT_RH_CLOUD_URL') || 'https://cert.cloud.redhat.com'
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
# Lightspeed/CLA is cloud-only. Use the cloud URL only when the admin
|
|
25
|
+
# enables force_cla_connection; otherwise follow cert_base_url (IoP when IoP is on).
|
|
26
|
+
def self.cloud_cert_base_url
|
|
27
|
+
return cert_base_url unless Setting[:force_cla_connection]
|
|
28
|
+
|
|
29
|
+
ENV['SATELLITE_CERT_RH_CLOUD_URL'] || 'https://cert.cloud.redhat.com'
|
|
30
|
+
end
|
|
31
|
+
|
|
24
32
|
def self.legacy_insights_url
|
|
25
33
|
env_or_on_premise_url('SATELLITE_LEGACY_INSIGHTS_URL') || 'https://cert-api.access.redhat.com'
|
|
26
34
|
end
|
|
@@ -48,11 +56,19 @@ module ForemanRhCloud
|
|
|
48
56
|
def self.proxy_string
|
|
49
57
|
return '' if ForemanRhCloud.with_iop_smart_proxy?
|
|
50
58
|
|
|
59
|
+
cloud_proxy_string
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def self.cloud_proxy_string
|
|
51
63
|
HttpProxy.default_global_content_proxy&.full_url ||
|
|
52
64
|
ForemanRhCloud.global_foreman_proxy ||
|
|
53
65
|
''
|
|
54
66
|
end
|
|
55
67
|
|
|
68
|
+
def self.transformed_cloud_http_proxy_string
|
|
69
|
+
transform_scheme(fix_port(cloud_proxy_string))
|
|
70
|
+
end
|
|
71
|
+
|
|
56
72
|
def self.fix_port(uri_string)
|
|
57
73
|
return '' if uri_string.empty?
|
|
58
74
|
|
|
@@ -1,39 +1,96 @@
|
|
|
1
1
|
module InsightsCloud
|
|
2
2
|
module Async
|
|
3
3
|
class CloudConnectorAnnounceTask < ::Actions::EntryAction
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
include ::Actions::RecurringAction
|
|
5
|
+
include ::ForemanRhCloud::CertAuth
|
|
6
|
+
include ForemanInventoryUpload::Async::DelayedStart
|
|
7
7
|
|
|
8
|
-
def
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
def plan(immediate = false)
|
|
9
|
+
if ForemanRhCloud.with_iop_smart_proxy?
|
|
10
|
+
logger.debug('Sources announcement skipped: running in IoP mode')
|
|
11
|
+
return
|
|
12
|
+
end
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
if Setting[:rhc_instance_id].blank?
|
|
15
|
+
logger.debug('Sources announcement skipped: rhc_instance_id is not set')
|
|
16
|
+
return
|
|
17
|
+
end
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
unless Setting[:allow_auto_inventory_upload]
|
|
20
|
+
logger.debug(
|
|
21
|
+
'Cloud connector is configured (rhc_instance_id is set) but automatic inventory upload is disabled. ' \
|
|
22
|
+
'Enable the "Automatic inventory upload" setting for full cloud connector functionality.'
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
if immediate
|
|
27
|
+
plan_self
|
|
28
|
+
else
|
|
29
|
+
after_delay do
|
|
30
|
+
plan_self
|
|
31
|
+
end
|
|
32
|
+
end
|
|
16
33
|
end
|
|
17
34
|
|
|
18
|
-
def
|
|
35
|
+
def run
|
|
36
|
+
registered = []
|
|
37
|
+
confirmed_by_remediation = []
|
|
38
|
+
already_registered = []
|
|
39
|
+
skipped = []
|
|
40
|
+
failed = {}
|
|
41
|
+
|
|
19
42
|
Organization.unscoped.each do |org|
|
|
43
|
+
unless cert_auth_available?(org)
|
|
44
|
+
skipped << org.name
|
|
45
|
+
next
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
if recent_cloud_remediation?(org)
|
|
49
|
+
confirmed_by_remediation << org.name
|
|
50
|
+
next
|
|
51
|
+
end
|
|
52
|
+
|
|
20
53
|
presence = ForemanRhCloud::CloudPresence.new(org, logger)
|
|
21
|
-
presence.announce_to_sources
|
|
54
|
+
result = presence.announce_to_sources
|
|
55
|
+
if result == :already_registered
|
|
56
|
+
already_registered << org.name
|
|
57
|
+
else
|
|
58
|
+
registered << org.name
|
|
59
|
+
end
|
|
22
60
|
rescue StandardError => ex
|
|
23
|
-
logger.warn(ex)
|
|
61
|
+
logger.warn("Failed to announce to Sources for organization #{org.name}: #{ex}")
|
|
62
|
+
logger.debug { ex.backtrace.join("\n") }
|
|
63
|
+
failed[org.name] = ex.message
|
|
24
64
|
end
|
|
25
|
-
end
|
|
26
65
|
|
|
27
|
-
|
|
28
|
-
|
|
66
|
+
parts = []
|
|
67
|
+
parts << "Registered: #{registered.join(', ')}" if registered.any?
|
|
68
|
+
parts << "Already registered: #{already_registered.join(', ')}" if already_registered.any?
|
|
69
|
+
parts << "Already registered (recent cloud remediation): #{confirmed_by_remediation.join(', ')}" if confirmed_by_remediation.any?
|
|
70
|
+
parts << "Skipped (no manifest): #{skipped.join(', ')}" if skipped.any?
|
|
71
|
+
if failed.any?
|
|
72
|
+
failed_details = failed.map { |name, msg| "#{name}: #{msg}" }.join('; ')
|
|
73
|
+
parts << "Failed: #{failed_details}"
|
|
74
|
+
end
|
|
75
|
+
output[:status] = parts.join('. ')
|
|
76
|
+
|
|
77
|
+
error!("Sources announcement failed for: #{failed.keys.join(', ')}") if failed.any?
|
|
29
78
|
end
|
|
30
79
|
|
|
31
|
-
def
|
|
32
|
-
|
|
80
|
+
def recent_cloud_remediation?(org)
|
|
81
|
+
feature = RemoteExecutionFeature.find_by(label: 'rh_cloud_connector_run_playbook')
|
|
82
|
+
return false unless feature
|
|
83
|
+
|
|
84
|
+
JobInvocation.where(remote_execution_feature_id: feature.id)
|
|
85
|
+
.joins(:task)
|
|
86
|
+
.joins(targeting: :hosts)
|
|
87
|
+
.where(hosts: { organization_id: org.id })
|
|
88
|
+
.where('foreman_tasks_tasks.started_at > ?', 24.hours.ago)
|
|
89
|
+
.exists?
|
|
33
90
|
end
|
|
34
91
|
|
|
35
|
-
def
|
|
36
|
-
|
|
92
|
+
def rescue_strategy_for_self
|
|
93
|
+
Dynflow::Action::Rescue::Skip
|
|
37
94
|
end
|
|
38
95
|
|
|
39
96
|
def logger
|
data/package.json
CHANGED
|
@@ -35,20 +35,22 @@ module InventoryUpload::Api
|
|
|
35
35
|
assert_equal test_task.id.to_s, actual_task['id']
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
test '
|
|
39
|
-
|
|
38
|
+
test 'Triggers Sources announcement task' do
|
|
39
|
+
test_task = FactoryBot.create(:some_task)
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
.
|
|
43
|
-
.returns(
|
|
41
|
+
ForemanTasks.expects(:async_task)
|
|
42
|
+
.with(InsightsCloud::Async::CloudConnectorAnnounceTask, true)
|
|
43
|
+
.returns(test_task)
|
|
44
44
|
|
|
45
|
-
post :
|
|
45
|
+
post :announce_to_sources, params: { instance_id: 'test-instance-id' }
|
|
46
46
|
|
|
47
47
|
assert_response :success
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
assert_equal 'test-instance-id', Setting[:rhc_instance_id]
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
actual_task = @response.parsed_body['task']
|
|
52
|
+
assert_not_nil actual_task
|
|
53
|
+
assert_equal test_task.id.to_s, actual_task['id']
|
|
52
54
|
end
|
|
53
55
|
end
|
|
54
56
|
end
|