foreman_rh_cloud 3.0.21 → 3.0.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +50 -0
  3. data/app/controllers/concerns/inventory_upload/report_actions.rb +26 -0
  4. data/app/controllers/concerns/inventory_upload/task_actions.rb +25 -0
  5. data/app/controllers/foreman_inventory_upload/reports_controller.rb +3 -1
  6. data/app/controllers/foreman_inventory_upload/tasks_controller.rb +5 -13
  7. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +4 -4
  8. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +1 -0
  9. data/app/controllers/insights_cloud/hits_controller.rb +7 -3
  10. data/app/helpers/foreman_insights_deprecations_helper.rb +9 -0
  11. data/app/helpers/foreman_insights_host_helper.rb +19 -0
  12. data/app/models/insights_client_report_status.rb +4 -0
  13. data/app/overrides/old_plugin_deprecation.rb +20 -0
  14. data/app/services/foreman_rh_cloud/cloud_auth.rb +12 -0
  15. data/app/services/foreman_rh_cloud/cloud_request.rb +14 -0
  16. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +1 -14
  17. data/app/services/foreman_rh_cloud/remediations_retriever.rb +1 -4
  18. data/config/package-lock.json.plugin +32774 -0
  19. data/config/routes.rb +19 -0
  20. data/lib/foreman_inventory_upload.rb +9 -1
  21. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +19 -0
  22. data/lib/foreman_inventory_upload/generators/queries.rb +1 -0
  23. data/lib/foreman_inventory_upload/generators/slice.rb +7 -6
  24. data/lib/foreman_rh_cloud/engine.rb +19 -8
  25. data/lib/foreman_rh_cloud/version.rb +1 -1
  26. data/lib/insights_cloud/async/insights_client_status_aging.rb +17 -0
  27. data/lib/insights_cloud/async/insights_full_sync.rb +4 -14
  28. data/lib/insights_cloud/async/insights_resolutions_sync.rb +1 -4
  29. data/lib/insights_cloud/async/insights_rules_sync.rb +2 -7
  30. data/lib/inventory_sync/async/host_result.rb +4 -0
  31. data/lib/inventory_sync/async/inventory_full_sync.rb +2 -1
  32. data/lib/inventory_sync/async/inventory_hosts_sync.rb +16 -2
  33. data/lib/inventory_sync/async/inventory_scheduled_sync.rb +12 -0
  34. data/lib/inventory_sync/async/inventory_self_host_sync.rb +30 -0
  35. data/lib/inventory_sync/async/query_inventory_job.rb +6 -5
  36. data/lib/tasks/rh_cloud_inventory.rake +8 -1
  37. data/package.json +1 -1
  38. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +41 -0
  39. data/test/controllers/inventory_upload/api/inventory_controller_test.rb +53 -0
  40. data/test/factories/inventory_upload_factories.rb +1 -1
  41. data/test/jobs/insights_client_status_aging_test.rb +33 -0
  42. data/test/jobs/insights_full_sync_test.rb +3 -0
  43. data/test/jobs/insights_resolutions_sync_test.rb +3 -0
  44. data/test/jobs/insights_rules_sync_test.rb +3 -0
  45. data/test/jobs/inventory_full_sync_test.rb +3 -0
  46. data/test/jobs/inventory_hosts_sync_test.rb +267 -0
  47. data/test/jobs/inventory_scheduled_sync_test.rb +22 -0
  48. data/test/jobs/inventory_self_host_sync_test.rb +103 -0
  49. data/test/test_plugin_helper.rb +2 -0
  50. data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +3 -3
  51. data/test/unit/slice_generator_test.rb +81 -29
  52. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModal.js +1 -1
  53. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/__snapshots__/FullScreenModal.test.js.snap +1 -1
  54. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/fullScreenModal.scss +14 -16
  55. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +11 -0
  56. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +11 -0
  57. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +28 -63
  58. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +2 -3
  59. data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +1 -1
  60. data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/Terminal.test.js +1 -1
  61. data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/__snapshots__/Terminal.test.js.snap +2 -2
  62. data/webpack/ForemanInventoryUpload/Components/Terminal/terminal.scss +25 -27
  63. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +19 -19
  64. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +14 -14
  65. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +1 -0
  66. data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +20 -13
  67. data/webpack/InsightsCloudSync/InsightsCloudSync.js +4 -1
  68. data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +44 -20
  69. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +2 -0
  70. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +2 -2
  71. data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +11 -7
  72. data/webpack/common/ForemanTasks/ForemanTasksActions.js +64 -0
  73. data/webpack/common/ForemanTasks/ForemanTasksHelpers.js +7 -0
  74. data/webpack/common/ForemanTasks/index.js +1 -0
  75. metadata +25 -2
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "3.0.21",
3
+ "version": "3.0.24",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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
+ "MTEyMzYyOFowTzELMAkGA1UEBhMCSUwxETAPBgNVBAgMCFRlbCBBdml2MRQwEgYD\r\n" +
20
+ "VQQKDAtUaGUgRm9yZW1hbjEXMBUGA1UEAwwOdGhlZm9yZW1hbi5vcmcwggIiMA0G\r\n" +
21
+ "CSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDF04/s4h+BgHPG1HDZ/sDlYq925pkc\r\n" +
22
+ "RTVAfnE2EXDAmZ6W4Q9ueDY65MHe3ZWO5Dg72kNSP2sK9kRI7Dk5CAFOgyw1rH8t\r\n" +
23
+ "Hd1+0xp/lv6e4SvSYghxIL68vFe0ftKkm1usqejBM5ZTgKr7JCI+XSIN36F65Kde\r\n" +
24
+ "c+vxwBnayuhP04r9/aaE/709SXML4eRVYW8I3qFy9FPtUOm+bY8U2PIv5fHayqbG\r\n" +
25
+ "cL/4t3+MCtMhHJsLzdBXya+1P5t+HcKjUNlmwoUF961YAktVuEFloGd0RMRlqF3/\r\n" +
26
+ "itU3QNlXgA5QBIciE5VPr/PiqgMC3zgd5avjF4OribZ+N9AATLiQMW78il5wSfcc\r\n" +
27
+ "kQjU9ChOLrzku455vQ8KE4bc0qvpCWGfUah6MvL9JB+TQkRl/8kxl0b9ZinIvJDH\r\n" +
28
+ "ynVMb4cB/TDEjrjOfzn9mWLH0ZJqjmc2bER/G12WQxOaYLxdVwRStD3Yh6PtiFWu\r\n" +
29
+ "sXOk19UOTVkeuvGFVtvzLfEwQ1lDEo7+VBQz8FG/HBu2Hpq3IwCFrHuicikwjQJk\r\n" +
30
+ "nfturgD0rBOKEc1qWNZRCvovYOLL6ihvv5Orujsx5ZCHOAtnVNxkvIlFt2RS45LF\r\n" +
31
+ "MtPJyhAc6SjitllfUEirxprsbmeSZqrIfzcGaEhgOSnyik1WMv6bYiqPfBg8Fzjh\r\n" +
32
+ "vOCbtiDNPmvgOwIDAQABo1MwUTAdBgNVHQ4EFgQUtkAgQopsTtG9zSG3MgW2IxHD\r\n" +
33
+ "MDwwHwYDVR0jBBgwFoAUtkAgQopsTtG9zSG3MgW2IxHDMDwwDwYDVR0TAQH/BAUw\r\n" +
34
+ "AwEB/zANBgkqhkiG9w0BAQsFAAOCAgEAJq7iN+ZroRBweNhvUobxs75bLIV6tNn1\r\n" +
35
+ "MdNHDRA+hezwf+gxHZhFyaAHfTpst2/9leK5Qe5Zd6gZLr3E5/8ppQuRod72H39B\r\n" +
36
+ "vxMlG5zxDss0WMo3vZeKZbTY6QhXi/lY2IZ6OGV4feSvCsYxn27GTjjrRUSLFeHH\r\n" +
37
+ "JVemCwCDMavaE3+OIY4v2P4FcG+MjUvfOB9ahI24TWL7YgrsNVmJjCILq+EeUj0t\r\n" +
38
+ "Gde1SXVyLkqt7PoxHRJAE0BCEMJSnjxaVB329acJgeehBUxjj4CCPqtDxtbz9HEH\r\n" +
39
+ "mOKfNdaKpFor+DUeEKUWVGnr9U9xOaC+Ws+oX7MIEUCDM7p2ob4JwcjnFs1jZgHh\r\n" +
40
+ "Hwig+i7doTlc701PvKWO96fuNHK3B3/jTb1fVvSZ49O/RvY1VWODdUdxWmXGHNh3\r\n" +
41
+ "LoR8tSPEb46lC2DXGaIQumqQt8PnBG+vL1qkQa1SGTV7dJ8TTbxbv0S+sS+igkk9\r\n" +
42
+ "zsIEK8Ea3Ep935cXximz0faAAKHSA+It+xHLAyDtqy2KaAEBgGsBuuWlUfK6TaP3\r\n" +
43
+ "Gwdjct3y4yYUO45lUsUfHqX8vk/4ttW5zYeDiW+HArJz+9VUXNbEdury4kGuHgBj\r\n" +
44
+ "xHD4Bsul65+hHZ9QywKU26F1A6TLkYpQ2rk/Dx9LGICM4m4IlHjWJPFsQdtkyOor\r\n" +
45
+ "osxMtcaZZ1E=\r\n" +
46
+ "-----END CERTIFICATE-----"
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| "uuid-#{n}-#{rand(500)}" }
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::NOT_MANAGED, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)
22
+ InsightsClientReportStatus.find_or_initialize_by(host_id: @host4.id).update(status: InsightsClientReportStatus::NOT_MANAGED_WITH_DATA, 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::NO_REPORT, @host1.get_status(InsightsClientReportStatus).status
29
+ assert_equal InsightsClientReportStatus::NO_REPORT, @host2.get_status(InsightsClientReportStatus).status
30
+ assert_equal InsightsClientReportStatus::NOT_MANAGED, @host3.get_status(InsightsClientReportStatus).status
31
+ assert_equal InsightsClientReportStatus::NOT_MANAGED, @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" => {
@@ -1,6 +1,9 @@
1
1
  require 'test_helper'
2
+ require 'foreman_tasks/test_helpers'
2
3
 
3
4
  class InsightsRulesSyncTest < ActiveSupport::TestCase
5
+ include ForemanTasks::TestHelpers::WithInThreadExecutor
6
+
4
7
  setup do
5
8
  rules_json = <<-'RULES_JSON'
6
9
  {
@@ -1,6 +1,9 @@
1
1
  require 'test_plugin_helper'
2
+ require 'foreman_tasks/test_helpers'
2
3
 
3
4
  class InventoryFullSyncTest < ActiveSupport::TestCase
5
+ include ForemanTasks::TestHelpers::WithInThreadExecutor
6
+
4
7
  setup do
5
8
  User.current = User.find_by(login: 'secret_admin')
6
9
 
@@ -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