foreman_rh_cloud 4.0.25 → 4.0.29
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/inventory_controller.rb +4 -1
- data/app/controllers/foreman_inventory_upload/cloud_status_controller.rb +26 -0
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +18 -4
- data/app/controllers/insights_cloud/hits_controller.rb +0 -1
- data/app/services/foreman_rh_cloud/cloud_ping_service.rb +83 -0
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +15 -3
- data/config/Gemfile.lock.gh_test +169 -160
- data/config/database.yml.example +2 -2
- data/config/rh_cert-api_chain.pem +74 -0
- data/config/routes.rb +3 -1
- data/lib/foreman_inventory_upload/generators/queries.rb +1 -16
- data/lib/foreman_inventory_upload/generators/tags.rb +1 -2
- data/lib/foreman_rh_cloud/engine.rb +2 -1
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/foreman_rh_cloud.rb +16 -1
- data/lib/insights_cloud/async/insights_client_status_aging.rb +4 -0
- data/lib/insights_cloud/async/insights_full_sync.rb +4 -0
- data/lib/insights_cloud/async/insights_generate_notifications.rb +4 -0
- data/lib/insights_cloud/async/insights_resolutions_sync.rb +7 -2
- data/lib/insights_cloud/async/insights_rules_sync.rb +10 -2
- data/lib/insights_cloud.rb +4 -0
- data/lib/inventory_sync/async/host_result.rb +0 -5
- data/lib/inventory_sync/async/inventory_full_sync.rb +18 -9
- data/lib/inventory_sync/async/inventory_hosts_sync.rb +6 -6
- data/lib/inventory_sync/async/inventory_scheduled_sync.rb +4 -0
- data/lib/inventory_sync/async/inventory_self_host_sync.rb +4 -0
- data/lib/inventory_sync/async/query_inventory_job.rb +4 -0
- data/lib/tasks/rh_cloud_inventory.rake +2 -9
- data/package.json +1 -1
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +20 -39
- data/test/controllers/inventory_upload/cloud_status_controller_test.rb +44 -0
- data/test/factories/inventory_upload_factories.rb +14 -0
- data/test/jobs/insights_resolutions_sync_test.rb +10 -1
- data/test/jobs/inventory_full_sync_test.rb +28 -2
- data/test/jobs/inventory_hosts_sync_test.rb +15 -0
- data/test/test_plugin_helper.rb +53 -0
- data/test/unit/foreman_rh_cloud_self_host_test.rb +28 -0
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +29 -34
- data/test/unit/services/foreman_rh_cloud/cloud_status_service_test.rb +66 -0
- data/test/unit/slice_generator_test.rb +36 -4
- data/test/unit/tags_generator_test.rb +16 -16
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.scss +0 -4
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageTitle.js +12 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageTitle.test.js.snap +10 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudPingModal/index.js +144 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudPingModal/index.scss +5 -0
- data/webpack/ForemanInventoryUpload/ForemanInventoryConstants.js +2 -0
- data/webpack/InsightsCloudSync/Components/InsightsHeader/InsightsHeader.scss +5 -1
- data/webpack/InsightsCloudSync/Components/InsightsHeader/index.js +6 -6
- data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettings.js +9 -5
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettings.test.js.snap +6 -6
- data/webpack/InsightsCloudSync/Components/InsightsSettings/insightsSettings.scss +1 -14
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +5 -24
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableConstants.js +11 -4
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableSelectors.js +0 -3
- data/webpack/InsightsCloudSync/Components/InsightsTable/Pagination.js +51 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +3 -68
- data/webpack/InsightsCloudSync/Components/InsightsTable/table.scss +10 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js +11 -10
- data/webpack/InsightsCloudSync/Components/RemediationModal/index.js +0 -2
- data/webpack/InsightsCloudSync/Components/ToolbarDropdown.js +32 -0
- data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/InsightsHeader.test.js.snap +5 -5
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +19 -13
- data/webpack/InsightsCloudSync/InsightsCloudSync.scss +82 -2
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +16 -6
- data/webpack/common/Switcher/HelpLabel.js +1 -1
- data/webpack/common/Switcher/SwitcherPF4.js +1 -1
- data/webpack/common/Switcher/SwitcherPF4.scss +6 -7
- data/webpack/common/Switcher/__tests__/__snapshots__/HelpLabel.test.js.snap +1 -1
- data/webpack/common/Switcher/__tests__/__snapshots__/SwitcherPF4.test.js.snap +1 -1
- metadata +16 -24
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/InsightsSyncSwitcher.fixtures.js +0 -1
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/InsightsSyncSwitcher.js +0 -45
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/__tests__/InsightsSyncSwitcher.test.js +0 -17
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/__tests__/__snapshots__/InsightsSyncSwitcher.test.js.snap +0 -38
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/index.js +0 -1
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/insightsSyncSwitcher.scss +0 -3
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +0 -59
@@ -0,0 +1,74 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIHZDCCBUygAwIBAgIJAOb+QiglyeZeMA0GCSqGSIb3DQEBBQUAMIGwMQswCQYD
|
3
|
+
VQQGEwJVUzEXMBUGA1UECAwOTm9ydGggQ2Fyb2xpbmExEDAO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WmCWWjYXtjoL9MlSAC/q+
|
64
|
+
NZfBi1iq0uuSus9JI/Uu8aRhoxTK56qGRed/JNixOHEmFn891cahIPpF0exWwtYD
|
65
|
+
ThwXo7Z6PI7t8EMKdSrGTOowp58yho8xYFL/Z7JmjL55Pf85GIrdiniNZd4i178J
|
66
|
+
07R9zsiLvdXq9mT33iJwkm+uhO+FA9d8OE3ji21pBbGUAQSWOdkemvUCsy8zANW9
|
67
|
+
fT+dBrMr5Buk7eaBBJ2PxECNiWLCRQJWmyff1O5zMT0daS2lBdEGUNhBZ0hnX13Q
|
68
|
+
kabUp0bxRrNRq+WkomP7onZhfZS6SjKm0UmwoV6o3V1ED6y7muQNRmgDpA5PcbvO
|
69
|
+
gl7OexNL4zcpyfMdAmTYf5yTRSvB42Yg5hVfuzPEnOIqupwES3mWkEHRlqbMUkHw
|
70
|
+
qIQAxIwQqZd5PdPpElQ/6j/ZT9DwW/I6zgndX2rsS0oGYcwFTkSj0/rKKkC13hk7
|
71
|
+
LchXMZu5ckdustM79U6OZIBairrJaL2OpR08un2nwIjgEGqhVFYc44UK1VpkE8mr
|
72
|
+
qvqJS6OHVlTlKcEDnhVkPS3i5qjuS/PtSq0CwH8bzYKFJayLDY/z36Zv6PdttzmU
|
73
|
+
Yb1NSDcJejHJ80pMINutyYQ=
|
74
|
+
-----END CERTIFICATE-----
|
data/config/routes.rb
CHANGED
@@ -11,6 +11,8 @@ Rails.application.routes.draw do
|
|
11
11
|
post 'cloud_connector', to: 'uploads#enable_cloud_connector'
|
12
12
|
|
13
13
|
resources :tasks, only: [:create, :show]
|
14
|
+
|
15
|
+
get 'status', to: 'cloud_status#index'
|
14
16
|
end
|
15
17
|
|
16
18
|
namespace :insights_cloud do
|
@@ -37,7 +39,7 @@ Rails.application.routes.draw do
|
|
37
39
|
end
|
38
40
|
|
39
41
|
scope '/r/insights' do
|
40
|
-
match '/*path', :constraints => lambda { |req| !req.path.include?('view/api') }, to: 'machine_telemetries#forward_request', via: [:get, :post, :delete,:put, :patch]
|
42
|
+
match '(/*path)(/)', :constraints => lambda { |req| !req.path.include?('view/api') }, to: 'machine_telemetries#forward_request', via: [:get, :post, :delete,:put, :patch]
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
@@ -34,6 +34,7 @@ module ForemanInventoryUpload
|
|
34
34
|
|
35
35
|
def self.for_slice(base)
|
36
36
|
base
|
37
|
+
.search_for("not params.#{InsightsCloud.enable_client_param} = f")
|
37
38
|
.joins(:subscription_facet)
|
38
39
|
.preload(
|
39
40
|
:interfaces,
|
@@ -45,26 +46,10 @@ module ForemanInventoryUpload
|
|
45
46
|
)
|
46
47
|
end
|
47
48
|
|
48
|
-
def self.for_report(portal_user)
|
49
|
-
org_ids = organizations_for_user(portal_user).pluck(:id)
|
50
|
-
for_org(org_ids)
|
51
|
-
end
|
52
|
-
|
53
49
|
def self.for_org(organization_id, use_batches: true)
|
54
50
|
base_query = for_slice(Host.unscoped.where(organization_id: organization_id))
|
55
51
|
use_batches ? base_query.in_batches(of: ForemanInventoryUpload.slice_size) : base_query
|
56
52
|
end
|
57
|
-
|
58
|
-
def self.organizations_for_user(portal_user)
|
59
|
-
Organization
|
60
|
-
.joins(:telemetry_configuration)
|
61
|
-
.where(
|
62
|
-
redhat_access_telemetry_configurations: {
|
63
|
-
portal_user: portal_user,
|
64
|
-
enable_telemetry: true,
|
65
|
-
}
|
66
|
-
)
|
67
|
-
end
|
68
53
|
end
|
69
54
|
end
|
70
55
|
end
|
@@ -19,8 +19,7 @@ module ForemanInventoryUpload
|
|
19
19
|
def generate_parameters
|
20
20
|
return [] unless Setting[:include_parameter_tags]
|
21
21
|
|
22
|
-
(@host.
|
23
|
-
.map { |item| [item.name, item.value] }
|
22
|
+
(@host.host_params || {})
|
24
23
|
.select { |_name, value| value.present? || value.is_a?(FalseClass) }
|
25
24
|
end
|
26
25
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'katello'
|
2
|
-
require 'redhat_access'
|
3
2
|
require 'foreman_ansible'
|
4
3
|
|
5
4
|
module ForemanRhCloud
|
@@ -43,6 +42,8 @@ module ForemanRhCloud
|
|
43
42
|
Foreman::Plugin.register :foreman_rh_cloud do
|
44
43
|
requires_foreman '>= 2.3'
|
45
44
|
|
45
|
+
apipie_documented_controllers ["#{ForemanRhCloud::Engine.root}/app/controllers/api/v2/**/*.rb"]
|
46
|
+
|
46
47
|
# Add permissions
|
47
48
|
security_block :foreman_rh_cloud do
|
48
49
|
permission(
|
data/lib/foreman_rh_cloud.rb
CHANGED
@@ -98,6 +98,21 @@ module ForemanRhCloud
|
|
98
98
|
|
99
99
|
# For testing purposes we can override the default hostname with an environment variable SATELLITE_RH_CLOUD_FOREMAN_HOST
|
100
100
|
def self.foreman_host
|
101
|
-
@foreman_host ||=
|
101
|
+
@foreman_host ||= begin
|
102
|
+
fullname = foreman_host_name
|
103
|
+
::Host.unscoped.friendly.find(fullname)
|
104
|
+
rescue ActiveRecord::RecordNotFound
|
105
|
+
# fullname didn't work. Let's try shortname
|
106
|
+
shortname = /(?<shortname>[^\.]*)\.?.*/.match(fullname)[:shortname]
|
107
|
+
::Host.unscoped.friendly.find(shortname)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.foreman_host_name
|
112
|
+
ENV['SATELLITE_RH_CLOUD_FOREMAN_HOST'] || ::SmartProxy.default_capsule.name
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.legacy_insights_ca
|
116
|
+
"#{ForemanRhCloud::Engine.root}/config/rh_cert-api_chain.pem"
|
102
117
|
end
|
103
118
|
end
|
@@ -19,8 +19,9 @@ module InsightsCloud
|
|
19
19
|
def run
|
20
20
|
InsightsResolution.transaction do
|
21
21
|
InsightsResolution.delete_all
|
22
|
-
|
23
|
-
|
22
|
+
rule_ids = relevant_rules
|
23
|
+
api_response = query_insights_resolutions(rule_ids) unless rule_ids.empty?
|
24
|
+
write_resolutions(api_response) if api_response
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
@@ -70,6 +71,10 @@ module InsightsCloud
|
|
70
71
|
def to_rule_id(resolution_rule_id)
|
71
72
|
RULE_ID_REGEX.match(resolution_rule_id).named_captures.fetch('id', resolution_rule_id)
|
72
73
|
end
|
74
|
+
|
75
|
+
def rescue_strategy_for_self
|
76
|
+
Dynflow::Action::Rescue::Fail
|
77
|
+
end
|
73
78
|
end
|
74
79
|
end
|
75
80
|
end
|
@@ -11,8 +11,12 @@ module InsightsCloud
|
|
11
11
|
return
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
# since the tasks are not connected, we need to force sequence execution here
|
15
|
+
# to make sure we don't run resolutions until we synced all our rules
|
16
|
+
sequence do
|
17
|
+
plan_self
|
18
|
+
plan_resolutions
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
def plan_resolutions
|
@@ -71,6 +75,10 @@ module InsightsCloud
|
|
71
75
|
rating: rule_hash['rating'],
|
72
76
|
}
|
73
77
|
end
|
78
|
+
|
79
|
+
def rescue_strategy_for_self
|
80
|
+
Dynflow::Action::Rescue::Fail
|
81
|
+
end
|
74
82
|
end
|
75
83
|
end
|
76
84
|
end
|
data/lib/insights_cloud.rb
CHANGED
@@ -17,7 +17,6 @@ module InventorySync
|
|
17
17
|
@sub_ids.map do |sub_id|
|
18
18
|
host_id = host_id(sub_id)
|
19
19
|
if host_id
|
20
|
-
touched << host_id
|
21
20
|
{
|
22
21
|
host_id: host_id,
|
23
22
|
status: InventorySync::InventoryStatus::SYNC,
|
@@ -28,10 +27,6 @@ module InventorySync
|
|
28
27
|
end.compact
|
29
28
|
end
|
30
29
|
|
31
|
-
def touched
|
32
|
-
@touched ||= []
|
33
|
-
end
|
34
|
-
|
35
30
|
def host_id(sub_id)
|
36
31
|
hosts[sub_id]
|
37
32
|
end
|
@@ -14,11 +14,7 @@ module InventorySync
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def setup_statuses
|
17
|
-
@subscribed_hosts_ids = Set.new(
|
18
|
-
ForemanInventoryUpload::Generators::Queries.for_slice(
|
19
|
-
Host.unscoped.where(organization: input[:organization_id])
|
20
|
-
).pluck(:id)
|
21
|
-
)
|
17
|
+
@subscribed_hosts_ids = Set.new(affected_host_ids)
|
22
18
|
|
23
19
|
InventorySync::InventoryStatus.transaction do
|
24
20
|
InventorySync::InventoryStatus.where(host_id: @subscribed_hosts_ids).delete_all
|
@@ -35,15 +31,22 @@ module InventorySync
|
|
35
31
|
def update_statuses_batch
|
36
32
|
results = yield
|
37
33
|
|
38
|
-
|
39
|
-
|
34
|
+
existing_hosts = results.status_hashes.select { |hash| @subscribed_hosts_ids.include?(hash[:host_id]) }
|
35
|
+
|
36
|
+
update_hosts_status(existing_hosts)
|
37
|
+
host_statuses[:sync] += existing_hosts.size
|
38
|
+
end
|
39
|
+
|
40
|
+
def rescue_strategy_for_self
|
41
|
+
Dynflow::Action::Rescue::Fail
|
40
42
|
end
|
41
43
|
|
42
44
|
private
|
43
45
|
|
44
|
-
def update_hosts_status(status_hashes
|
46
|
+
def update_hosts_status(status_hashes)
|
45
47
|
InventorySync::InventoryStatus.create(status_hashes)
|
46
|
-
|
48
|
+
updated_ids = status_hashes.map { |hash| hash[:host_id] }
|
49
|
+
@subscribed_hosts_ids.subtract(updated_ids)
|
47
50
|
end
|
48
51
|
|
49
52
|
def add_missing_hosts_statuses(hosts_ids)
|
@@ -64,6 +67,12 @@ module InventorySync
|
|
64
67
|
disconnect: 0,
|
65
68
|
}
|
66
69
|
end
|
70
|
+
|
71
|
+
def affected_host_ids
|
72
|
+
ForemanInventoryUpload::Generators::Queries.for_slice(
|
73
|
+
Host.unscoped.where(organization: input[:organization_id])
|
74
|
+
).pluck(:id)
|
75
|
+
end
|
67
76
|
end
|
68
77
|
end
|
69
78
|
end
|
@@ -28,21 +28,21 @@ module InventorySync
|
|
28
28
|
results
|
29
29
|
end
|
30
30
|
|
31
|
+
def rescue_strategy_for_self
|
32
|
+
Dynflow::Action::Rescue::Fail
|
33
|
+
end
|
34
|
+
|
31
35
|
private
|
32
36
|
|
33
37
|
def add_missing_insights_facets(uuids_hash)
|
34
|
-
|
35
|
-
missing_facets = uuids_hash.except(*existing_facets.map(&:first)).map do |host_id, uuid|
|
38
|
+
all_facets = uuids_hash.map do |host_id, uuid|
|
36
39
|
{
|
37
40
|
host_id: host_id,
|
38
41
|
uuid: uuid,
|
39
42
|
}
|
40
43
|
end
|
41
|
-
InsightsFacet.create(missing_facets)
|
42
44
|
|
43
|
-
|
44
|
-
InsightsFacet.where(host_id: host_id).update_all(uuid: uuids_hash[host_id])
|
45
|
-
end
|
45
|
+
InsightsFacet.upsert_all(all_facets, unique_by: :host_id) unless all_facets.empty?
|
46
46
|
end
|
47
47
|
|
48
48
|
def plan_self_host_sync
|
@@ -19,7 +19,6 @@ namespace :rh_cloud_inventory do
|
|
19
19
|
end
|
20
20
|
desc 'Generate inventory report to be sent to Red Hat cloud'
|
21
21
|
task generate: :environment do
|
22
|
-
portal_user = ENV['portal_user']
|
23
22
|
organizations = [ENV['organization_id']]
|
24
23
|
base_folder = ENV['target'] || Dir.pwd
|
25
24
|
|
@@ -29,18 +28,12 @@ namespace :rh_cloud_inventory do
|
|
29
28
|
puts "Using #{base_folder} for the output"
|
30
29
|
end
|
31
30
|
|
32
|
-
if
|
33
|
-
puts "Must specify
|
31
|
+
if organizations.empty?
|
32
|
+
puts "Must specify organization_id"
|
34
33
|
return
|
35
34
|
end
|
36
35
|
|
37
36
|
User.as_anonymous_admin do
|
38
|
-
if portal_user
|
39
|
-
puts "Generating report for all organizations associated with #{portal_user}"
|
40
|
-
base_folder = File.join(base_folder, portal_user)
|
41
|
-
organizations = ForemanInventoryUpload::Generators::Queries.organizations_for_user(portal_user).pluck(:id)
|
42
|
-
end
|
43
|
-
|
44
37
|
organizations.each do |organization|
|
45
38
|
target = File.join(base_folder, ForemanInventoryUpload.facts_archive_name(organization))
|
46
39
|
archived_report_generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
|
data/package.json
CHANGED
@@ -2,7 +2,13 @@ require 'test_plugin_helper'
|
|
2
2
|
|
3
3
|
module InsightsCloud::Api
|
4
4
|
class MachineTelemetriesControllerTest < ActionController::TestCase
|
5
|
+
setup do
|
6
|
+
FactoryBot.create(:common_parameter, name: InsightsCloud.enable_client_param, key_type: 'boolean', value: true)
|
7
|
+
end
|
8
|
+
|
5
9
|
context '#forward_request' do
|
10
|
+
include MockCerts
|
11
|
+
|
6
12
|
setup do
|
7
13
|
@body = 'Cloud response body'
|
8
14
|
@http_req = RestClient::Request.new(:method => 'GET', :url => 'http://test.theforeman.org')
|
@@ -12,38 +18,9 @@ module InsightsCloud::Api
|
|
12
18
|
User.current = ::Katello::CpConsumerUser.new(:uuid => host.subscription_facet.uuid, :login => host.subscription_facet.uuid)
|
13
19
|
InsightsCloud::Api::MachineTelemetriesController.any_instance.stubs(:upstream_owner).returns({ 'uuid' => 'abcdefg' })
|
14
20
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
"FzAVBgNVBAMMDnRoZWZvcmVtYW4ub3JnMB4XDTE4MDMyNDEyMzYyOFoXDTI4MDMy\r\n" +
|
19
|
-
"MTEyMzYyOFowTzELMAkGA1UEBhMCSUwxETAPBgNVBAgMCFRlbCBBdml2MRQwEgYD\r\n" +
|
20
|
-
"VQQKDAtUaGUgRm9yZW1hbjEXMBUGA1UEAwwOdGhlZm9yZW1hbi5vcmcwggIiMA0G\r\n" +
|
21
|
-
"CSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDF04/s4h+BgHPG1HDZ/sDlYq925pkc\r\n" +
|
22
|
-
"RTVAfnE2EXDAmZ6W4Q9ueDY65MHe3ZWO5Dg72kNSP2sK9kRI7Dk5CAFOgyw1rH8t\r\n" +
|
23
|
-
"Hd1+0xp/lv6e4SvSYghxIL68vFe0ftKkm1usqejBM5ZTgKr7JCI+XSIN36F65Kde\r\n" +
|
24
|
-
"c+vxwBnayuhP04r9/aaE/709SXML4eRVYW8I3qFy9FPtUOm+bY8U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
"Gde1SXVyLkqt7PoxHRJAE0BCEMJSnjxaVB329acJgeehBUxjj4CCPqtDxtbz9HEH\r\n" +
|
39
|
-
"mOKfNdaKpFor+DUeEKUWVGnr9U9xOaC+Ws+oX7MIEUCDM7p2ob4JwcjnFs1jZgHh\r\n" +
|
40
|
-
"Hwig+i7doTlc701PvKWO96fuNHK3B3/jTb1fVvSZ49O/RvY1VWODdUdxWmXGHNh3\r\n" +
|
41
|
-
"LoR8tSPEb46lC2DXGaIQumqQt8PnBG+vL1qkQa1SGTV7dJ8TTbxbv0S+sS+igkk9\r\n" +
|
42
|
-
"zsIEK8Ea3Ep935cXximz0faAAKHSA+It+xHLAyDtqy2KaAEBgGsBuuWlUfK6TaP3\r\n" +
|
43
|
-
"Gwdjct3y4yYUO45lUsUfHqX8vk/4ttW5zYeDiW+HArJz+9VUXNbEdury4kGuHgBj\r\n" +
|
44
|
-
"xHD4Bsul65+hHZ9QywKU26F1A6TLkYpQ2rk/Dx9LGICM4m4IlHjWJPFsQdtkyOor\r\n" +
|
45
|
-
"osxMtcaZZ1E=\r\n" +
|
46
|
-
"-----END CERTIFICATE-----"
|
21
|
+
setup_certs_expectation do
|
22
|
+
InsightsCloud::Api::MachineTelemetriesController.any_instance.stubs(:candlepin_id_cert)
|
23
|
+
end
|
47
24
|
end
|
48
25
|
|
49
26
|
test "should respond with response from cloud" do
|
@@ -63,13 +40,6 @@ module InsightsCloud::Api
|
|
63
40
|
::ForemanRhCloud::CloudRequestForwarder.any_instance.expects(:execute_cloud_request).with do |opts|
|
64
41
|
opts[:headers][:content_type] == 'application/json'
|
65
42
|
end.returns(res)
|
66
|
-
InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:candlepin_id_cert)
|
67
|
-
.returns(
|
68
|
-
{
|
69
|
-
cert: @cert1,
|
70
|
-
key: OpenSSL::PKey::RSA.new(1024).to_pem,
|
71
|
-
}
|
72
|
-
)
|
73
43
|
InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:cp_owner_id).returns('123')
|
74
44
|
|
75
45
|
post :forward_request, as: :json, params: { "path" => "static/v1/test", "machine_telemetry" => {"foo" => "bar"} }
|
@@ -99,6 +69,17 @@ module InsightsCloud::Api
|
|
99
69
|
assert_equal 502, @response.status
|
100
70
|
assert_equal 'Authentication to the Insights Service failed.', JSON.parse(@response.body)['message']
|
101
71
|
end
|
72
|
+
|
73
|
+
test "should forward errors to the client" do
|
74
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 500, "TEST_RESPONSE")
|
75
|
+
res = RestClient::Response.create(@body, net_http_resp, @http_req)
|
76
|
+
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:execute_cloud_request).raises(RestClient::InternalServerError.new(res))
|
77
|
+
|
78
|
+
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
79
|
+
assert_equal 500, @response.status
|
80
|
+
assert_equal 'Cloud request failed', JSON.parse(@response.body)['message']
|
81
|
+
assert_match /#{@body}/, JSON.parse(@response.body)['response']
|
82
|
+
end
|
102
83
|
end
|
103
84
|
|
104
85
|
context '#branch_info' do
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class CloudStatusControllerTest < ActionController::TestCase
|
4
|
+
include MockCerts
|
5
|
+
tests ForemanInventoryUpload::CloudStatusController
|
6
|
+
|
7
|
+
test 'return ping status hash for each organization' do
|
8
|
+
organizations = FactoryBot.create_list(:organization, 2)
|
9
|
+
user = users(:admin)
|
10
|
+
User.stubs(:current).returns(user)
|
11
|
+
user.stubs(:my_organizations).returns(organizations)
|
12
|
+
|
13
|
+
ForemanRhCloud::CloudPingService::TokenPing.any_instance.expects(:execute_cloud_request).returns(
|
14
|
+
RestClient::Response.new('TEST RESPONSE')
|
15
|
+
)
|
16
|
+
|
17
|
+
setup_certs_expectation do
|
18
|
+
ForemanRhCloud::CloudPingService::CertPing.any_instance.expects(:candlepin_id_cert).with { |actual| actual.id == organizations[0].id }
|
19
|
+
end
|
20
|
+
ForemanRhCloud::CloudPingService::CertPing.any_instance.expects(:execute_cloud_request).returns(
|
21
|
+
RestClient::Response.new('TEST RESPONSE ORG 0')
|
22
|
+
)
|
23
|
+
|
24
|
+
setup_certs_expectation do
|
25
|
+
ForemanRhCloud::CloudPingService::CertPing.any_instance.expects(:candlepin_id_cert).with { |actual| actual.id == organizations[1].id }
|
26
|
+
end
|
27
|
+
|
28
|
+
ForemanRhCloud::CloudPingService::CertPing.any_instance.expects(:execute_cloud_request).returns(
|
29
|
+
RestClient::Response.new('TEST RESPONSE ORG 1')
|
30
|
+
)
|
31
|
+
|
32
|
+
get :index, session: set_session_user
|
33
|
+
|
34
|
+
assert_response :success
|
35
|
+
actual = JSON.parse(response.body)
|
36
|
+
assert_not_nil (actual_ping = actual['ping'])
|
37
|
+
assert actual_ping['token_auth']['success']
|
38
|
+
assert_nil actual_ping['token_auth']['error']
|
39
|
+
assert actual_ping['cert_auth'][0]['success']
|
40
|
+
assert_nil actual_ping['cert_auth'][0]['error']
|
41
|
+
assert actual_ping['cert_auth'][1]['success']
|
42
|
+
assert_nil actual_ping['cert_auth'][1]['error']
|
43
|
+
end
|
44
|
+
end
|
@@ -54,10 +54,24 @@ FactoryBot.define do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
FactoryBot.define do
|
58
|
+
factory :katello_subscription, :class => Katello::Subscription do
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
57
62
|
FactoryBot.define do
|
58
63
|
factory :katello_pool, :class => Katello::Pool do
|
59
64
|
active { true }
|
60
65
|
end_date { Date.today + 1.year }
|
66
|
+
cp_id { 1 }
|
67
|
+
|
68
|
+
association :organization, :factory => :katello_organization
|
69
|
+
|
70
|
+
after(:build) do |pool, _evaluator|
|
71
|
+
pool.subscription.organization = pool.organization
|
72
|
+
end
|
73
|
+
|
74
|
+
association :subscription, :factory => :katello_subscription
|
61
75
|
end
|
62
76
|
end
|
63
77
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_plugin_helper'
|
2
2
|
require 'foreman_tasks/test_helpers'
|
3
3
|
|
4
4
|
class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
@@ -75,4 +75,13 @@ class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
|
75
75
|
assert_equal 5, InsightsResolution.all.count
|
76
76
|
assert_equal 2, @rule.resolutions.count
|
77
77
|
end
|
78
|
+
|
79
|
+
test 'Skips pinging the cloud if no rule ids were found' do
|
80
|
+
InsightsCloud::Async::InsightsResolutionsSync.any_instance.expects(:query_insights_resolutions).never
|
81
|
+
InsightsRule.all.delete_all
|
82
|
+
|
83
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsResolutionsSync)
|
84
|
+
|
85
|
+
assert_equal 0, InsightsResolution.all.count
|
86
|
+
end
|
78
87
|
end
|