foreman_rh_cloud 3.0.21.1 → 3.0.24.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +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 +20 -7
- data/app/controllers/insights_cloud/hits_controller.rb +7 -3
- data/app/helpers/foreman_insights_deprecations_helper.rb +9 -0
- data/app/helpers/foreman_insights_host_helper.rb +19 -0
- data/app/models/insights_client_report_status.rb +47 -0
- data/app/overrides/old_plugin_deprecation.rb +20 -0
- data/app/services/foreman_rh_cloud/cloud_auth.rb +12 -0
- data/app/services/foreman_rh_cloud/cloud_request.rb +14 -0
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +1 -14
- data/app/services/foreman_rh_cloud/insights_status_cleaner.rb +17 -0
- data/app/services/foreman_rh_cloud/remediations_retriever.rb +1 -4
- data/config/package-lock.json.plugin +32774 -0
- data/config/routes.rb +19 -0
- data/db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb +6 -0
- data/lib/foreman_inventory_upload.rb +9 -1
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +19 -0
- data/lib/foreman_inventory_upload/generators/queries.rb +1 -0
- data/lib/foreman_inventory_upload/generators/slice.rb +7 -6
- data/lib/foreman_rh_cloud/engine.rb +20 -10
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud/async/insights_client_status_aging.rb +23 -0
- data/lib/insights_cloud/async/insights_full_sync.rb +4 -14
- data/lib/insights_cloud/async/insights_resolutions_sync.rb +1 -4
- data/lib/insights_cloud/async/insights_rules_sync.rb +2 -7
- data/lib/inventory_sync/async/host_result.rb +4 -0
- data/lib/inventory_sync/async/inventory_full_sync.rb +2 -1
- data/lib/inventory_sync/async/inventory_hosts_sync.rb +16 -2
- data/lib/inventory_sync/async/inventory_scheduled_sync.rb +12 -0
- data/lib/inventory_sync/async/inventory_self_host_sync.rb +30 -0
- data/lib/inventory_sync/async/query_inventory_job.rb +6 -5
- data/lib/tasks/insights.rake +15 -0
- data/lib/tasks/rh_cloud_inventory.rake +8 -1
- data/package.json +1 -1
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +41 -0
- data/test/controllers/inventory_upload/api/inventory_controller_test.rb +53 -0
- data/test/factories/inventory_upload_factories.rb +1 -1
- data/test/jobs/insights_client_status_aging_test.rb +33 -0
- data/test/jobs/insights_full_sync_test.rb +3 -0
- data/test/jobs/insights_resolutions_sync_test.rb +3 -0
- data/test/jobs/insights_rules_sync_test.rb +3 -0
- data/test/jobs/inventory_full_sync_test.rb +3 -0
- data/test/jobs/inventory_hosts_sync_test.rb +267 -0
- data/test/jobs/inventory_scheduled_sync_test.rb +22 -0
- data/test/jobs/inventory_self_host_sync_test.rb +103 -0
- data/test/models/insights_client_report_status_test.rb +75 -0
- data/test/test_plugin_helper.rb +2 -0
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +3 -3
- data/test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb +31 -0
- data/test/unit/slice_generator_test.rb +81 -29
- 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/PageHeader/components/PageDescription/PageDescription.js +11 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +11 -0
- 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/InsightsTableActions.js +19 -19
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +14 -14
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +1 -0
- data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +20 -13
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +4 -1
- data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +44 -20
- data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +2 -0
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +2 -2
- 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
- metadata +33 -3
data/lib/tasks/insights.rake
CHANGED
@@ -4,4 +4,19 @@ 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
|
7
22
|
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
|
data/package.json
CHANGED
@@ -11,6 +11,39 @@ module InsightsCloud::Api
|
|
11
11
|
host = FactoryBot.create(:host, :with_subscription, :organization => org)
|
12
12
|
User.current = ::Katello::CpConsumerUser.new(:uuid => host.subscription_facet.uuid, :login => host.subscription_facet.uuid)
|
13
13
|
InsightsCloud::Api::MachineTelemetriesController.any_instance.stubs(:upstream_owner).returns({ 'uuid' => 'abcdefg' })
|
14
|
+
|
15
|
+
@cert1 = "-----BEGIN CERTIFICATE-----\r\n" +
|
16
|
+
"MIIFdDCCA1ygAwIBAgIJAM5Uqykb3EAtMA0GCSqGSIb3DQEBCwUAME8xCzAJBgNV\r\n" +
|
17
|
+
"BAYTAklMMREwDwYDVQQIDAhUZWwgQXZpdjEUMBIGA1UECgwLVGhlIEZvcmVtYW4x\r\n" +
|
18
|
+
"FzAVBgNVBAMMDnRoZWZvcmVtYW4ub3JnMB4XDTE4MDMyNDEyMzYyOFoXDTI4MDMy\r\n" +
|
19
|
+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
14
47
|
end
|
15
48
|
|
16
49
|
test "should respond with response from cloud" do
|
@@ -30,6 +63,14 @@ module InsightsCloud::Api
|
|
30
63
|
::ForemanRhCloud::CloudRequestForwarder.any_instance.expects(:execute_cloud_request).with do |opts|
|
31
64
|
opts[:headers][:content_type] == 'application/json'
|
32
65
|
end.returns(res)
|
66
|
+
InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:candlepin_id_cert)
|
67
|
+
.returns(
|
68
|
+
{
|
69
|
+
cert: @cert1,
|
70
|
+
key: OpenSSL::PKey::RSA.new(1024).to_pem,
|
71
|
+
}
|
72
|
+
)
|
73
|
+
InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:cp_owner_id).returns('123')
|
33
74
|
|
34
75
|
post :forward_request, as: :json, params: { "path" => "static/v1/test", "machine_telemetry" => {"foo" => "bar"} }
|
35
76
|
assert_equal @body, @response.body
|
@@ -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
|
@@ -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
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
require 'foreman_tasks/test_helpers'
|
3
|
+
|
4
|
+
class InsightsClientStatusAgingTest < ActiveSupport::TestCase
|
5
|
+
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
6
|
+
|
7
|
+
setup do
|
8
|
+
User.current = User.find_by(login: 'secret_admin')
|
9
|
+
|
10
|
+
@host1 = FactoryBot.create(:host)
|
11
|
+
@host2 = FactoryBot.create(:host)
|
12
|
+
@host3 = FactoryBot.create(:host)
|
13
|
+
@host4 = FactoryBot.create(:host)
|
14
|
+
|
15
|
+
@hosts = [@host1, @host2, @host3, @host4]
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'stale statuses should change' do
|
19
|
+
InsightsClientReportStatus.find_or_initialize_by(host_id: @host1.id).update(status: InsightsClientReportStatus::REPORTING, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL + 1.day)
|
20
|
+
InsightsClientReportStatus.find_or_initialize_by(host_id: @host2.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL + 1.day)
|
21
|
+
InsightsClientReportStatus.find_or_initialize_by(host_id: @host3.id).update(status: InsightsClientReportStatus::REPORTING, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)
|
22
|
+
InsightsClientReportStatus.find_or_initialize_by(host_id: @host4.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)
|
23
|
+
|
24
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsClientStatusAging)
|
25
|
+
|
26
|
+
@hosts.each(&:reload)
|
27
|
+
|
28
|
+
assert_equal InsightsClientReportStatus::REPORTING, @host1.get_status(InsightsClientReportStatus).status
|
29
|
+
assert_equal InsightsClientReportStatus::NO_REPORT, @host2.get_status(InsightsClientReportStatus).status
|
30
|
+
assert_equal InsightsClientReportStatus::NO_REPORT, @host3.get_status(InsightsClientReportStatus).status
|
31
|
+
assert_equal InsightsClientReportStatus::NO_REPORT, @host4.get_status(InsightsClientReportStatus).status
|
32
|
+
end
|
33
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'foreman_tasks/test_helpers'
|
2
3
|
|
3
4
|
class InsightsFullSyncTest < ActiveSupport::TestCase
|
5
|
+
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
6
|
+
|
4
7
|
setup do
|
5
8
|
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_rules_sync)
|
6
9
|
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_notifications)
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'foreman_tasks/test_helpers'
|
2
3
|
|
3
4
|
class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
5
|
+
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
6
|
+
|
4
7
|
setup do
|
5
8
|
@resolutions = {
|
6
9
|
"advisor:ansible_deprecated_repo|ANSIBLE_DEPRECATED_REPO" => {
|
@@ -0,0 +1,267 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
require 'foreman_tasks/test_helpers'
|
3
|
+
|
4
|
+
class InventoryHostsSyncTest < ActiveSupport::TestCase
|
5
|
+
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
6
|
+
|
7
|
+
setup do
|
8
|
+
User.current = User.find_by(login: 'secret_admin')
|
9
|
+
|
10
|
+
env = FactoryBot.create(:katello_k_t_environment)
|
11
|
+
cv = env.content_views << FactoryBot.create(:katello_content_view, organization: env.organization)
|
12
|
+
|
13
|
+
# this host would pass our plugin queries, so it could be uploaded to the cloud.
|
14
|
+
@host1 = FactoryBot.create(
|
15
|
+
:host,
|
16
|
+
:with_subscription,
|
17
|
+
:with_content,
|
18
|
+
content_view: cv.first,
|
19
|
+
lifecycle_environment: env,
|
20
|
+
organization: env.organization
|
21
|
+
)
|
22
|
+
|
23
|
+
pool = FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
|
24
|
+
|
25
|
+
@host1.subscription_facet.pools << pool
|
26
|
+
|
27
|
+
# this host would pass our plugin queries, so it could be uploaded to the cloud.
|
28
|
+
@host2 = FactoryBot.create(
|
29
|
+
:host,
|
30
|
+
:with_subscription,
|
31
|
+
:with_content,
|
32
|
+
content_view: cv.first,
|
33
|
+
lifecycle_environment: env,
|
34
|
+
organization: env.organization
|
35
|
+
)
|
36
|
+
|
37
|
+
@host2.subscription_facet.pools << pool
|
38
|
+
@host2_inventory_id = '4536bf5c-ff03-4154-a8c9-32ff4b40e40c'
|
39
|
+
|
40
|
+
ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
|
41
|
+
|
42
|
+
inventory_json = <<-INVENTORY_JSON
|
43
|
+
{
|
44
|
+
"total": 3,
|
45
|
+
"count": 3,
|
46
|
+
"page": 1,
|
47
|
+
"per_page": 3,
|
48
|
+
"results": [
|
49
|
+
{
|
50
|
+
"insights_id": "72d29d75-dbbf-4121-9566-2f581ab77f36",
|
51
|
+
"rhel_machine_id": null,
|
52
|
+
"subscription_manager_id": "#{@host2.subscription_facet.uuid}",
|
53
|
+
"satellite_id": "bb72bf95-0a19-4090-8009-f0d8c68aca61",
|
54
|
+
"bios_uuid": "b48a7e5f-cb50-4029-a75e-366bf43db641",
|
55
|
+
"ip_addresses": [
|
56
|
+
"192.168.122.56"
|
57
|
+
],
|
58
|
+
"fqdn": "#{@host2.fqdn}",
|
59
|
+
"mac_addresses": [
|
60
|
+
"52:54:00:aa:12:12",
|
61
|
+
"00:00:00:00:00:00"
|
62
|
+
],
|
63
|
+
"external_id": null,
|
64
|
+
"id": "#{@host2_inventory_id}",
|
65
|
+
"account": "1460290",
|
66
|
+
"display_name": "insights-rh7.example.com",
|
67
|
+
"ansible_host": null,
|
68
|
+
"facts": [
|
69
|
+
{
|
70
|
+
"namespace": "satellite",
|
71
|
+
"facts": {
|
72
|
+
"virtual_host_name": "virt-who-nobody.home-1",
|
73
|
+
"satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
|
74
|
+
"is_simple_content_access": false,
|
75
|
+
"distribution_version": "7.3",
|
76
|
+
"satellite_version": "6.8.4",
|
77
|
+
"organization_id": 1,
|
78
|
+
"is_hostname_obfuscated": false,
|
79
|
+
"virtual_host_uuid": "a90e6294-4766-420a-8dc0-3ec5b96d60ec"
|
80
|
+
}
|
81
|
+
},
|
82
|
+
{
|
83
|
+
"namespace": "yupana",
|
84
|
+
"facts": {
|
85
|
+
"report_platform_id": "d37afa50-08ce-4efb-a0e5-759c2a016661",
|
86
|
+
"report_slice_id": "5bf791d7-5e30-4a3c-929a-11dd9fa6eb72",
|
87
|
+
"source": "Satellite",
|
88
|
+
"yupana_host_id": "e85958b6-58db-4cfd-aeb6-01ee81bc0f43",
|
89
|
+
"account": "1460290"
|
90
|
+
}
|
91
|
+
}
|
92
|
+
],
|
93
|
+
"reporter": "puptoo",
|
94
|
+
"stale_timestamp": "2021-03-19T07:57:42.466399+00:00",
|
95
|
+
"stale_warning_timestamp": "2021-03-26T07:57:42.466399+00:00",
|
96
|
+
"culled_timestamp": "2021-04-02T07:57:42.466399+00:00",
|
97
|
+
"created": "2021-02-08T14:36:03.613880+00:00",
|
98
|
+
"updated": "2021-03-18T02:57:42.535250+00:00"
|
99
|
+
},
|
100
|
+
{
|
101
|
+
"insights_id": "e0dc5144-d78e-43ed-97be-a7a21d1b6946",
|
102
|
+
"rhel_machine_id": null,
|
103
|
+
"subscription_manager_id": "0f97ee19-6862-4900-aea4-f121c8754776",
|
104
|
+
"satellite_id": "0f97ee19-6862-4900-aea4-f121c8754776",
|
105
|
+
"bios_uuid": "6a0b199a-8225-4ade-ae44-3b18cfc84a01",
|
106
|
+
"ip_addresses": [
|
107
|
+
"192.168.122.136"
|
108
|
+
],
|
109
|
+
"fqdn": "#{@host1.fqdn}",
|
110
|
+
"mac_addresses": [
|
111
|
+
"52:54:00:02:d1:2a",
|
112
|
+
"00:00:00:00:00:00"
|
113
|
+
],
|
114
|
+
"external_id": null,
|
115
|
+
"id": "3255d080-e6c1-44e2-8d72-b044b9a38d8f",
|
116
|
+
"account": "1460290",
|
117
|
+
"display_name": "insights-rh8.example.com",
|
118
|
+
"ansible_host": null,
|
119
|
+
"facts": [
|
120
|
+
{
|
121
|
+
"namespace": "satellite",
|
122
|
+
"facts": {
|
123
|
+
"virtual_host_name": "virt-who-nobody.home-1",
|
124
|
+
"satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
|
125
|
+
"is_simple_content_access": false,
|
126
|
+
"distribution_version": "8.3",
|
127
|
+
"satellite_version": "6.8.4",
|
128
|
+
"organization_id": 1,
|
129
|
+
"is_hostname_obfuscated": false,
|
130
|
+
"virtual_host_uuid": "a90e6294-4766-420a-8dc0-3ec5b96d60ec"
|
131
|
+
}
|
132
|
+
},
|
133
|
+
{
|
134
|
+
"namespace": "yupana",
|
135
|
+
"facts": {
|
136
|
+
"report_platform_id": "d37afa50-08ce-4efb-a0e5-759c2a016661",
|
137
|
+
"report_slice_id": "5bf791d7-5e30-4a3c-929a-11dd9fa6eb72",
|
138
|
+
"source": "Satellite",
|
139
|
+
"yupana_host_id": "78c62486-0ac4-406c-a4c0-3a1f81112a2d",
|
140
|
+
"account": "1460290"
|
141
|
+
}
|
142
|
+
}
|
143
|
+
],
|
144
|
+
"reporter": "puptoo",
|
145
|
+
"stale_timestamp": "2021-03-19T06:05:12.092136+00:00",
|
146
|
+
"stale_warning_timestamp": "2021-03-26T06:05:12.092136+00:00",
|
147
|
+
"culled_timestamp": "2021-04-02T06:05:12.092136+00:00",
|
148
|
+
"created": "2021-02-08T13:22:50.555671+00:00",
|
149
|
+
"updated": "2021-03-18T01:05:12.131847+00:00"
|
150
|
+
},
|
151
|
+
{
|
152
|
+
"insights_id": "b533848e-465f-4f1a-9b2b-b71cb2d5239d",
|
153
|
+
"rhel_machine_id": null,
|
154
|
+
"subscription_manager_id": "d29bde40-348e-437c-8acf-8fa98320fc1b",
|
155
|
+
"satellite_id": "d29bde40-348e-437c-8acf-8fa98320fc1b",
|
156
|
+
"bios_uuid": "3cd5d972-cfb5-451a-8314-fd2f56629d7c",
|
157
|
+
"ip_addresses": [
|
158
|
+
"172.16.5.39",
|
159
|
+
"fd6e:2298:736e::857",
|
160
|
+
"fd6e:2298:736e:0:2c66:6101:9cc6:2b23"
|
161
|
+
],
|
162
|
+
"fqdn": "rhel8-demo.oss-lab.net",
|
163
|
+
"mac_addresses": [
|
164
|
+
"6e:66:a6:fe:fc:07",
|
165
|
+
"00:00:00:00:00:00"
|
166
|
+
],
|
167
|
+
"external_id": null,
|
168
|
+
"id": "59ab38db-c25b-4fc7-bfb2-c8eb01d865a9",
|
169
|
+
"account": "1460290",
|
170
|
+
"display_name": "rhel8-demo.oss-lab.net",
|
171
|
+
"ansible_host": null,
|
172
|
+
"facts": [
|
173
|
+
{
|
174
|
+
"namespace": "satellite",
|
175
|
+
"facts": {
|
176
|
+
"satellite_instance_id": "fb3643d8-9030-487b-b95c-684783806ffd",
|
177
|
+
"system_purpose_sla": "",
|
178
|
+
"is_simple_content_access": false,
|
179
|
+
"distribution_version": "8.3",
|
180
|
+
"satellite_version": "6.8.1",
|
181
|
+
"organization_id": 1,
|
182
|
+
"system_purpose_role": "",
|
183
|
+
"system_purpose_usage": "",
|
184
|
+
"is_hostname_obfuscated": false
|
185
|
+
}
|
186
|
+
},
|
187
|
+
{
|
188
|
+
"namespace": "yupana",
|
189
|
+
"facts": {
|
190
|
+
"report_platform_id": "fa8b924c-51ee-479d-97d2-b4623cf1d4aa",
|
191
|
+
"report_slice_id": "0b49103f-6471-4ade-ad74-a51537bc5691",
|
192
|
+
"source": "Satellite",
|
193
|
+
"yupana_host_id": "30e43340-12fb-445d-b23f-faaf5cbc2092",
|
194
|
+
"account": "1460290"
|
195
|
+
}
|
196
|
+
}
|
197
|
+
],
|
198
|
+
"reporter": "puptoo",
|
199
|
+
"stale_timestamp": "2021-03-19T05:55:23.700781+00:00",
|
200
|
+
"stale_warning_timestamp": "2021-03-26T05:55:23.700781+00:00",
|
201
|
+
"culled_timestamp": "2021-04-02T05:55:23.700781+00:00",
|
202
|
+
"created": "2021-01-13T20:05:51.059012+00:00",
|
203
|
+
"updated": "2021-03-18T00:55:23.739162+00:00"
|
204
|
+
}
|
205
|
+
]
|
206
|
+
}
|
207
|
+
INVENTORY_JSON
|
208
|
+
@inventory = JSON.parse(inventory_json)
|
209
|
+
end
|
210
|
+
|
211
|
+
def interesting_facts
|
212
|
+
[
|
213
|
+
'dmi::system::uuid',
|
214
|
+
'virt::uuid',
|
215
|
+
'cpu::cpu(s)',
|
216
|
+
'cpu::cpu_socket(s)',
|
217
|
+
'cpu::core(s)_per_socket',
|
218
|
+
'memory::memtotal',
|
219
|
+
'dmi::bios::vendor',
|
220
|
+
'dmi::bios::version',
|
221
|
+
'dmi::bios::relase_date',
|
222
|
+
'uname::release',
|
223
|
+
'lscpu::flags',
|
224
|
+
'distribution::name',
|
225
|
+
'distribution::version',
|
226
|
+
'distribution::id',
|
227
|
+
'virt::is_guest',
|
228
|
+
'dmi::system::manufacturer',
|
229
|
+
'dmi::system::product_name',
|
230
|
+
'dmi::chassis::asset_tag',
|
231
|
+
'insights_client::obfuscate_hostname_enabled',
|
232
|
+
'insights_client::hostname',
|
233
|
+
]
|
234
|
+
end
|
235
|
+
|
236
|
+
def fact_names
|
237
|
+
@fact_names ||= Hash[
|
238
|
+
interesting_facts.map do |fact|
|
239
|
+
[fact, FactoryBot.create(:fact_name, name: fact, type: 'Katello::RhsmFactName')]
|
240
|
+
end
|
241
|
+
]
|
242
|
+
end
|
243
|
+
|
244
|
+
test 'Inventory should sync UUID for existing Insights Facets' do
|
245
|
+
InventorySync::Async::InventoryHostsSync.any_instance.expects(:query_inventory).returns(@inventory)
|
246
|
+
InventorySync::Async::InventoryHostsSync.any_instance.expects(:plan_self_host_sync)
|
247
|
+
|
248
|
+
@host2.build_insights.save
|
249
|
+
|
250
|
+
ForemanTasks.sync_task(InventorySync::Async::InventoryHostsSync)
|
251
|
+
|
252
|
+
@host2.reload
|
253
|
+
|
254
|
+
assert_equal @host2_inventory_id, @host2.insights.uuid
|
255
|
+
end
|
256
|
+
|
257
|
+
test 'Inventory should sync UUID for new Insights Facets' do
|
258
|
+
InventorySync::Async::InventoryHostsSync.any_instance.expects(:query_inventory).returns(@inventory)
|
259
|
+
InventorySync::Async::InventoryHostsSync.any_instance.expects(:plan_self_host_sync)
|
260
|
+
|
261
|
+
ForemanTasks.sync_task(InventorySync::Async::InventoryHostsSync)
|
262
|
+
|
263
|
+
@host2.reload
|
264
|
+
|
265
|
+
assert_equal @host2_inventory_id, @host2.insights.uuid
|
266
|
+
end
|
267
|
+
end
|