foreman_rh_cloud 4.0.21.1 → 4.0.24.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) 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 +6 -3
  9. data/app/controllers/insights_cloud/hits_controller.rb +7 -3
  10. data/app/helpers/foreman_insights_host_helper.rb +19 -0
  11. data/app/models/insights_client_report_status.rb +11 -22
  12. data/app/services/foreman_rh_cloud/cloud_auth.rb +12 -0
  13. data/app/services/foreman_rh_cloud/cloud_request.rb +14 -0
  14. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +1 -14
  15. data/app/services/foreman_rh_cloud/insights_status_cleaner.rb +17 -0
  16. data/app/services/foreman_rh_cloud/remediations_retriever.rb +1 -4
  17. data/config/package-lock.json.plugin +30931 -0
  18. data/config/routes.rb +19 -0
  19. data/db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb +6 -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 +6 -5
  24. data/lib/foreman_rh_cloud/engine.rb +17 -10
  25. data/lib/foreman_rh_cloud/version.rb +1 -1
  26. data/lib/insights_cloud/async/insights_client_status_aging.rb +23 -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/insights.rake +15 -0
  37. data/lib/tasks/rh_cloud_inventory.rake +8 -1
  38. data/package.json +1 -1
  39. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +41 -0
  40. data/test/controllers/inventory_upload/api/inventory_controller_test.rb +53 -0
  41. data/test/factories/inventory_upload_factories.rb +1 -1
  42. data/test/jobs/insights_client_status_aging_test.rb +33 -0
  43. data/test/jobs/inventory_hosts_sync_test.rb +267 -0
  44. data/test/jobs/inventory_scheduled_sync_test.rb +22 -0
  45. data/test/jobs/inventory_self_host_sync_test.rb +103 -0
  46. data/test/models/insights_client_report_status_test.rb +70 -72
  47. data/test/test_plugin_helper.rb +2 -1
  48. data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +3 -3
  49. data/test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb +31 -0
  50. data/test/unit/slice_generator_test.rb +70 -27
  51. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +11 -0
  52. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +11 -0
  53. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +28 -63
  54. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +2 -3
  55. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +19 -19
  56. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +0 -2
  57. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +14 -14
  58. data/webpack/InsightsCloudSync/InsightsCloudSync.js +4 -1
  59. data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +44 -20
  60. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +2 -0
  61. data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +11 -7
  62. data/webpack/common/ForemanTasks/ForemanTasksActions.js +64 -0
  63. data/webpack/common/ForemanTasks/ForemanTasksHelpers.js +7 -0
  64. data/webpack/common/ForemanTasks/index.js +1 -0
  65. metadata +28 -4
  66. data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +0 -9
@@ -0,0 +1,22 @@
1
+ require 'test_plugin_helper'
2
+ require 'foreman_tasks/test_helpers'
3
+
4
+ class InventoryScheduledSyncTest < ActiveSupport::TestCase
5
+ include ForemanTasks::TestHelpers::WithInThreadExecutor
6
+
7
+ test 'Schedules an execution if auto upload is enabled' do
8
+ FactoryBot.create(:setting, :name => 'allow_auto_inventory_upload', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => true)
9
+
10
+ InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).times(Organization.unscoped.count)
11
+
12
+ ForemanTasks.sync_task(InventorySync::Async::InventoryScheduledSync)
13
+ end
14
+
15
+ test 'Skips execution if auto upload is disabled' do
16
+ FactoryBot.create(:setting, :name => 'allow_auto_inventory_upload', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => false)
17
+
18
+ InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).never
19
+
20
+ ForemanTasks.sync_task(InventorySync::Async::InventoryScheduledSync)
21
+ end
22
+ end
@@ -0,0 +1,103 @@
1
+ require 'test_plugin_helper'
2
+ require 'foreman_tasks/test_helpers'
3
+
4
+ class InventorySelfHostSyncTest < ActiveSupport::TestCase
5
+ include ForemanTasks::TestHelpers::WithInThreadExecutor
6
+
7
+ setup do
8
+ User.current = User.find_by(login: 'secret_admin')
9
+
10
+ # this host would pass our plugin queries, so it could be uploaded to the cloud.
11
+ @host1 = FactoryBot.create(:host)
12
+ @host1_inventory_id = '3255d080-e6c1-44e2-8d72-b044b9a38d8f'
13
+
14
+ ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
15
+
16
+ ForemanRhCloud.stubs(:foreman_host).returns(@host1)
17
+
18
+ inventory_json = <<-INVENTORY_JSON
19
+ {
20
+ "total": 1,
21
+ "count": 1,
22
+ "page": 1,
23
+ "per_page": 1,
24
+ "results": [
25
+ {
26
+ "insights_id": "e0dc5144-d78e-43ed-97be-a7a21d1b6946",
27
+ "rhel_machine_id": null,
28
+ "subscription_manager_id": "0f97ee19-6862-4900-aea4-f121c8754776",
29
+ "satellite_id": "0f97ee19-6862-4900-aea4-f121c8754776",
30
+ "bios_uuid": "6a0b199a-8225-4ade-ae44-3b18cfc84a01",
31
+ "ip_addresses": [
32
+ "192.168.122.136"
33
+ ],
34
+ "fqdn": "#{@host1.fqdn}",
35
+ "mac_addresses": [
36
+ "52:54:00:02:d1:2a",
37
+ "00:00:00:00:00:00"
38
+ ],
39
+ "external_id": null,
40
+ "id": "#{@host1_inventory_id}",
41
+ "account": "1460290",
42
+ "display_name": "insights-rh8.example.com",
43
+ "ansible_host": null,
44
+ "facts": [
45
+ {
46
+ "namespace": "satellite",
47
+ "facts": {
48
+ "virtual_host_name": "virt-who-nobody.home-1",
49
+ "satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
50
+ "is_simple_content_access": false,
51
+ "distribution_version": "8.3",
52
+ "satellite_version": "6.8.4",
53
+ "organization_id": 1,
54
+ "is_hostname_obfuscated": false,
55
+ "virtual_host_uuid": "a90e6294-4766-420a-8dc0-3ec5b96d60ec"
56
+ }
57
+ },
58
+ {
59
+ "namespace": "yupana",
60
+ "facts": {
61
+ "report_platform_id": "d37afa50-08ce-4efb-a0e5-759c2a016661",
62
+ "report_slice_id": "5bf791d7-5e30-4a3c-929a-11dd9fa6eb72",
63
+ "source": "Satellite",
64
+ "yupana_host_id": "78c62486-0ac4-406c-a4c0-3a1f81112a2d",
65
+ "account": "1460290"
66
+ }
67
+ }
68
+ ],
69
+ "reporter": "puptoo",
70
+ "stale_timestamp": "2021-03-19T06:05:12.092136+00:00",
71
+ "stale_warning_timestamp": "2021-03-26T06:05:12.092136+00:00",
72
+ "culled_timestamp": "2021-04-02T06:05:12.092136+00:00",
73
+ "created": "2021-02-08T13:22:50.555671+00:00",
74
+ "updated": "2021-03-18T01:05:12.131847+00:00"
75
+ }
76
+ ]
77
+ }
78
+ INVENTORY_JSON
79
+ @inventory = JSON.parse(inventory_json)
80
+ end
81
+
82
+ test 'Inventory should sync UUID for existing Insights Facets' do
83
+ InventorySync::Async::InventorySelfHostSync.any_instance.expects(:query_inventory).returns(@inventory)
84
+
85
+ @host1.build_insights.save
86
+
87
+ ForemanTasks.sync_task(InventorySync::Async::InventorySelfHostSync)
88
+
89
+ @host1.reload
90
+
91
+ assert_equal @host1_inventory_id, @host1.insights.uuid
92
+ end
93
+
94
+ test 'Inventory should sync UUID for new Insights Facets' do
95
+ InventorySync::Async::InventorySelfHostSync.any_instance.expects(:query_inventory).returns(@inventory)
96
+
97
+ ForemanTasks.sync_task(InventorySync::Async::InventorySelfHostSync)
98
+
99
+ @host1.reload
100
+
101
+ assert_equal @host1_inventory_id, @host1.insights.uuid
102
+ end
103
+ end
@@ -1,77 +1,75 @@
1
1
  require 'test_plugin_helper'
2
2
 
3
3
  class InsightsClientReportStatusTest < ActiveSupport::TestCase
4
- describe 'to_status' do
5
- let(:host) { FactoryBot.create(:host, :managed) }
6
-
7
- setup do
8
- CommonParameter.where(name: 'host_registration_insights').destroy_all
9
- end
10
-
11
- test 'host_registration_insights = true & is getting data' do
12
- FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
13
- host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
14
-
15
- assert_equal 0, host_status.to_status(data: true)
16
- end
17
-
18
- test 'host_registration_insights = true & no data in less than 48 hours' do
19
- FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
20
- host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
21
- host_status.update(reported_at: 1.day.ago)
22
- assert_equal 0, host_status.to_status
23
- end
24
-
25
- test 'host_registration_insights = true & no data in more than 48 hours' do
26
- FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
27
- host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
28
- host_status.update(reported_at: 3.days.ago)
29
- assert_equal 1, host_status.to_status
30
- end
31
-
32
- test 'host_registration_insights = false & no data' do
33
- FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false)
34
- host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
35
- assert_equal 2, host_status.to_status
36
- end
37
-
38
- test 'host_registration_insights = false & getting data' do
39
- FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false)
40
- host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
41
- assert_equal 3, host_status.to_status(data: true)
42
- end
43
-
44
- test 'host_registration_insights = nil & is getting data' do
45
- host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
46
- assert_equal 3, host_status.to_status(data: true)
47
- end
48
-
49
- test 'host_registration_insights = nil & no data in less than 48 hours' do
50
- host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
51
- host_status.update(reported_at: 1.day.ago)
52
- assert_equal 2, host_status.to_status
53
- end
54
-
55
- test 'host_registration_insights = nil & no data in more than 48 hours' do
56
- host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
57
- host_status.update(reported_at: 3.days.ago)
58
- assert_equal 2, host_status.to_status
59
- end
60
-
61
- test 'override param on host level from `false` to `true`' do
62
- FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false)
63
- FactoryBot.create(:host_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true, host: host)
64
-
65
- host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
66
- assert_equal 0, host_status.to_status(data: true)
67
- end
68
-
69
- test 'override param on host level from `true` to `false`' do
70
- FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
71
- FactoryBot.create(:host_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false, host: host)
72
-
73
- host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
74
- assert_equal 2, host_status.to_status
75
- end
4
+ setup do
5
+ @host = FactoryBot.create(:host, :managed)
6
+ end
7
+
8
+ test 'fresh host does not have insights status' do
9
+ @host.reload
10
+
11
+ refute @host.host_statuses.where(type: 'InsightsClientReportStatus').exists?
12
+ insights_status = @host.get_status(InsightsClientReportStatus)
13
+ refute insights_status.relevant?
14
+ end
15
+
16
+ test 'host can refresh all its statuses' do
17
+ @host.refresh_statuses
18
+ @host.reload
19
+
20
+ refute @host.host_statuses.where(type: 'InsightsClientReportStatus').exists?
21
+ end
22
+
23
+ test 'host with correct report status sets global status to OK' do
24
+ global_status = @host.get_status(HostStatus.find_status_by_humanized_name('Global'))
25
+ # Status has to be OK before action
26
+ assert_equal HostStatus::Global::OK, global_status.status
27
+
28
+ # force create record
29
+ @host.get_status(InsightsClientReportStatus).refresh!
30
+ # now refresh should work
31
+ @host.refresh_statuses([InsightsClientReportStatus])
32
+
33
+ @host.reload
34
+ global_status = @host.get_status(HostStatus.find_status_by_humanized_name('Global'))
35
+ # Status has to be OK after the action too
36
+ assert_equal HostStatus::Global::OK, global_status.status
37
+
38
+ insights_status = @host.get_status(InsightsClientReportStatus)
39
+ # assert the status would be displayed
40
+ assert insights_status.relevant?
41
+ end
42
+
43
+ test 'host will return to OK once the status is refreshed' do
44
+ global_status = @host.get_status(HostStatus.find_status_by_humanized_name('Global'))
45
+ # Status has to be OK before action
46
+ assert_equal HostStatus::Global::OK, global_status.status
47
+
48
+ insights_status = @host.get_status(InsightsClientReportStatus)
49
+ insights_status.status = InsightsClientReportStatus::NO_REPORT
50
+ insights_status.save!
51
+ @host.refresh_global_status!
52
+ global_status = @host.global_status
53
+ assert_equal HostStatus::Global::ERROR, global_status
54
+
55
+ @host.refresh_statuses([InsightsClientReportStatus])
56
+
57
+ @host.reload
58
+ # Status has to be OK after the action too
59
+ assert_equal HostStatus::Global::OK, @host.global_status
60
+ end
61
+
62
+ test 'host with stale status would set global to ERROR' do
63
+ global_status = @host.get_status(HostStatus.find_status_by_humanized_name('Global'))
64
+ # Status has to be OK before action
65
+ assert_equal HostStatus::Global::OK, global_status.status
66
+
67
+ insights_status = @host.get_status(InsightsClientReportStatus)
68
+ insights_status.status = InsightsClientReportStatus::NO_REPORT
69
+ insights_status.save!
70
+ @host.refresh_global_status!
71
+ @host.reload
72
+
73
+ assert_equal HostStatus::Global::ERROR, @host.global_status
76
74
  end
77
75
  end
@@ -2,6 +2,8 @@
2
2
  require 'test_helper'
3
3
 
4
4
  # Add plugin to FactoryBot's paths
5
+ FactoryBot.definition_file_paths << "#{ForemanTasks::Engine.root}/test/factories"
6
+ FactoryBot.definition_file_paths << "#{ForemanRemoteExecution::Engine.root}/test/factories"
5
7
  FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
6
8
  # FactoryBot.definition_file_paths << "#{Katello::Engine.root}/test/factories"
7
9
  FactoryBot.reload
@@ -33,7 +35,6 @@ module KatelloLocationFix
33
35
  FactoryBot.create(:setting, name: 'default_location_subscribed_hosts')
34
36
  FactoryBot.create(:setting, name: 'default_location_puppet_content')
35
37
  Setting[:default_location_subscribed_hosts] = Location.first.title
36
- Setting[:default_location_puppet_content] = Location.first.title
37
38
  end
38
39
  end
39
40
  end
@@ -42,9 +42,9 @@ class CloudRequestForwarderTest < ActiveSupport::TestCase
42
42
  test 'should prepare correct cloud url' do
43
43
  paths = {
44
44
  "/redhat_access/r/insights/platform/module-update-router/v1/channel?module=insights-core" => "https://cert.cloud.redhat.com/api/module-update-router/v1/channel?module=insights-core",
45
- "/redhat_access/r/insights/v1/static/release/insights-core.egg" => "https://cloud.redhat.com/api/v1/static/release/insights-core.egg",
46
- "/redhat_access/r/insights/v1/static/uploader.v2.json" => "https://cloud.redhat.com/api/v1/static/uploader.v2.json",
47
- "/redhat_access/r/insights/v1/static/uploader.v2.json.asc" => "https://cloud.redhat.com/api/v1/static/uploader.v2.json.asc",
45
+ "/redhat_access/r/insights/v1/static/release/insights-core.egg" => "https://cert-api.access.redhat.com/r/insights/v1/static/release/insights-core.egg",
46
+ "/redhat_access/r/insights/v1/static/uploader.v2.json" => "https://cert-api.access.redhat.com/r/insights/v1/static/uploader.v2.json",
47
+ "/redhat_access/r/insights/v1/static/uploader.v2.json.asc" => "https://cert-api.access.redhat.com/r/insights/v1/static/uploader.v2.json.asc",
48
48
  "/redhat_access/r/insights/platform/inventory/v1/hosts" => "https://cert.cloud.redhat.com/api/inventory/v1/hosts",
49
49
  "/redhat_access/r/insights/platform/ingress/v1/upload" => "https://cert.cloud.redhat.com/api/ingress/v1/upload",
50
50
  "/redhat_access/r/insights/uploads/67200803-132b-474b-a6f9-37be74185df4" => "https://cert-api.access.redhat.com/r/insights/uploads/67200803-132b-474b-a6f9-37be74185df4",
@@ -0,0 +1,31 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class InsightsStatusCleanerTest < ActiveSupport::TestCase
4
+ setup do
5
+ @host1 = FactoryBot.create(:host)
6
+ @host2 = FactoryBot.create(:host)
7
+
8
+ InsightsClientReportStatus.find_or_initialize_by(host_id: @host1.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL + 1.day)
9
+ InsightsClientReportStatus.find_or_initialize_by(host_id: @host2.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL + 1.day)
10
+
11
+ @host1.refresh_global_status!
12
+ @host2.refresh_global_status!
13
+ end
14
+
15
+ test 'Cleans hosts by search condition' do
16
+ assert_equal HostStatus::Global::ERROR, @host1.global_status
17
+ assert_equal HostStatus::Global::ERROR, @host2.global_status
18
+
19
+ instance = ForemanRhCloud::InsightsStatusCleaner.new
20
+ actual_count = instance.clean("name = #{@host1.name}")
21
+
22
+ @host1.reload
23
+ @host2.refresh_global_status!
24
+
25
+ assert_equal 1, actual_count
26
+ assert_equal HostStatus::Global::OK, @host1.global_status
27
+ assert_equal HostStatus::Global::ERROR, @host2.global_status
28
+ assert InsightsClientReportStatus.where(host_id: @host1.id).empty?
29
+ refute InsightsClientReportStatus.where(host_id: @host2.id).empty?
30
+ end
31
+ end
@@ -53,6 +53,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
53
53
  'insights_client::hostname',
54
54
  'insights_client::obfuscate_ip_enabled',
55
55
  'insights_client::ips',
56
+ 'insights_id',
56
57
  ]
57
58
  end
58
59
 
@@ -71,7 +72,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
71
72
  json_str = generator.render
72
73
  actual = JSON.parse(json_str.join("\n"))
73
74
 
74
- assert_equal 'slice_123', actual['report_slice_id']
75
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
75
76
  assert_not_nil(actual_host = actual['hosts'].first)
76
77
  assert_nil actual_host['ip_addresses']
77
78
  assert_nil actual_host['mac_addresses']
@@ -102,7 +103,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
102
103
  json_str = generator.render
103
104
  actual = JSON.parse(json_str.join("\n"))
104
105
 
105
- assert_equal 'slice_123', actual['report_slice_id']
106
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
106
107
  assert_not_nil(actual_host = actual['hosts'].first)
107
108
  assert_not_nil(actual_system_profile = actual_host['system_profile'])
108
109
  assert_equal 4, actual_system_profile['number_of_cpus']
@@ -120,7 +121,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
120
121
  json_str = generator.render
121
122
  actual = JSON.parse(json_str.join("\n"))
122
123
 
123
- assert_equal 'slice_123', actual['report_slice_id']
124
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
124
125
  assert_not_nil(actual_host = actual['hosts'].first)
125
126
  assert_equal @host.interfaces.where.not(ip: nil).first.ip, actual_host['ip_addresses'].first
126
127
  assert_equal @host.interfaces.where.not(mac: nil).first.mac, actual_host['mac_addresses'].first
@@ -142,7 +143,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
142
143
  json_str = generator.render
143
144
  actual = JSON.parse(json_str.join("\n"))
144
145
 
145
- assert_equal 'slice_123', actual['report_slice_id']
146
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
146
147
  assert_not_nil(actual_host = actual['hosts'].first)
147
148
  assert_equal @host.interfaces.where.not(ip: nil).first.ip, actual_host['ip_addresses'].first
148
149
  assert_equal @host.interfaces.where.not(mac: nil).first.mac, actual_host['mac_addresses'].first
@@ -172,7 +173,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
172
173
  json_str = generator.render
173
174
  actual = JSON.parse(json_str.join("\n"))
174
175
 
175
- assert_equal 'slice_123', actual['report_slice_id']
176
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
176
177
  assert_not_nil(actual_host = actual['hosts'].first)
177
178
  assert_equal @host.interfaces.where.not(ip: nil).first.ip, actual_host['ip_addresses'].first
178
179
  assert_equal @host.interfaces.where.not(mac: nil).first.mac, actual_host['mac_addresses'].first
@@ -191,7 +192,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
191
192
  json_str = generator.render
192
193
  actual = JSON.parse(json_str.join("\n"))
193
194
 
194
- assert_equal 'slice_123', actual['report_slice_id']
195
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
195
196
  assert_not_nil(actual_host = actual['hosts'].first)
196
197
  assert_equal '10.230.230.1', actual_host['ip_addresses'].first
197
198
  assert_not_nil(actual_system_profile = actual_host['system_profile'])
@@ -221,7 +222,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
221
222
  json_str = generator.render
222
223
  actual = JSON.parse(json_str.join("\n"))
223
224
 
224
- assert_equal 'slice_123', actual['report_slice_id']
225
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
225
226
  assert_not_nil(actual_host = actual['hosts'].first)
226
227
  assert_equal '10.230.230.100', actual_host['ip_addresses'].first
227
228
  assert_not_nil(actual_system_profile = actual_host['system_profile'])
@@ -243,7 +244,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
243
244
  json_str = generator.render
244
245
  actual = JSON.parse(json_str.join("\n"))
245
246
 
246
- assert_equal 'slice_123', actual['report_slice_id']
247
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
247
248
  assert_not_nil(actual_host = actual['hosts'].first)
248
249
  assert_equal 'obfuscated_name', actual_host['fqdn']
249
250
  assert_equal '1234', actual_host['account']
@@ -263,7 +264,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
263
264
 
264
265
  obfuscated_fqdn = Digest::SHA1.hexdigest(@host.fqdn) + '.example.com'
265
266
 
266
- assert_equal 'slice_123', actual['report_slice_id']
267
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
267
268
  assert_not_nil(actual_host = actual['hosts'].first)
268
269
  assert_equal obfuscated_fqdn, actual_host['fqdn']
269
270
  assert_equal '1234', actual_host['account']
@@ -282,7 +283,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
282
283
  json_str = generator.render
283
284
  actual = JSON.parse(json_str.join("\n"))
284
285
 
285
- assert_equal 'slice_123', actual['report_slice_id']
286
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
286
287
  assert_not_nil(actual_host = actual['hosts'].first)
287
288
  assert_equal @host.fqdn, actual_host['fqdn']
288
289
  assert_equal '1234', actual_host['account']
@@ -355,7 +356,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
355
356
  json_str = generator.render
356
357
  actual = JSON.parse(json_str.join("\n"))
357
358
 
358
- assert_equal 'slice_123', actual['report_slice_id']
359
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
359
360
  assert_not_nil(actual_host = actual['hosts'].first)
360
361
  assert_equal @host.fqdn, actual_host['fqdn']
361
362
  assert_not_nil(host_facts = actual_host['facts']&.first)
@@ -377,7 +378,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
377
378
  json_str = generator.render
378
379
  actual = JSON.parse(json_str.join("\n"))
379
380
 
380
- assert_equal 'slice_123', actual['report_slice_id']
381
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
381
382
  assert_not_nil(actual_host = actual['hosts'].first)
382
383
  assert_equal @host.fqdn, actual_host['fqdn']
383
384
  assert_not_nil(host_facts = actual_host['facts']&.first)
@@ -397,7 +398,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
397
398
  json_str = generator.render
398
399
  actual = JSON.parse(json_str.join("\n"))
399
400
 
400
- assert_equal 'slice_123', actual['report_slice_id']
401
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
401
402
  assert_not_nil(actual_host = actual['hosts'].first)
402
403
  assert_equal @host.fqdn, actual_host['fqdn']
403
404
  assert_equal '1234', actual_host['account']
@@ -417,7 +418,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
417
418
  json_str = generator.render
418
419
  actual = JSON.parse(json_str.join("\n"))
419
420
 
420
- assert_equal 'slice_123', actual['report_slice_id']
421
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
421
422
  assert_not_nil(actual_host = actual['hosts'].first)
422
423
  assert_equal @host.fqdn, actual_host['fqdn']
423
424
  assert_equal '1234', actual_host['account']
@@ -436,7 +437,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
436
437
  json_str = generator.render
437
438
  actual = JSON.parse(json_str.join("\n"))
438
439
 
439
- assert_equal 'slice_123', actual['report_slice_id']
440
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
440
441
  assert_equal 1, generator.hosts_count
441
442
  end
442
443
 
@@ -449,7 +450,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
449
450
  json_str = generator.render
450
451
  actual = JSON.parse(json_str.join("\n"))
451
452
 
452
- assert_equal 'slice_123', actual['report_slice_id']
453
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
453
454
  assert_not_nil(actual_host = actual['hosts'].first)
454
455
  assert_not_nil(actual_profile = actual_host['system_profile'])
455
456
  assert_equal 1024, actual_profile['system_memory_bytes']
@@ -475,7 +476,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
475
476
  json_str = generator.render
476
477
  actual = JSON.parse(json_str.join("\n"))
477
478
 
478
- assert_equal 'slice_123', actual['report_slice_id']
479
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
479
480
  assert_not_nil(actual_host = actual['hosts'].first)
480
481
  assert_not_nil(actual_host['account'])
481
482
  assert_not_empty(actual_host['account'])
@@ -492,7 +493,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
492
493
  json_str = generator.render
493
494
  actual = JSON.parse(json_str.join("\n"))
494
495
 
495
- assert_equal 'slice_123', actual['report_slice_id']
496
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
496
497
  assert_not_nil(actual_host = actual['hosts'].first)
497
498
  assert_not_nil(actual_profile = actual_host['system_profile'])
498
499
  assert_equal 'Red Hat Test Linux 7.1 (TestId)', actual_profile['os_release']
@@ -507,7 +508,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
507
508
  json_str = generator.render
508
509
  actual = JSON.parse(json_str.join("\n"))
509
510
 
510
- assert_equal 'slice_123', actual['report_slice_id']
511
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
511
512
  assert_not_nil(actual_host = actual['hosts'].first)
512
513
  assert_not_nil(actual_profile = actual_host['system_profile'])
513
514
  assert_equal 'virtual', actual_profile['infrastructure_type']
@@ -522,7 +523,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
522
523
  json_str = generator.render
523
524
  actual = JSON.parse(json_str.join("\n"))
524
525
 
525
- assert_equal 'slice_123', actual['report_slice_id']
526
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
526
527
  assert_not_nil(actual_host = actual['hosts'].first)
527
528
  assert_not_nil(actual_profile = actual_host['system_profile'])
528
529
  assert_equal 'physical', actual_profile['infrastructure_type']
@@ -537,7 +538,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
537
538
  json_str = generator.render
538
539
  actual = JSON.parse(json_str.join("\n"))
539
540
 
540
- assert_equal 'slice_123', actual['report_slice_id']
541
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
541
542
  assert_not_nil(actual_host = actual['hosts'].first)
542
543
  assert_not_nil(actual_profile = actual_host['system_profile'])
543
544
  assert_equal 'aws', actual_profile['cloud_provider']
@@ -552,7 +553,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
552
553
  json_str = generator.render
553
554
  actual = JSON.parse(json_str.join("\n"))
554
555
 
555
- assert_equal 'slice_123', actual['report_slice_id']
556
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
556
557
  assert_not_nil(actual_host = actual['hosts'].first)
557
558
  assert_not_nil(actual_profile = actual_host['system_profile'])
558
559
  assert_equal 'google', actual_profile['cloud_provider']
@@ -567,7 +568,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
567
568
  json_str = generator.render
568
569
  actual = JSON.parse(json_str.join("\n"))
569
570
 
570
- assert_equal 'slice_123', actual['report_slice_id']
571
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
571
572
  assert_not_nil(actual_host = actual['hosts'].first)
572
573
  assert_not_nil(actual_profile = actual_host['system_profile'])
573
574
  assert_equal 'azure', actual_profile['cloud_provider']
@@ -582,7 +583,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
582
583
  json_str = generator.render
583
584
  actual = JSON.parse(json_str.join("\n"))
584
585
 
585
- assert_equal 'slice_123', actual['report_slice_id']
586
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
586
587
  assert_not_nil(actual_host = actual['hosts'].first)
587
588
  assert_not_nil(actual_profile = actual_host['system_profile'])
588
589
  assert_equal 'alibaba', actual_profile['cloud_provider']
@@ -597,7 +598,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
597
598
  json_str = generator.render
598
599
  actual = JSON.parse(json_str.join("\n"))
599
600
 
600
- assert_equal 'slice_123', actual['report_slice_id']
601
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
601
602
  assert_not_nil(actual_host = actual['hosts'].first)
602
603
  assert_not_nil(actual_profile = actual_host['system_profile'])
603
604
  assert_equal 'alibaba', actual_profile['cloud_provider']
@@ -623,15 +624,57 @@ class SliceGeneratorTest < ActiveSupport::TestCase
623
624
  json_str = generator.render
624
625
  actual = JSON.parse(json_str.join("\n"))
625
626
 
626
- assert_equal 'slice_123', actual['report_slice_id']
627
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
627
628
  assert_not_nil(actual_host = actual['hosts'].first)
628
629
  assert_not_nil(actual_profile = actual_host['system_profile'])
629
630
  assert_not_nil(actual_profile['installed_packages'])
630
631
  end
631
632
 
633
+ test 'omits malformed bios_uuid field' do
634
+ FactoryBot.create(:fact_value, fact_name: fact_names['dmi::system::uuid'], value: 'test value', host: @host)
635
+
636
+ batch = Host.where(id: @host.id).in_batches.first
637
+ generator = create_generator(batch)
638
+
639
+ json_str = generator.render
640
+ actual = JSON.parse(json_str.join("\n"))
641
+
642
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
643
+ assert_not_nil(actual_host = actual['hosts'].first)
644
+ assert_nil actual_host['bios_uuid']
645
+ end
646
+
647
+ test 'passes valid bios_uuid field' do
648
+ FactoryBot.create(:fact_value, fact_name: fact_names['dmi::system::uuid'], value: 'D30B0B42-7824-2635-C62D-491394DE43F7', host: @host)
649
+
650
+ batch = Host.where(id: @host.id).in_batches.first
651
+ generator = create_generator(batch)
652
+
653
+ json_str = generator.render
654
+ actual = JSON.parse(json_str.join("\n"))
655
+
656
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
657
+ assert_not_nil(actual_host = actual['hosts'].first)
658
+ assert_not_nil actual_host['bios_uuid']
659
+ end
660
+
661
+ test 'passes valid insights_id field' do
662
+ FactoryBot.create(:fact_value, fact_name: fact_names['insights_id'], value: 'D30B0B42-7824-2635-C62D-491394DE43F7', host: @host)
663
+
664
+ batch = Host.where(id: @host.id).in_batches.first
665
+ generator = create_generator(batch)
666
+
667
+ json_str = generator.render
668
+ actual = JSON.parse(json_str.join("\n"))
669
+
670
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
671
+ assert_not_nil(actual_host = actual['hosts'].first)
672
+ assert_not_nil actual_host['insights_id']
673
+ end
674
+
632
675
  private
633
676
 
634
- def create_generator(batch, name = 'slice_123')
677
+ def create_generator(batch, name = '00000000-0000-0000-0000-000000000000')
635
678
  generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], name)
636
679
  if block_given?
637
680
  yield(generator)