foreman_rh_cloud 3.0.18.1 → 4.0.21.1
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/foreman_inventory_upload/tasks_controller.rb +14 -3
- data/app/controllers/foreman_inventory_upload/uploads_settings_controller.rb +8 -0
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +17 -7
- data/app/controllers/insights_cloud/hits_controller.rb +37 -0
- data/app/controllers/insights_cloud/settings_controller.rb +1 -1
- data/app/controllers/insights_cloud/tasks_controller.rb +1 -2
- data/app/models/insights_client_report_status.rb +58 -0
- data/app/models/insights_resolution.rb +1 -1
- 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_connector.rb +1 -1
- data/app/services/foreman_rh_cloud/remediations_retriever.rb +78 -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/routes.rb +2 -1
- 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 +9 -0
- data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +8 -2
- data/lib/foreman_inventory_upload/generators/queries.rb +3 -2
- data/lib/foreman_inventory_upload/generators/slice.rb +1 -1
- data/lib/foreman_inventory_upload/generators/tags.rb +8 -6
- data/lib/foreman_inventory_upload/scripts/uploader.sh.erb +5 -1
- data/lib/foreman_rh_cloud.rb +18 -0
- data/lib/foreman_rh_cloud/engine.rb +36 -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 +39 -24
- data/lib/insights_cloud/async/insights_generate_notifications.rb +58 -0
- data/lib/insights_cloud/async/insights_resolutions_sync.rb +69 -0
- data/lib/insights_cloud/async/insights_rules_sync.rb +13 -17
- data/lib/insights_cloud/async/insights_scheduled_sync.rb +1 -1
- data/lib/inventory_sync/async/host_result.rb +11 -6
- data/lib/inventory_sync/async/inventory_full_sync.rb +24 -41
- data/lib/inventory_sync/async/inventory_hosts_sync.rb +34 -0
- data/lib/inventory_sync/async/inventory_scheduled_sync.rb +17 -0
- data/lib/inventory_sync/async/query_inventory_job.rb +54 -0
- data/lib/tasks/insights.rake +4 -12
- data/lib/tasks/rh_cloud_inventory.rake +12 -4
- data/package.json +1 -1
- data/test/factories/insights_factories.rb +22 -0
- data/test/jobs/insights_full_sync_test.rb +28 -15
- 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 +185 -12
- data/test/models/insights_client_report_status_test.rb +77 -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 +11 -2
- 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/InventoryFilter/InventoryFilter.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +0 -1
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/AdvancedSettingsConstants.js +5 -3
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +15 -2
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +13 -2
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +81 -46
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonConstants.js +3 -3
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonSelectors.js +6 -12
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonFixtures.js +1 -9
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonSelectors.test.js +18 -27
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonSelectors.test.js.snap +1 -16
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +58 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/integrations.test.js +51 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/index.js +2 -5
- 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/ForemanInventoryUpload/ForemanInventoryUploadReducers.js +0 -2
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +1 -1
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableSelectors.js +3 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +2 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +59 -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/InsightsCloudSync.js +8 -3
- data/webpack/InsightsCloudSync/InsightsCloudSync.scss +5 -0
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +9 -6
- data/webpack/__mocks__/foremanReact/redux/middlewares/IntervalMiddleware.js +4 -0
- data/webpack/{InsightsCloudSync/Components/InsightsTable/components → common/table}/EmptyState.js +0 -0
- data/webpack/common/table/helpers.js +7 -0
- metadata +56 -26
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonReducer.js +0 -36
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonActions.test.js +0 -31
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonReducer.test.js +0 -26
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonActions.test.js.snap +0 -98
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonReducer.test.js.snap +0 -18
@@ -1,16 +1,27 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'foreman_tasks/test_helpers'
|
3
|
+
|
4
|
+
class InsightsFullSyncTest < ActiveSupport::TestCase
|
5
|
+
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
2
6
|
|
3
|
-
class InsightsFullSyncTest < ActiveJob::TestCase
|
4
7
|
setup do
|
8
|
+
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_rules_sync)
|
9
|
+
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_notifications)
|
10
|
+
|
11
|
+
uuid1 = 'accdf444-5628-451d-bf3e-cf909ad72756'
|
5
12
|
@host1 = FactoryBot.create(:host, :managed, name: 'host1')
|
13
|
+
FactoryBot.create(:insights_facet, host_id: @host1.id, uuid: uuid1)
|
14
|
+
|
15
|
+
uuid2 = 'accdf444-5628-451d-bf3e-cf909ad72757'
|
6
16
|
@host2 = FactoryBot.create(:host, :managed, name: 'host2')
|
17
|
+
FactoryBot.create(:insights_facet, host_id: @host2.id, uuid: uuid2)
|
7
18
|
|
8
19
|
hits_json = <<-HITS_JSON
|
9
20
|
[
|
10
21
|
{
|
11
22
|
"hostname": "#{@host1.name}",
|
12
23
|
"rhel_version": "7.5",
|
13
|
-
"uuid": "
|
24
|
+
"uuid": "#{uuid1}",
|
14
25
|
"last_seen": "2019-11-22T08:41:42.447244Z",
|
15
26
|
"title": "New Ansible Engine packages are inaccessible when dedicated Ansible repo is not enabled",
|
16
27
|
"solution_url": "",
|
@@ -22,7 +33,7 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
22
33
|
{
|
23
34
|
"hostname": "#{@host1.name}",
|
24
35
|
"rhel_version": "7.5",
|
25
|
-
"uuid": "
|
36
|
+
"uuid": "#{uuid1}",
|
26
37
|
"last_seen": "2019-11-22T08:41:42.447244Z",
|
27
38
|
"title": "CPU vulnerable to side-channel attacks using Microarchitectural Data Sampling (CVE-2018-12130, CVE-2018-12126, CVE-2018-12127, CVE-2019-11091)",
|
28
39
|
"solution_url": "https://access.redhat.com/node/4134081",
|
@@ -34,7 +45,7 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
34
45
|
{
|
35
46
|
"hostname": "#{@host2.name}",
|
36
47
|
"rhel_version": "7.5",
|
37
|
-
"uuid": "
|
48
|
+
"uuid": "#{uuid2}",
|
38
49
|
"last_seen": "2019-11-22T08:41:42.447244Z",
|
39
50
|
"title": "CPU vulnerable to side-channel attacks using L1 Terminal Fault (CVE-2018-3620)",
|
40
51
|
"solution_url": "https://access.redhat.com/node/3560291",
|
@@ -51,23 +62,26 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
51
62
|
test 'Hits data is replaced with data from cloud' do
|
52
63
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).returns(@hits)
|
53
64
|
|
54
|
-
InsightsCloud::Async::InsightsFullSync.
|
65
|
+
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_hosts_sync)
|
66
|
+
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_rules_sync)
|
67
|
+
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_notifications)
|
68
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsFullSync)
|
55
69
|
|
56
70
|
@host1.reload
|
57
71
|
@host2.reload
|
58
72
|
|
59
73
|
assert_equal 2, @host1.insights.hits.count
|
60
74
|
assert_equal 1, @host2.insights.hits.count
|
61
|
-
assert_equal 'accdf444-5628-451d-bf3e-cf909ad72756', @host1.insights.uuid
|
62
|
-
assert_equal 'accdf444-5628-451d-bf3e-cf909ad72757', @host2.insights.uuid
|
63
75
|
end
|
64
76
|
|
65
77
|
test 'Hits counters are reset correctly' do
|
66
78
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).returns(@hits).twice
|
67
79
|
|
68
|
-
InsightsCloud::Async::InsightsFullSync.
|
80
|
+
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_hosts_sync)
|
81
|
+
|
82
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsFullSync)
|
69
83
|
# Invoke again
|
70
|
-
InsightsCloud::Async::InsightsFullSync
|
84
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsFullSync)
|
71
85
|
|
72
86
|
@host1.reload
|
73
87
|
@host2.reload
|
@@ -75,8 +89,6 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
75
89
|
# Check that the counters are correct
|
76
90
|
assert_equal 2, @host1.insights.hits.count
|
77
91
|
assert_equal 1, @host2.insights.hits.count
|
78
|
-
assert_equal 'accdf444-5628-451d-bf3e-cf909ad72756', @host1.insights.uuid
|
79
|
-
assert_equal 'accdf444-5628-451d-bf3e-cf909ad72757', @host2.insights.uuid
|
80
92
|
end
|
81
93
|
|
82
94
|
test 'Hits ignoring non-existent hosts' do
|
@@ -85,7 +97,7 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
85
97
|
{
|
86
98
|
"hostname": "#{@host1.name}_non_existent",
|
87
99
|
"rhel_version": "7.5",
|
88
|
-
"uuid": "accdf444-5628-451d-bf3e-
|
100
|
+
"uuid": "accdf444-5628-451d-bf3e-cf909ad00000",
|
89
101
|
"last_seen": "2019-11-22T08:41:42.447244Z",
|
90
102
|
"title": "New Ansible Engine packages are inaccessible when dedicated Ansible repo is not enabled",
|
91
103
|
"solution_url": "",
|
@@ -98,14 +110,15 @@ class InsightsFullSyncTest < ActiveJob::TestCase
|
|
98
110
|
HITS_JSON
|
99
111
|
hits = JSON.parse(hits_json)
|
100
112
|
|
113
|
+
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_hosts_sync)
|
101
114
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).returns(hits)
|
102
115
|
|
103
|
-
InsightsCloud::Async::InsightsFullSync
|
116
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsFullSync)
|
104
117
|
|
105
118
|
@host1.reload
|
106
119
|
@host2.reload
|
107
120
|
|
108
|
-
|
109
|
-
|
121
|
+
assert_equal 0, @host1.insights.hits_count
|
122
|
+
assert_equal 0, @host2.insights.hits_count
|
110
123
|
end
|
111
124
|
end
|
@@ -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,14 +1,29 @@
|
|
1
1
|
require 'test_plugin_helper'
|
2
|
+
require 'foreman_tasks/test_helpers'
|
2
3
|
|
3
|
-
class InventoryFullSyncTest <
|
4
|
-
|
5
|
-
@host1 = FactoryBot.create(:host, :managed, name: 'host1')
|
4
|
+
class InventoryFullSyncTest < ActiveSupport::TestCase
|
5
|
+
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
6
6
|
|
7
|
+
setup do
|
7
8
|
User.current = User.find_by(login: 'secret_admin')
|
8
9
|
|
9
10
|
env = FactoryBot.create(:katello_k_t_environment)
|
10
11
|
cv = env.content_views << FactoryBot.create(:katello_content_view, organization: env.organization)
|
11
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
|
+
|
12
27
|
# this host would pass our plugin queries, so it could be uploaded to the cloud.
|
13
28
|
@host2 = FactoryBot.create(
|
14
29
|
:host,
|
@@ -19,7 +34,8 @@ class InventoryFullSyncTest < ActiveJob::TestCase
|
|
19
34
|
organization: env.organization
|
20
35
|
)
|
21
36
|
|
22
|
-
@host2.subscription_facet.pools <<
|
37
|
+
@host2.subscription_facet.pools << pool
|
38
|
+
@host2_inventory_id = '4536bf5c-ff03-4154-a8c9-32ff4b40e40c'
|
23
39
|
|
24
40
|
ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
|
25
41
|
|
@@ -28,8 +44,165 @@ class InventoryFullSyncTest < ActiveJob::TestCase
|
|
28
44
|
"total": 3,
|
29
45
|
"count": 3,
|
30
46
|
"page": 1,
|
31
|
-
"per_page":
|
32
|
-
"results": [
|
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
|
+
]
|
33
206
|
}
|
34
207
|
INVENTORY_JSON
|
35
208
|
@inventory = JSON.parse(inventory_json)
|
@@ -71,21 +244,21 @@ class InventoryFullSyncTest < ActiveJob::TestCase
|
|
71
244
|
test 'Host status should be SYNC for inventory hosts' do
|
72
245
|
InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
|
73
246
|
|
74
|
-
InventorySync::Async::InventoryFullSync
|
247
|
+
ForemanTasks.sync_task(InventorySync::Async::InventoryFullSync, @host2.organization)
|
75
248
|
|
76
|
-
@
|
249
|
+
@host2.reload
|
77
250
|
|
78
|
-
assert_equal InventorySync::InventoryStatus::SYNC, InventorySync::InventoryStatus.where(host_id: @
|
251
|
+
assert_equal InventorySync::InventoryStatus::SYNC, InventorySync::InventoryStatus.where(host_id: @host2.id).first.status
|
252
|
+
assert_equal @host2_inventory_id, @host2.insights.uuid
|
79
253
|
end
|
80
254
|
|
81
255
|
test 'Host status should be DISCONNECT for hosts that are not returned from cloud' do
|
82
256
|
InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
|
83
257
|
FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
|
84
258
|
|
85
|
-
InventorySync::Async::InventoryFullSync
|
86
|
-
|
259
|
+
ForemanTasks.sync_task(InventorySync::Async::InventoryFullSync, @host1.organization)
|
87
260
|
@host2.reload
|
88
261
|
|
89
|
-
assert_equal InventorySync::InventoryStatus::DISCONNECT, InventorySync::InventoryStatus.where(host_id: @
|
262
|
+
assert_equal InventorySync::InventoryStatus::DISCONNECT, InventorySync::InventoryStatus.where(host_id: @host1.id).first.status
|
90
263
|
end
|
91
264
|
end
|