foreman_rh_cloud 13.0.7 → 13.0.9
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.
- checksums.yaml +4 -4
- data/app/controllers/concerns/foreman_rh_cloud/registration_manager_extensions.rb +39 -0
- data/app/controllers/foreman_inventory_upload/accounts_controller.rb +1 -1
- data/app/controllers/foreman_inventory_upload/uploads_controller.rb +1 -1
- data/lib/foreman_inventory_upload/async/create_missing_insights_facets.rb +3 -2
- data/lib/foreman_inventory_upload/async/queue_for_upload_job.rb +1 -23
- data/lib/foreman_inventory_upload/async/upload_report_direct_job.rb +200 -0
- data/lib/foreman_inventory_upload.rb +6 -6
- data/lib/foreman_rh_cloud/engine.rb +1 -0
- data/lib/foreman_rh_cloud/plugin.rb +4 -0
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/inventory_sync/async/inventory_hosts_sync.rb +0 -2
- data/lib/tasks/rh_cloud_inventory.rake +11 -1
- data/package.json +1 -1
- data/test/controllers/accounts_controller_test.rb +1 -1
- data/test/controllers/uploads_controller_test.rb +1 -1
- data/test/jobs/cloud_connector_announce_task_test.rb +3 -2
- data/test/jobs/connector_playbook_execution_reporter_task_test.rb +32 -20
- data/test/jobs/create_missing_insights_facets_test.rb +151 -0
- data/test/jobs/exponential_backoff_test.rb +9 -8
- data/test/jobs/generate_host_report_test.rb +100 -0
- data/test/jobs/generate_report_job_test.rb +146 -0
- data/test/jobs/host_inventory_report_job_test.rb +244 -0
- data/test/jobs/insights_client_status_aging_test.rb +3 -2
- data/test/jobs/insights_full_sync_test.rb +13 -7
- data/test/jobs/insights_resolutions_sync_test.rb +9 -5
- data/test/jobs/insights_rules_sync_test.rb +5 -3
- data/test/jobs/inventory_full_sync_test.rb +9 -5
- data/test/jobs/inventory_hosts_sync_test.rb +11 -6
- data/test/jobs/inventory_scheduled_sync_test.rb +10 -6
- data/test/jobs/inventory_self_host_sync_test.rb +1 -1
- data/test/jobs/queue_for_upload_job_test.rb +10 -19
- data/test/jobs/remove_insights_hosts_job_test.rb +14 -15
- data/test/jobs/single_host_report_job_test.rb +155 -0
- data/test/jobs/upload_report_direct_job_test.rb +399 -0
- data/test/unit/lib/foreman_rh_cloud/registration_manager_extensions_test.rb +192 -0
- data/webpack/ForemanColumnExtensions/index.js +2 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItem.fixtures.js +4 -5
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItem.js +4 -2
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/__snapshots__/ListItem.test.js.snap +9 -10
- data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.js +4 -1
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js +24 -17
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/PageHeader.test.js +178 -8
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js +3 -1
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/ToolbarButtons.test.js +69 -51
- data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettings.js +3 -3
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +3 -9
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTable.test.js +12 -7
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js +2 -2
- data/webpack/InsightsCloudSync/Components/ToolbarDropdown.js +3 -3
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +3 -3
- data/webpack/InsightsCloudSync/InsightsCloudSync.test.js +10 -0
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +1 -1
- data/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js +5 -5
- data/webpack/InsightsVulnerabilityHostIndexExtensions/CVECountCell.js +2 -2
- data/webpack/InsightsVulnerabilityHostIndexExtensions/__tests__/CVECountCell.test.js +77 -22
- data/webpack/common/Hooks/ConfigHooks.js +3 -16
- metadata +17 -8
- data/lib/foreman_inventory_upload/async/upload_report_job.rb +0 -97
- data/lib/foreman_inventory_upload/scripts/uploader.sh.erb +0 -55
- data/test/jobs/upload_report_job_test.rb +0 -37
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap +0 -36
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +0 -112
- data/webpack/__mocks__/foremanReact/common/hooks/API/APIHooks.js +0 -3
|
@@ -2,7 +2,7 @@ require 'test_plugin_helper'
|
|
|
2
2
|
require 'foreman_tasks/test_helpers'
|
|
3
3
|
|
|
4
4
|
class InsightsFullSyncTest < ActiveSupport::TestCase
|
|
5
|
-
include
|
|
5
|
+
include Dynflow::Testing::Factories
|
|
6
6
|
include MockCerts
|
|
7
7
|
|
|
8
8
|
setup do
|
|
@@ -72,7 +72,8 @@ class InsightsFullSyncTest < ActiveSupport::TestCase
|
|
|
72
72
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_hosts_sync)
|
|
73
73
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_rules_sync)
|
|
74
74
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_notifications)
|
|
75
|
-
|
|
75
|
+
action = create_and_plan_action(InsightsCloud::Async::InsightsFullSync, [@host1.organization, @host2.organization])
|
|
76
|
+
run_action(action)
|
|
76
77
|
|
|
77
78
|
@host1.reload
|
|
78
79
|
@host2.reload
|
|
@@ -89,7 +90,8 @@ class InsightsFullSyncTest < ActiveSupport::TestCase
|
|
|
89
90
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_hosts_sync).never
|
|
90
91
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_self).never
|
|
91
92
|
|
|
92
|
-
|
|
93
|
+
action = create_and_plan_action(InsightsCloud::Async::InsightsFullSync, [@host1.organization])
|
|
94
|
+
run_action(action)
|
|
93
95
|
end
|
|
94
96
|
|
|
95
97
|
test 'Manifest is deleted do not run task steps' do
|
|
@@ -100,7 +102,8 @@ class InsightsFullSyncTest < ActiveSupport::TestCase
|
|
|
100
102
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_hosts_sync).never
|
|
101
103
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_self).never
|
|
102
104
|
|
|
103
|
-
|
|
105
|
+
action = create_and_plan_action(InsightsCloud::Async::InsightsFullSync, [@host1.organization])
|
|
106
|
+
run_action(action)
|
|
104
107
|
end
|
|
105
108
|
|
|
106
109
|
test 'Hits counters are reset correctly' do
|
|
@@ -110,9 +113,11 @@ class InsightsFullSyncTest < ActiveSupport::TestCase
|
|
|
110
113
|
|
|
111
114
|
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_hosts_sync)
|
|
112
115
|
|
|
113
|
-
|
|
116
|
+
action = create_and_plan_action(InsightsCloud::Async::InsightsFullSync, [@host1.organization, @host2.organization])
|
|
117
|
+
run_action(action)
|
|
114
118
|
# Invoke again
|
|
115
|
-
|
|
119
|
+
action = create_and_plan_action(InsightsCloud::Async::InsightsFullSync, [@host1.organization, @host2.organization])
|
|
120
|
+
run_action(action)
|
|
116
121
|
|
|
117
122
|
@host1.reload
|
|
118
123
|
@host2.reload
|
|
@@ -146,7 +151,8 @@ class InsightsFullSyncTest < ActiveSupport::TestCase
|
|
|
146
151
|
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_hosts_sync)
|
|
147
152
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).returns(hits)
|
|
148
153
|
|
|
149
|
-
|
|
154
|
+
action = create_and_plan_action(InsightsCloud::Async::InsightsFullSync, [@host1.organization, @host2.organization])
|
|
155
|
+
run_action(action)
|
|
150
156
|
|
|
151
157
|
@host1.reload
|
|
152
158
|
@host2.reload
|
|
@@ -2,7 +2,7 @@ require 'test_plugin_helper'
|
|
|
2
2
|
require 'foreman_tasks/test_helpers'
|
|
3
3
|
|
|
4
4
|
class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
|
5
|
-
include
|
|
5
|
+
include Dynflow::Testing::Factories
|
|
6
6
|
include MockCerts
|
|
7
7
|
|
|
8
8
|
setup do
|
|
@@ -76,7 +76,8 @@ class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
|
|
76
76
|
Katello::UpstreamConnectionChecker.any_instance.stubs(:can_connect?).returns(true)
|
|
77
77
|
InsightsCloud::Async::InsightsResolutionsSync.any_instance.stubs(:query_insights_resolutions).returns(@resolutions)
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
action = create_and_plan_action(InsightsCloud::Async::InsightsResolutionsSync)
|
|
80
|
+
run_action(action)
|
|
80
81
|
@rule.reload
|
|
81
82
|
|
|
82
83
|
assert_equal 5, InsightsResolution.all.count
|
|
@@ -88,7 +89,8 @@ class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
|
|
88
89
|
Katello::UpstreamConnectionChecker.any_instance.stubs(:can_connect?).returns(false)
|
|
89
90
|
InsightsCloud::Async::InsightsResolutionsSync.any_instance.expects(:query_insights_resolutions).never
|
|
90
91
|
|
|
91
|
-
|
|
92
|
+
action = create_and_plan_action(InsightsCloud::Async::InsightsResolutionsSync)
|
|
93
|
+
run_action(action)
|
|
92
94
|
|
|
93
95
|
assert_equal 0, InsightsResolution.all.count
|
|
94
96
|
end
|
|
@@ -98,7 +100,8 @@ class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
|
|
98
100
|
Katello::UpstreamConnectionChecker.any_instance.stubs(:can_connect?).returns(true)
|
|
99
101
|
InsightsCloud::Async::InsightsResolutionsSync.any_instance.expects(:query_insights_resolutions).never
|
|
100
102
|
|
|
101
|
-
|
|
103
|
+
action = create_and_plan_action(InsightsCloud::Async::InsightsResolutionsSync)
|
|
104
|
+
run_action(action)
|
|
102
105
|
|
|
103
106
|
assert_equal 0, InsightsResolution.all.count
|
|
104
107
|
end
|
|
@@ -108,7 +111,8 @@ class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
|
|
108
111
|
InsightsCloud::Async::InsightsResolutionsSync.any_instance.expects(:query_insights_resolutions).never
|
|
109
112
|
InsightsRule.all.delete_all
|
|
110
113
|
|
|
111
|
-
|
|
114
|
+
action = create_and_plan_action(InsightsCloud::Async::InsightsResolutionsSync)
|
|
115
|
+
run_action(action)
|
|
112
116
|
|
|
113
117
|
assert_equal 0, InsightsResolution.all.count
|
|
114
118
|
end
|
|
@@ -2,7 +2,7 @@ require 'test_plugin_helper'
|
|
|
2
2
|
require 'foreman_tasks/test_helpers'
|
|
3
3
|
|
|
4
4
|
class InsightsRulesSyncTest < ActiveSupport::TestCase
|
|
5
|
-
include
|
|
5
|
+
include Dynflow::Testing::Factories
|
|
6
6
|
|
|
7
7
|
setup do
|
|
8
8
|
rules_json = <<-'RULES_JSON'
|
|
@@ -119,7 +119,8 @@ class InsightsRulesSyncTest < ActiveSupport::TestCase
|
|
|
119
119
|
# do not cleanup unused rules for tests
|
|
120
120
|
InsightsCloud::Async::InsightsRulesSync.any_instance.stubs(:cleanup_rules)
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
action = create_and_plan_action(InsightsCloud::Async::InsightsRulesSync, Organization.all)
|
|
123
|
+
run_action(action)
|
|
123
124
|
@hit.reload
|
|
124
125
|
|
|
125
126
|
assert_equal 2, InsightsRule.all.count
|
|
@@ -201,7 +202,8 @@ class InsightsRulesSyncTest < ActiveSupport::TestCase
|
|
|
201
202
|
# do not cleanup unused rules for tests
|
|
202
203
|
InsightsCloud::Async::InsightsRulesSync.any_instance.stubs(:cleanup_rules)
|
|
203
204
|
|
|
204
|
-
|
|
205
|
+
action = create_and_plan_action(InsightsCloud::Async::InsightsRulesSync, Organization.all)
|
|
206
|
+
run_action(action)
|
|
205
207
|
|
|
206
208
|
assert_equal 3, InsightsRule.all.count
|
|
207
209
|
end
|
|
@@ -2,7 +2,7 @@ require 'test_plugin_helper'
|
|
|
2
2
|
require 'foreman_tasks/test_helpers'
|
|
3
3
|
|
|
4
4
|
class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
5
|
-
include
|
|
5
|
+
include Dynflow::Testing::Factories
|
|
6
6
|
include MockCerts
|
|
7
7
|
include KatelloCVEHelper
|
|
8
8
|
|
|
@@ -265,7 +265,8 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
|
265
265
|
|
|
266
266
|
InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
|
|
267
267
|
|
|
268
|
-
|
|
268
|
+
action = create_and_plan_action(InventorySync::Async::InventoryFullSync, @host2.organization)
|
|
269
|
+
run_action(action)
|
|
269
270
|
|
|
270
271
|
@host2.reload
|
|
271
272
|
|
|
@@ -280,7 +281,8 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
|
280
281
|
InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
|
|
281
282
|
FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
|
|
282
283
|
|
|
283
|
-
|
|
284
|
+
action = create_and_plan_action(InventorySync::Async::InventoryFullSync, @host1.organization)
|
|
285
|
+
run_action(action)
|
|
284
286
|
@host2.reload
|
|
285
287
|
|
|
286
288
|
assert_equal InventorySync::InventoryStatus::DISCONNECT, InventorySync::InventoryStatus.where(host_id: @host1.id).first.status
|
|
@@ -291,7 +293,8 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
|
291
293
|
|
|
292
294
|
InventorySync::Async::InventoryFullSync.any_instance.expects(:plan_self).never
|
|
293
295
|
|
|
294
|
-
|
|
296
|
+
action = create_and_plan_action(InventorySync::Async::InventoryFullSync, @host1.organization)
|
|
297
|
+
run_action(action)
|
|
295
298
|
end
|
|
296
299
|
|
|
297
300
|
test 'Should skip hosts that are not returned in query' do
|
|
@@ -304,7 +307,8 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
|
304
307
|
InventorySync::Async::InventoryFullSync.any_instance.expects(:affected_host_ids).returns([@host1.id, @host2.id])
|
|
305
308
|
FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
|
|
306
309
|
|
|
307
|
-
|
|
310
|
+
action = create_and_plan_action(InventorySync::Async::InventoryFullSync, @host1.organization)
|
|
311
|
+
run_action(action)
|
|
308
312
|
@host2.reload
|
|
309
313
|
|
|
310
314
|
assert_nil InventorySync::InventoryStatus.where(host_id: @host3.id).first
|
|
@@ -2,7 +2,7 @@ require 'test_plugin_helper'
|
|
|
2
2
|
require 'foreman_tasks/test_helpers'
|
|
3
3
|
|
|
4
4
|
class InventoryHostsSyncTest < ActiveSupport::TestCase
|
|
5
|
-
include
|
|
5
|
+
include Dynflow::Testing::Factories
|
|
6
6
|
include MockCerts
|
|
7
7
|
include KatelloCVEHelper
|
|
8
8
|
|
|
@@ -302,7 +302,8 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
|
|
|
302
302
|
|
|
303
303
|
@host2.build_insights.save
|
|
304
304
|
|
|
305
|
-
|
|
305
|
+
action = create_and_plan_action(InventorySync::Async::InventoryHostsSync, [@host1.organization, @host2.organization])
|
|
306
|
+
run_action(action)
|
|
306
307
|
|
|
307
308
|
@host2.reload
|
|
308
309
|
|
|
@@ -317,7 +318,8 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
|
|
|
317
318
|
InventorySync::Async::InventoryHostsSync.any_instance.stubs(:candlepin_id_cert)
|
|
318
319
|
end
|
|
319
320
|
|
|
320
|
-
|
|
321
|
+
action = create_and_plan_action(InventorySync::Async::InventoryHostsSync, [@host1.organization, @host2.organization])
|
|
322
|
+
run_action(action)
|
|
321
323
|
|
|
322
324
|
@host2.reload
|
|
323
325
|
|
|
@@ -336,7 +338,8 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
|
|
|
336
338
|
|
|
337
339
|
assert_nil @host2.insights
|
|
338
340
|
|
|
339
|
-
|
|
341
|
+
action = create_and_plan_action(InventorySync::Async::InventoryHostsSync, [@host1.organization, @host2.organization])
|
|
342
|
+
run_action(action)
|
|
340
343
|
|
|
341
344
|
@host2.reload
|
|
342
345
|
|
|
@@ -353,7 +356,8 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
|
|
|
353
356
|
InventorySync::Async::InventoryHostsSync.any_instance.stubs(:candlepin_id_cert)
|
|
354
357
|
end
|
|
355
358
|
|
|
356
|
-
|
|
359
|
+
action = create_and_plan_action(InventorySync::Async::InventoryHostsSync, [org])
|
|
360
|
+
run_action(action)
|
|
357
361
|
|
|
358
362
|
assert_equal 3, InsightsMissingHost.count
|
|
359
363
|
end
|
|
@@ -370,7 +374,8 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
|
|
|
370
374
|
InventorySync::Async::InventoryHostsSync.any_instance.stubs(:candlepin_id_cert)
|
|
371
375
|
end
|
|
372
376
|
|
|
373
|
-
|
|
377
|
+
action = create_and_plan_action(InventorySync::Async::InventoryHostsSync, [org])
|
|
378
|
+
run_action(action)
|
|
374
379
|
|
|
375
380
|
assert_equal 3, InsightsMissingHost.count
|
|
376
381
|
end
|
|
@@ -2,7 +2,7 @@ require 'test_plugin_helper'
|
|
|
2
2
|
require 'foreman_tasks/test_helpers'
|
|
3
3
|
|
|
4
4
|
class InventoryScheduledSyncTest < ActiveSupport::TestCase
|
|
5
|
-
include
|
|
5
|
+
include Dynflow::Testing::Factories
|
|
6
6
|
|
|
7
7
|
test 'Schedules an execution if auto upload is enabled' do
|
|
8
8
|
Setting[:allow_auto_inventory_upload] = true
|
|
@@ -11,7 +11,8 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase
|
|
|
11
11
|
InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).times(Organization.unscoped.count)
|
|
12
12
|
InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_remove_insights_hosts).times(Organization.unscoped.count)
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
action = create_and_plan_action(InventorySync::Async::InventoryScheduledSync)
|
|
15
|
+
run_action(action)
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
test 'Skips execution if with_iop_smart_proxy? is true' do
|
|
@@ -19,8 +20,9 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase
|
|
|
19
20
|
|
|
20
21
|
InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).never
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
action = create_and_plan_action(InventorySync::Async::InventoryScheduledSync)
|
|
24
|
+
action = run_action(action)
|
|
25
|
+
status = action.output[:status].to_s
|
|
24
26
|
assert_match(/Foreman is configured with a local IoP Smart Proxy/, status)
|
|
25
27
|
end
|
|
26
28
|
|
|
@@ -29,7 +31,8 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase
|
|
|
29
31
|
|
|
30
32
|
InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).never
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
action = create_and_plan_action(InventorySync::Async::InventoryScheduledSync)
|
|
35
|
+
run_action(action)
|
|
33
36
|
end
|
|
34
37
|
|
|
35
38
|
test 'Skips mismatch deletion if the setting is disabled' do
|
|
@@ -39,6 +42,7 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase
|
|
|
39
42
|
InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).times(Organization.unscoped.count)
|
|
40
43
|
InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_remove_insights_hosts).never
|
|
41
44
|
|
|
42
|
-
|
|
45
|
+
action = create_and_plan_action(InventorySync::Async::InventoryScheduledSync)
|
|
46
|
+
run_action(action)
|
|
43
47
|
end
|
|
44
48
|
end
|
|
@@ -2,24 +2,15 @@ require 'test_plugin_helper'
|
|
|
2
2
|
require 'foreman_tasks/test_helpers'
|
|
3
3
|
|
|
4
4
|
class QueueForUploadJobTest < ActiveSupport::TestCase
|
|
5
|
-
include
|
|
6
|
-
include FolderIsolation
|
|
5
|
+
include Dynflow::Testing::Factories
|
|
7
6
|
|
|
8
7
|
let(:organization) { FactoryBot.create(:organization) }
|
|
9
|
-
let(:base_folder) {
|
|
8
|
+
let(:base_folder) { Dir.mktmpdir }
|
|
10
9
|
let(:report_file) { 'test_report.tar.xz' }
|
|
11
10
|
let(:report_path) { File.join(base_folder, report_file) }
|
|
12
11
|
let(:uploads_folder) { ForemanInventoryUpload.uploads_folder }
|
|
13
|
-
subject { ForemanTasks.sync_task(ForemanInventoryUpload::Async::QueueForUploadJob, base_folder, report_file, organization.id) }
|
|
14
12
|
|
|
15
13
|
setup do
|
|
16
|
-
# Stub the script template source
|
|
17
|
-
script_source = File.join(ForemanRhCloud::Engine.root, 'lib/foreman_inventory_upload/scripts/uploader.sh.erb')
|
|
18
|
-
File.stubs(:read).with(script_source).returns('#!/bin/bash\necho "Test script"')
|
|
19
|
-
|
|
20
|
-
# Stub template rendering
|
|
21
|
-
Foreman::Renderer.stubs(:render).returns('#!/bin/bash\necho "Rendered script"')
|
|
22
|
-
|
|
23
14
|
# Stub additional settings that are accessed
|
|
24
15
|
Setting.stubs(:[]).with(:content_default_http_proxy).returns(nil)
|
|
25
16
|
Setting.stubs(:[]).with(:http_proxy).returns(nil)
|
|
@@ -29,35 +20,35 @@ class QueueForUploadJobTest < ActiveSupport::TestCase
|
|
|
29
20
|
|
|
30
21
|
teardown do
|
|
31
22
|
FileUtils.rm_rf(uploads_folder) if Dir.exist?(uploads_folder)
|
|
23
|
+
FileUtils.remove_entry base_folder if Dir.exist?(base_folder)
|
|
32
24
|
end
|
|
33
25
|
|
|
34
26
|
test 'plan method sets up the job correctly and calls plan_upload_report' do
|
|
35
27
|
# Mock plan_upload_report to verify it's called
|
|
36
28
|
ForemanInventoryUpload::Async::QueueForUploadJob.any_instance.expects(:plan_upload_report).once
|
|
37
29
|
|
|
38
|
-
|
|
30
|
+
action = create_and_plan_action(ForemanInventoryUpload::Async::QueueForUploadJob, base_folder, report_file, organization.id)
|
|
31
|
+
run_action(action)
|
|
39
32
|
end
|
|
40
33
|
|
|
41
34
|
test 'run method processes file and moves it to uploads folder' do
|
|
42
35
|
ForemanInventoryUpload::Async::QueueForUploadJob.any_instance.stubs(:plan_upload_report)
|
|
43
36
|
|
|
44
|
-
|
|
37
|
+
action = create_and_plan_action(ForemanInventoryUpload::Async::QueueForUploadJob, base_folder, report_file, organization.id)
|
|
38
|
+
run_action(action)
|
|
45
39
|
|
|
46
40
|
# Verify the file was moved
|
|
47
41
|
refute File.exist?(report_path), "Original file should be moved"
|
|
48
42
|
assert File.exist?(File.join(uploads_folder, report_file)), "File should exist in uploads folder"
|
|
49
43
|
end
|
|
50
44
|
|
|
51
|
-
test 'creates necessary folders
|
|
45
|
+
test 'creates necessary folders' do
|
|
52
46
|
ForemanInventoryUpload::Async::QueueForUploadJob.any_instance.stubs(:plan_upload_report)
|
|
53
47
|
|
|
54
|
-
|
|
48
|
+
action = create_and_plan_action(ForemanInventoryUpload::Async::QueueForUploadJob, base_folder, report_file, organization.id)
|
|
49
|
+
run_action(action)
|
|
55
50
|
|
|
56
51
|
# Verify the uploads folder was created
|
|
57
52
|
assert Dir.exist?(uploads_folder), "Uploads folder should be created"
|
|
58
|
-
|
|
59
|
-
# Verify the script file was created
|
|
60
|
-
script_path = File.join(uploads_folder, ForemanInventoryUpload.upload_script_file)
|
|
61
|
-
assert File.exist?(script_path), "Upload script should be created"
|
|
62
53
|
end
|
|
63
54
|
end
|
|
@@ -2,7 +2,7 @@ require 'test_plugin_helper'
|
|
|
2
2
|
require 'foreman_tasks/test_helpers'
|
|
3
3
|
|
|
4
4
|
class RemoveInsightsHostJobTest < ActiveSupport::TestCase
|
|
5
|
-
include
|
|
5
|
+
include Dynflow::Testing::Factories
|
|
6
6
|
|
|
7
7
|
setup do
|
|
8
8
|
User.current = User.find_by(login: 'secret_admin')
|
|
@@ -18,10 +18,10 @@ class RemoveInsightsHostJobTest < ActiveSupport::TestCase
|
|
|
18
18
|
|
|
19
19
|
FactoryBot.create(:insights_missing_host, organization: @org)
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
action = create_and_plan_action(ForemanInventoryUpload::Async::RemoveInsightsHostsJob, '', @org.id)
|
|
22
|
+
run_action(action)
|
|
22
23
|
|
|
23
24
|
assert_equal 0, InsightsMissingHost.count
|
|
24
|
-
assert_equal 'success', task.result
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
test 'Does not delete hosts on cloud failure' do
|
|
@@ -31,14 +31,13 @@ class RemoveInsightsHostJobTest < ActiveSupport::TestCase
|
|
|
31
31
|
|
|
32
32
|
FactoryBot.create(:insights_missing_host, organization: @org)
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
action = create_and_plan_action(ForemanInventoryUpload::Async::RemoveInsightsHostsJob, '', @org.id)
|
|
35
|
+
|
|
36
|
+
assert_raises(StandardError) do
|
|
37
|
+
run_action(action)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
assert_equal 1, InsightsMissingHost.count
|
|
41
|
-
assert_equal 'error', task.result
|
|
42
41
|
end
|
|
43
42
|
|
|
44
43
|
test 'Paginates the hosts list' do
|
|
@@ -54,12 +53,12 @@ class RemoveInsightsHostJobTest < ActiveSupport::TestCase
|
|
|
54
53
|
FactoryBot.create(:insights_missing_host, organization: @org)
|
|
55
54
|
FactoryBot.create(:insights_missing_host, organization: @org)
|
|
56
55
|
|
|
57
|
-
|
|
56
|
+
action = create_and_plan_action(ForemanInventoryUpload::Async::RemoveInsightsHostsJob, '', @org.id)
|
|
57
|
+
action = run_action(action)
|
|
58
58
|
|
|
59
59
|
assert_equal 0, InsightsMissingHost.count
|
|
60
|
-
assert_equal '
|
|
61
|
-
assert_equal '
|
|
62
|
-
assert_equal 'response2', task.output[:response_page2]
|
|
60
|
+
assert_equal 'response1', action.output[:response_page1]
|
|
61
|
+
assert_equal 'response2', action.output[:response_page2]
|
|
63
62
|
end
|
|
64
63
|
|
|
65
64
|
test 'Uses scoped_search to select hosts' do
|
|
@@ -73,12 +72,12 @@ class RemoveInsightsHostJobTest < ActiveSupport::TestCase
|
|
|
73
72
|
FactoryBot.create(:insights_missing_host, name: 'test a', organization: @org)
|
|
74
73
|
FactoryBot.create(:insights_missing_host, name: 'test b', organization: @org)
|
|
75
74
|
|
|
76
|
-
|
|
75
|
+
action = create_and_plan_action(ForemanInventoryUpload::Async::RemoveInsightsHostsJob, 'name ~ b', @org.id)
|
|
76
|
+
action = run_action(action)
|
|
77
77
|
|
|
78
78
|
assert_equal 1, InsightsMissingHost.count
|
|
79
79
|
assert_equal 'test a', InsightsMissingHost.first.name
|
|
80
|
-
assert_equal '
|
|
81
|
-
assert_equal 'response1', task.output[:response_page1]
|
|
80
|
+
assert_equal 'response1', action.output[:response_page1]
|
|
82
81
|
end
|
|
83
82
|
|
|
84
83
|
def mock_response(code: 200, body: '')
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
require 'test_plugin_helper'
|
|
2
|
+
require 'foreman_tasks/test_helpers'
|
|
3
|
+
|
|
4
|
+
class SingleHostReportJobTest < ActiveSupport::TestCase
|
|
5
|
+
include Dynflow::Testing::Factories
|
|
6
|
+
include Dynflow::Testing::Assertions
|
|
7
|
+
include KatelloCVEHelper
|
|
8
|
+
|
|
9
|
+
let(:base_folder) { Dir.mktmpdir }
|
|
10
|
+
|
|
11
|
+
setup do
|
|
12
|
+
User.current = User.find_by(login: 'secret_admin')
|
|
13
|
+
cve = make_cve
|
|
14
|
+
env = cve.lifecycle_environment
|
|
15
|
+
|
|
16
|
+
@host = FactoryBot.create(
|
|
17
|
+
:host,
|
|
18
|
+
:with_subscription,
|
|
19
|
+
:with_content,
|
|
20
|
+
content_view: cve.content_view,
|
|
21
|
+
lifecycle_environment: env,
|
|
22
|
+
organization: env.organization
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
teardown do
|
|
27
|
+
FileUtils.remove_entry base_folder if Dir.exist?(base_folder)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
test 'plan sets host_id in input' do
|
|
31
|
+
action = create_and_plan_action(
|
|
32
|
+
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
33
|
+
base_folder,
|
|
34
|
+
@host.organization_id,
|
|
35
|
+
@host.id
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
assert_equal @host.id, action.input[:host_id]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test 'plan calls super with id filter' do
|
|
42
|
+
expected_filter = "id=#{@host.id}"
|
|
43
|
+
|
|
44
|
+
action = create_and_plan_action(
|
|
45
|
+
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
46
|
+
base_folder,
|
|
47
|
+
@host.organization_id,
|
|
48
|
+
@host.id
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
assert_action_planned_with(
|
|
52
|
+
action,
|
|
53
|
+
ForemanInventoryUpload::Async::GenerateHostReport,
|
|
54
|
+
base_folder,
|
|
55
|
+
@host.organization_id,
|
|
56
|
+
expected_filter
|
|
57
|
+
)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
test 'inherits behavior from HostInventoryReportJob' do
|
|
61
|
+
action = create_and_plan_action(
|
|
62
|
+
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
63
|
+
base_folder,
|
|
64
|
+
@host.organization_id,
|
|
65
|
+
@host.id
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
# Should schedule all parent actions
|
|
69
|
+
assert_action_planned(action, ForemanInventoryUpload::Async::GenerateHostReport)
|
|
70
|
+
assert_action_planned(action, ForemanInventoryUpload::Async::QueueForUploadJob)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
test 'humanized_name includes hostname' do
|
|
74
|
+
action = create_and_plan_action(
|
|
75
|
+
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
76
|
+
base_folder,
|
|
77
|
+
@host.organization_id,
|
|
78
|
+
@host.id
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
assert_equal "Single-host report job for host #{@host.name}", action.humanized_name
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
test 'humanized_name handles missing host' do
|
|
85
|
+
non_existent_host_id = 999_999
|
|
86
|
+
|
|
87
|
+
action = create_and_plan_action(
|
|
88
|
+
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
89
|
+
base_folder,
|
|
90
|
+
@host.organization_id,
|
|
91
|
+
non_existent_host_id
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
assert_equal 'Single-host report job', action.humanized_name
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
test 'hostname method returns correct name' do
|
|
98
|
+
action = create_and_plan_action(
|
|
99
|
+
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
100
|
+
base_folder,
|
|
101
|
+
@host.organization_id,
|
|
102
|
+
@host.id
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
assert_equal @host.name, action.hostname(@host.id)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
test 'hostname method handles nil gracefully' do
|
|
109
|
+
action = create_and_plan_action(
|
|
110
|
+
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
111
|
+
base_folder,
|
|
112
|
+
@host.organization_id,
|
|
113
|
+
@host.id
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
assert_nil action.hostname(999_999)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
test 'generates report with correct archive name for single host' do
|
|
120
|
+
expected_filter = "id=#{@host.id}"
|
|
121
|
+
expected_archive_name = ForemanInventoryUpload.facts_archive_name(@host.organization_id, expected_filter)
|
|
122
|
+
|
|
123
|
+
action = create_and_plan_action(
|
|
124
|
+
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
125
|
+
base_folder,
|
|
126
|
+
@host.organization_id,
|
|
127
|
+
@host.id
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
assert_action_planned_with(
|
|
131
|
+
action,
|
|
132
|
+
ForemanInventoryUpload::Async::QueueForUploadJob,
|
|
133
|
+
base_folder,
|
|
134
|
+
expected_archive_name,
|
|
135
|
+
@host.organization_id
|
|
136
|
+
)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
test 'respects IoP mode for facet creation' do
|
|
140
|
+
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
|
|
141
|
+
|
|
142
|
+
action = create_and_plan_action(
|
|
143
|
+
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
144
|
+
base_folder,
|
|
145
|
+
@host.organization_id,
|
|
146
|
+
@host.id
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
assert_action_planned_with(
|
|
150
|
+
action,
|
|
151
|
+
ForemanInventoryUpload::Async::CreateMissingInsightsFacets,
|
|
152
|
+
@host.organization_id
|
|
153
|
+
)
|
|
154
|
+
end
|
|
155
|
+
end
|