foreman_rh_cloud 3.0.33 → 4.0.21.1
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/foreman_inventory_upload/reports_controller.rb +1 -3
- data/app/controllers/foreman_inventory_upload/tasks_controller.rb +13 -5
- data/app/controllers/foreman_inventory_upload/uploads_controller.rb +4 -4
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +7 -29
- data/app/controllers/insights_cloud/hits_controller.rb +3 -7
- data/app/models/insights_client_report_status.rb +22 -11
- data/app/services/foreman_rh_cloud/cloud_auth.rb +0 -16
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +17 -27
- data/app/services/foreman_rh_cloud/remediations_retriever.rb +4 -6
- data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +9 -0
- data/config/Gemfile.lock.gh_test +95 -93
- data/config/database.yml.example +2 -2
- data/config/routes.rb +1 -20
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +1 -22
- data/lib/foreman_inventory_upload/generators/queries.rb +0 -1
- data/lib/foreman_inventory_upload/generators/slice.rb +5 -6
- data/lib/foreman_inventory_upload/generators/tags.rb +2 -11
- data/lib/foreman_inventory_upload.rb +1 -9
- data/lib/foreman_rh_cloud/engine.rb +10 -17
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/foreman_rh_cloud.rb +1 -12
- data/lib/insights_cloud/async/insights_full_sync.rb +14 -9
- data/lib/insights_cloud/async/insights_resolutions_sync.rb +6 -13
- data/lib/insights_cloud/async/insights_rules_sync.rb +9 -13
- data/lib/inventory_sync/async/host_result.rb +5 -4
- data/lib/inventory_sync/async/inventory_full_sync.rb +10 -21
- data/lib/inventory_sync/async/inventory_hosts_sync.rb +3 -18
- data/lib/inventory_sync/async/inventory_scheduled_sync.rb +0 -12
- data/lib/inventory_sync/async/query_inventory_job.rb +5 -6
- data/lib/tasks/insights.rake +0 -15
- data/lib/tasks/rh_cloud_inventory.rake +1 -8
- data/package.json +3 -3
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +0 -41
- data/test/factories/inventory_upload_factories.rb +1 -1
- data/test/jobs/insights_full_sync_test.rb +0 -1
- data/test/jobs/insights_resolutions_sync_test.rb +1 -11
- data/test/jobs/insights_rules_sync_test.rb +0 -1
- data/test/jobs/inventory_full_sync_test.rb +2 -38
- data/test/models/insights_client_report_status_test.rb +72 -70
- data/test/test_plugin_helper.rb +0 -55
- data/test/unit/fact_helpers_test.rb +2 -2
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +3 -21
- data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +0 -1
- data/test/unit/slice_generator_test.rb +27 -70
- data/test/unit/tags_generator_test.rb +0 -56
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +0 -11
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +0 -11
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +63 -28
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +3 -2
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +19 -19
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +14 -14
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +0 -1
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +0 -14
- data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +13 -20
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +1 -4
- data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +20 -44
- data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +0 -2
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +2 -2
- data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +7 -11
- metadata +4 -32
- data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +0 -50
- data/app/controllers/concerns/inventory_upload/report_actions.rb +0 -26
- data/app/controllers/concerns/inventory_upload/task_actions.rb +0 -25
- data/app/helpers/foreman_insights_deprecations_helper.rb +0 -9
- data/app/helpers/foreman_insights_host_helper.rb +0 -19
- data/app/overrides/old_plugin_deprecation.rb +0 -20
- data/app/services/foreman_rh_cloud/cloud_request.rb +0 -14
- data/app/services/foreman_rh_cloud/insights_status_cleaner.rb +0 -17
- data/config/package-lock.json.plugin +0 -32774
- data/db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb +0 -6
- data/lib/insights_cloud/async/insights_client_status_aging.rb +0 -23
- data/lib/inventory_sync/async/inventory_self_host_sync.rb +0 -39
- data/test/controllers/inventory_upload/api/inventory_controller_test.rb +0 -53
- data/test/jobs/insights_client_status_aging_test.rb +0 -33
- data/test/jobs/inventory_hosts_sync_test.rb +0 -283
- data/test/jobs/inventory_scheduled_sync_test.rb +0 -22
- data/test/jobs/inventory_self_host_sync_test.rb +0 -104
- data/test/unit/foreman_rh_cloud_self_host_test.rb +0 -28
- data/test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb +0 -31
- data/webpack/common/ForemanTasks/ForemanTasksActions.js +0 -64
- data/webpack/common/ForemanTasks/ForemanTasksHelpers.js +0 -7
- data/webpack/common/ForemanTasks/index.js +0 -1
|
@@ -6,11 +6,6 @@ module InsightsCloud
|
|
|
6
6
|
include ::ForemanRhCloud::CloudAuth
|
|
7
7
|
|
|
8
8
|
def plan
|
|
9
|
-
unless cloud_auth_available?
|
|
10
|
-
logger.debug('Cloud authentication is not available, skipping insights sync')
|
|
11
|
-
return
|
|
12
|
-
end
|
|
13
|
-
|
|
14
9
|
sequence do
|
|
15
10
|
# This can be turned off when we enable automatic status syncs
|
|
16
11
|
# This step will query cloud inventory to retrieve inventory uuids for each host
|
|
@@ -55,18 +50,28 @@ module InsightsCloud
|
|
|
55
50
|
end
|
|
56
51
|
|
|
57
52
|
def query_insights_hits
|
|
58
|
-
hits_response =
|
|
53
|
+
hits_response = RestClient::Request.execute(
|
|
59
54
|
method: :get,
|
|
60
|
-
url: InsightsCloud.hits_export_url
|
|
55
|
+
url: InsightsCloud.hits_export_url,
|
|
56
|
+
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
|
57
|
+
proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
|
|
58
|
+
headers: {
|
|
59
|
+
Authorization: "Bearer #{rh_credentials}",
|
|
60
|
+
}
|
|
61
61
|
)
|
|
62
62
|
|
|
63
63
|
JSON.parse(hits_response)
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
def query_insights_rules
|
|
67
|
-
rules_response =
|
|
67
|
+
rules_response = RestClient::Request.execute(
|
|
68
68
|
method: :get,
|
|
69
|
-
url: InsightsCloud.rules_url
|
|
69
|
+
url: InsightsCloud.rules_url,
|
|
70
|
+
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
|
71
|
+
proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
|
|
72
|
+
headers: {
|
|
73
|
+
Authorization: "Bearer #{rh_credentials}",
|
|
74
|
+
}
|
|
70
75
|
)
|
|
71
76
|
|
|
72
77
|
JSON.parse(rules_response)
|
|
@@ -7,21 +7,11 @@ module InsightsCloud
|
|
|
7
7
|
|
|
8
8
|
RULE_ID_REGEX = /[^:]*:(?<id>.*)/
|
|
9
9
|
|
|
10
|
-
def plan
|
|
11
|
-
unless cloud_auth_available?
|
|
12
|
-
logger.debug('Cloud authentication is not available, skipping resolutions sync')
|
|
13
|
-
return
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
plan_self
|
|
17
|
-
end
|
|
18
|
-
|
|
19
10
|
def run
|
|
20
11
|
InsightsResolution.transaction do
|
|
21
12
|
InsightsResolution.delete_all
|
|
22
|
-
|
|
23
|
-
api_response
|
|
24
|
-
write_resolutions(api_response) if api_response
|
|
13
|
+
api_response = query_insights_resolutions(relevant_rules)
|
|
14
|
+
write_resolutions(api_response)
|
|
25
15
|
end
|
|
26
16
|
end
|
|
27
17
|
|
|
@@ -32,11 +22,14 @@ module InsightsCloud
|
|
|
32
22
|
private
|
|
33
23
|
|
|
34
24
|
def query_insights_resolutions(rule_ids)
|
|
35
|
-
resolutions_response =
|
|
25
|
+
resolutions_response = RestClient::Request.execute(
|
|
36
26
|
method: :post,
|
|
37
27
|
url: InsightsCloud.resolutions_url,
|
|
28
|
+
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
|
29
|
+
proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
|
|
38
30
|
headers: {
|
|
39
31
|
content_type: :json,
|
|
32
|
+
Authorization: "Bearer #{rh_credentials}",
|
|
40
33
|
},
|
|
41
34
|
payload: {
|
|
42
35
|
issues: rule_ids,
|
|
@@ -6,17 +6,8 @@ module InsightsCloud
|
|
|
6
6
|
include ::ForemanRhCloud::CloudAuth
|
|
7
7
|
|
|
8
8
|
def plan
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
end
|
|
13
|
-
|
|
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
|
|
9
|
+
plan_self
|
|
10
|
+
plan_resolutions
|
|
20
11
|
end
|
|
21
12
|
|
|
22
13
|
def plan_resolutions
|
|
@@ -46,9 +37,14 @@ module InsightsCloud
|
|
|
46
37
|
private
|
|
47
38
|
|
|
48
39
|
def query_insights_rules(offset)
|
|
49
|
-
rules_response =
|
|
40
|
+
rules_response = RestClient::Request.execute(
|
|
50
41
|
method: :get,
|
|
51
|
-
url: InsightsCloud.rules_url(offset: offset)
|
|
42
|
+
url: InsightsCloud.rules_url(offset: offset),
|
|
43
|
+
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
|
44
|
+
proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
|
|
45
|
+
headers: {
|
|
46
|
+
Authorization: "Bearer #{rh_credentials}",
|
|
47
|
+
}
|
|
52
48
|
)
|
|
53
49
|
|
|
54
50
|
JSON.parse(rules_response)
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
module InventorySync
|
|
2
2
|
module Async
|
|
3
3
|
class HostResult
|
|
4
|
-
attr_reader :uuid_by_fqdn
|
|
5
|
-
|
|
6
4
|
def initialize(result)
|
|
7
5
|
@total = result['total']
|
|
8
6
|
@count = result['count']
|
|
@@ -10,23 +8,26 @@ module InventorySync
|
|
|
10
8
|
@per_page = result['per_page']
|
|
11
9
|
@sub_ids = result["results"].map { |host| host['subscription_manager_id'] }
|
|
12
10
|
@uuid_by_sub_id = Hash[result["results"].map { |host| [host['subscription_manager_id'], host['id']] }]
|
|
13
|
-
@uuid_by_fqdn = Hash[result["results"].map { |host| [host['fqdn'].downcase, host['id']] }]
|
|
14
11
|
end
|
|
15
12
|
|
|
16
13
|
def status_hashes
|
|
17
14
|
@sub_ids.map do |sub_id|
|
|
18
15
|
host_id = host_id(sub_id)
|
|
19
16
|
if host_id
|
|
17
|
+
touched << host_id
|
|
20
18
|
{
|
|
21
19
|
host_id: host_id,
|
|
22
20
|
status: InventorySync::InventoryStatus::SYNC,
|
|
23
21
|
reported_at: DateTime.current,
|
|
24
|
-
type: InventorySync::InventoryStatus.name,
|
|
25
22
|
}
|
|
26
23
|
end
|
|
27
24
|
end.compact
|
|
28
25
|
end
|
|
29
26
|
|
|
27
|
+
def touched
|
|
28
|
+
@touched ||= []
|
|
29
|
+
end
|
|
30
|
+
|
|
30
31
|
def host_id(sub_id)
|
|
31
32
|
hosts[sub_id]
|
|
32
33
|
end
|
|
@@ -5,16 +5,15 @@ module InventorySync
|
|
|
5
5
|
set_callback :step, :around, :update_statuses_batch
|
|
6
6
|
|
|
7
7
|
def plan(organization)
|
|
8
|
-
unless cloud_auth_available?
|
|
9
|
-
logger.debug('Cloud authentication is not available, skipping inventory hosts sync')
|
|
10
|
-
return
|
|
11
|
-
end
|
|
12
|
-
|
|
13
8
|
plan_self(organization_id: organization.id)
|
|
14
9
|
end
|
|
15
10
|
|
|
16
11
|
def setup_statuses
|
|
17
|
-
@subscribed_hosts_ids = Set.new(
|
|
12
|
+
@subscribed_hosts_ids = Set.new(
|
|
13
|
+
ForemanInventoryUpload::Generators::Queries.for_slice(
|
|
14
|
+
Host.unscoped.where(organization: input[:organization_id])
|
|
15
|
+
).pluck(:id)
|
|
16
|
+
)
|
|
18
17
|
|
|
19
18
|
InventorySync::InventoryStatus.transaction do
|
|
20
19
|
InventorySync::InventoryStatus.where(host_id: @subscribed_hosts_ids).delete_all
|
|
@@ -25,24 +24,20 @@ module InventorySync
|
|
|
25
24
|
|
|
26
25
|
logger.debug("Synced hosts amount: #{host_statuses[:sync]}")
|
|
27
26
|
logger.debug("Disconnected hosts amount: #{host_statuses[:disconnect]}")
|
|
28
|
-
output[:host_statuses] = host_statuses
|
|
29
27
|
end
|
|
30
28
|
|
|
31
29
|
def update_statuses_batch
|
|
32
30
|
results = yield
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
update_hosts_status(existing_hosts)
|
|
37
|
-
host_statuses[:sync] += existing_hosts.size
|
|
32
|
+
update_hosts_status(results.status_hashes, results.touched)
|
|
33
|
+
host_statuses[:sync] += results.touched.size
|
|
38
34
|
end
|
|
39
35
|
|
|
40
36
|
private
|
|
41
37
|
|
|
42
|
-
def update_hosts_status(status_hashes)
|
|
38
|
+
def update_hosts_status(status_hashes, touched)
|
|
43
39
|
InventorySync::InventoryStatus.create(status_hashes)
|
|
44
|
-
|
|
45
|
-
@subscribed_hosts_ids.subtract(updated_ids)
|
|
40
|
+
@subscribed_hosts_ids.subtract(touched)
|
|
46
41
|
end
|
|
47
42
|
|
|
48
43
|
def add_missing_hosts_statuses(hosts_ids)
|
|
@@ -58,17 +53,11 @@ module InventorySync
|
|
|
58
53
|
end
|
|
59
54
|
|
|
60
55
|
def host_statuses
|
|
61
|
-
|
|
56
|
+
output[:host_statuses] ||= {
|
|
62
57
|
sync: 0,
|
|
63
58
|
disconnect: 0,
|
|
64
59
|
}
|
|
65
60
|
end
|
|
66
|
-
|
|
67
|
-
def affected_host_ids
|
|
68
|
-
ForemanInventoryUpload::Generators::Queries.for_slice(
|
|
69
|
-
Host.unscoped.where(organization: input[:organization_id])
|
|
70
|
-
).pluck(:id)
|
|
71
|
-
end
|
|
72
61
|
end
|
|
73
62
|
end
|
|
74
63
|
end
|
|
@@ -4,17 +4,6 @@ module InventorySync
|
|
|
4
4
|
set_callback :iteration, :around, :setup_facet_transaction
|
|
5
5
|
set_callback :step, :around, :create_facets
|
|
6
6
|
|
|
7
|
-
def plan
|
|
8
|
-
unless cloud_auth_available?
|
|
9
|
-
logger.debug('Cloud authentication is not available, skipping inventory hosts sync')
|
|
10
|
-
return
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
# by default the tasks will be executed concurrently
|
|
14
|
-
plan_self
|
|
15
|
-
plan_self_host_sync
|
|
16
|
-
end
|
|
17
|
-
|
|
18
7
|
def setup_facet_transaction
|
|
19
8
|
InsightsFacet.transaction do
|
|
20
9
|
yield
|
|
@@ -31,18 +20,14 @@ module InventorySync
|
|
|
31
20
|
private
|
|
32
21
|
|
|
33
22
|
def add_missing_insights_facets(uuids_hash)
|
|
34
|
-
|
|
23
|
+
existing_facets = InsightsFacet.where(host_id: uuids_hash.keys).pluck(:host_id)
|
|
24
|
+
missing_facets = uuids_hash.except(*existing_facets).map do |host_id, uuid|
|
|
35
25
|
{
|
|
36
26
|
host_id: host_id,
|
|
37
27
|
uuid: uuid,
|
|
38
28
|
}
|
|
39
29
|
end
|
|
40
|
-
|
|
41
|
-
InsightsFacet.upsert_all(all_facets, unique_by: :host_id) unless all_facets.empty?
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def plan_self_host_sync
|
|
45
|
-
plan_action InventorySync::Async::InventorySelfHostSync
|
|
30
|
+
InsightsFacet.create(missing_facets)
|
|
46
31
|
end
|
|
47
32
|
end
|
|
48
33
|
end
|
|
@@ -4,14 +4,6 @@ module InventorySync
|
|
|
4
4
|
include ::Actions::RecurringAction
|
|
5
5
|
|
|
6
6
|
def plan
|
|
7
|
-
unless Setting[:allow_auto_inventory_upload]
|
|
8
|
-
logger.debug(
|
|
9
|
-
'The scheduled process is disabled due to the "allow_auto_inventory_upload"
|
|
10
|
-
setting being set to false.'
|
|
11
|
-
)
|
|
12
|
-
return
|
|
13
|
-
end
|
|
14
|
-
|
|
15
7
|
Organization.unscoped.each do |org|
|
|
16
8
|
plan_org_sync(org)
|
|
17
9
|
end
|
|
@@ -20,10 +12,6 @@ module InventorySync
|
|
|
20
12
|
def plan_org_sync(org)
|
|
21
13
|
plan_action InventoryFullSync, org
|
|
22
14
|
end
|
|
23
|
-
|
|
24
|
-
def logger
|
|
25
|
-
action_logger
|
|
26
|
-
end
|
|
27
15
|
end
|
|
28
16
|
end
|
|
29
17
|
end
|
|
@@ -29,10 +29,13 @@ module InventorySync
|
|
|
29
29
|
private
|
|
30
30
|
|
|
31
31
|
def query_inventory(page = 1)
|
|
32
|
-
hosts_inventory_response =
|
|
32
|
+
hosts_inventory_response = RestClient::Request.execute(
|
|
33
33
|
method: :get,
|
|
34
|
-
url:
|
|
34
|
+
url: ForemanInventoryUpload.inventory_export_url,
|
|
35
|
+
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
|
36
|
+
proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
|
|
35
37
|
headers: {
|
|
38
|
+
Authorization: "Bearer #{rh_credentials}",
|
|
36
39
|
params: {
|
|
37
40
|
per_page: 100,
|
|
38
41
|
page: page,
|
|
@@ -46,10 +49,6 @@ module InventorySync
|
|
|
46
49
|
def logger
|
|
47
50
|
action_logger
|
|
48
51
|
end
|
|
49
|
-
|
|
50
|
-
def request_url
|
|
51
|
-
ForemanInventoryUpload.inventory_export_url
|
|
52
|
-
end
|
|
53
52
|
end
|
|
54
53
|
end
|
|
55
54
|
end
|
data/lib/tasks/insights.rake
CHANGED
|
@@ -4,19 +4,4 @@ namespace :rh_cloud_insights do
|
|
|
4
4
|
ForemanTasks.sync_task(InsightsCloud::Async::InsightsFullSync)
|
|
5
5
|
puts "Synchronized Insights hosts hits data"
|
|
6
6
|
end
|
|
7
|
-
|
|
8
|
-
desc "Remove insights client report statuses by searching on host criteria"
|
|
9
|
-
task clean_statuses: [:environment] do
|
|
10
|
-
hosts_search = ENV['SEARCH']
|
|
11
|
-
|
|
12
|
-
if hosts_search.empty?
|
|
13
|
-
puts 'Must specify SEARCH= criteria for hosts search'
|
|
14
|
-
next
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
cleaner = ForemanRhCloud::InsightsStatusCleaner.new
|
|
18
|
-
deleted_count = cleaner.clean(hosts_search)
|
|
19
|
-
|
|
20
|
-
puts "Deleted #{deleted_count} insights statuses"
|
|
21
|
-
end
|
|
22
7
|
end
|
|
@@ -23,15 +23,8 @@ namespace :rh_cloud_inventory do
|
|
|
23
23
|
organizations = [ENV['organization_id']]
|
|
24
24
|
base_folder = ENV['target'] || Dir.pwd
|
|
25
25
|
|
|
26
|
-
unless
|
|
27
|
-
puts "#{base_folder} is not writable by the current process"
|
|
28
|
-
base_folder = Dir.mktmpdir
|
|
29
|
-
puts "Using #{base_folder} for the output"
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
if portal_user.empty? && organizations.empty?
|
|
26
|
+
unless portal_user || organizations.empty?
|
|
33
27
|
puts "Must specify either portal_user or organization_id"
|
|
34
|
-
return
|
|
35
28
|
end
|
|
36
29
|
|
|
37
30
|
User.as_anonymous_admin do
|
data/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foreman_rh_cloud",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.21.1",
|
|
4
4
|
"description": "Inventory Upload =============",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "~7.7.0",
|
|
29
|
+
"@redhat-cloud-services/frontend-components": "^2.5.0",
|
|
29
30
|
"@theforeman/builder": "~4.14.0",
|
|
30
31
|
"@theforeman/stories": "~4.14.0",
|
|
31
32
|
"@theforeman/test": "~4.14.0",
|
|
@@ -42,7 +43,6 @@
|
|
|
42
43
|
},
|
|
43
44
|
"dependencies": {
|
|
44
45
|
"jed": "~1.1.1",
|
|
45
|
-
"react-intl": "~2.8.0"
|
|
46
|
-
"@redhat-cloud-services/frontend-components": "^2.5.0"
|
|
46
|
+
"react-intl": "~2.8.0"
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -3,8 +3,6 @@ require 'test_plugin_helper'
|
|
|
3
3
|
module InsightsCloud::Api
|
|
4
4
|
class MachineTelemetriesControllerTest < ActionController::TestCase
|
|
5
5
|
context '#forward_request' do
|
|
6
|
-
include MockCerts
|
|
7
|
-
|
|
8
6
|
setup do
|
|
9
7
|
@body = 'Cloud response body'
|
|
10
8
|
@http_req = RestClient::Request.new(:method => 'GET', :url => 'http://test.theforeman.org')
|
|
@@ -13,10 +11,6 @@ module InsightsCloud::Api
|
|
|
13
11
|
host = FactoryBot.create(:host, :with_subscription, :organization => org)
|
|
14
12
|
User.current = ::Katello::CpConsumerUser.new(:uuid => host.subscription_facet.uuid, :login => host.subscription_facet.uuid)
|
|
15
13
|
InsightsCloud::Api::MachineTelemetriesController.any_instance.stubs(:upstream_owner).returns({ 'uuid' => 'abcdefg' })
|
|
16
|
-
|
|
17
|
-
setup_certs_expectation do
|
|
18
|
-
InsightsCloud::Api::MachineTelemetriesController.any_instance.stubs(:candlepin_id_cert)
|
|
19
|
-
end
|
|
20
14
|
end
|
|
21
15
|
|
|
22
16
|
test "should respond with response from cloud" do
|
|
@@ -36,7 +30,6 @@ module InsightsCloud::Api
|
|
|
36
30
|
::ForemanRhCloud::CloudRequestForwarder.any_instance.expects(:execute_cloud_request).with do |opts|
|
|
37
31
|
opts[:headers][:content_type] == 'application/json'
|
|
38
32
|
end.returns(res)
|
|
39
|
-
InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:cp_owner_id).returns('123')
|
|
40
33
|
|
|
41
34
|
post :forward_request, as: :json, params: { "path" => "static/v1/test", "machine_telemetry" => {"foo" => "bar"} }
|
|
42
35
|
assert_equal @body, @response.body
|
|
@@ -56,29 +49,6 @@ module InsightsCloud::Api
|
|
|
56
49
|
assert_equal x_rh_insights_request_id, @response.headers['x_rh_insights_request_id']
|
|
57
50
|
end
|
|
58
51
|
|
|
59
|
-
test "should set etag header to response from cloud" do
|
|
60
|
-
etag = '12345'
|
|
61
|
-
req = RestClient::Request.new(:method => 'GET', :url => 'http://test.theforeman.org', :headers => { "If-None-Match": etag})
|
|
62
|
-
net_http_resp = Net::HTTPResponse.new(1.0, 200, "OK")
|
|
63
|
-
net_http_resp[Rack::ETAG] = etag
|
|
64
|
-
res = RestClient::Response.create(@body, net_http_resp, req)
|
|
65
|
-
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:forward_request).returns(res)
|
|
66
|
-
|
|
67
|
-
get :forward_request, params: { "path" => "static/v1/release/insights-core.egg" }
|
|
68
|
-
assert_equal etag, @response.headers[Rack::ETAG]
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
test "should set content type header to response from cloud" do
|
|
72
|
-
req = RestClient::Request.new(:method => 'GET', :url => 'http://test.theforeman.org')
|
|
73
|
-
net_http_resp = Net::HTTPResponse.new(1.0, 200, "OK")
|
|
74
|
-
net_http_resp['Content-Type'] = 'application/zip'
|
|
75
|
-
res = RestClient::Response.create(@body, net_http_resp, req)
|
|
76
|
-
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:forward_request).returns(res)
|
|
77
|
-
|
|
78
|
-
get :forward_request, params: { "path" => "static/v1/release/insights-core.egg" }
|
|
79
|
-
assert_equal net_http_resp['Content-Type'], @response.headers['Content-Type']
|
|
80
|
-
end
|
|
81
|
-
|
|
82
52
|
test "should handle failed authentication to cloud" do
|
|
83
53
|
net_http_resp = Net::HTTPResponse.new(1.0, 401, "Unauthorized")
|
|
84
54
|
res = RestClient::Response.create(@body, net_http_resp, @http_req)
|
|
@@ -88,17 +58,6 @@ module InsightsCloud::Api
|
|
|
88
58
|
assert_equal 502, @response.status
|
|
89
59
|
assert_equal 'Authentication to the Insights Service failed.', JSON.parse(@response.body)['message']
|
|
90
60
|
end
|
|
91
|
-
|
|
92
|
-
test "should forward errors to the client" do
|
|
93
|
-
net_http_resp = Net::HTTPResponse.new(1.0, 500, "TEST_RESPONSE")
|
|
94
|
-
res = RestClient::Response.create(@body, net_http_resp, @http_req)
|
|
95
|
-
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:execute_cloud_request).raises(RestClient::InternalServerError.new(res))
|
|
96
|
-
|
|
97
|
-
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
|
98
|
-
assert_equal 500, @response.status
|
|
99
|
-
assert_equal 'Cloud request failed', JSON.parse(@response.body)['message']
|
|
100
|
-
assert_match /#{@body}/, JSON.parse(@response.body)['response']
|
|
101
|
-
end
|
|
102
61
|
end
|
|
103
62
|
|
|
104
63
|
context '#branch_info' do
|
|
@@ -49,7 +49,7 @@ end
|
|
|
49
49
|
|
|
50
50
|
FactoryBot.define do
|
|
51
51
|
factory :katello_subscription_facets, :aliases => [:subscription_facet], :class => ::Katello::Host::SubscriptionFacet do
|
|
52
|
-
sequence(:uuid) { |n| "
|
|
52
|
+
sequence(:uuid) { |n| "uuid-#{n}-#{rand(500)}" }
|
|
53
53
|
facts { { 'memory.memtotal' => "12 GB" } }
|
|
54
54
|
end
|
|
55
55
|
end
|
|
@@ -7,7 +7,6 @@ class InsightsFullSyncTest < ActiveSupport::TestCase
|
|
|
7
7
|
setup do
|
|
8
8
|
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_rules_sync)
|
|
9
9
|
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_notifications)
|
|
10
|
-
FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
|
|
11
10
|
|
|
12
11
|
uuid1 = 'accdf444-5628-451d-bf3e-cf909ad72756'
|
|
13
12
|
@host1 = FactoryBot.create(:host, :managed, name: 'host1')
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
require 'foreman_tasks/test_helpers'
|
|
3
3
|
|
|
4
4
|
class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
|
@@ -63,7 +63,6 @@ class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
@rule = FactoryBot.create(:insights_rule, rule_id: 'network_tcp_connection_hang|NETWORK_TCP_CONNECTION_HANG_WARN')
|
|
66
|
-
FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
|
|
67
66
|
end
|
|
68
67
|
|
|
69
68
|
test 'Resolutions data is replaced with data from cloud' do
|
|
@@ -75,13 +74,4 @@ class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
|
|
75
74
|
assert_equal 5, InsightsResolution.all.count
|
|
76
75
|
assert_equal 2, @rule.resolutions.count
|
|
77
76
|
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
|
|
87
77
|
end
|
|
@@ -112,7 +112,6 @@ class InsightsRulesSyncTest < ActiveSupport::TestCase
|
|
|
112
112
|
@hit = FactoryBot.create(:insights_hit, host_id: @host.id)
|
|
113
113
|
|
|
114
114
|
InsightsCloud::Async::InsightsRulesSync.any_instance.stubs(:plan_resolutions)
|
|
115
|
-
FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
|
|
116
115
|
end
|
|
117
116
|
|
|
118
117
|
test 'Hits data is replaced with data from cloud' do
|
|
@@ -37,18 +37,6 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
|
37
37
|
@host2.subscription_facet.pools << pool
|
|
38
38
|
@host2_inventory_id = '4536bf5c-ff03-4154-a8c9-32ff4b40e40c'
|
|
39
39
|
|
|
40
|
-
# this host would pass our plugin queries, so it could be uploaded to the cloud.
|
|
41
|
-
@host3 = FactoryBot.create(
|
|
42
|
-
:host,
|
|
43
|
-
:with_subscription,
|
|
44
|
-
:with_content,
|
|
45
|
-
content_view: cv.first,
|
|
46
|
-
lifecycle_environment: env,
|
|
47
|
-
organization: env.organization
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
@host3.subscription_facet.pools << pool
|
|
51
|
-
|
|
52
40
|
ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
|
|
53
41
|
|
|
54
42
|
inventory_json = <<-INVENTORY_JSON
|
|
@@ -163,7 +151,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
|
163
151
|
{
|
|
164
152
|
"insights_id": "b533848e-465f-4f1a-9b2b-b71cb2d5239d",
|
|
165
153
|
"rhel_machine_id": null,
|
|
166
|
-
"subscription_manager_id": "
|
|
154
|
+
"subscription_manager_id": "d29bde40-348e-437c-8acf-8fa98320fc1b",
|
|
167
155
|
"satellite_id": "d29bde40-348e-437c-8acf-8fa98320fc1b",
|
|
168
156
|
"bios_uuid": "3cd5d972-cfb5-451a-8314-fd2f56629d7c",
|
|
169
157
|
"ip_addresses": [
|
|
@@ -171,7 +159,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
|
171
159
|
"fd6e:2298:736e::857",
|
|
172
160
|
"fd6e:2298:736e:0:2c66:6101:9cc6:2b23"
|
|
173
161
|
],
|
|
174
|
-
"fqdn": "
|
|
162
|
+
"fqdn": "rhel8-demo.oss-lab.net",
|
|
175
163
|
"mac_addresses": [
|
|
176
164
|
"6e:66:a6:fe:fc:07",
|
|
177
165
|
"00:00:00:00:00:00"
|
|
@@ -254,7 +242,6 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
|
254
242
|
end
|
|
255
243
|
|
|
256
244
|
test 'Host status should be SYNC for inventory hosts' do
|
|
257
|
-
FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'TEST TOKEN')
|
|
258
245
|
InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
|
|
259
246
|
|
|
260
247
|
ForemanTasks.sync_task(InventorySync::Async::InventoryFullSync, @host2.organization)
|
|
@@ -266,7 +253,6 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
|
266
253
|
end
|
|
267
254
|
|
|
268
255
|
test 'Host status should be DISCONNECT for hosts that are not returned from cloud' do
|
|
269
|
-
FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'TEST TOKEN')
|
|
270
256
|
InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
|
|
271
257
|
FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
|
|
272
258
|
|
|
@@ -275,26 +261,4 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
|
275
261
|
|
|
276
262
|
assert_equal InventorySync::InventoryStatus::DISCONNECT, InventorySync::InventoryStatus.where(host_id: @host1.id).first.status
|
|
277
263
|
end
|
|
278
|
-
|
|
279
|
-
test 'Task should be aborted if token is not present' do
|
|
280
|
-
FactoryBot.create(:setting, name: 'rh_cloud_token', value: '')
|
|
281
|
-
|
|
282
|
-
InventorySync::Async::InventoryFullSync.any_instance.expects(:plan_self).never
|
|
283
|
-
|
|
284
|
-
ForemanTasks.sync_task(InventorySync::Async::InventoryFullSync, @host1.organization)
|
|
285
|
-
end
|
|
286
|
-
|
|
287
|
-
test 'Should skip hosts that are not returned in query' do
|
|
288
|
-
assert_nil InventorySync::InventoryStatus.where(host_id: @host3.id).first
|
|
289
|
-
|
|
290
|
-
FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'TEST TOKEN')
|
|
291
|
-
InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
|
|
292
|
-
InventorySync::Async::InventoryFullSync.any_instance.expects(:affected_host_ids).returns([@host1.id, @host2.id])
|
|
293
|
-
FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
|
|
294
|
-
|
|
295
|
-
ForemanTasks.sync_task(InventorySync::Async::InventoryFullSync, @host1.organization)
|
|
296
|
-
@host2.reload
|
|
297
|
-
|
|
298
|
-
assert_nil InventorySync::InventoryStatus.where(host_id: @host3.id).first
|
|
299
|
-
end
|
|
300
264
|
end
|