foreman_rh_cloud 3.0.19 → 3.0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -5
- data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +50 -0
- data/app/controllers/concerns/inventory_upload/report_actions.rb +26 -0
- data/app/controllers/concerns/inventory_upload/task_actions.rb +25 -0
- data/app/controllers/foreman_inventory_upload/reports_controller.rb +3 -1
- data/app/controllers/foreman_inventory_upload/tasks_controller.rb +5 -13
- data/app/controllers/foreman_inventory_upload/uploads_controller.rb +4 -4
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +18 -7
- data/app/controllers/insights_cloud/hits_controller.rb +42 -1
- data/app/controllers/insights_cloud/settings_controller.rb +1 -1
- data/app/controllers/insights_cloud/tasks_controller.rb +1 -2
- data/app/helpers/foreman_insights_host_helper.rb +19 -0
- data/app/models/insights_client_report_status.rb +58 -0
- data/app/models/inventory_sync/inventory_status.rb +6 -0
- data/app/models/setting/rh_cloud.rb +5 -5
- data/app/services/foreman_rh_cloud/cloud_auth.rb +12 -0
- data/app/services/foreman_rh_cloud/cloud_connector.rb +1 -1
- data/app/services/foreman_rh_cloud/cloud_request.rb +14 -0
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +1 -6
- data/app/services/foreman_rh_cloud/remediations_retriever.rb +75 -0
- data/app/services/foreman_rh_cloud/template_renderer_helper.rb +22 -0
- data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +9 -0
- data/app/views/job_templates/rh_cloud_remediations.erb +14 -0
- data/config/package-lock.json.plugin +32774 -0
- data/config/routes.rb +20 -0
- data/db/migrate/20210404000001_change_resolutions.foreman_rh_cloud.rb +10 -0
- data/db/seeds.d/179_ui_notifications.rb +11 -0
- data/db/seeds.d/50_job_templates.rb +14 -0
- data/lib/foreman_inventory_upload.rb +5 -1
- data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +8 -2
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +19 -0
- data/lib/foreman_inventory_upload/generators/queries.rb +3 -2
- data/lib/foreman_inventory_upload/generators/slice.rb +6 -6
- data/lib/foreman_inventory_upload/generators/tags.rb +8 -6
- data/lib/foreman_rh_cloud.rb +18 -0
- data/lib/foreman_rh_cloud/engine.rb +40 -2
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud.rb +12 -0
- data/lib/insights_cloud/async/insights_full_sync.rb +31 -22
- data/lib/insights_cloud/async/insights_generate_notifications.rb +58 -0
- data/lib/insights_cloud/async/insights_resolutions_sync.rb +66 -0
- data/lib/insights_cloud/async/insights_rules_sync.rb +15 -24
- data/lib/insights_cloud/async/insights_scheduled_sync.rb +1 -1
- data/lib/inventory_sync/async/inventory_full_sync.rb +2 -1
- data/lib/inventory_sync/async/inventory_hosts_sync.rb +6 -2
- data/lib/inventory_sync/async/inventory_scheduled_sync.rb +29 -0
- data/lib/inventory_sync/async/query_inventory_job.rb +1 -4
- data/lib/tasks/insights.rake +4 -12
- data/lib/tasks/rh_cloud_inventory.rake +20 -5
- data/package.json +1 -1
- data/test/controllers/inventory_upload/api/inventory_controller_test.rb +53 -0
- data/test/factories/insights_factories.rb +22 -0
- data/test/factories/inventory_upload_factories.rb +1 -1
- data/test/jobs/insights_full_sync_test.rb +17 -8
- data/test/jobs/insights_resolutions_sync_test.rb +77 -0
- data/test/jobs/insights_rules_sync_test.rb +8 -3
- data/test/jobs/inventory_full_sync_test.rb +4 -1
- data/test/jobs/inventory_hosts_sync_test.rb +265 -0
- data/test/jobs/inventory_scheduled_sync_test.rb +22 -0
- data/test/models/insights_client_report_status_test.rb +77 -0
- data/test/test_plugin_helper.rb +2 -0
- data/test/unit/rh_cloud_http_proxy_test.rb +4 -4
- data/test/unit/services/foreman_rh_cloud/remediations_retriever_test.rb +49 -0
- data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +28 -0
- data/test/unit/slice_generator_test.rb +66 -29
- data/test/unit/tags_generator_test.rb +10 -0
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModal.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/__snapshots__/FullScreenModal.test.js.snap +1 -1
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/fullScreenModal.scss +14 -16
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/AdvancedSettingsConstants.js +5 -3
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +26 -2
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +24 -2
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +28 -63
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +2 -3
- data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/Terminal.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/__snapshots__/Terminal.test.js.snap +2 -2
- data/webpack/ForemanInventoryUpload/Components/Terminal/terminal.scss +25 -27
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +1 -1
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +19 -19
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableSelectors.js +3 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +14 -14
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +60 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationActions.js +12 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationHelpers.js +43 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js +101 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +9 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModalFooter.js +43 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationTableConstants.js +38 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/Resolutions.js +55 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/index.js +34 -0
- data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +20 -13
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +11 -3
- data/webpack/InsightsCloudSync/InsightsCloudSync.scss +5 -0
- data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +44 -20
- data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +2 -0
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +9 -6
- data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +11 -7
- data/webpack/common/ForemanTasks/ForemanTasksActions.js +64 -0
- data/webpack/common/ForemanTasks/ForemanTasksHelpers.js +7 -0
- data/webpack/common/ForemanTasks/index.js +1 -0
- data/webpack/{InsightsCloudSync/Components/InsightsTable/components → common/table}/EmptyState.js +0 -0
- data/webpack/common/table/helpers.js +7 -0
- metadata +49 -4
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'foreman_tasks/test_helpers'
|
3
|
+
|
4
|
+
class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
5
|
+
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@resolutions = {
|
9
|
+
"advisor:ansible_deprecated_repo|ANSIBLE_DEPRECATED_REPO" => {
|
10
|
+
"id" => "advisor:ansible_deprecated_repo|ANSIBLE_DEPRECATED_REPO",
|
11
|
+
"resolution_risk" => 1,
|
12
|
+
"resolutions" => [
|
13
|
+
{
|
14
|
+
"description" => "Enable ansible repo and update ansible package",
|
15
|
+
"id" => "fix",
|
16
|
+
"needs_reboot" => false,
|
17
|
+
"resolution_risk" => 1,
|
18
|
+
},
|
19
|
+
],
|
20
|
+
},
|
21
|
+
"advisor:hardening_logging_auditd|HARDENING_LOGGING_5_AUDITD" => {
|
22
|
+
"id" => "advisor:hardening_logging_auditd|HARDENING_LOGGING_5_AUDITD",
|
23
|
+
"resolution_risk" => 1,
|
24
|
+
"resolutions" => [
|
25
|
+
{
|
26
|
+
"description" => "Install and enable auditd",
|
27
|
+
"id" => "fix",
|
28
|
+
"needs_reboot" => false,
|
29
|
+
"resolution_risk" => 1,
|
30
|
+
},
|
31
|
+
],
|
32
|
+
},
|
33
|
+
"advisor:network_manager_dhcp_client_network_issue|NETWORK_MANAGER_DHCP_CLIENT_NETWORK_ISSUE" => {
|
34
|
+
"id" => "advisor:network_manager_dhcp_client_network_issue|NETWORK_MANAGER_DHCP_CLIENT_NETWORK_ISSUE",
|
35
|
+
"resolution_risk" => 1,
|
36
|
+
"resolutions" => [
|
37
|
+
{
|
38
|
+
"description" => "Update the NetworkManager package to fix this issue",
|
39
|
+
"id" => "fix",
|
40
|
+
"needs_reboot" => false,
|
41
|
+
"resolution_risk" => 1,
|
42
|
+
},
|
43
|
+
],
|
44
|
+
},
|
45
|
+
"advisor:network_tcp_connection_hang|NETWORK_TCP_CONNECTION_HANG_WARN" => {
|
46
|
+
"id" => "advisor:network_tcp_connection_hang|NETWORK_TCP_CONNECTION_HANG_WARN",
|
47
|
+
"resolution_risk" => 3,
|
48
|
+
"resolutions" => [
|
49
|
+
{
|
50
|
+
"description" => "Update system to the latest kernel and reboot",
|
51
|
+
"id" => "kernel_update",
|
52
|
+
"needs_reboot" => true,
|
53
|
+
"resolution_risk" => 3,
|
54
|
+
},
|
55
|
+
{
|
56
|
+
"description" => "Run in panic and scream",
|
57
|
+
"id" => "panic",
|
58
|
+
"needs_reboot" => true,
|
59
|
+
"resolution_risk" => 10,
|
60
|
+
},
|
61
|
+
],
|
62
|
+
},
|
63
|
+
}
|
64
|
+
|
65
|
+
@rule = FactoryBot.create(:insights_rule, rule_id: 'network_tcp_connection_hang|NETWORK_TCP_CONNECTION_HANG_WARN')
|
66
|
+
end
|
67
|
+
|
68
|
+
test 'Resolutions data is replaced with data from cloud' do
|
69
|
+
InsightsCloud::Async::InsightsResolutionsSync.any_instance.stubs(:query_insights_resolutions).returns(@resolutions)
|
70
|
+
|
71
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsResolutionsSync)
|
72
|
+
@rule.reload
|
73
|
+
|
74
|
+
assert_equal 5, InsightsResolution.all.count
|
75
|
+
assert_equal 2, @rule.resolutions.count
|
76
|
+
end
|
77
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'foreman_tasks/test_helpers'
|
3
|
+
|
4
|
+
class InsightsRulesSyncTest < ActiveSupport::TestCase
|
5
|
+
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
2
6
|
|
3
|
-
class InsightsRulesSyncTest < ActiveJob::TestCase
|
4
7
|
setup do
|
5
8
|
rules_json = <<-'RULES_JSON'
|
6
9
|
{
|
@@ -107,12 +110,14 @@ class InsightsRulesSyncTest < ActiveJob::TestCase
|
|
107
110
|
@rules = JSON.parse(rules_json)
|
108
111
|
@host = FactoryBot.create(:host, :managed, name: 'host1')
|
109
112
|
@hit = FactoryBot.create(:insights_hit, host_id: @host.id)
|
113
|
+
|
114
|
+
InsightsCloud::Async::InsightsRulesSync.any_instance.stubs(:plan_resolutions)
|
110
115
|
end
|
111
116
|
|
112
117
|
test 'Hits data is replaced with data from cloud' do
|
113
118
|
InsightsCloud::Async::InsightsRulesSync.any_instance.expects(:query_insights_rules).returns(@rules)
|
114
119
|
|
115
|
-
InsightsCloud::Async::InsightsRulesSync
|
120
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsRulesSync)
|
116
121
|
@hit.reload
|
117
122
|
|
118
123
|
assert_equal 2, InsightsRule.all.count
|
@@ -191,7 +196,7 @@ class InsightsRulesSyncTest < ActiveJob::TestCase
|
|
191
196
|
InsightsCloud::Async::InsightsRulesSync.any_instance.
|
192
197
|
stubs(:query_insights_rules).returns(@rules).then.returns(@last_rule)
|
193
198
|
|
194
|
-
InsightsCloud::Async::InsightsRulesSync
|
199
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsRulesSync)
|
195
200
|
|
196
201
|
assert_equal 3, InsightsRule.all.count
|
197
202
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'test_plugin_helper'
|
2
|
+
require 'foreman_tasks/test_helpers'
|
3
|
+
|
4
|
+
class InventoryFullSyncTest < ActiveSupport::TestCase
|
5
|
+
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
2
6
|
|
3
|
-
class InventoryFullSyncTest < ActiveJob::TestCase
|
4
7
|
setup do
|
5
8
|
User.current = User.find_by(login: 'secret_admin')
|
6
9
|
|
@@ -0,0 +1,265 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
require 'foreman_tasks/test_helpers'
|
3
|
+
|
4
|
+
class InventoryHostsSyncTest < ActiveSupport::TestCase
|
5
|
+
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
6
|
+
|
7
|
+
setup do
|
8
|
+
User.current = User.find_by(login: 'secret_admin')
|
9
|
+
|
10
|
+
env = FactoryBot.create(:katello_k_t_environment)
|
11
|
+
cv = env.content_views << FactoryBot.create(:katello_content_view, organization: env.organization)
|
12
|
+
|
13
|
+
# this host would pass our plugin queries, so it could be uploaded to the cloud.
|
14
|
+
@host1 = FactoryBot.create(
|
15
|
+
:host,
|
16
|
+
:with_subscription,
|
17
|
+
:with_content,
|
18
|
+
content_view: cv.first,
|
19
|
+
lifecycle_environment: env,
|
20
|
+
organization: env.organization
|
21
|
+
)
|
22
|
+
|
23
|
+
pool = FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
|
24
|
+
|
25
|
+
@host1.subscription_facet.pools << pool
|
26
|
+
|
27
|
+
# this host would pass our plugin queries, so it could be uploaded to the cloud.
|
28
|
+
@host2 = FactoryBot.create(
|
29
|
+
:host,
|
30
|
+
:with_subscription,
|
31
|
+
:with_content,
|
32
|
+
content_view: cv.first,
|
33
|
+
lifecycle_environment: env,
|
34
|
+
organization: env.organization
|
35
|
+
)
|
36
|
+
|
37
|
+
@host2.subscription_facet.pools << pool
|
38
|
+
@host2_inventory_id = '4536bf5c-ff03-4154-a8c9-32ff4b40e40c'
|
39
|
+
|
40
|
+
ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
|
41
|
+
|
42
|
+
inventory_json = <<-INVENTORY_JSON
|
43
|
+
{
|
44
|
+
"total": 3,
|
45
|
+
"count": 3,
|
46
|
+
"page": 1,
|
47
|
+
"per_page": 3,
|
48
|
+
"results": [
|
49
|
+
{
|
50
|
+
"insights_id": "72d29d75-dbbf-4121-9566-2f581ab77f36",
|
51
|
+
"rhel_machine_id": null,
|
52
|
+
"subscription_manager_id": "#{@host2.subscription_facet.uuid}",
|
53
|
+
"satellite_id": "bb72bf95-0a19-4090-8009-f0d8c68aca61",
|
54
|
+
"bios_uuid": "b48a7e5f-cb50-4029-a75e-366bf43db641",
|
55
|
+
"ip_addresses": [
|
56
|
+
"192.168.122.56"
|
57
|
+
],
|
58
|
+
"fqdn": "#{@host2.fqdn}",
|
59
|
+
"mac_addresses": [
|
60
|
+
"52:54:00:aa:12:12",
|
61
|
+
"00:00:00:00:00:00"
|
62
|
+
],
|
63
|
+
"external_id": null,
|
64
|
+
"id": "#{@host2_inventory_id}",
|
65
|
+
"account": "1460290",
|
66
|
+
"display_name": "insights-rh7.example.com",
|
67
|
+
"ansible_host": null,
|
68
|
+
"facts": [
|
69
|
+
{
|
70
|
+
"namespace": "satellite",
|
71
|
+
"facts": {
|
72
|
+
"virtual_host_name": "virt-who-nobody.home-1",
|
73
|
+
"satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
|
74
|
+
"is_simple_content_access": false,
|
75
|
+
"distribution_version": "7.3",
|
76
|
+
"satellite_version": "6.8.4",
|
77
|
+
"organization_id": 1,
|
78
|
+
"is_hostname_obfuscated": false,
|
79
|
+
"virtual_host_uuid": "a90e6294-4766-420a-8dc0-3ec5b96d60ec"
|
80
|
+
}
|
81
|
+
},
|
82
|
+
{
|
83
|
+
"namespace": "yupana",
|
84
|
+
"facts": {
|
85
|
+
"report_platform_id": "d37afa50-08ce-4efb-a0e5-759c2a016661",
|
86
|
+
"report_slice_id": "5bf791d7-5e30-4a3c-929a-11dd9fa6eb72",
|
87
|
+
"source": "Satellite",
|
88
|
+
"yupana_host_id": "e85958b6-58db-4cfd-aeb6-01ee81bc0f43",
|
89
|
+
"account": "1460290"
|
90
|
+
}
|
91
|
+
}
|
92
|
+
],
|
93
|
+
"reporter": "puptoo",
|
94
|
+
"stale_timestamp": "2021-03-19T07:57:42.466399+00:00",
|
95
|
+
"stale_warning_timestamp": "2021-03-26T07:57:42.466399+00:00",
|
96
|
+
"culled_timestamp": "2021-04-02T07:57:42.466399+00:00",
|
97
|
+
"created": "2021-02-08T14:36:03.613880+00:00",
|
98
|
+
"updated": "2021-03-18T02:57:42.535250+00:00"
|
99
|
+
},
|
100
|
+
{
|
101
|
+
"insights_id": "e0dc5144-d78e-43ed-97be-a7a21d1b6946",
|
102
|
+
"rhel_machine_id": null,
|
103
|
+
"subscription_manager_id": "0f97ee19-6862-4900-aea4-f121c8754776",
|
104
|
+
"satellite_id": "0f97ee19-6862-4900-aea4-f121c8754776",
|
105
|
+
"bios_uuid": "6a0b199a-8225-4ade-ae44-3b18cfc84a01",
|
106
|
+
"ip_addresses": [
|
107
|
+
"192.168.122.136"
|
108
|
+
],
|
109
|
+
"fqdn": "#{@host1.fqdn}",
|
110
|
+
"mac_addresses": [
|
111
|
+
"52:54:00:02:d1:2a",
|
112
|
+
"00:00:00:00:00:00"
|
113
|
+
],
|
114
|
+
"external_id": null,
|
115
|
+
"id": "3255d080-e6c1-44e2-8d72-b044b9a38d8f",
|
116
|
+
"account": "1460290",
|
117
|
+
"display_name": "insights-rh8.example.com",
|
118
|
+
"ansible_host": null,
|
119
|
+
"facts": [
|
120
|
+
{
|
121
|
+
"namespace": "satellite",
|
122
|
+
"facts": {
|
123
|
+
"virtual_host_name": "virt-who-nobody.home-1",
|
124
|
+
"satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
|
125
|
+
"is_simple_content_access": false,
|
126
|
+
"distribution_version": "8.3",
|
127
|
+
"satellite_version": "6.8.4",
|
128
|
+
"organization_id": 1,
|
129
|
+
"is_hostname_obfuscated": false,
|
130
|
+
"virtual_host_uuid": "a90e6294-4766-420a-8dc0-3ec5b96d60ec"
|
131
|
+
}
|
132
|
+
},
|
133
|
+
{
|
134
|
+
"namespace": "yupana",
|
135
|
+
"facts": {
|
136
|
+
"report_platform_id": "d37afa50-08ce-4efb-a0e5-759c2a016661",
|
137
|
+
"report_slice_id": "5bf791d7-5e30-4a3c-929a-11dd9fa6eb72",
|
138
|
+
"source": "Satellite",
|
139
|
+
"yupana_host_id": "78c62486-0ac4-406c-a4c0-3a1f81112a2d",
|
140
|
+
"account": "1460290"
|
141
|
+
}
|
142
|
+
}
|
143
|
+
],
|
144
|
+
"reporter": "puptoo",
|
145
|
+
"stale_timestamp": "2021-03-19T06:05:12.092136+00:00",
|
146
|
+
"stale_warning_timestamp": "2021-03-26T06:05:12.092136+00:00",
|
147
|
+
"culled_timestamp": "2021-04-02T06:05:12.092136+00:00",
|
148
|
+
"created": "2021-02-08T13:22:50.555671+00:00",
|
149
|
+
"updated": "2021-03-18T01:05:12.131847+00:00"
|
150
|
+
},
|
151
|
+
{
|
152
|
+
"insights_id": "b533848e-465f-4f1a-9b2b-b71cb2d5239d",
|
153
|
+
"rhel_machine_id": null,
|
154
|
+
"subscription_manager_id": "d29bde40-348e-437c-8acf-8fa98320fc1b",
|
155
|
+
"satellite_id": "d29bde40-348e-437c-8acf-8fa98320fc1b",
|
156
|
+
"bios_uuid": "3cd5d972-cfb5-451a-8314-fd2f56629d7c",
|
157
|
+
"ip_addresses": [
|
158
|
+
"172.16.5.39",
|
159
|
+
"fd6e:2298:736e::857",
|
160
|
+
"fd6e:2298:736e:0:2c66:6101:9cc6:2b23"
|
161
|
+
],
|
162
|
+
"fqdn": "rhel8-demo.oss-lab.net",
|
163
|
+
"mac_addresses": [
|
164
|
+
"6e:66:a6:fe:fc:07",
|
165
|
+
"00:00:00:00:00:00"
|
166
|
+
],
|
167
|
+
"external_id": null,
|
168
|
+
"id": "59ab38db-c25b-4fc7-bfb2-c8eb01d865a9",
|
169
|
+
"account": "1460290",
|
170
|
+
"display_name": "rhel8-demo.oss-lab.net",
|
171
|
+
"ansible_host": null,
|
172
|
+
"facts": [
|
173
|
+
{
|
174
|
+
"namespace": "satellite",
|
175
|
+
"facts": {
|
176
|
+
"satellite_instance_id": "fb3643d8-9030-487b-b95c-684783806ffd",
|
177
|
+
"system_purpose_sla": "",
|
178
|
+
"is_simple_content_access": false,
|
179
|
+
"distribution_version": "8.3",
|
180
|
+
"satellite_version": "6.8.1",
|
181
|
+
"organization_id": 1,
|
182
|
+
"system_purpose_role": "",
|
183
|
+
"system_purpose_usage": "",
|
184
|
+
"is_hostname_obfuscated": false
|
185
|
+
}
|
186
|
+
},
|
187
|
+
{
|
188
|
+
"namespace": "yupana",
|
189
|
+
"facts": {
|
190
|
+
"report_platform_id": "fa8b924c-51ee-479d-97d2-b4623cf1d4aa",
|
191
|
+
"report_slice_id": "0b49103f-6471-4ade-ad74-a51537bc5691",
|
192
|
+
"source": "Satellite",
|
193
|
+
"yupana_host_id": "30e43340-12fb-445d-b23f-faaf5cbc2092",
|
194
|
+
"account": "1460290"
|
195
|
+
}
|
196
|
+
}
|
197
|
+
],
|
198
|
+
"reporter": "puptoo",
|
199
|
+
"stale_timestamp": "2021-03-19T05:55:23.700781+00:00",
|
200
|
+
"stale_warning_timestamp": "2021-03-26T05:55:23.700781+00:00",
|
201
|
+
"culled_timestamp": "2021-04-02T05:55:23.700781+00:00",
|
202
|
+
"created": "2021-01-13T20:05:51.059012+00:00",
|
203
|
+
"updated": "2021-03-18T00:55:23.739162+00:00"
|
204
|
+
}
|
205
|
+
]
|
206
|
+
}
|
207
|
+
INVENTORY_JSON
|
208
|
+
@inventory = JSON.parse(inventory_json)
|
209
|
+
end
|
210
|
+
|
211
|
+
def interesting_facts
|
212
|
+
[
|
213
|
+
'dmi::system::uuid',
|
214
|
+
'virt::uuid',
|
215
|
+
'cpu::cpu(s)',
|
216
|
+
'cpu::cpu_socket(s)',
|
217
|
+
'cpu::core(s)_per_socket',
|
218
|
+
'memory::memtotal',
|
219
|
+
'dmi::bios::vendor',
|
220
|
+
'dmi::bios::version',
|
221
|
+
'dmi::bios::relase_date',
|
222
|
+
'uname::release',
|
223
|
+
'lscpu::flags',
|
224
|
+
'distribution::name',
|
225
|
+
'distribution::version',
|
226
|
+
'distribution::id',
|
227
|
+
'virt::is_guest',
|
228
|
+
'dmi::system::manufacturer',
|
229
|
+
'dmi::system::product_name',
|
230
|
+
'dmi::chassis::asset_tag',
|
231
|
+
'insights_client::obfuscate_hostname_enabled',
|
232
|
+
'insights_client::hostname',
|
233
|
+
]
|
234
|
+
end
|
235
|
+
|
236
|
+
def fact_names
|
237
|
+
@fact_names ||= Hash[
|
238
|
+
interesting_facts.map do |fact|
|
239
|
+
[fact, FactoryBot.create(:fact_name, name: fact, type: 'Katello::RhsmFactName')]
|
240
|
+
end
|
241
|
+
]
|
242
|
+
end
|
243
|
+
|
244
|
+
test 'Inventory should sync UUID for existing Insights Facets' do
|
245
|
+
InventorySync::Async::InventoryHostsSync.any_instance.expects(:query_inventory).returns(@inventory)
|
246
|
+
|
247
|
+
@host2.build_insights.save
|
248
|
+
|
249
|
+
ForemanTasks.sync_task(InventorySync::Async::InventoryHostsSync)
|
250
|
+
|
251
|
+
@host2.reload
|
252
|
+
|
253
|
+
assert_equal @host2_inventory_id, @host2.insights.uuid
|
254
|
+
end
|
255
|
+
|
256
|
+
test 'Inventory should sync UUID for new Insights Facets' do
|
257
|
+
InventorySync::Async::InventoryHostsSync.any_instance.expects(:query_inventory).returns(@inventory)
|
258
|
+
|
259
|
+
ForemanTasks.sync_task(InventorySync::Async::InventoryHostsSync)
|
260
|
+
|
261
|
+
@host2.reload
|
262
|
+
|
263
|
+
assert_equal @host2_inventory_id, @host2.insights.uuid
|
264
|
+
end
|
265
|
+
end
|
@@ -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,77 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class InsightsClientReportStatusTest < ActiveSupport::TestCase
|
4
|
+
describe 'to_status' do
|
5
|
+
let(:host) { FactoryBot.create(:host, :managed) }
|
6
|
+
|
7
|
+
setup do
|
8
|
+
CommonParameter.where(name: 'host_registration_insights').destroy_all
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'host_registration_insights = true & is getting data' do
|
12
|
+
FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
|
13
|
+
host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
|
14
|
+
|
15
|
+
assert_equal 0, host_status.to_status(data: true)
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'host_registration_insights = true & no data in less than 48 hours' do
|
19
|
+
FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
|
20
|
+
host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
|
21
|
+
host_status.update(reported_at: 1.day.ago)
|
22
|
+
assert_equal 0, host_status.to_status
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'host_registration_insights = true & no data in more than 48 hours' do
|
26
|
+
FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
|
27
|
+
host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
|
28
|
+
host_status.update(reported_at: 3.days.ago)
|
29
|
+
assert_equal 1, host_status.to_status
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'host_registration_insights = false & no data' do
|
33
|
+
FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false)
|
34
|
+
host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
|
35
|
+
assert_equal 2, host_status.to_status
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'host_registration_insights = false & getting data' do
|
39
|
+
FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false)
|
40
|
+
host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
|
41
|
+
assert_equal 3, host_status.to_status(data: true)
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'host_registration_insights = nil & is getting data' do
|
45
|
+
host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
|
46
|
+
assert_equal 3, host_status.to_status(data: true)
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'host_registration_insights = nil & no data in less than 48 hours' do
|
50
|
+
host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
|
51
|
+
host_status.update(reported_at: 1.day.ago)
|
52
|
+
assert_equal 2, host_status.to_status
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'host_registration_insights = nil & no data in more than 48 hours' do
|
56
|
+
host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
|
57
|
+
host_status.update(reported_at: 3.days.ago)
|
58
|
+
assert_equal 2, host_status.to_status
|
59
|
+
end
|
60
|
+
|
61
|
+
test 'override param on host level from `false` to `true`' do
|
62
|
+
FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false)
|
63
|
+
FactoryBot.create(:host_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true, host: host)
|
64
|
+
|
65
|
+
host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
|
66
|
+
assert_equal 0, host_status.to_status(data: true)
|
67
|
+
end
|
68
|
+
|
69
|
+
test 'override param on host level from `true` to `false`' do
|
70
|
+
FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
|
71
|
+
FactoryBot.create(:host_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false, host: host)
|
72
|
+
|
73
|
+
host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
|
74
|
+
assert_equal 2, host_status.to_status
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|