foreman_rh_cloud 3.0.18.1 → 3.0.19
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/tasks_controller.rb +14 -3
- data/app/controllers/foreman_inventory_upload/uploads_settings_controller.rb +8 -0
- data/app/models/insights_resolution.rb +1 -1
- data/config/routes.rb +1 -1
- data/lib/foreman_inventory_upload.rb +5 -0
- data/lib/foreman_inventory_upload/generators/queries.rb +1 -1
- data/lib/foreman_inventory_upload/scripts/uploader.sh.erb +5 -1
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud/async/insights_full_sync.rb +17 -21
- data/lib/inventory_sync/async/host_result.rb +11 -6
- data/lib/inventory_sync/async/inventory_full_sync.rb +24 -41
- data/lib/inventory_sync/async/inventory_hosts_sync.rb +34 -0
- data/lib/inventory_sync/async/query_inventory_job.rb +54 -0
- data/lib/tasks/insights.rake +1 -1
- data/package.json +1 -1
- data/test/jobs/insights_full_sync_test.rb +14 -10
- data/test/jobs/inventory_full_sync_test.rb +181 -11
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +0 -1
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +81 -46
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonConstants.js +3 -3
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonSelectors.js +6 -12
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonFixtures.js +1 -9
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonSelectors.test.js +18 -27
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonSelectors.test.js.snap +1 -16
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +58 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/integrations.test.js +51 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/index.js +2 -5
- data/webpack/ForemanInventoryUpload/ForemanInventoryUploadReducers.js +0 -2
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +2 -0
- data/webpack/__mocks__/foremanReact/redux/middlewares/IntervalMiddleware.js +4 -0
- metadata +25 -25
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonReducer.js +0 -36
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonActions.test.js +0 -31
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonReducer.test.js +0 -26
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonActions.test.js.snap +0 -98
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonReducer.test.js.snap +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43110585639a77e33c9c4fb1fce44855b6fb4c9793db3fc624a01b567c09e400
|
4
|
+
data.tar.gz: '00285b699105835e629127cc96801082ece7ff41c9a93d82fcb7e7a6b2662c65'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa89cca9fb72a26453a44cba2120c51ab3f47f67ec40ca8e539a1dfaeddae73687bd909e3f3880cd3eed94c7c5d4b509bb55e2450f5bf4e55a8db2f73ceaabe9
|
7
|
+
data.tar.gz: 33d4200395db6f2f9a0e2dbd8b27d8c55ff66d7da87efa9c9c39663468f0dd9c43c8949b0ce09b2158875d053375e39d03e4550b821732df4d49fb52f5872cb3
|
@@ -13,12 +13,23 @@ module ForemanInventoryUpload
|
|
13
13
|
message: N_('Nothing to sync, there are no hosts with subscription for this organization.'),
|
14
14
|
}, status: :method_not_allowed
|
15
15
|
else
|
16
|
-
|
16
|
+
task = ForemanTasks.async_task(InventorySync::Async::InventoryFullSync, selected_org)
|
17
17
|
end
|
18
|
+
return render json: { message: N_('there was an issue triggering the task') }, status: :internal_server_error unless task
|
18
19
|
|
19
20
|
render json: {
|
20
|
-
|
21
|
-
|
21
|
+
task: task,
|
22
|
+
}, status: :ok
|
23
|
+
end
|
24
|
+
|
25
|
+
def show
|
26
|
+
task = ForemanTasks::Task.find_by(id: params[:id])
|
27
|
+
return render json: { message: N_('No task was found') }, status: :internal_server_error unless task
|
28
|
+
|
29
|
+
render json: {
|
30
|
+
endedAt: task.ended_at,
|
31
|
+
output: task.output,
|
32
|
+
result: task.result,
|
22
33
|
}, status: :ok
|
23
34
|
end
|
24
35
|
end
|
@@ -8,6 +8,7 @@ module ForemanInventoryUpload
|
|
8
8
|
excludePackagesEnabled: Setting[:exclude_installed_packages],
|
9
9
|
CloudConnectorStatus: ForemanInventoryUpload::UploadsSettingsController.cloud_connector_status,
|
10
10
|
cloudToken: !Setting[:rh_cloud_token].empty?,
|
11
|
+
lastSyncTask: last_successful_inventory_sync_task,
|
11
12
|
}, status: :ok
|
12
13
|
end
|
13
14
|
|
@@ -22,5 +23,12 @@ module ForemanInventoryUpload
|
|
22
23
|
return nil unless job
|
23
24
|
{ id: job.id, task: ForemanTasks::Task.where(:id => job.task_id).first }
|
24
25
|
end
|
26
|
+
|
27
|
+
def last_successful_inventory_sync_task
|
28
|
+
task = ForemanTasks::Task.where(label: 'InventorySync::Async::InventoryFullSync', result: 'success')
|
29
|
+
.reorder('ended_at desc').first
|
30
|
+
return nil unless task
|
31
|
+
{ output: task.output, endedAt: task.ended_at }
|
32
|
+
end
|
25
33
|
end
|
26
34
|
end
|
data/config/routes.rb
CHANGED
@@ -56,6 +56,11 @@ module ForemanInventoryUpload
|
|
56
56
|
@upload_url ||= ENV['SATELLITE_INVENTORY_UPLOAD_URL'] || 'https://cert.cloud.redhat.com/api/ingress/v1/upload'
|
57
57
|
end
|
58
58
|
|
59
|
+
def self.slice_size
|
60
|
+
# for testing set ENV to 'https://ci.cloud.redhat.com/api/ingress/v1/upload'
|
61
|
+
@slice_size ||= (ENV['SATELLITE_INVENTORY_SLICE_SIZE'] || '1000').to_i
|
62
|
+
end
|
63
|
+
|
59
64
|
def self.ensure_folder(folder)
|
60
65
|
FileUtils.mkdir_p(folder)
|
61
66
|
folder
|
@@ -50,7 +50,7 @@ module ForemanInventoryUpload
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def self.for_org(organization_id)
|
53
|
-
for_slice(Host.unscoped.where(organization_id: organization_id)).in_batches(of:
|
53
|
+
for_slice(Host.unscoped.where(organization_id: organization_id)).in_batches(of: ForemanInventoryUpload.slice_size)
|
54
54
|
end
|
55
55
|
|
56
56
|
def self.organizations_for_user(portal_user)
|
@@ -37,9 +37,13 @@ mkdir -p $DONE_DIR
|
|
37
37
|
for f in $FILES
|
38
38
|
do
|
39
39
|
curl -k -vvv -# --fail -F "file=@$f;type=application/vnd.redhat.qpc.tar+tgz" $DEST "$AUTH_KEY" "$AUTH_VAL"
|
40
|
-
|
40
|
+
status=$?
|
41
|
+
if [ $status -eq 0 ]; then
|
41
42
|
mv $f $DONE_DIR
|
42
43
|
echo "Done: $f"
|
43
44
|
fi
|
44
45
|
done
|
45
46
|
echo "Uploaded files moved to done/ folder"
|
47
|
+
|
48
|
+
# return the error code from the curl command
|
49
|
+
exit $status
|
@@ -6,14 +6,22 @@ module InsightsCloud
|
|
6
6
|
include ::ForemanRhCloud::CloudAuth
|
7
7
|
|
8
8
|
def perform
|
9
|
+
# This can be turned off when we enable automatic status syncs
|
10
|
+
# This step will query cloud inventory to retrieve inventory uuids for each host
|
11
|
+
ForemanTasks.sync_task(InventorySync::Async::InventoryHostsSync)
|
12
|
+
|
13
|
+
perform_hits_sync
|
14
|
+
|
15
|
+
InsightsRulesSync.perform_later
|
16
|
+
end
|
17
|
+
|
18
|
+
def perform_hits_sync
|
9
19
|
hits = query_insights_hits
|
10
20
|
|
11
|
-
|
12
|
-
|
21
|
+
uuids = hits.map { |hit| hit['uuid'] }
|
22
|
+
setup_host_ids(uuids)
|
13
23
|
|
14
24
|
replace_hits_data(hits)
|
15
|
-
|
16
|
-
InsightsRulesSync.perform_later
|
17
25
|
end
|
18
26
|
|
19
27
|
def logger
|
@@ -50,39 +58,27 @@ module InsightsCloud
|
|
50
58
|
JSON.parse(rules_response)
|
51
59
|
end
|
52
60
|
|
53
|
-
def
|
61
|
+
def setup_host_ids(uuids)
|
54
62
|
@host_ids = Hash[
|
55
|
-
|
63
|
+
InsightsFacet.where(uuid: uuids).pluck(:uuid, :host_id)
|
56
64
|
]
|
57
65
|
end
|
58
66
|
|
59
|
-
def host_id(
|
60
|
-
@host_ids[
|
67
|
+
def host_id(uuid)
|
68
|
+
@host_ids[uuid]
|
61
69
|
end
|
62
70
|
|
63
71
|
def replace_hits_data(hits)
|
64
72
|
InsightsHit.transaction do
|
65
73
|
# Reset hit counters to 0, they will be recreated later
|
66
74
|
InsightsFacet.unscoped.update_all(hits_count: 0)
|
67
|
-
# create new facets for hosts that are missing one
|
68
|
-
hosts_with_existing_facets = InsightsFacet.where(host_id: @host_ids.values).pluck(:host_id)
|
69
|
-
InsightsFacet.create(
|
70
|
-
@host_ids.map do |host_name, host_id|
|
71
|
-
unless hosts_with_existing_facets.include?(host_id)
|
72
|
-
{
|
73
|
-
host_id: host_id,
|
74
|
-
uuid: @hits_host_names[host_name],
|
75
|
-
}
|
76
|
-
end
|
77
|
-
end.compact
|
78
|
-
)
|
79
75
|
InsightsHit.delete_all
|
80
76
|
InsightsHit.create(hits.map { |hits_hash| to_model_hash(hits_hash) }.compact)
|
81
77
|
end
|
82
78
|
end
|
83
79
|
|
84
80
|
def to_model_hash(hit_hash)
|
85
|
-
hit_host_id = host_id(hit_hash['
|
81
|
+
hit_host_id = host_id(hit_hash['uuid'])
|
86
82
|
|
87
83
|
return unless hit_host_id
|
88
84
|
|
@@ -6,12 +6,13 @@ module InventorySync
|
|
6
6
|
@count = result['count']
|
7
7
|
@page = result['page']
|
8
8
|
@per_page = result['per_page']
|
9
|
-
@
|
9
|
+
@sub_ids = result["results"].map { |host| host['subscription_manager_id'] }
|
10
|
+
@uuid_by_sub_id = Hash[result["results"].map { |host| [host['subscription_manager_id'], host['id']] }]
|
10
11
|
end
|
11
12
|
|
12
13
|
def status_hashes
|
13
|
-
@
|
14
|
-
host_id = host_id(
|
14
|
+
@sub_ids.map do |sub_id|
|
15
|
+
host_id = host_id(sub_id)
|
15
16
|
if host_id
|
16
17
|
touched << host_id
|
17
18
|
{
|
@@ -27,16 +28,20 @@ module InventorySync
|
|
27
28
|
@touched ||= []
|
28
29
|
end
|
29
30
|
|
30
|
-
def host_id(
|
31
|
-
hosts[
|
31
|
+
def host_id(sub_id)
|
32
|
+
hosts[sub_id]
|
32
33
|
end
|
33
34
|
|
34
35
|
def hosts
|
35
36
|
@hosts ||= Hash[
|
36
|
-
Host.where(
|
37
|
+
Katello::Host::SubscriptionFacet.where(uuid: @sub_ids).pluck(:uuid, :host_id)
|
37
38
|
]
|
38
39
|
end
|
39
40
|
|
41
|
+
def host_uuids
|
42
|
+
@host_uuids ||= Hash[@sub_ids.map { |sub_id| [host_id(sub_id), @uuid_by_sub_id[sub_id]] }].except(nil)
|
43
|
+
end
|
44
|
+
|
40
45
|
def percentage
|
41
46
|
ratio = @per_page * @page * 1.0 / @total * 100
|
42
47
|
ratio > 100 ? 100 : ratio.truncate(2)
|
@@ -1,42 +1,36 @@
|
|
1
|
-
require 'rest-client'
|
2
|
-
|
3
1
|
module InventorySync
|
4
2
|
module Async
|
5
|
-
class InventoryFullSync <
|
6
|
-
|
3
|
+
class InventoryFullSync < InventoryHostsSync
|
4
|
+
set_callback :iteration, :around, :setup_statuses
|
5
|
+
set_callback :step, :around, :update_statuses_batch
|
6
|
+
|
7
|
+
def plan(organization)
|
8
|
+
plan_self(organization_id: organization.id)
|
9
|
+
end
|
7
10
|
|
8
|
-
def
|
9
|
-
@organization = organization
|
11
|
+
def setup_statuses
|
10
12
|
@subscribed_hosts_ids = Set.new(
|
11
13
|
ForemanInventoryUpload::Generators::Queries.for_slice(
|
12
|
-
Host.unscoped.where(organization:
|
14
|
+
Host.unscoped.where(organization: input[:organization_id])
|
13
15
|
).pluck(:id)
|
14
16
|
)
|
15
|
-
@host_statuses = {
|
16
|
-
sync: 0,
|
17
|
-
disconnect: 0,
|
18
|
-
}
|
19
17
|
|
20
18
|
InventorySync::InventoryStatus.transaction do
|
21
19
|
InventorySync::InventoryStatus.where(host_id: @subscribed_hosts_ids).delete_all
|
22
|
-
|
23
|
-
loop do
|
24
|
-
api_response = query_inventory(page)
|
25
|
-
results = HostResult.new(api_response)
|
26
|
-
logger.debug("Downloading cloud inventory data: #{results.percentage}%")
|
27
|
-
update_hosts_status(results.status_hashes, results.touched)
|
28
|
-
@host_statuses[:sync] += results.touched.size
|
29
|
-
page += 1
|
30
|
-
break if results.last?
|
31
|
-
end
|
20
|
+
yield
|
32
21
|
add_missing_hosts_statuses(@subscribed_hosts_ids)
|
33
|
-
|
22
|
+
host_statuses[:disconnect] += @subscribed_hosts_ids.size
|
34
23
|
end
|
35
24
|
|
36
|
-
logger.debug("Synced hosts amount: #{
|
37
|
-
logger.debug("Disconnected hosts amount: #{
|
25
|
+
logger.debug("Synced hosts amount: #{host_statuses[:sync]}")
|
26
|
+
logger.debug("Disconnected hosts amount: #{host_statuses[:disconnect]}")
|
27
|
+
end
|
28
|
+
|
29
|
+
def update_statuses_batch
|
30
|
+
results = yield
|
38
31
|
|
39
|
-
|
32
|
+
update_hosts_status(results.status_hashes, results.touched)
|
33
|
+
host_statuses[:sync] += results.touched.size
|
40
34
|
end
|
41
35
|
|
42
36
|
private
|
@@ -58,22 +52,11 @@ module InventorySync
|
|
58
52
|
)
|
59
53
|
end
|
60
54
|
|
61
|
-
def
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
|
67
|
-
headers: {
|
68
|
-
Authorization: "Bearer #{rh_credentials}",
|
69
|
-
params: {
|
70
|
-
per_page: 100,
|
71
|
-
page: page,
|
72
|
-
},
|
73
|
-
}
|
74
|
-
)
|
75
|
-
|
76
|
-
JSON.parse(hosts_inventory_response)
|
55
|
+
def host_statuses
|
56
|
+
output[:host_statuses] ||= {
|
57
|
+
sync: 0,
|
58
|
+
disconnect: 0,
|
59
|
+
}
|
77
60
|
end
|
78
61
|
end
|
79
62
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module InventorySync
|
2
|
+
module Async
|
3
|
+
class InventoryHostsSync < QueryInventoryJob
|
4
|
+
set_callback :iteration, :around, :setup_facet_transaction
|
5
|
+
set_callback :step, :around, :create_facets
|
6
|
+
|
7
|
+
def setup_facet_transaction
|
8
|
+
InsightsFacet.transaction do
|
9
|
+
yield
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_facets
|
14
|
+
# get the results from the event
|
15
|
+
results = yield
|
16
|
+
add_missing_insights_facets(results.host_uuids)
|
17
|
+
results
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
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|
|
25
|
+
{
|
26
|
+
host_id: host_id,
|
27
|
+
uuid: uuid,
|
28
|
+
}
|
29
|
+
end
|
30
|
+
InsightsFacet.create(missing_facets)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module InventorySync
|
4
|
+
module Async
|
5
|
+
class QueryInventoryJob < ::Actions::EntryAction
|
6
|
+
include ActiveSupport::Callbacks
|
7
|
+
include ::ForemanRhCloud::CloudAuth
|
8
|
+
|
9
|
+
define_callbacks :iteration, :step
|
10
|
+
|
11
|
+
def run
|
12
|
+
run_callbacks :iteration do
|
13
|
+
page = 1
|
14
|
+
loop do
|
15
|
+
api_response = query_inventory(page)
|
16
|
+
results = HostResult.new(api_response)
|
17
|
+
logger.debug("Downloaded cloud inventory data: #{results.percentage}%")
|
18
|
+
|
19
|
+
run_callbacks :step do
|
20
|
+
results
|
21
|
+
end
|
22
|
+
|
23
|
+
page += 1
|
24
|
+
break if results.last?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def query_inventory(page = 1)
|
32
|
+
hosts_inventory_response = RestClient::Request.execute(
|
33
|
+
method: :get,
|
34
|
+
url: ForemanInventoryUpload.inventory_export_url,
|
35
|
+
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
36
|
+
proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
|
37
|
+
headers: {
|
38
|
+
Authorization: "Bearer #{rh_credentials}",
|
39
|
+
params: {
|
40
|
+
per_page: 100,
|
41
|
+
page: page,
|
42
|
+
},
|
43
|
+
}
|
44
|
+
)
|
45
|
+
|
46
|
+
JSON.parse(hosts_inventory_response)
|
47
|
+
end
|
48
|
+
|
49
|
+
def logger
|
50
|
+
action_logger
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/tasks/insights.rake
CHANGED
@@ -8,7 +8,7 @@ namespace :rh_cloud_insights do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
organizations.each do |organization|
|
11
|
-
InventorySync::Async::InventoryFullSync
|
11
|
+
ForemanTasks.async_task(InventorySync::Async::InventoryFullSync, organization)
|
12
12
|
puts "Synchronized inventory for organization '#{organization.name}'"
|
13
13
|
end
|
14
14
|
end
|
data/package.json
CHANGED
@@ -2,15 +2,20 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class InsightsFullSyncTest < ActiveJob::TestCase
|
4
4
|
setup do
|
5
|
+
uuid1 = 'accdf444-5628-451d-bf3e-cf909ad72756'
|
5
6
|
@host1 = FactoryBot.create(:host, :managed, name: 'host1')
|
7
|
+
FactoryBot.create(:insights_facet, host_id: @host1.id, uuid: uuid1)
|
8
|
+
|
9
|
+
uuid2 = 'accdf444-5628-451d-bf3e-cf909ad72757'
|
6
10
|
@host2 = FactoryBot.create(:host, :managed, name: 'host2')
|
11
|
+
FactoryBot.create(:insights_facet, host_id: @host2.id, uuid: uuid2)
|
7
12
|
|
8
13
|
hits_json = <<-HITS_JSON
|
9
14
|
[
|
10
15
|
{
|
11
16
|
"hostname": "#{@host1.name}",
|
12
17
|
"rhel_version": "7.5",
|
13
|
-
"uuid": "
|
18
|
+
"uuid": "#{uuid1}",
|
14
19
|
"last_seen": "2019-11-22T08:41:42.447244Z",
|
15
20
|
"title": "New Ansible Engine packages are inaccessible when dedicated Ansible repo is not enabled",
|
16
21
|
"solution_url": "",
|
@@ -22,7 +27,7 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
22
27
|
{
|
23
28
|
"hostname": "#{@host1.name}",
|
24
29
|
"rhel_version": "7.5",
|
25
|
-
"uuid": "
|
30
|
+
"uuid": "#{uuid1}",
|
26
31
|
"last_seen": "2019-11-22T08:41:42.447244Z",
|
27
32
|
"title": "CPU vulnerable to side-channel attacks using Microarchitectural Data Sampling (CVE-2018-12130, CVE-2018-12126, CVE-2018-12127, CVE-2019-11091)",
|
28
33
|
"solution_url": "https://access.redhat.com/node/4134081",
|
@@ -34,7 +39,7 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
34
39
|
{
|
35
40
|
"hostname": "#{@host2.name}",
|
36
41
|
"rhel_version": "7.5",
|
37
|
-
"uuid": "
|
42
|
+
"uuid": "#{uuid2}",
|
38
43
|
"last_seen": "2019-11-22T08:41:42.447244Z",
|
39
44
|
"title": "CPU vulnerable to side-channel attacks using L1 Terminal Fault (CVE-2018-3620)",
|
40
45
|
"solution_url": "https://access.redhat.com/node/3560291",
|
@@ -51,6 +56,7 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
51
56
|
test 'Hits data is replaced with data from cloud' do
|
52
57
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).returns(@hits)
|
53
58
|
|
59
|
+
ForemanTasks.expects(:sync_task).with(InventorySync::Async::InventoryHostsSync)
|
54
60
|
InsightsCloud::Async::InsightsFullSync.perform_now()
|
55
61
|
|
56
62
|
@host1.reload
|
@@ -58,12 +64,11 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
58
64
|
|
59
65
|
assert_equal 2, @host1.insights.hits.count
|
60
66
|
assert_equal 1, @host2.insights.hits.count
|
61
|
-
assert_equal 'accdf444-5628-451d-bf3e-cf909ad72756', @host1.insights.uuid
|
62
|
-
assert_equal 'accdf444-5628-451d-bf3e-cf909ad72757', @host2.insights.uuid
|
63
67
|
end
|
64
68
|
|
65
69
|
test 'Hits counters are reset correctly' do
|
66
70
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).returns(@hits).twice
|
71
|
+
ForemanTasks.stubs(:sync_task)
|
67
72
|
|
68
73
|
InsightsCloud::Async::InsightsFullSync.perform_now()
|
69
74
|
# Invoke again
|
@@ -75,8 +80,6 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
75
80
|
# Check that the counters are correct
|
76
81
|
assert_equal 2, @host1.insights.hits.count
|
77
82
|
assert_equal 1, @host2.insights.hits.count
|
78
|
-
assert_equal 'accdf444-5628-451d-bf3e-cf909ad72756', @host1.insights.uuid
|
79
|
-
assert_equal 'accdf444-5628-451d-bf3e-cf909ad72757', @host2.insights.uuid
|
80
83
|
end
|
81
84
|
|
82
85
|
test 'Hits ignoring non-existent hosts' do
|
@@ -85,7 +88,7 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
85
88
|
{
|
86
89
|
"hostname": "#{@host1.name}_non_existent",
|
87
90
|
"rhel_version": "7.5",
|
88
|
-
"uuid": "accdf444-5628-451d-bf3e-
|
91
|
+
"uuid": "accdf444-5628-451d-bf3e-cf909ad00000",
|
89
92
|
"last_seen": "2019-11-22T08:41:42.447244Z",
|
90
93
|
"title": "New Ansible Engine packages are inaccessible when dedicated Ansible repo is not enabled",
|
91
94
|
"solution_url": "",
|
@@ -98,6 +101,7 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
98
101
|
HITS_JSON
|
99
102
|
hits = JSON.parse(hits_json)
|
100
103
|
|
104
|
+
ForemanTasks.stubs(:sync_task)
|
101
105
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).returns(hits)
|
102
106
|
|
103
107
|
InsightsCloud::Async::InsightsFullSync.perform_now()
|
@@ -105,7 +109,7 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
105
109
|
@host1.reload
|
106
110
|
@host2.reload
|
107
111
|
|
108
|
-
|
109
|
-
|
112
|
+
assert_equal 0, @host1.insights.hits_count
|
113
|
+
assert_equal 0, @host2.insights.hits_count
|
110
114
|
end
|
111
115
|
end
|