foreman_rh_cloud 13.2.9 → 14.0.1

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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/foreman_rh_cloud/locale/fr/foreman_rh_cloud.js +61 -61
  3. data/app/assets/javascripts/foreman_rh_cloud/locale/ja/foreman_rh_cloud.js +68 -68
  4. data/app/assets/javascripts/foreman_rh_cloud/locale/ka/foreman_rh_cloud.js +9 -9
  5. data/app/assets/javascripts/foreman_rh_cloud/locale/ko/foreman_rh_cloud.js +60 -60
  6. data/app/assets/javascripts/foreman_rh_cloud/locale/zh_CN/foreman_rh_cloud.js +60 -60
  7. data/app/controllers/concerns/insights_cloud/package_profile_upload_extensions.rb +0 -9
  8. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +2 -9
  9. data/app/models/concerns/rh_cloud_host.rb +3 -35
  10. data/app/models/insights_client_report_status.rb +1 -9
  11. data/app/models/inventory_sync/inventory_status.rb +4 -16
  12. data/app/services/foreman_rh_cloud/insights_api_forwarder.rb +5 -12
  13. data/lib/foreman_inventory_upload/async/create_missing_insights_facets.rb +2 -8
  14. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +0 -8
  15. data/lib/foreman_inventory_upload/generators/queries.rb +1 -1
  16. data/lib/foreman_inventory_upload/generators/slice.rb +1 -1
  17. data/lib/foreman_rh_cloud/engine.rb +0 -1
  18. data/lib/foreman_rh_cloud/version.rb +1 -1
  19. data/lib/insights_cloud/async/vmaas_reposcan_sync.rb +8 -23
  20. data/lib/inventory_sync/async/inventory_full_sync.rb +3 -39
  21. data/locale/fr/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  22. data/locale/fr/foreman_rh_cloud.edit.po +1032 -0
  23. data/locale/fr/foreman_rh_cloud.po +65 -66
  24. data/locale/fr/foreman_rh_cloud.po.time_stamp +0 -0
  25. data/locale/ja/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  26. data/locale/ja/foreman_rh_cloud.edit.po +1026 -0
  27. data/locale/ja/foreman_rh_cloud.po +70 -72
  28. data/locale/ja/foreman_rh_cloud.po.time_stamp +0 -0
  29. data/locale/ka/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  30. data/locale/ka/foreman_rh_cloud.edit.po +1025 -0
  31. data/locale/ka/foreman_rh_cloud.po +10 -11
  32. data/locale/ka/foreman_rh_cloud.po.time_stamp +0 -0
  33. data/locale/ko/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  34. data/locale/ko/foreman_rh_cloud.edit.po +1029 -0
  35. data/locale/ko/foreman_rh_cloud.po +63 -64
  36. data/locale/ko/foreman_rh_cloud.po.time_stamp +0 -0
  37. data/locale/zh_CN/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  38. data/locale/zh_CN/foreman_rh_cloud.edit.po +1031 -0
  39. data/locale/zh_CN/foreman_rh_cloud.po +64 -65
  40. data/locale/zh_CN/foreman_rh_cloud.po.time_stamp +0 -0
  41. data/package.json +1 -1
  42. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +1 -41
  43. data/test/jobs/insights_client_status_aging_test.rb +0 -40
  44. data/test/jobs/inventory_full_sync_test.rb +4 -219
  45. data/test/jobs/inventory_hosts_sync_test.rb +5 -7
  46. data/test/jobs/inventory_self_host_sync_test.rb +1 -1
  47. data/test/models/insights_client_report_status_test.rb +0 -109
  48. data/test/unit/archived_report_generator_test.rb +1 -2
  49. data/test/unit/fact_helpers_test.rb +0 -16
  50. data/test/unit/lib/insights_cloud/async/vmaas_reposcan_sync_test.rb +25 -80
  51. data/test/unit/rh_cloud_host_test.rb +0 -214
  52. data/test/unit/services/foreman_rh_cloud/branch_info_test.rb +1 -1
  53. data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +1 -1
  54. data/test/unit/slice_generator_test.rb +2 -21
  55. data/webpack/CVEsHostDetailsTab/CVEsHostDetailsTab.js +1 -6
  56. data/webpack/CVEsHostDetailsTab/__tests__/CVEsHostDetailsTab.test.js +6 -45
  57. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +1 -3
  58. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +2 -8
  59. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +0 -1
  60. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/integrations.test.js +0 -1
  61. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Toast.js +17 -43
  62. data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +0 -7
  63. data/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js +14 -44
  64. metadata +16 -10
  65. data/app/controllers/concerns/insights_cloud/candlepin_proxies_extensions.rb +0 -23
  66. data/test/controllers/insights_cloud/candlepin_proxies_extensions_test.rb +0 -70
  67. data/test/models/inventory_sync/inventory_status_test.rb +0 -85
  68. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/__tests__/Toast.test.js +0 -82
  69. data/webpack/InsightsHostDetailsTab/__tests__/NewHostDetailsTab.test.js +0 -154
@@ -5,7 +5,6 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
5
5
  include Dynflow::Testing::Factories
6
6
  include MockCerts
7
7
  include KatelloCVEHelper
8
- include CandlepinIsolation
9
8
 
10
9
  setup do
11
10
  User.current = User.find_by(login: 'secret_admin')
@@ -28,7 +27,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
28
27
 
29
28
  pool = FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
30
29
 
31
- @host1.subscription_facet.pools << pool
30
+ @host1.organization.pools << pool
32
31
 
33
32
  # this host would pass our plugin queries, so it could be uploaded to the cloud.
34
33
  @host2 = FactoryBot.create(
@@ -40,7 +39,6 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
40
39
  organization: env.organization
41
40
  )
42
41
 
43
- @host2.subscription_facet.pools << pool
44
42
  @host2_inventory_id = '4536bf5c-ff03-4154-a8c9-32ff4b40e40c'
45
43
 
46
44
  # this host would pass our plugin queries, so it could be uploaded to the cloud.
@@ -53,8 +51,6 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
53
51
  organization: env.organization
54
52
  )
55
53
 
56
- @host3.subscription_facet.pools << pool
57
-
58
54
  ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
59
55
 
60
56
  inventory_json = <<-INVENTORY_JSON
@@ -89,7 +85,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
89
85
  "facts": {
90
86
  "virtual_host_name": "virt-who-nobody.home-1",
91
87
  "satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
92
- "is_simple_content_access": false,
88
+ "is_simple_content_access": true,
93
89
  "distribution_version": "7.3",
94
90
  "satellite_version": "6.8.4",
95
91
  "organization_id": 1,
@@ -140,7 +136,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
140
136
  "facts": {
141
137
  "virtual_host_name": "virt-who-nobody.home-1",
142
138
  "satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
143
- "is_simple_content_access": false,
139
+ "is_simple_content_access": true,
144
140
  "distribution_version": "8.3",
145
141
  "satellite_version": "6.8.4",
146
142
  "organization_id": 1,
@@ -193,7 +189,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
193
189
  "facts": {
194
190
  "satellite_instance_id": "fb3643d8-9030-487b-b95c-684783806ffd",
195
191
  "system_purpose_sla": "",
196
- "is_simple_content_access": false,
192
+ "is_simple_content_access": true,
197
193
  "distribution_version": "8.3",
198
194
  "satellite_version": "6.8.1",
199
195
  "organization_id": 1,
@@ -314,215 +310,4 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
314
310
 
315
311
  assert_nil InventorySync::InventoryStatus.where(host_id: @host3.id).first
316
312
  end
317
-
318
- test 'user-omitted hosts get USER_OMITTED status' do
319
- # Add parameter to exclude host1
320
- @host1.host_parameters << HostParameter.create(
321
- name: 'host_registration_insights_inventory',
322
- value: 'false',
323
- parameter_type: 'boolean'
324
- )
325
- @host1.save!
326
-
327
- setup_certs_expectation do
328
- InventorySync::Async::InventoryFullSync.any_instance.stubs(:candlepin_id_cert)
329
- end
330
- InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
331
- FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
332
-
333
- action = create_and_plan_action(InventorySync::Async::InventoryFullSync, @host1.organization)
334
- run_action(action)
335
-
336
- @host1.reload
337
- @host2.reload
338
-
339
- # Host1 should be USER_OMITTED
340
- assert_equal InventorySync::InventoryStatus::USER_OMITTED,
341
- InventorySync::InventoryStatus.where(host_id: @host1.id).first.status,
342
- 'Host with host_registration_insights_inventory=false should have USER_OMITTED status'
343
-
344
- # Host2 should be SYNC
345
- assert_equal InventorySync::InventoryStatus::SYNC,
346
- InventorySync::InventoryStatus.where(host_id: @host2.id).first.status,
347
- 'Normal host should have SYNC status'
348
- end
349
-
350
- test 'user-omitted hosts are not marked as disconnected' do
351
- # Add parameter to exclude host1
352
- @host1.host_parameters << HostParameter.create(
353
- name: 'host_registration_insights_inventory',
354
- value: 'false',
355
- parameter_type: 'boolean'
356
- )
357
- @host1.save!
358
-
359
- # Host1 is not in the cloud inventory response
360
- setup_certs_expectation do
361
- InventorySync::Async::InventoryFullSync.any_instance.stubs(:candlepin_id_cert)
362
- end
363
- InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
364
- InventorySync::Async::InventoryFullSync.any_instance.expects(:affected_host_ids).returns([@host1.id, @host2.id])
365
- FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
366
-
367
- action = create_and_plan_action(InventorySync::Async::InventoryFullSync, @host1.organization)
368
- run_action(action)
369
-
370
- @host1.reload
371
-
372
- # Host1 should be USER_OMITTED, not DISCONNECT
373
- assert_equal InventorySync::InventoryStatus::USER_OMITTED,
374
- InventorySync::InventoryStatus.where(host_id: @host1.id).first.status,
375
- 'User-omitted host should have USER_OMITTED status even if not in cloud inventory'
376
- end
377
-
378
- test 'host_statuses output includes all three counts' do
379
- # Create a mix of hosts with different statuses
380
- # Host1: will be user-omitted
381
- @host1.host_parameters << HostParameter.create(
382
- name: 'host_registration_insights_inventory',
383
- value: 'false',
384
- parameter_type: 'boolean'
385
- )
386
- @host1.save!
387
-
388
- # Host2: will be synced (in cloud inventory)
389
- # Host3: will be disconnected (not in cloud inventory)
390
-
391
- # Create inventory response with only host2 (exclude host1 and host3)
392
- inventory_with_host2_only = @inventory.dup
393
- inventory_with_host2_only['results'] = [@inventory['results'][0]] # Only host2
394
- inventory_with_host2_only['total'] = 1
395
- inventory_with_host2_only['count'] = 1
396
-
397
- setup_certs_expectation do
398
- InventorySync::Async::InventoryFullSync.any_instance.stubs(:candlepin_id_cert)
399
- end
400
- InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(inventory_with_host2_only)
401
- InventorySync::Async::InventoryFullSync.any_instance.expects(:affected_host_ids).returns([@host1.id, @host2.id, @host3.id])
402
- FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
403
-
404
- action = create_and_plan_action(InventorySync::Async::InventoryFullSync, @host1.organization)
405
- run_action(action)
406
-
407
- # Verify the statuses were actually set correctly
408
- @host1.reload
409
- @host2.reload
410
- @host3.reload
411
-
412
- assert_equal InventorySync::InventoryStatus::USER_OMITTED,
413
- InventorySync::InventoryStatus.where(host_id: @host1.id).first.status,
414
- 'Host with host_registration_insights_inventory=false should have USER_OMITTED status'
415
- assert_equal InventorySync::InventoryStatus::SYNC,
416
- InventorySync::InventoryStatus.where(host_id: @host2.id).first.status,
417
- 'Host in cloud inventory should have SYNC status'
418
- assert_equal InventorySync::InventoryStatus::DISCONNECT,
419
- InventorySync::InventoryStatus.where(host_id: @host3.id).first.status,
420
- 'Host not in cloud inventory and not user-omitted should have DISCONNECT status'
421
- end
422
-
423
- test 'user-omitted status respects parameter inheritance from hostgroup' do
424
- # Create a hostgroup and assign it to host1
425
- hostgroup = FactoryBot.create(:hostgroup)
426
- hostgroup.organizations << @host1.organization
427
- @host1.hostgroup = hostgroup
428
- @host1.save!
429
-
430
- # Set parameter at hostgroup level, not directly on host
431
- # This verifies the fix that uses search_for instead of querying HostParameter directly
432
- hostgroup.group_parameters << GroupParameter.create(
433
- name: 'host_registration_insights_inventory',
434
- value: 'false',
435
- key_type: 'boolean'
436
- )
437
- hostgroup.save!
438
-
439
- # Verify parameter is inherited (not set directly on host)
440
- assert_nil @host1.parameters.find_by(name: 'host_registration_insights_inventory'),
441
- 'Test setup: parameter should not be set directly on host'
442
- refute ::Foreman::Cast.to_bool(@host1.host_param('host_registration_insights_inventory')),
443
- 'Test setup: parameter should be inherited from hostgroup'
444
-
445
- # Host2 remains normal (no parameter)
446
- setup_certs_expectation do
447
- InventorySync::Async::InventoryFullSync.any_instance.stubs(:candlepin_id_cert)
448
- end
449
- InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
450
- InventorySync::Async::InventoryFullSync.any_instance.expects(:affected_host_ids).returns([@host1.id, @host2.id])
451
- FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
452
-
453
- action = create_and_plan_action(InventorySync::Async::InventoryFullSync, @host1.organization)
454
- run_action(action)
455
-
456
- @host1.reload
457
- @host2.reload
458
-
459
- # Host1 should be USER_OMITTED (inherited parameter from hostgroup)
460
- host1_status = InventorySync::InventoryStatus.where(host_id: @host1.id).first
461
- assert_not_nil host1_status, 'Host1 should have an inventory status'
462
- assert_equal InventorySync::InventoryStatus::USER_OMITTED, host1_status.status,
463
- 'Host with inherited host_registration_insights_inventory=false should have USER_OMITTED status'
464
-
465
- # Host2 should be SYNC
466
- assert_equal InventorySync::InventoryStatus::SYNC,
467
- InventorySync::InventoryStatus.where(host_id: @host2.id).first.status,
468
- 'Normal host should have SYNC status'
469
- end
470
-
471
- test 'user-omitted statuses are cleared before re-creating them to avoid silent create failures' do
472
- # First sync: host1 is user-omitted
473
- @host1.host_parameters << HostParameter.create(
474
- name: 'host_registration_insights_inventory',
475
- value: 'false',
476
- parameter_type: 'boolean'
477
- )
478
- @host1.save!
479
-
480
- setup_certs_expectation do
481
- InventorySync::Async::InventoryFullSync.any_instance.stubs(:candlepin_id_cert)
482
- end
483
- InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory).twice
484
- InventorySync::Async::InventoryFullSync.any_instance.expects(:affected_host_ids).returns([@host1.id, @host2.id]).twice
485
- FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
486
-
487
- # Run first sync
488
- action = create_and_plan_action(InventorySync::Async::InventoryFullSync, @host1.organization)
489
- run_action(action)
490
-
491
- @host1.reload
492
- initial_status = InventorySync::InventoryStatus.where(host_id: @host1.id).first
493
- assert_equal InventorySync::InventoryStatus::USER_OMITTED, initial_status.status,
494
- 'Initial sync: host should be USER_OMITTED'
495
- initial_status_id = initial_status.id
496
-
497
- # Verify there's only one status record for host1
498
- assert_equal 1, InventorySync::InventoryStatus.where(host_id: @host1.id).count,
499
- 'Should have exactly one status record after first sync'
500
-
501
- # Run second sync (parameter still false)
502
- # Without clearing old user_omitted statuses, the .create would silently fail
503
- # with 'Host has already been taken' due to uniqueness constraint
504
- setup_certs_expectation do
505
- InventorySync::Async::InventoryFullSync.any_instance.stubs(:candlepin_id_cert)
506
- end
507
-
508
- action2 = create_and_plan_action(InventorySync::Async::InventoryFullSync, @host1.organization)
509
- run_action(action2)
510
-
511
- @host1.reload
512
- final_status = InventorySync::InventoryStatus.where(host_id: @host1.id).first
513
-
514
- # Verify status is still USER_OMITTED (not stale from first sync)
515
- assert_equal InventorySync::InventoryStatus::USER_OMITTED, final_status.status,
516
- 'Status should be USER_OMITTED after second sync'
517
-
518
- # Verify there's still only one status record (old one was deleted before creating new one)
519
- assert_equal 1, InventorySync::InventoryStatus.where(host_id: @host1.id).count,
520
- 'Should have exactly one status record (old cleared before new created)'
521
-
522
- # Verify the old status record was actually deleted and replaced with a new one
523
- refute InventorySync::InventoryStatus.exists?(initial_status_id),
524
- 'Old status record should have been deleted before creating new one'
525
- assert_not_equal initial_status_id, final_status.id,
526
- 'New status record should have different ID, proving old was deleted'
527
- end
528
313
  end
@@ -23,7 +23,7 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
23
23
 
24
24
  pool = FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
25
25
 
26
- @host1.subscription_facet.pools << pool
26
+ @host1.organization.pools << pool
27
27
 
28
28
  # this host would pass our plugin queries, so it could be uploaded to the cloud.
29
29
  @host2 = FactoryBot.create(
@@ -34,8 +34,6 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
34
34
  lifecycle_environment: env,
35
35
  organization: env.organization
36
36
  )
37
-
38
- @host2.subscription_facet.pools << pool
39
37
  @host2_inventory_id = '4536bf5c-ff03-4154-a8c9-32ff4b40e40c'
40
38
 
41
39
  ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
@@ -71,7 +69,7 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
71
69
  "facts": {
72
70
  "virtual_host_name": "virt-who-nobody.home-1",
73
71
  "satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
74
- "is_simple_content_access": false,
72
+ "is_simple_content_access": true,
75
73
  "distribution_version": "7.3",
76
74
  "satellite_version": "6.8.4",
77
75
  "organization_id": 1,
@@ -122,7 +120,7 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
122
120
  "facts": {
123
121
  "virtual_host_name": "virt-who-nobody.home-1",
124
122
  "satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
125
- "is_simple_content_access": false,
123
+ "is_simple_content_access": true,
126
124
  "distribution_version": "7.3",
127
125
  "satellite_version": "6.8.4",
128
126
  "organization_id": 1,
@@ -173,7 +171,7 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
173
171
  "facts": {
174
172
  "virtual_host_name": "virt-who-nobody.home-1",
175
173
  "satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
176
- "is_simple_content_access": false,
174
+ "is_simple_content_access": true,
177
175
  "distribution_version": "8.3",
178
176
  "satellite_version": "6.8.4",
179
177
  "organization_id": 1,
@@ -226,7 +224,7 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
226
224
  "facts": {
227
225
  "satellite_instance_id": "fb3643d8-9030-487b-b95c-684783806ffd",
228
226
  "system_purpose_sla": "",
229
- "is_simple_content_access": false,
227
+ "is_simple_content_access": true,
230
228
  "distribution_version": "8.3",
231
229
  "satellite_version": "6.8.1",
232
230
  "organization_id": 1,
@@ -53,7 +53,7 @@ class InventorySelfHostSyncTest < ActiveSupport::TestCase
53
53
  "facts": {
54
54
  "virtual_host_name": "virt-who-nobody.home-1",
55
55
  "satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
56
- "is_simple_content_access": false,
56
+ "is_simple_content_access": true,
57
57
  "distribution_version": "8.3",
58
58
  "satellite_version": "6.8.4",
59
59
  "organization_id": 1,
@@ -72,113 +72,4 @@ class InsightsClientReportStatusTest < ActiveSupport::TestCase
72
72
 
73
73
  assert_equal HostStatus::Global::ERROR, @host.global_status
74
74
  end
75
-
76
- test 'host with host_registration_insights parameter set to false gets USER_OMITTED status' do
77
- @host.host_parameters << HostParameter.create(
78
- name: 'host_registration_insights',
79
- value: 'false',
80
- parameter_type: 'boolean'
81
- )
82
- @host.save!
83
-
84
- insights_status = @host.get_status(InsightsClientReportStatus)
85
- insights_status.refresh!
86
-
87
- assert_equal InsightsClientReportStatus::USER_OMITTED, insights_status.status
88
- assert_equal HostStatus::Global::OK, insights_status.to_global
89
- end
90
-
91
- test 'USER_OMITTED status has correct label' do
92
- insights_status = @host.get_status(InsightsClientReportStatus)
93
- insights_status.status = InsightsClientReportStatus::USER_OMITTED
94
- insights_status.save!
95
-
96
- label = insights_status.to_label
97
- assert_match(/host_registration_insights/, label)
98
- assert_match(/false/, label)
99
- end
100
-
101
- test 'stale scope excludes USER_OMITTED hosts' do
102
- host1 = FactoryBot.create(:host, :managed)
103
- host2 = FactoryBot.create(:host, :managed)
104
- host3 = FactoryBot.create(:host, :managed)
105
-
106
- # Host 1: USER_OMITTED with old reported_at (should NOT be in stale scope)
107
- status1 = host1.get_status(InsightsClientReportStatus)
108
- status1.status = InsightsClientReportStatus::USER_OMITTED
109
- status1.reported_at = Time.zone.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day
110
- status1.save!
111
-
112
- # Host 2: REPORTING with old reported_at (should be in stale scope)
113
- status2 = host2.get_status(InsightsClientReportStatus)
114
- status2.status = InsightsClientReportStatus::REPORTING
115
- status2.reported_at = Time.zone.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day
116
- status2.save!
117
-
118
- # Host 3: NO_REPORT with old reported_at (should be in stale scope)
119
- status3 = host3.get_status(InsightsClientReportStatus)
120
- status3.status = InsightsClientReportStatus::NO_REPORT
121
- status3.reported_at = Time.zone.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day
122
- status3.save!
123
-
124
- stale_statuses = InsightsClientReportStatus.stale
125
- stale_host_ids = stale_statuses.pluck(:host_id)
126
-
127
- assert_not_includes stale_host_ids, host1.id, 'USER_OMITTED host should not be in stale scope'
128
- assert_includes stale_host_ids, host2.id, 'REPORTING host with old report should be in stale scope'
129
- assert_includes stale_host_ids, host3.id, 'NO_REPORT host with old report should be in stale scope'
130
- end
131
-
132
- test 'USER_OMITTED status respects parameter inheritance from hostgroup' do
133
- # Create a hostgroup with parameter = false
134
- hostgroup = FactoryBot.create(:hostgroup)
135
- hostgroup.group_parameters << GroupParameter.create(
136
- name: 'host_registration_insights',
137
- value: 'false',
138
- key_type: 'boolean'
139
- )
140
- hostgroup.save!
141
-
142
- @host.hostgroup = hostgroup
143
- @host.save!
144
-
145
- # Verify parameter is inherited (not set directly on host)
146
- assert_nil @host.parameters.find_by(name: 'host_registration_insights'),
147
- 'Test setup: parameter should not be set directly on host'
148
-
149
- insights_status = @host.get_status(InsightsClientReportStatus)
150
- insights_status.refresh!
151
-
152
- assert_equal InsightsClientReportStatus::USER_OMITTED, insights_status.status,
153
- 'Status should be USER_OMITTED when host_registration_insights=false is inherited from hostgroup'
154
- assert_equal HostStatus::Global::OK, insights_status.to_global,
155
- 'USER_OMITTED status should not affect global status'
156
- end
157
-
158
- test 'host parameter overrides inherited parameter from hostgroup' do
159
- # Create a hostgroup with parameter = false
160
- hostgroup = FactoryBot.create(:hostgroup)
161
- hostgroup.group_parameters << GroupParameter.create(
162
- name: 'host_registration_insights',
163
- value: 'false',
164
- key_type: 'boolean'
165
- )
166
- hostgroup.save!
167
-
168
- @host.hostgroup = hostgroup
169
-
170
- # Override with host parameter = true
171
- @host.host_parameters << HostParameter.create(
172
- name: 'host_registration_insights',
173
- value: 'true',
174
- parameter_type: 'boolean'
175
- )
176
- @host.save!
177
-
178
- insights_status = @host.get_status(InsightsClientReportStatus)
179
- insights_status.refresh!
180
-
181
- assert_not_equal InsightsClientReportStatus::USER_OMITTED, insights_status.status,
182
- 'Status should not be USER_OMITTED when host parameter overrides hostgroup parameter with true'
183
- end
184
75
  end
@@ -18,7 +18,7 @@ class ArchivedReportGeneratorTest < ActiveSupport::TestCase
18
18
  organization: env.organization
19
19
  )
20
20
 
21
- @host.subscription_facet.pools << FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
21
+ @host.organization.pools << FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
22
22
  end
23
23
 
24
24
  def interesting_facts
@@ -51,7 +51,6 @@ class ArchivedReportGeneratorTest < ActiveSupport::TestCase
51
51
  test_org = FactoryBot.create(:organization)
52
52
 
53
53
  ForemanInventoryUpload::Generators::Queries.expects(:for_org).with(test_org.id, hosts_query: '').returns(batches)
54
- ForemanInventoryUpload::Generators::Slice.any_instance.stubs(:golden_ticket?).returns(false)
55
54
  Dir.mktmpdir do |tmpdir|
56
55
  target = File.join(tmpdir, 'test.tar.gz')
57
56
  generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
@@ -12,22 +12,6 @@ class FactHelpersTest < ActiveSupport::TestCase
12
12
  @org = FactoryBot.create(:organization)
13
13
  end
14
14
 
15
- test 'golden_ticket uses golden_ticket method when defined' do
16
- @org.expects(:golden_ticket?).returns(true)
17
-
18
- actual = @instance.golden_ticket?(@org)
19
-
20
- assert actual
21
- end
22
-
23
- test 'golden_ticket uses content_access_mode method when golden_ticket not defined' do
24
- @org.expects(:content_access_mode).returns('org_environment')
25
-
26
- actual = @instance.golden_ticket?(@org)
27
-
28
- assert actual
29
- end
30
-
31
15
  test 'obfuscates ips with insights-client data' do
32
16
  host = mock('host')
33
17
  @instance.expects(:fact_value).with(host, 'insights_client::obfuscated_ipv4').returns(
@@ -5,17 +5,19 @@ class VmaasReposcanSyncTest < ActiveSupport::TestCase
5
5
  include ForemanTasks::TestHelpers::WithInThreadExecutor
6
6
 
7
7
  setup do
8
- @organization = FactoryBot.create(:organization)
9
- # Create a simple repository - we only need id and organization_id for the action
10
- @repo = ::Katello::Repository.new(id: 1)
11
- @repo.stubs(:organization_id).returns(@organization.id)
12
- ::Katello::Repository.stubs(:find).with(1).returns(@repo)
13
-
8
+ @root = FactoryBot.build(:katello_root_repository, :fedora_17_x86_64_dev_root)
9
+ @root.save(validate: false)
10
+ @repo = FactoryBot.create(
11
+ :katello_repository,
12
+ :with_product,
13
+ distribution_family: 'Red Hat',
14
+ distribution_version: '7.5',
15
+ root: @root
16
+ )
14
17
  @repo_payload = { id: @repo.id }
15
18
  @expected_url = 'https://example.com/api/v1/vmaas/reposcan/sync'
16
19
  InsightsCloud.stubs(:vmaas_reposcan_sync_url).returns(@expected_url)
17
20
  ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
18
- Organization.stubs(:find).with(@organization.id).returns(@organization)
19
21
  end
20
22
 
21
23
  teardown do
@@ -81,7 +83,7 @@ class VmaasReposcanSyncTest < ActiveSupport::TestCase
81
83
  params[:url] == @expected_url &&
82
84
  params[:headers].is_a?(Hash) &&
83
85
  params[:headers]['Content-Type'] == 'application/json' &&
84
- params[:organization] == @organization
86
+ params[:organization] == @repo.organization
85
87
  end
86
88
  .returns(mock_response)
87
89
 
@@ -114,94 +116,37 @@ class VmaasReposcanSyncTest < ActiveSupport::TestCase
114
116
  .stubs(:execute_cloud_request)
115
117
  .raises(exception)
116
118
 
117
- task = ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
119
+ error = assert_raises(ForemanTasks::TaskError) do
120
+ ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
121
+ end
118
122
 
119
- assert_equal 'VMaaS reposcan sync failed: 500 - Server Error', task.output[:message]
123
+ assert_equal 'VMaaS reposcan sync failed: 500 - Server Error', error.task.output[:message]
120
124
  end
121
125
 
122
126
  test 'run sets error message in task output for StandardError exception' do
123
- mock_logger = mock('logger')
124
- mock_logger.expects(:error).with('Error triggering VMaaS reposcan sync: Network timeout')
125
- InsightsCloud::Async::VmaasReposcanSync.any_instance.stubs(:logger).returns(mock_logger)
126
-
127
127
  InsightsCloud::Async::VmaasReposcanSync.any_instance
128
128
  .stubs(:execute_cloud_request)
129
129
  .raises(StandardError.new('Network timeout'))
130
130
 
131
- task = ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
132
-
133
- assert_equal 'Error triggering VMaaS reposcan sync: Network timeout', task.output[:message]
134
- end
135
-
136
- test 'run logs and handles error response without raising' do
137
- error_response = mock('error_response')
138
- error_response.stubs(:code).returns(500)
139
- error_response.stubs(:body).returns('error')
140
- exception = RestClient::ExceptionWithResponse.new(error_response)
141
-
142
- InsightsCloud::Async::VmaasReposcanSync.any_instance
143
- .stubs(:execute_cloud_request)
144
- .raises(exception)
145
-
146
- task = ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
147
-
148
- assert_equal 'VMaaS reposcan sync failed: 500 - error', task.output[:message]
149
- end
150
-
151
- test 'run handles 429 error with warning log level' do
152
- error_response = mock('error_response')
153
- error_response.stubs(:code).returns(429)
154
- error_response.stubs(:body).returns('{"msg": "Another task already in progress"}')
155
- exception = RestClient::ExceptionWithResponse.new(error_response)
156
-
157
- mock_logger = mock('logger')
158
- mock_logger.expects(:warn).with('VMaaS reposcan sync skipped: another sync already in progress (429)')
159
- InsightsCloud::Async::VmaasReposcanSync.any_instance.stubs(:logger).returns(mock_logger)
160
-
161
- InsightsCloud::Async::VmaasReposcanSync.any_instance
162
- .stubs(:execute_cloud_request)
163
- .raises(exception)
164
-
165
- task = ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
131
+ error = assert_raises(ForemanTasks::TaskError) do
132
+ ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
133
+ end
166
134
 
167
- assert_equal 'VMaaS reposcan sync skipped: another sync already in progress (429)',
168
- task.output[:message]
135
+ # The task is available via main_action
136
+ assert_match(/Error triggering VMaaS reposcan sync: Network timeout, response: /,
137
+ error.task.main_action.output[:message])
169
138
  end
170
139
 
171
- test 'run handles non-429 errors with error log level' do
172
- error_response = mock('error_response')
173
- error_response.stubs(:code).returns(500)
174
- error_response.stubs(:body).returns('Internal Server Error')
140
+ test 'run logs and re-raises when cloud request returns error response' do
141
+ error_response = mock('error_response', code: 500, body: 'error')
175
142
  exception = RestClient::ExceptionWithResponse.new(error_response)
176
143
 
177
- mock_logger = mock('logger')
178
- mock_logger.expects(:error).with('VMaaS reposcan sync failed: 500 - Internal Server Error')
179
- InsightsCloud::Async::VmaasReposcanSync.any_instance.stubs(:logger).returns(mock_logger)
180
-
181
144
  InsightsCloud::Async::VmaasReposcanSync.any_instance
182
145
  .stubs(:execute_cloud_request)
183
146
  .raises(exception)
184
147
 
185
- task = ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
186
-
187
- assert_equal 'VMaaS reposcan sync failed: 500 - Internal Server Error',
188
- task.output[:message]
189
- end
190
-
191
- test 'run handles RestClient::ExceptionWithResponse with nil response' do
192
- exception = RestClient::ExceptionWithResponse.new(nil)
193
-
194
- mock_logger = mock('logger')
195
- mock_logger.expects(:error).with('VMaaS reposcan sync failed: - ')
196
- InsightsCloud::Async::VmaasReposcanSync.any_instance.stubs(:logger).returns(mock_logger)
197
-
198
- InsightsCloud::Async::VmaasReposcanSync.any_instance
199
- .stubs(:execute_cloud_request)
200
- .raises(exception)
201
-
202
- task = ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
203
-
204
- refute_nil task.output[:message]
205
- assert_equal 'VMaaS reposcan sync failed: - ', task.output[:message]
148
+ assert_raises(ForemanTasks::TaskError) do
149
+ ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
150
+ end
206
151
  end
207
152
  end