foreman_rh_cloud 3.0.19 → 3.0.23
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/api/v2/rh_cloud/inventory_controller.rb +50 -0
- data/app/controllers/concerns/inventory_upload/report_actions.rb +26 -0
- data/app/controllers/concerns/inventory_upload/task_actions.rb +25 -0
- data/app/controllers/foreman_inventory_upload/reports_controller.rb +3 -1
- data/app/controllers/foreman_inventory_upload/tasks_controller.rb +5 -13
- data/app/controllers/foreman_inventory_upload/uploads_controller.rb +4 -4
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +18 -7
- data/app/controllers/insights_cloud/hits_controller.rb +42 -1
- data/app/controllers/insights_cloud/settings_controller.rb +1 -1
- data/app/controllers/insights_cloud/tasks_controller.rb +1 -2
- data/app/helpers/foreman_insights_host_helper.rb +19 -0
- 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/package-lock.json.plugin +32774 -0
- data/config/routes.rb +20 -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 +40 -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_hosts_sync.rb +6 -2
- data/lib/inventory_sync/async/inventory_scheduled_sync.rb +29 -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 +20 -5
- data/package.json +1 -1
- data/test/controllers/inventory_upload/api/inventory_controller_test.rb +53 -0
- 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/jobs/inventory_hosts_sync_test.rb +265 -0
- data/test/jobs/inventory_scheduled_sync_test.rb +22 -0
- data/test/models/insights_client_report_status_test.rb +77 -0
- data/test/test_plugin_helper.rb +2 -0
- 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 +26 -2
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +24 -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 +60 -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/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +20 -13
- 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 +49 -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
|
}
|
@@ -20,14 +20,18 @@ module InventorySync
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def add_missing_insights_facets(uuids_hash)
|
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|
|
23
|
+
existing_facets = InsightsFacet.where(host_id: uuids_hash.keys).pluck(:host_id, :uuid)
|
24
|
+
missing_facets = uuids_hash.except(*existing_facets.map(&:first)).map do |host_id, uuid|
|
25
25
|
{
|
26
26
|
host_id: host_id,
|
27
27
|
uuid: uuid,
|
28
28
|
}
|
29
29
|
end
|
30
30
|
InsightsFacet.create(missing_facets)
|
31
|
+
|
32
|
+
existing_facets.select { |host_id, uuid| uuid.empty? }.each do |host_id, _uuid|
|
33
|
+
InsightsFacet.where(host_id: host_id).update_all(uuid: uuids_hash[host_id])
|
34
|
+
end
|
31
35
|
end
|
32
36
|
end
|
33
37
|
end
|
@@ -0,0 +1,29 @@
|
|
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
|
+
|
24
|
+
def logger
|
25
|
+
action_logger
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
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,8 +23,15 @@ namespace :rh_cloud_inventory do
|
|
23
23
|
organizations = [ENV['organization_id']]
|
24
24
|
base_folder = ENV['target'] || Dir.pwd
|
25
25
|
|
26
|
-
unless
|
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
|
+
|
32
|
+
if portal_user.empty? && organizations.empty?
|
27
33
|
puts "Must specify either portal_user or organization_id"
|
34
|
+
return
|
28
35
|
end
|
29
36
|
|
30
37
|
User.as_anonymous_admin do
|
@@ -52,9 +59,17 @@ namespace :rh_cloud_inventory do
|
|
52
59
|
end
|
53
60
|
end
|
54
61
|
|
55
|
-
desc "Synchronize
|
56
|
-
task sync: :environment do
|
57
|
-
|
58
|
-
|
62
|
+
desc "Synchronize Hosts inventory"
|
63
|
+
task sync: [:environment, 'dynflow:client'] do
|
64
|
+
if ! ENV['organization_id'].nil?
|
65
|
+
organizations = [ Organization.where(:id => ENV['organization_id']).first ]
|
66
|
+
else
|
67
|
+
organizations = Organization.all
|
68
|
+
end
|
69
|
+
|
70
|
+
organizations.each do |organization|
|
71
|
+
ForemanTasks.async_task(InventorySync::Async::InventoryFullSync, organization)
|
72
|
+
puts "Synchronized inventory for organization '#{organization.name}'"
|
73
|
+
end
|
59
74
|
end
|
60
75
|
end
|
data/package.json
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module InventoryUpload::Api
|
4
|
+
class InventoryControllerTest < ActionController::TestCase
|
5
|
+
tests Api::V2::RhCloud::InventoryController
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@test_org = FactoryBot.create(:organization)
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'Starts report generation' do
|
12
|
+
Api::V2::RhCloud::InventoryController.any_instance
|
13
|
+
.expects(:start_report_generation)
|
14
|
+
.with(@test_org.id.to_s)
|
15
|
+
|
16
|
+
post :generate_report, params: { organization_id: @test_org.id }
|
17
|
+
|
18
|
+
assert_response :success
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'Starts inventory sync action' do
|
22
|
+
test_task = FactoryBot.create(:some_task)
|
23
|
+
|
24
|
+
Api::V2::RhCloud::InventoryController.any_instance
|
25
|
+
.expects(:start_inventory_sync)
|
26
|
+
.with() { |actual_org| @test_org.id == actual_org.id }
|
27
|
+
.returns(test_task)
|
28
|
+
|
29
|
+
post :sync_inventory_status, params: { organization_id: @test_org.id }
|
30
|
+
|
31
|
+
assert_response :success
|
32
|
+
|
33
|
+
assert_not_nil(actual_task = @response.parsed_body['task'])
|
34
|
+
assert_equal test_task.id.to_s, actual_task['id']
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'Starts cloud connector configuration job' do
|
38
|
+
test_job = FactoryBot.create(:job_invocation)
|
39
|
+
|
40
|
+
ForemanRhCloud::CloudConnector.any_instance
|
41
|
+
.expects(:install)
|
42
|
+
.returns(test_job)
|
43
|
+
|
44
|
+
post :enable_cloud_connector
|
45
|
+
|
46
|
+
assert_response :success
|
47
|
+
|
48
|
+
actual_job = @response.parsed_body
|
49
|
+
|
50
|
+
assert_equal test_job.id, actual_job['id']
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -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
|