foreman_rh_cloud 3.0.21 → 3.0.24

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.
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
@@ -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
@@ -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
@@ -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",
@@ -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']
@@ -296,6 +297,13 @@ class SliceGeneratorTest < ActiveSupport::TestCase
296
297
  @host.hostgroup = hostgroup
297
298
  @host.save!
298
299
 
300
+ ForemanInventoryUpload::Generators::Tags.any_instance.expects(:generate_parameters).returns(
301
+ [
302
+ ['bool_param', true],
303
+ ['int_param', 1],
304
+ ]
305
+ )
306
+
299
307
  Foreman.expects(:instance_id).twice.returns('satellite-id')
300
308
  batch = Host.where(id: @host.id).in_batches.first
301
309
  generator = create_generator(batch)
@@ -316,6 +324,8 @@ class SliceGeneratorTest < ActiveSupport::TestCase
316
324
  assert_tag(@host.location.name, actual_host, 'location')
317
325
  assert_tag(@host.organization.name, actual_host, 'organization')
318
326
  assert_tag(@host.hostgroup.name, actual_host, 'hostgroup')
327
+ assert_tag('true', actual_host, 'bool_param', 'satellite_parameter')
328
+ assert_tag('1', actual_host, 'int_param', 'satellite_parameter')
319
329
 
320
330
  assert_equal false, satellite_facts['is_hostname_obfuscated']
321
331
 
@@ -346,7 +356,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
346
356
  json_str = generator.render
347
357
  actual = JSON.parse(json_str.join("\n"))
348
358
 
349
- assert_equal 'slice_123', actual['report_slice_id']
359
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
350
360
  assert_not_nil(actual_host = actual['hosts'].first)
351
361
  assert_equal @host.fqdn, actual_host['fqdn']
352
362
  assert_not_nil(host_facts = actual_host['facts']&.first)
@@ -368,7 +378,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
368
378
  json_str = generator.render
369
379
  actual = JSON.parse(json_str.join("\n"))
370
380
 
371
- assert_equal 'slice_123', actual['report_slice_id']
381
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
372
382
  assert_not_nil(actual_host = actual['hosts'].first)
373
383
  assert_equal @host.fqdn, actual_host['fqdn']
374
384
  assert_not_nil(host_facts = actual_host['facts']&.first)
@@ -388,7 +398,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
388
398
  json_str = generator.render
389
399
  actual = JSON.parse(json_str.join("\n"))
390
400
 
391
- assert_equal 'slice_123', actual['report_slice_id']
401
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
392
402
  assert_not_nil(actual_host = actual['hosts'].first)
393
403
  assert_equal @host.fqdn, actual_host['fqdn']
394
404
  assert_equal '1234', actual_host['account']
@@ -408,7 +418,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
408
418
  json_str = generator.render
409
419
  actual = JSON.parse(json_str.join("\n"))
410
420
 
411
- assert_equal 'slice_123', actual['report_slice_id']
421
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
412
422
  assert_not_nil(actual_host = actual['hosts'].first)
413
423
  assert_equal @host.fqdn, actual_host['fqdn']
414
424
  assert_equal '1234', actual_host['account']
@@ -427,7 +437,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
427
437
  json_str = generator.render
428
438
  actual = JSON.parse(json_str.join("\n"))
429
439
 
430
- assert_equal 'slice_123', actual['report_slice_id']
440
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
431
441
  assert_equal 1, generator.hosts_count
432
442
  end
433
443
 
@@ -440,7 +450,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
440
450
  json_str = generator.render
441
451
  actual = JSON.parse(json_str.join("\n"))
442
452
 
443
- assert_equal 'slice_123', actual['report_slice_id']
453
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
444
454
  assert_not_nil(actual_host = actual['hosts'].first)
445
455
  assert_not_nil(actual_profile = actual_host['system_profile'])
446
456
  assert_equal 1024, actual_profile['system_memory_bytes']
@@ -466,7 +476,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
466
476
  json_str = generator.render
467
477
  actual = JSON.parse(json_str.join("\n"))
468
478
 
469
- assert_equal 'slice_123', actual['report_slice_id']
479
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
470
480
  assert_not_nil(actual_host = actual['hosts'].first)
471
481
  assert_not_nil(actual_host['account'])
472
482
  assert_not_empty(actual_host['account'])
@@ -483,7 +493,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
483
493
  json_str = generator.render
484
494
  actual = JSON.parse(json_str.join("\n"))
485
495
 
486
- assert_equal 'slice_123', actual['report_slice_id']
496
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
487
497
  assert_not_nil(actual_host = actual['hosts'].first)
488
498
  assert_not_nil(actual_profile = actual_host['system_profile'])
489
499
  assert_equal 'Red Hat Test Linux 7.1 (TestId)', actual_profile['os_release']
@@ -498,7 +508,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
498
508
  json_str = generator.render
499
509
  actual = JSON.parse(json_str.join("\n"))
500
510
 
501
- assert_equal 'slice_123', actual['report_slice_id']
511
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
502
512
  assert_not_nil(actual_host = actual['hosts'].first)
503
513
  assert_not_nil(actual_profile = actual_host['system_profile'])
504
514
  assert_equal 'virtual', actual_profile['infrastructure_type']
@@ -513,7 +523,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
513
523
  json_str = generator.render
514
524
  actual = JSON.parse(json_str.join("\n"))
515
525
 
516
- assert_equal 'slice_123', actual['report_slice_id']
526
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
517
527
  assert_not_nil(actual_host = actual['hosts'].first)
518
528
  assert_not_nil(actual_profile = actual_host['system_profile'])
519
529
  assert_equal 'physical', actual_profile['infrastructure_type']
@@ -528,7 +538,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
528
538
  json_str = generator.render
529
539
  actual = JSON.parse(json_str.join("\n"))
530
540
 
531
- assert_equal 'slice_123', actual['report_slice_id']
541
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
532
542
  assert_not_nil(actual_host = actual['hosts'].first)
533
543
  assert_not_nil(actual_profile = actual_host['system_profile'])
534
544
  assert_equal 'aws', actual_profile['cloud_provider']
@@ -543,7 +553,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
543
553
  json_str = generator.render
544
554
  actual = JSON.parse(json_str.join("\n"))
545
555
 
546
- assert_equal 'slice_123', actual['report_slice_id']
556
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
547
557
  assert_not_nil(actual_host = actual['hosts'].first)
548
558
  assert_not_nil(actual_profile = actual_host['system_profile'])
549
559
  assert_equal 'google', actual_profile['cloud_provider']
@@ -558,7 +568,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
558
568
  json_str = generator.render
559
569
  actual = JSON.parse(json_str.join("\n"))
560
570
 
561
- assert_equal 'slice_123', actual['report_slice_id']
571
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
562
572
  assert_not_nil(actual_host = actual['hosts'].first)
563
573
  assert_not_nil(actual_profile = actual_host['system_profile'])
564
574
  assert_equal 'azure', actual_profile['cloud_provider']
@@ -573,7 +583,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
573
583
  json_str = generator.render
574
584
  actual = JSON.parse(json_str.join("\n"))
575
585
 
576
- assert_equal 'slice_123', actual['report_slice_id']
586
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
577
587
  assert_not_nil(actual_host = actual['hosts'].first)
578
588
  assert_not_nil(actual_profile = actual_host['system_profile'])
579
589
  assert_equal 'alibaba', actual_profile['cloud_provider']
@@ -588,7 +598,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
588
598
  json_str = generator.render
589
599
  actual = JSON.parse(json_str.join("\n"))
590
600
 
591
- assert_equal 'slice_123', actual['report_slice_id']
601
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
592
602
  assert_not_nil(actual_host = actual['hosts'].first)
593
603
  assert_not_nil(actual_profile = actual_host['system_profile'])
594
604
  assert_equal 'alibaba', actual_profile['cloud_provider']
@@ -614,15 +624,57 @@ class SliceGeneratorTest < ActiveSupport::TestCase
614
624
  json_str = generator.render
615
625
  actual = JSON.parse(json_str.join("\n"))
616
626
 
617
- assert_equal 'slice_123', actual['report_slice_id']
627
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
618
628
  assert_not_nil(actual_host = actual['hosts'].first)
619
629
  assert_not_nil(actual_profile = actual_host['system_profile'])
620
630
  assert_not_nil(actual_profile['installed_packages'])
621
631
  end
622
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
+
623
675
  private
624
676
 
625
- def create_generator(batch, name = 'slice_123')
677
+ def create_generator(batch, name = '00000000-0000-0000-0000-000000000000')
626
678
  generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], name)
627
679
  if block_given?
628
680
  yield(generator)
@@ -632,8 +684,8 @@ class SliceGeneratorTest < ActiveSupport::TestCase
632
684
  generator
633
685
  end
634
686
 
635
- def assert_tag(expected_value, host, tag_id)
636
- actual_tag = host['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == tag_id }
687
+ def assert_tag(expected_value, host, tag_id, namespace = 'satellite')
688
+ actual_tag = host['tags'].find { |tag| tag['namespace'] == namespace && tag['key'] == tag_id }
637
689
  assert_not_nil actual_tag
638
690
  assert_equal expected_value, actual_tag['value']
639
691
  end