foreman_rh_cloud 3.0.19 → 4.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -5
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +17 -7
- data/app/controllers/insights_cloud/hits_controller.rb +37 -0
- data/app/controllers/insights_cloud/settings_controller.rb +1 -1
- data/app/controllers/insights_cloud/tasks_controller.rb +1 -2
- data/app/models/insights_client_report_status.rb +58 -0
- data/app/models/inventory_sync/inventory_status.rb +6 -0
- data/app/models/setting/rh_cloud.rb +5 -5
- data/app/services/foreman_rh_cloud/cloud_auth.rb +12 -0
- data/app/services/foreman_rh_cloud/cloud_connector.rb +1 -1
- data/app/services/foreman_rh_cloud/cloud_request.rb +14 -0
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +1 -6
- data/app/services/foreman_rh_cloud/remediations_retriever.rb +75 -0
- data/app/services/foreman_rh_cloud/template_renderer_helper.rb +22 -0
- data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +9 -0
- data/app/views/job_templates/rh_cloud_remediations.erb +14 -0
- data/config/routes.rb +1 -0
- data/db/migrate/20210404000001_change_resolutions.foreman_rh_cloud.rb +10 -0
- data/db/seeds.d/179_ui_notifications.rb +11 -0
- data/db/seeds.d/50_job_templates.rb +14 -0
- data/lib/foreman_inventory_upload.rb +5 -1
- data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +8 -2
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +19 -0
- data/lib/foreman_inventory_upload/generators/queries.rb +3 -2
- data/lib/foreman_inventory_upload/generators/slice.rb +6 -6
- data/lib/foreman_inventory_upload/generators/tags.rb +8 -6
- data/lib/foreman_rh_cloud.rb +18 -0
- data/lib/foreman_rh_cloud/engine.rb +36 -2
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud.rb +12 -0
- data/lib/insights_cloud/async/insights_full_sync.rb +31 -22
- data/lib/insights_cloud/async/insights_generate_notifications.rb +58 -0
- data/lib/insights_cloud/async/insights_resolutions_sync.rb +66 -0
- data/lib/insights_cloud/async/insights_rules_sync.rb +15 -24
- data/lib/insights_cloud/async/insights_scheduled_sync.rb +1 -1
- data/lib/inventory_sync/async/inventory_full_sync.rb +2 -1
- data/lib/inventory_sync/async/inventory_scheduled_sync.rb +25 -0
- data/lib/inventory_sync/async/query_inventory_job.rb +1 -4
- data/lib/tasks/insights.rake +4 -12
- data/lib/tasks/rh_cloud_inventory.rake +18 -4
- data/package.json +1 -1
- data/test/factories/insights_factories.rb +22 -0
- data/test/factories/inventory_upload_factories.rb +1 -1
- data/test/jobs/insights_full_sync_test.rb +17 -8
- data/test/jobs/insights_resolutions_sync_test.rb +77 -0
- data/test/jobs/insights_rules_sync_test.rb +8 -3
- data/test/jobs/inventory_full_sync_test.rb +4 -1
- data/test/models/insights_client_report_status_test.rb +77 -0
- data/test/test_plugin_helper.rb +0 -1
- data/test/unit/rh_cloud_http_proxy_test.rb +4 -4
- data/test/unit/services/foreman_rh_cloud/remediations_retriever_test.rb +49 -0
- data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +28 -0
- data/test/unit/slice_generator_test.rb +66 -29
- data/test/unit/tags_generator_test.rb +10 -0
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModal.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/__snapshots__/FullScreenModal.test.js.snap +1 -1
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/fullScreenModal.scss +14 -16
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/AdvancedSettingsConstants.js +5 -3
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +15 -2
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +13 -2
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +28 -63
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +2 -3
- data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/Terminal.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/__snapshots__/Terminal.test.js.snap +2 -2
- data/webpack/ForemanInventoryUpload/Components/Terminal/terminal.scss +25 -27
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +1 -1
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +19 -19
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableSelectors.js +3 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +14 -14
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +59 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationActions.js +12 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationHelpers.js +43 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js +101 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +9 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModalFooter.js +43 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationTableConstants.js +38 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/Resolutions.js +55 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/index.js +34 -0
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +11 -3
- data/webpack/InsightsCloudSync/InsightsCloudSync.scss +5 -0
- data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +44 -20
- data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +2 -0
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +9 -6
- data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +11 -7
- data/webpack/common/ForemanTasks/ForemanTasksActions.js +64 -0
- data/webpack/common/ForemanTasks/ForemanTasksHelpers.js +7 -0
- data/webpack/common/ForemanTasks/index.js +1 -0
- data/webpack/{InsightsCloudSync/Components/InsightsTable/components → common/table}/EmptyState.js +0 -0
- data/webpack/common/table/helpers.js +7 -0
- metadata +38 -4
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module InsightsCloud
|
4
|
+
module Async
|
5
|
+
class InsightsResolutionsSync < ::Actions::EntryAction
|
6
|
+
include ::ForemanRhCloud::CloudAuth
|
7
|
+
|
8
|
+
RULE_ID_REGEX = /[^:]*:(?<id>.*)/
|
9
|
+
|
10
|
+
def run
|
11
|
+
InsightsResolution.transaction do
|
12
|
+
InsightsResolution.delete_all
|
13
|
+
api_response = query_insights_resolutions(relevant_rules)
|
14
|
+
write_resolutions(api_response)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def logger
|
19
|
+
action_logger
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def query_insights_resolutions(rule_ids)
|
25
|
+
resolutions_response = execute_cloud_request(
|
26
|
+
method: :post,
|
27
|
+
url: InsightsCloud.resolutions_url,
|
28
|
+
headers: {
|
29
|
+
content_type: :json,
|
30
|
+
},
|
31
|
+
payload: {
|
32
|
+
issues: rule_ids,
|
33
|
+
}.to_json
|
34
|
+
)
|
35
|
+
|
36
|
+
JSON.parse(resolutions_response)
|
37
|
+
end
|
38
|
+
|
39
|
+
def relevant_rules
|
40
|
+
InsightsRule.all.pluck(:rule_id).map { |id| InsightsCloud.remediation_rule_id(id) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_resolution_hash(rule_id, resolution_hash)
|
44
|
+
{
|
45
|
+
rule_id: rule_id,
|
46
|
+
description: resolution_hash['description'],
|
47
|
+
resolution_type: resolution_hash['id'],
|
48
|
+
needs_reboot: resolution_hash['needs_reboot'],
|
49
|
+
resolution_risk: resolution_hash['resolution_risk'],
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def write_resolutions(response)
|
54
|
+
all_resolutions = response.map do |rule_id, rule_details|
|
55
|
+
rule_details['resolutions'].map { |resolution| to_resolution_hash(to_rule_id(rule_id), resolution) }
|
56
|
+
end.flatten
|
57
|
+
|
58
|
+
InsightsResolution.create(all_resolutions)
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_rule_id(resolution_rule_id)
|
62
|
+
RULE_ID_REGEX.match(resolution_rule_id).named_captures.fetch('id', resolution_rule_id)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -2,13 +2,21 @@ require 'rest-client'
|
|
2
2
|
|
3
3
|
module InsightsCloud
|
4
4
|
module Async
|
5
|
-
class InsightsRulesSync < ::
|
5
|
+
class InsightsRulesSync < ::Actions::EntryAction
|
6
6
|
include ::ForemanRhCloud::CloudAuth
|
7
7
|
|
8
|
-
def
|
8
|
+
def plan
|
9
|
+
plan_self
|
10
|
+
plan_resolutions
|
11
|
+
end
|
12
|
+
|
13
|
+
def plan_resolutions
|
14
|
+
plan_action InsightsResolutionsSync
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
9
18
|
offset = 0
|
10
19
|
InsightsRule.transaction do
|
11
|
-
InsightsResolution.delete_all
|
12
20
|
InsightsRule.delete_all
|
13
21
|
loop do
|
14
22
|
api_response = query_insights_rules(offset)
|
@@ -16,26 +24,22 @@ module InsightsCloud
|
|
16
24
|
logger.debug("Downloaded #{offset + results.count} of #{results.total}")
|
17
25
|
write_rules_page(results.rules)
|
18
26
|
offset += results.count
|
27
|
+
output[:rules_count] = results.total
|
19
28
|
break if offset >= results.total
|
20
29
|
end
|
21
30
|
end
|
22
31
|
end
|
23
32
|
|
24
33
|
def logger
|
25
|
-
|
34
|
+
action_logger
|
26
35
|
end
|
27
36
|
|
28
37
|
private
|
29
38
|
|
30
39
|
def query_insights_rules(offset)
|
31
|
-
rules_response =
|
40
|
+
rules_response = execute_cloud_request(
|
32
41
|
method: :get,
|
33
|
-
url: InsightsCloud.rules_url(offset: offset)
|
34
|
-
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
35
|
-
proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
|
36
|
-
headers: {
|
37
|
-
Authorization: "Bearer #{rh_credentials}",
|
38
|
-
}
|
42
|
+
url: InsightsCloud.rules_url(offset: offset)
|
39
43
|
)
|
40
44
|
|
41
45
|
JSON.parse(rules_response)
|
@@ -43,12 +47,8 @@ module InsightsCloud
|
|
43
47
|
|
44
48
|
def write_rules_page(rules)
|
45
49
|
rules_attributes = rules.map { |rule| to_rule_hash(rule) }
|
46
|
-
resolutions_attributes = rules.map do |rule|
|
47
|
-
rule['resolution_set'].map { |resolution| to_resolution_hash(rule['rule_id'], resolution) }
|
48
|
-
end.flatten
|
49
50
|
|
50
51
|
InsightsRule.create(rules_attributes)
|
51
|
-
InsightsResolution.create(resolutions_attributes)
|
52
52
|
end
|
53
53
|
|
54
54
|
def to_rule_hash(rule_hash)
|
@@ -66,15 +66,6 @@ module InsightsCloud
|
|
66
66
|
rating: rule_hash['rating'],
|
67
67
|
}
|
68
68
|
end
|
69
|
-
|
70
|
-
def to_resolution_hash(rule_id, resolution_hash)
|
71
|
-
{
|
72
|
-
rule_id: rule_id,
|
73
|
-
system_type: resolution_hash['system_type'],
|
74
|
-
resolution: resolution_hash['resolution'],
|
75
|
-
has_playbook: resolution_hash['has_playbook'],
|
76
|
-
}
|
77
|
-
end
|
78
69
|
end
|
79
70
|
end
|
80
71
|
end
|
@@ -24,6 +24,7 @@ module InventorySync
|
|
24
24
|
|
25
25
|
logger.debug("Synced hosts amount: #{host_statuses[:sync]}")
|
26
26
|
logger.debug("Disconnected hosts amount: #{host_statuses[:disconnect]}")
|
27
|
+
output[:host_statuses] = host_statuses
|
27
28
|
end
|
28
29
|
|
29
30
|
def update_statuses_batch
|
@@ -53,7 +54,7 @@ module InventorySync
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def host_statuses
|
56
|
-
|
57
|
+
@host_statuses ||= {
|
57
58
|
sync: 0,
|
58
59
|
disconnect: 0,
|
59
60
|
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module InventorySync
|
2
|
+
module Async
|
3
|
+
class InventoryScheduledSync < ::Actions::EntryAction
|
4
|
+
include ::Actions::RecurringAction
|
5
|
+
|
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
|
+
Organization.unscoped.each do |org|
|
16
|
+
plan_org_sync(org)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def plan_org_sync(org)
|
21
|
+
plan_action InventoryFullSync, org
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -29,13 +29,10 @@ module InventorySync
|
|
29
29
|
private
|
30
30
|
|
31
31
|
def query_inventory(page = 1)
|
32
|
-
hosts_inventory_response =
|
32
|
+
hosts_inventory_response = execute_cloud_request(
|
33
33
|
method: :get,
|
34
34
|
url: ForemanInventoryUpload.inventory_export_url,
|
35
|
-
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
36
|
-
proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
|
37
35
|
headers: {
|
38
|
-
Authorization: "Bearer #{rh_credentials}",
|
39
36
|
params: {
|
40
37
|
per_page: 100,
|
41
38
|
page: page,
|
data/lib/tasks/insights.rake
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
namespace :rh_cloud_insights do
|
2
|
-
desc "Synchronize Insights
|
3
|
-
task sync: :environment do
|
4
|
-
|
5
|
-
|
6
|
-
else
|
7
|
-
organizations = Organization.all
|
8
|
-
end
|
9
|
-
|
10
|
-
organizations.each do |organization|
|
11
|
-
ForemanTasks.async_task(InventorySync::Async::InventoryFullSync, organization)
|
12
|
-
puts "Synchronized inventory for organization '#{organization.name}'"
|
13
|
-
end
|
2
|
+
desc "Synchronize Insights hosts hits"
|
3
|
+
task sync: [:environment, 'dynflow:client'] do
|
4
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsFullSync)
|
5
|
+
puts "Synchronized Insights hosts hits data"
|
14
6
|
end
|
15
7
|
end
|
@@ -23,6 +23,12 @@ namespace :rh_cloud_inventory do
|
|
23
23
|
organizations = [ENV['organization_id']]
|
24
24
|
base_folder = ENV['target'] || Dir.pwd
|
25
25
|
|
26
|
+
unless File.writable?(base_folder)
|
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
|
+
|
26
32
|
unless portal_user || organizations.empty?
|
27
33
|
puts "Must specify either portal_user or organization_id"
|
28
34
|
end
|
@@ -52,9 +58,17 @@ namespace :rh_cloud_inventory do
|
|
52
58
|
end
|
53
59
|
end
|
54
60
|
|
55
|
-
desc "Synchronize
|
56
|
-
task sync: :environment do
|
57
|
-
|
58
|
-
|
61
|
+
desc "Synchronize Hosts inventory"
|
62
|
+
task sync: [:environment, 'dynflow:client'] do
|
63
|
+
if ! ENV['organization_id'].nil?
|
64
|
+
organizations = [ Organization.where(:id => ENV['organization_id']).first ]
|
65
|
+
else
|
66
|
+
organizations = Organization.all
|
67
|
+
end
|
68
|
+
|
69
|
+
organizations.each do |organization|
|
70
|
+
ForemanTasks.async_task(InventorySync::Async::InventoryFullSync, organization)
|
71
|
+
puts "Synchronized inventory for organization '#{organization.name}'"
|
72
|
+
end
|
59
73
|
end
|
60
74
|
end
|
data/package.json
CHANGED
@@ -19,6 +19,28 @@ FactoryBot.define do
|
|
19
19
|
sequence(:results_url) { |n| "https://cloud.redhat.com/insights/overview/stability/test_rule%7CTEST_RULE/accdf444-5628-451d-bf3e-cf909ad7275#{n}/" }
|
20
20
|
rule_id { "test_rule|TEST_RULE" }
|
21
21
|
end
|
22
|
+
|
23
|
+
factory :insights_rule do
|
24
|
+
sequence(:rule_id) { |n| "test_rule#{n}|TEST_RULE#{n}" }
|
25
|
+
description { 'test rule description' }
|
26
|
+
category_name { 'Testing' }
|
27
|
+
impact_name { 'Testing error' }
|
28
|
+
summary { 'Testing summary' }
|
29
|
+
generic { 'Testing generic' }
|
30
|
+
reason { 'No apparent reason' }
|
31
|
+
total_risk { -1 }
|
32
|
+
reboot_required { true }
|
33
|
+
more_info { 'more test info' }
|
34
|
+
rating { 0 }
|
35
|
+
end
|
36
|
+
|
37
|
+
factory :insights_resolution do
|
38
|
+
sequence(:rule_id) { |n| "test_rule#{n}|TEST_RULE#{n}" }
|
39
|
+
description { 'fix the issue on the fly' }
|
40
|
+
needs_reboot { false }
|
41
|
+
resolution_risk { 1 }
|
42
|
+
resolution_type { 'fix' }
|
43
|
+
end
|
22
44
|
end
|
23
45
|
|
24
46
|
FactoryBot.modify 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| "00000000-%<n>04d-%<r>04d-0000-000000000000" % {n: n, r: rand(500)} }
|
53
53
|
facts { { 'memory.memtotal' => "12 GB" } }
|
54
54
|
end
|
55
55
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'foreman_tasks/test_helpers'
|
3
|
+
|
4
|
+
class InsightsFullSyncTest < ActiveSupport::TestCase
|
5
|
+
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
2
6
|
|
3
|
-
class InsightsFullSyncTest < ActiveJob::TestCase
|
4
7
|
setup do
|
8
|
+
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_rules_sync)
|
9
|
+
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_notifications)
|
10
|
+
|
5
11
|
uuid1 = 'accdf444-5628-451d-bf3e-cf909ad72756'
|
6
12
|
@host1 = FactoryBot.create(:host, :managed, name: 'host1')
|
7
13
|
FactoryBot.create(:insights_facet, host_id: @host1.id, uuid: uuid1)
|
@@ -56,8 +62,10 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
56
62
|
test 'Hits data is replaced with data from cloud' do
|
57
63
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).returns(@hits)
|
58
64
|
|
59
|
-
|
60
|
-
InsightsCloud::Async::InsightsFullSync.
|
65
|
+
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_hosts_sync)
|
66
|
+
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_rules_sync)
|
67
|
+
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_notifications)
|
68
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsFullSync)
|
61
69
|
|
62
70
|
@host1.reload
|
63
71
|
@host2.reload
|
@@ -68,11 +76,12 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
68
76
|
|
69
77
|
test 'Hits counters are reset correctly' do
|
70
78
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).returns(@hits).twice
|
71
|
-
ForemanTasks.stubs(:sync_task)
|
72
79
|
|
73
|
-
InsightsCloud::Async::InsightsFullSync.
|
80
|
+
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_hosts_sync)
|
81
|
+
|
82
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsFullSync)
|
74
83
|
# Invoke again
|
75
|
-
InsightsCloud::Async::InsightsFullSync
|
84
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsFullSync)
|
76
85
|
|
77
86
|
@host1.reload
|
78
87
|
@host2.reload
|
@@ -101,10 +110,10 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
101
110
|
HITS_JSON
|
102
111
|
hits = JSON.parse(hits_json)
|
103
112
|
|
104
|
-
|
113
|
+
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_hosts_sync)
|
105
114
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).returns(hits)
|
106
115
|
|
107
|
-
InsightsCloud::Async::InsightsFullSync
|
116
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsFullSync)
|
108
117
|
|
109
118
|
@host1.reload
|
110
119
|
@host2.reload
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'foreman_tasks/test_helpers'
|
3
|
+
|
4
|
+
class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
5
|
+
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@resolutions = {
|
9
|
+
"advisor:ansible_deprecated_repo|ANSIBLE_DEPRECATED_REPO" => {
|
10
|
+
"id" => "advisor:ansible_deprecated_repo|ANSIBLE_DEPRECATED_REPO",
|
11
|
+
"resolution_risk" => 1,
|
12
|
+
"resolutions" => [
|
13
|
+
{
|
14
|
+
"description" => "Enable ansible repo and update ansible package",
|
15
|
+
"id" => "fix",
|
16
|
+
"needs_reboot" => false,
|
17
|
+
"resolution_risk" => 1,
|
18
|
+
},
|
19
|
+
],
|
20
|
+
},
|
21
|
+
"advisor:hardening_logging_auditd|HARDENING_LOGGING_5_AUDITD" => {
|
22
|
+
"id" => "advisor:hardening_logging_auditd|HARDENING_LOGGING_5_AUDITD",
|
23
|
+
"resolution_risk" => 1,
|
24
|
+
"resolutions" => [
|
25
|
+
{
|
26
|
+
"description" => "Install and enable auditd",
|
27
|
+
"id" => "fix",
|
28
|
+
"needs_reboot" => false,
|
29
|
+
"resolution_risk" => 1,
|
30
|
+
},
|
31
|
+
],
|
32
|
+
},
|
33
|
+
"advisor:network_manager_dhcp_client_network_issue|NETWORK_MANAGER_DHCP_CLIENT_NETWORK_ISSUE" => {
|
34
|
+
"id" => "advisor:network_manager_dhcp_client_network_issue|NETWORK_MANAGER_DHCP_CLIENT_NETWORK_ISSUE",
|
35
|
+
"resolution_risk" => 1,
|
36
|
+
"resolutions" => [
|
37
|
+
{
|
38
|
+
"description" => "Update the NetworkManager package to fix this issue",
|
39
|
+
"id" => "fix",
|
40
|
+
"needs_reboot" => false,
|
41
|
+
"resolution_risk" => 1,
|
42
|
+
},
|
43
|
+
],
|
44
|
+
},
|
45
|
+
"advisor:network_tcp_connection_hang|NETWORK_TCP_CONNECTION_HANG_WARN" => {
|
46
|
+
"id" => "advisor:network_tcp_connection_hang|NETWORK_TCP_CONNECTION_HANG_WARN",
|
47
|
+
"resolution_risk" => 3,
|
48
|
+
"resolutions" => [
|
49
|
+
{
|
50
|
+
"description" => "Update system to the latest kernel and reboot",
|
51
|
+
"id" => "kernel_update",
|
52
|
+
"needs_reboot" => true,
|
53
|
+
"resolution_risk" => 3,
|
54
|
+
},
|
55
|
+
{
|
56
|
+
"description" => "Run in panic and scream",
|
57
|
+
"id" => "panic",
|
58
|
+
"needs_reboot" => true,
|
59
|
+
"resolution_risk" => 10,
|
60
|
+
},
|
61
|
+
],
|
62
|
+
},
|
63
|
+
}
|
64
|
+
|
65
|
+
@rule = FactoryBot.create(:insights_rule, rule_id: 'network_tcp_connection_hang|NETWORK_TCP_CONNECTION_HANG_WARN')
|
66
|
+
end
|
67
|
+
|
68
|
+
test 'Resolutions data is replaced with data from cloud' do
|
69
|
+
InsightsCloud::Async::InsightsResolutionsSync.any_instance.stubs(:query_insights_resolutions).returns(@resolutions)
|
70
|
+
|
71
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsResolutionsSync)
|
72
|
+
@rule.reload
|
73
|
+
|
74
|
+
assert_equal 5, InsightsResolution.all.count
|
75
|
+
assert_equal 2, @rule.resolutions.count
|
76
|
+
end
|
77
|
+
end
|