foreman_rh_cloud 4.0.23 → 4.0.25.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/foreman_inventory_upload/cloud_status_controller.rb +26 -0
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +15 -7
- data/app/controllers/insights_cloud/hits_controller.rb +0 -1
- data/app/models/insights_client_report_status.rb +11 -22
- data/app/services/foreman_rh_cloud/cloud_auth.rb +4 -0
- data/app/services/foreman_rh_cloud/cloud_ping_service.rb +83 -0
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +1 -9
- data/app/services/foreman_rh_cloud/insights_status_cleaner.rb +17 -0
- data/app/services/foreman_rh_cloud/remediations_retriever.rb +5 -0
- data/config/Gemfile.lock.gh_test +0 -8
- data/config/rh_cert-api_chain.pem +74 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb +6 -0
- data/lib/foreman_inventory_upload.rb +9 -1
- data/lib/foreman_inventory_upload/generators/queries.rb +1 -16
- data/lib/foreman_inventory_upload/generators/slice.rb +1 -0
- data/lib/foreman_inventory_upload/generators/tags.rb +3 -1
- data/lib/foreman_rh_cloud.rb +4 -0
- data/lib/foreman_rh_cloud/engine.rb +14 -12
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud.rb +4 -0
- data/lib/insights_cloud/async/insights_client_status_aging.rb +23 -0
- data/lib/insights_cloud/async/insights_full_sync.rb +5 -0
- data/lib/insights_cloud/async/insights_resolutions_sync.rb +9 -0
- data/lib/insights_cloud/async/insights_rules_sync.rb +5 -0
- data/lib/inventory_sync/async/host_result.rb +4 -0
- data/lib/inventory_sync/async/inventory_full_sync.rb +5 -0
- data/lib/inventory_sync/async/inventory_hosts_sync.rb +15 -0
- data/lib/inventory_sync/async/inventory_self_host_sync.rb +39 -0
- data/lib/inventory_sync/async/query_inventory_job.rb +5 -1
- data/lib/tasks/insights.rake +15 -0
- data/lib/tasks/rh_cloud_inventory.rake +2 -9
- data/package.json +2 -2
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +45 -0
- data/test/controllers/inventory_upload/cloud_status_controller_test.rb +44 -0
- data/test/jobs/insights_client_status_aging_test.rb +33 -0
- data/test/jobs/insights_full_sync_test.rb +1 -0
- data/test/jobs/insights_resolutions_sync_test.rb +1 -0
- data/test/jobs/insights_rules_sync_test.rb +1 -0
- data/test/jobs/inventory_full_sync_test.rb +10 -0
- data/test/jobs/inventory_hosts_sync_test.rb +3 -0
- data/test/jobs/inventory_self_host_sync_test.rb +104 -0
- data/test/models/insights_client_report_status_test.rb +70 -72
- data/test/test_plugin_helper.rb +53 -0
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +6 -37
- data/test/unit/services/foreman_rh_cloud/cloud_status_service_test.rb +66 -0
- data/test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb +31 -0
- data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +1 -0
- data/test/unit/slice_generator_test.rb +15 -0
- data/test/unit/tags_generator_test.rb +41 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/EmptyState.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/__snapshots__/EmptyState.test.js.snap +1 -2
- data/webpack/ForemanInventoryUpload/Components/FileDownload/FileDownload.js +3 -1
- data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/__snapshots__/FileDownload.test.js.snap +2 -1
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.js +1 -2
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterConstants.js +3 -1
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.scss +0 -4
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageTitle.js +12 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageTitle.test.js.snap +10 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudPingModal/index.js +144 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudPingModal/index.scss +5 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +2 -2
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Modal.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Toast.js +2 -2
- data/webpack/ForemanInventoryUpload/Components/StatusChart/StatusChart.js +4 -3
- data/webpack/ForemanInventoryUpload/ForemanInventoryConstants.js +2 -0
- data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/InventoryAutoUpload.js +3 -1
- data/webpack/InsightsCloudSync/Components/InsightsHeader/InsightsHeader.scss +5 -1
- data/webpack/InsightsCloudSync/Components/InsightsHeader/index.js +6 -4
- data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettings.js +9 -5
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettings.test.js.snap +6 -6
- data/webpack/InsightsCloudSync/Components/InsightsSettings/insightsSettings.scss +0 -14
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +4 -22
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableConstants.js +25 -4
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableSelectors.js +0 -3
- data/webpack/InsightsCloudSync/Components/InsightsTable/Pagination.js +51 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/SelectAllAlert.js +1 -1
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +3 -68
- data/webpack/InsightsCloudSync/Components/InsightsTable/table.scss +10 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js +11 -10
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +14 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/index.js +0 -2
- data/webpack/InsightsCloudSync/Components/ToolbarDropdown.js +32 -0
- data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/InsightsHeader.test.js.snap +5 -4
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +17 -13
- data/webpack/InsightsCloudSync/InsightsCloudSync.scss +82 -2
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +15 -6
- data/webpack/InsightsHostDetailsTab/InsightsTab.js +3 -2
- data/webpack/InsightsHostDetailsTab/InsightsTab.scss +4 -4
- data/webpack/InsightsHostDetailsTab/components/ListItem/ListItem.js +9 -7
- data/webpack/common/Switcher/SwitcherPF4.js +1 -1
- data/webpack/common/Switcher/SwitcherPF4.scss +6 -7
- data/webpack/common/Switcher/__tests__/__snapshots__/SwitcherPF4.test.js.snap +1 -1
- metadata +23 -24
- data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +0 -9
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/InsightsSyncSwitcher.fixtures.js +0 -1
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/InsightsSyncSwitcher.js +0 -45
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/__tests__/InsightsSyncSwitcher.test.js +0 -17
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/__tests__/__snapshots__/InsightsSyncSwitcher.test.js.snap +0 -38
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/index.js +0 -1
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/insightsSyncSwitcher.scss +0 -3
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +0 -59
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
require 'foreman_tasks/test_helpers'
|
3
|
+
|
4
|
+
class InsightsClientStatusAgingTest < ActiveSupport::TestCase
|
5
|
+
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
6
|
+
|
7
|
+
setup do
|
8
|
+
User.current = User.find_by(login: 'secret_admin')
|
9
|
+
|
10
|
+
@host1 = FactoryBot.create(:host)
|
11
|
+
@host2 = FactoryBot.create(:host)
|
12
|
+
@host3 = FactoryBot.create(:host)
|
13
|
+
@host4 = FactoryBot.create(:host)
|
14
|
+
|
15
|
+
@hosts = [@host1, @host2, @host3, @host4]
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'stale statuses should change' do
|
19
|
+
InsightsClientReportStatus.find_or_initialize_by(host_id: @host1.id).update(status: InsightsClientReportStatus::REPORTING, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL + 1.day)
|
20
|
+
InsightsClientReportStatus.find_or_initialize_by(host_id: @host2.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL + 1.day)
|
21
|
+
InsightsClientReportStatus.find_or_initialize_by(host_id: @host3.id).update(status: InsightsClientReportStatus::REPORTING, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)
|
22
|
+
InsightsClientReportStatus.find_or_initialize_by(host_id: @host4.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)
|
23
|
+
|
24
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsClientStatusAging)
|
25
|
+
|
26
|
+
@hosts.each(&:reload)
|
27
|
+
|
28
|
+
assert_equal InsightsClientReportStatus::REPORTING, @host1.get_status(InsightsClientReportStatus).status
|
29
|
+
assert_equal InsightsClientReportStatus::NO_REPORT, @host2.get_status(InsightsClientReportStatus).status
|
30
|
+
assert_equal InsightsClientReportStatus::NO_REPORT, @host3.get_status(InsightsClientReportStatus).status
|
31
|
+
assert_equal InsightsClientReportStatus::NO_REPORT, @host4.get_status(InsightsClientReportStatus).status
|
32
|
+
end
|
33
|
+
end
|
@@ -7,6 +7,7 @@ class InsightsFullSyncTest < ActiveSupport::TestCase
|
|
7
7
|
setup do
|
8
8
|
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_rules_sync)
|
9
9
|
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_notifications)
|
10
|
+
FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
|
10
11
|
|
11
12
|
uuid1 = 'accdf444-5628-451d-bf3e-cf909ad72756'
|
12
13
|
@host1 = FactoryBot.create(:host, :managed, name: 'host1')
|
@@ -63,6 +63,7 @@ class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
|
63
63
|
}
|
64
64
|
|
65
65
|
@rule = FactoryBot.create(:insights_rule, rule_id: 'network_tcp_connection_hang|NETWORK_TCP_CONNECTION_HANG_WARN')
|
66
|
+
FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
|
66
67
|
end
|
67
68
|
|
68
69
|
test 'Resolutions data is replaced with data from cloud' do
|
@@ -112,6 +112,7 @@ class InsightsRulesSyncTest < ActiveSupport::TestCase
|
|
112
112
|
@hit = FactoryBot.create(:insights_hit, host_id: @host.id)
|
113
113
|
|
114
114
|
InsightsCloud::Async::InsightsRulesSync.any_instance.stubs(:plan_resolutions)
|
115
|
+
FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
|
115
116
|
end
|
116
117
|
|
117
118
|
test 'Hits data is replaced with data from cloud' do
|
@@ -242,6 +242,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
242
242
|
end
|
243
243
|
|
244
244
|
test 'Host status should be SYNC for inventory hosts' do
|
245
|
+
FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'TEST TOKEN')
|
245
246
|
InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
|
246
247
|
|
247
248
|
ForemanTasks.sync_task(InventorySync::Async::InventoryFullSync, @host2.organization)
|
@@ -253,6 +254,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
253
254
|
end
|
254
255
|
|
255
256
|
test 'Host status should be DISCONNECT for hosts that are not returned from cloud' do
|
257
|
+
FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'TEST TOKEN')
|
256
258
|
InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
|
257
259
|
FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
|
258
260
|
|
@@ -261,4 +263,12 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
261
263
|
|
262
264
|
assert_equal InventorySync::InventoryStatus::DISCONNECT, InventorySync::InventoryStatus.where(host_id: @host1.id).first.status
|
263
265
|
end
|
266
|
+
|
267
|
+
test 'Task should be aborted if token is not present' do
|
268
|
+
FactoryBot.create(:setting, name: 'rh_cloud_token', value: '')
|
269
|
+
|
270
|
+
InventorySync::Async::InventoryFullSync.any_instance.expects(:plan_self).never
|
271
|
+
|
272
|
+
ForemanTasks.sync_task(InventorySync::Async::InventoryFullSync, @host1.organization)
|
273
|
+
end
|
264
274
|
end
|
@@ -6,6 +6,7 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
|
|
6
6
|
|
7
7
|
setup do
|
8
8
|
User.current = User.find_by(login: 'secret_admin')
|
9
|
+
FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
|
9
10
|
|
10
11
|
env = FactoryBot.create(:katello_k_t_environment)
|
11
12
|
cv = env.content_views << FactoryBot.create(:katello_content_view, organization: env.organization)
|
@@ -243,6 +244,7 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
|
|
243
244
|
|
244
245
|
test 'Inventory should sync UUID for existing Insights Facets' do
|
245
246
|
InventorySync::Async::InventoryHostsSync.any_instance.expects(:query_inventory).returns(@inventory)
|
247
|
+
InventorySync::Async::InventoryHostsSync.any_instance.expects(:plan_self_host_sync)
|
246
248
|
|
247
249
|
@host2.build_insights.save
|
248
250
|
|
@@ -255,6 +257,7 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
|
|
255
257
|
|
256
258
|
test 'Inventory should sync UUID for new Insights Facets' do
|
257
259
|
InventorySync::Async::InventoryHostsSync.any_instance.expects(:query_inventory).returns(@inventory)
|
260
|
+
InventorySync::Async::InventoryHostsSync.any_instance.expects(:plan_self_host_sync)
|
258
261
|
|
259
262
|
ForemanTasks.sync_task(InventorySync::Async::InventoryHostsSync)
|
260
263
|
|
@@ -0,0 +1,104 @@
|
|
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
|
+
FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
|
10
|
+
|
11
|
+
# this host would pass our plugin queries, so it could be uploaded to the cloud.
|
12
|
+
@host1 = FactoryBot.create(:host)
|
13
|
+
@host1_inventory_id = '3255d080-e6c1-44e2-8d72-b044b9a38d8f'
|
14
|
+
|
15
|
+
ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
|
16
|
+
|
17
|
+
ForemanRhCloud.stubs(:foreman_host).returns(@host1)
|
18
|
+
|
19
|
+
inventory_json = <<-INVENTORY_JSON
|
20
|
+
{
|
21
|
+
"total": 1,
|
22
|
+
"count": 1,
|
23
|
+
"page": 1,
|
24
|
+
"per_page": 1,
|
25
|
+
"results": [
|
26
|
+
{
|
27
|
+
"insights_id": "e0dc5144-d78e-43ed-97be-a7a21d1b6946",
|
28
|
+
"rhel_machine_id": null,
|
29
|
+
"subscription_manager_id": "0f97ee19-6862-4900-aea4-f121c8754776",
|
30
|
+
"satellite_id": "0f97ee19-6862-4900-aea4-f121c8754776",
|
31
|
+
"bios_uuid": "6a0b199a-8225-4ade-ae44-3b18cfc84a01",
|
32
|
+
"ip_addresses": [
|
33
|
+
"192.168.122.136"
|
34
|
+
],
|
35
|
+
"fqdn": "#{@host1.fqdn}",
|
36
|
+
"mac_addresses": [
|
37
|
+
"52:54:00:02:d1:2a",
|
38
|
+
"00:00:00:00:00:00"
|
39
|
+
],
|
40
|
+
"external_id": null,
|
41
|
+
"id": "#{@host1_inventory_id}",
|
42
|
+
"account": "1460290",
|
43
|
+
"display_name": "insights-rh8.example.com",
|
44
|
+
"ansible_host": null,
|
45
|
+
"facts": [
|
46
|
+
{
|
47
|
+
"namespace": "satellite",
|
48
|
+
"facts": {
|
49
|
+
"virtual_host_name": "virt-who-nobody.home-1",
|
50
|
+
"satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
|
51
|
+
"is_simple_content_access": false,
|
52
|
+
"distribution_version": "8.3",
|
53
|
+
"satellite_version": "6.8.4",
|
54
|
+
"organization_id": 1,
|
55
|
+
"is_hostname_obfuscated": false,
|
56
|
+
"virtual_host_uuid": "a90e6294-4766-420a-8dc0-3ec5b96d60ec"
|
57
|
+
}
|
58
|
+
},
|
59
|
+
{
|
60
|
+
"namespace": "yupana",
|
61
|
+
"facts": {
|
62
|
+
"report_platform_id": "d37afa50-08ce-4efb-a0e5-759c2a016661",
|
63
|
+
"report_slice_id": "5bf791d7-5e30-4a3c-929a-11dd9fa6eb72",
|
64
|
+
"source": "Satellite",
|
65
|
+
"yupana_host_id": "78c62486-0ac4-406c-a4c0-3a1f81112a2d",
|
66
|
+
"account": "1460290"
|
67
|
+
}
|
68
|
+
}
|
69
|
+
],
|
70
|
+
"reporter": "puptoo",
|
71
|
+
"stale_timestamp": "2021-03-19T06:05:12.092136+00:00",
|
72
|
+
"stale_warning_timestamp": "2021-03-26T06:05:12.092136+00:00",
|
73
|
+
"culled_timestamp": "2021-04-02T06:05:12.092136+00:00",
|
74
|
+
"created": "2021-02-08T13:22:50.555671+00:00",
|
75
|
+
"updated": "2021-03-18T01:05:12.131847+00:00"
|
76
|
+
}
|
77
|
+
]
|
78
|
+
}
|
79
|
+
INVENTORY_JSON
|
80
|
+
@inventory = JSON.parse(inventory_json)
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'Inventory should sync UUID for existing Insights Facets' do
|
84
|
+
InventorySync::Async::InventorySelfHostSync.any_instance.expects(:query_inventory).returns(@inventory)
|
85
|
+
|
86
|
+
@host1.build_insights.save
|
87
|
+
|
88
|
+
ForemanTasks.sync_task(InventorySync::Async::InventorySelfHostSync)
|
89
|
+
|
90
|
+
@host1.reload
|
91
|
+
|
92
|
+
assert_equal @host1_inventory_id, @host1.insights.uuid
|
93
|
+
end
|
94
|
+
|
95
|
+
test 'Inventory should sync UUID for new Insights Facets' do
|
96
|
+
InventorySync::Async::InventorySelfHostSync.any_instance.expects(:query_inventory).returns(@inventory)
|
97
|
+
|
98
|
+
ForemanTasks.sync_task(InventorySync::Async::InventorySelfHostSync)
|
99
|
+
|
100
|
+
@host1.reload
|
101
|
+
|
102
|
+
assert_equal @host1_inventory_id, @host1.insights.uuid
|
103
|
+
end
|
104
|
+
end
|
@@ -1,77 +1,75 @@
|
|
1
1
|
require 'test_plugin_helper'
|
2
2
|
|
3
3
|
class InsightsClientReportStatusTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
assert_equal 2, host_status.to_status
|
75
|
-
end
|
4
|
+
setup do
|
5
|
+
@host = FactoryBot.create(:host, :managed)
|
6
|
+
end
|
7
|
+
|
8
|
+
test 'fresh host does not have insights status' do
|
9
|
+
@host.reload
|
10
|
+
|
11
|
+
refute @host.host_statuses.where(type: 'InsightsClientReportStatus').exists?
|
12
|
+
insights_status = @host.get_status(InsightsClientReportStatus)
|
13
|
+
refute insights_status.relevant?
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'host can refresh all its statuses' do
|
17
|
+
@host.refresh_statuses
|
18
|
+
@host.reload
|
19
|
+
|
20
|
+
refute @host.host_statuses.where(type: 'InsightsClientReportStatus').exists?
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'host with correct report status sets global status to OK' do
|
24
|
+
global_status = @host.get_status(HostStatus.find_status_by_humanized_name('Global'))
|
25
|
+
# Status has to be OK before action
|
26
|
+
assert_equal HostStatus::Global::OK, global_status.status
|
27
|
+
|
28
|
+
# force create record
|
29
|
+
@host.get_status(InsightsClientReportStatus).refresh!
|
30
|
+
# now refresh should work
|
31
|
+
@host.refresh_statuses([InsightsClientReportStatus])
|
32
|
+
|
33
|
+
@host.reload
|
34
|
+
global_status = @host.get_status(HostStatus.find_status_by_humanized_name('Global'))
|
35
|
+
# Status has to be OK after the action too
|
36
|
+
assert_equal HostStatus::Global::OK, global_status.status
|
37
|
+
|
38
|
+
insights_status = @host.get_status(InsightsClientReportStatus)
|
39
|
+
# assert the status would be displayed
|
40
|
+
assert insights_status.relevant?
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'host will return to OK once the status is refreshed' do
|
44
|
+
global_status = @host.get_status(HostStatus.find_status_by_humanized_name('Global'))
|
45
|
+
# Status has to be OK before action
|
46
|
+
assert_equal HostStatus::Global::OK, global_status.status
|
47
|
+
|
48
|
+
insights_status = @host.get_status(InsightsClientReportStatus)
|
49
|
+
insights_status.status = InsightsClientReportStatus::NO_REPORT
|
50
|
+
insights_status.save!
|
51
|
+
@host.refresh_global_status!
|
52
|
+
global_status = @host.global_status
|
53
|
+
assert_equal HostStatus::Global::ERROR, global_status
|
54
|
+
|
55
|
+
@host.refresh_statuses([InsightsClientReportStatus])
|
56
|
+
|
57
|
+
@host.reload
|
58
|
+
# Status has to be OK after the action too
|
59
|
+
assert_equal HostStatus::Global::OK, @host.global_status
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'host with stale status would set global to ERROR' do
|
63
|
+
global_status = @host.get_status(HostStatus.find_status_by_humanized_name('Global'))
|
64
|
+
# Status has to be OK before action
|
65
|
+
assert_equal HostStatus::Global::OK, global_status.status
|
66
|
+
|
67
|
+
insights_status = @host.get_status(InsightsClientReportStatus)
|
68
|
+
insights_status.status = InsightsClientReportStatus::NO_REPORT
|
69
|
+
insights_status.save!
|
70
|
+
@host.refresh_global_status!
|
71
|
+
@host.reload
|
72
|
+
|
73
|
+
assert_equal HostStatus::Global::ERROR, @host.global_status
|
76
74
|
end
|
77
75
|
end
|
data/test/test_plugin_helper.rb
CHANGED
@@ -38,3 +38,56 @@ module KatelloLocationFix
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
module MockCerts
|
43
|
+
extend ActiveSupport::Concern
|
44
|
+
|
45
|
+
def test_certificate
|
46
|
+
@test_certificate ||= "-----BEGIN CERTIFICATE-----\r\n" +
|
47
|
+
"MIIFdDCCA1ygAwIBAgIJAM5Uqykb3EAtMA0GCSqGSIb3DQEBCwUAME8xCzAJBgNV\r\n" +
|
48
|
+
"BAYTAklMMREwDwYDVQQIDAhUZWwgQXZpdjEUMBIGA1UECgwLVGhlIEZvcmVtYW4x\r\n" +
|
49
|
+
"FzAVBgNVBAMMDnRoZWZvcmVtYW4ub3JnMB4XDTE4MDMyNDEyMzYyOFoXDTI4MDMy\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CERTIFICATE-----"
|
78
|
+
end
|
79
|
+
|
80
|
+
def generate_certs_hash
|
81
|
+
{
|
82
|
+
cert: test_certificate,
|
83
|
+
key: OpenSSL::PKey::RSA.new(1024).to_pem,
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def setup_certs_expectation
|
88
|
+
expectation = yield
|
89
|
+
expectation.returns(
|
90
|
+
generate_certs_hash
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
@@ -2,56 +2,25 @@ require 'test_plugin_helper'
|
|
2
2
|
require 'puma/null_io'
|
3
3
|
|
4
4
|
class CloudRequestForwarderTest < ActiveSupport::TestCase
|
5
|
+
include MockCerts
|
6
|
+
|
5
7
|
setup do
|
6
8
|
@forwarder = ::ForemanRhCloud::CloudRequestForwarder.new
|
7
|
-
|
8
|
-
@cert1 = "-----BEGIN CERTIFICATE-----\r\n" +
|
9
|
-
"MIIFdDCCA1ygAwIBAgIJAM5Uqykb3EAtMA0GCSqGSIb3DQEBCwUAME8xCzAJBgNV\r\n" +
|
10
|
-
"BAYTAklMMREwDwYDVQQIDAhUZWwgQXZpdjEUMBIGA1UECgwLVGhlIEZvcmVtYW4x\r\n" +
|
11
|
-
"FzAVBgNVBAMMDnRoZWZvcmVtYW4ub3JnMB4XDTE4MDMyNDEyMzYyOFoXDTI4MDMy\r\n" +
|
12
|
-
"MTEyMzYyOFowTzELMAkGA1UEBhMCSUwxETAPBgNVBAgMCFRlbCBBdml2MRQwEgYD\r\n" +
|
13
|
-
"VQQKDAtUaGUgRm9yZW1hbjEXMBUGA1UEAwwOdGhlZm9yZW1hbi5vcmcwggIiMA0G\r\n" +
|
14
|
-
"CSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDF04/s4h+BgHPG1HDZ/sDlYq925pkc\r\n" +
|
15
|
-
"RTVAfnE2EXDAmZ6W4Q9ueDY65MHe3ZWO5Dg72kNSP2sK9kRI7Dk5CAFOgyw1rH8t\r\n" +
|
16
|
-
"Hd1+0xp/lv6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SvCsYxn27GTjjrRUSLFeHH\r\n" +
|
30
|
-
"JVemCwCDMavaE3+OIY4v2P4FcG+MjUvfOB9ahI24TWL7YgrsNVmJjCILq+EeUj0t\r\n" +
|
31
|
-
"Gde1SXVyLkqt7PoxHRJAE0BCEMJSnjxaVB329acJgeehBUxjj4CCPqtDxtbz9HEH\r\n" +
|
32
|
-
"mOKfNdaKpFor+DUeEKUWVGnr9U9xOaC+Ws+oX7MIEUCDM7p2ob4JwcjnFs1jZgHh\r\n" +
|
33
|
-
"Hwig+i7doTlc701PvKWO96fuNHK3B3/jTb1fVvSZ49O/RvY1VWODdUdxWmXGHNh3\r\n" +
|
34
|
-
"LoR8tSPEb46lC2DXGaIQumqQt8PnBG+vL1qkQa1SGTV7dJ8TTbxbv0S+sS+igkk9\r\n" +
|
35
|
-
"zsIEK8Ea3Ep935cXximz0faAAKHSA+It+xHLAyDtqy2KaAEBgGsBuuWlUfK6TaP3\r\n" +
|
36
|
-
"Gwdjct3y4yYUO45lUsUfHqX8vk/4ttW5zYeDiW+HArJz+9VUXNbEdury4kGuHgBj\r\n" +
|
37
|
-
"xHD4Bsul65+hHZ9QywKU26F1A6TLkYpQ2rk/Dx9LGICM4m4IlHjWJPFsQdtkyOor\r\n" +
|
38
|
-
"osxMtcaZZ1E=\r\n" +
|
39
|
-
"-----END CERTIFICATE-----"
|
40
9
|
end
|
41
10
|
|
42
11
|
test 'should prepare correct cloud url' do
|
43
12
|
paths = {
|
44
13
|
"/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://
|
46
|
-
"/redhat_access/r/insights/v1/static/uploader.v2.json" => "https://
|
47
|
-
"/redhat_access/r/insights/v1/static/uploader.v2.json.asc" => "https://
|
14
|
+
"/redhat_access/r/insights/v1/static/release/insights-core.egg" => "https://cert-api.access.redhat.com/r/insights/v1/static/release/insights-core.egg",
|
15
|
+
"/redhat_access/r/insights/v1/static/uploader.v2.json" => "https://cert-api.access.redhat.com/r/insights/v1/static/uploader.v2.json",
|
16
|
+
"/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
17
|
"/redhat_access/r/insights/platform/inventory/v1/hosts" => "https://cert.cloud.redhat.com/api/inventory/v1/hosts",
|
49
18
|
"/redhat_access/r/insights/platform/ingress/v1/upload" => "https://cert.cloud.redhat.com/api/ingress/v1/upload",
|
50
19
|
"/redhat_access/r/insights/uploads/67200803-132b-474b-a6f9-37be74185df4" => "https://cert-api.access.redhat.com/r/insights/uploads/67200803-132b-474b-a6f9-37be74185df4",
|
51
20
|
}
|
52
21
|
|
53
22
|
paths.each do |key, value|
|
54
|
-
actual_params = @forwarder.path_params(key,
|
23
|
+
actual_params = @forwarder.path_params(key, generate_certs_hash)
|
55
24
|
assert_equal value, actual_params[:url]
|
56
25
|
end
|
57
26
|
end
|