foreman_rh_cloud 12.2.13 → 13.0.0
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/assets/javascripts/foreman_rh_cloud/locale/fr/foreman_rh_cloud.js +24 -78
- data/app/assets/javascripts/foreman_rh_cloud/locale/ja/foreman_rh_cloud.js +24 -78
- data/app/assets/javascripts/foreman_rh_cloud/locale/ka/foreman_rh_cloud.js +23 -77
- data/app/assets/javascripts/foreman_rh_cloud/locale/ko/foreman_rh_cloud.js +23 -77
- data/app/assets/javascripts/foreman_rh_cloud/locale/zh_CN/foreman_rh_cloud.js +23 -77
- data/app/controllers/concerns/insights_cloud/package_profile_upload_extensions.rb +3 -2
- data/app/models/insights_hit.rb +1 -1
- data/app/services/foreman_rh_cloud/cert_auth.rb +3 -13
- data/app/services/foreman_rh_cloud/gateway_request.rb +26 -0
- data/app/services/foreman_rh_cloud/insights_api_forwarder.rb +1 -3
- data/app/services/foreman_rh_cloud/tags_auth.rb +1 -2
- data/lib/foreman_inventory_upload/async/generate_report_job.rb +8 -13
- data/lib/foreman_inventory_upload/async/queue_for_upload_job.rb +4 -4
- data/lib/foreman_inventory_upload/async/upload_report_job.rb +5 -6
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +2 -2
- data/lib/foreman_inventory_upload/generators/slice.rb +3 -3
- data/lib/foreman_inventory_upload/scripts/uploader.sh.erb +1 -7
- data/lib/foreman_inventory_upload.rb +2 -6
- data/lib/foreman_rh_cloud/engine.rb +15 -34
- data/lib/foreman_rh_cloud/plugin.rb +9 -9
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/tasks/rh_cloud_inventory.rake +31 -14
- data/locale/foreman_rh_cloud.pot +157 -261
- data/locale/fr/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
- data/locale/fr/foreman_rh_cloud.po +26 -79
- data/locale/ja/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
- data/locale/ja/foreman_rh_cloud.po +26 -79
- data/locale/ka/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
- data/locale/ka/foreman_rh_cloud.po +24 -77
- data/locale/ko/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
- data/locale/ko/foreman_rh_cloud.po +25 -78
- data/locale/zh_CN/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
- data/locale/zh_CN/foreman_rh_cloud.po +25 -78
- data/package.json +1 -1
- data/test/jobs/cloud_connector_announce_task_test.rb +2 -3
- data/test/jobs/connector_playbook_execution_reporter_task_test.rb +20 -32
- data/test/jobs/exponential_backoff_test.rb +8 -9
- data/test/jobs/insights_client_status_aging_test.rb +2 -3
- data/test/jobs/insights_full_sync_test.rb +7 -13
- data/test/jobs/insights_resolutions_sync_test.rb +5 -9
- data/test/jobs/insights_rules_sync_test.rb +3 -5
- data/test/jobs/inventory_full_sync_test.rb +5 -9
- data/test/jobs/inventory_hosts_sync_test.rb +6 -11
- data/test/jobs/inventory_scheduled_sync_test.rb +6 -10
- data/test/jobs/inventory_self_host_sync_test.rb +1 -1
- data/test/jobs/remove_insights_hosts_job_test.rb +15 -14
- data/test/jobs/upload_report_job_test.rb +5 -7
- data/test/unit/fact_helpers_test.rb +0 -47
- data/test/unit/slice_generator_test.rb +0 -57
- data/webpack/ForemanRhCloudFills.js +2 -6
- data/webpack/ForemanRhCloudHelpers.js +0 -4
- data/webpack/InsightsHostDetailsTab/InsightsTab.scss +0 -4
- data/webpack/InsightsHostDetailsTab/InsightsTotalRiskChart.js +23 -59
- data/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js +16 -3
- data/webpack/InsightsVulnerabilityHostIndexExtensions/CVECountCell.js +2 -8
- data/webpack/InsightsVulnerabilityHostIndexExtensions/__tests__/CVECountCell.test.js +2 -48
- data/webpack/__tests__/ForemanRhCloudHelpers.test.js +1 -16
- data/webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap +0 -6
- metadata +4 -23
- data/app/controllers/concerns/foreman_rh_cloud/registration_manager_extensions.rb +0 -39
- data/lib/foreman_inventory_upload/async/create_missing_insights_facets.rb +0 -30
- data/lib/foreman_inventory_upload/async/generate_host_report.rb +0 -20
- data/lib/foreman_inventory_upload/async/host_inventory_report_job.rb +0 -39
- data/lib/foreman_inventory_upload/async/single_host_report_job.rb +0 -20
- data/test/jobs/create_missing_insights_facets_test.rb +0 -151
- data/test/jobs/generate_host_report_test.rb +0 -100
- data/test/jobs/generate_report_job_test.rb +0 -146
- data/test/jobs/host_inventory_report_job_test.rb +0 -244
- data/test/jobs/queue_for_upload_job_test.rb +0 -65
- data/test/jobs/single_host_report_job_test.rb +0 -155
- data/test/unit/lib/foreman_rh_cloud/registration_manager_extensions_test.rb +0 -192
- data/webpack/InsightsHostDetailsTab/__tests__/InsightsTotalRiskChart.test.js +0 -194
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { testSelectorsSnapshotWithFixtures } from '@theforeman/test';
|
|
2
|
-
import { foremanUrl, vulnerabilityDisabled
|
|
2
|
+
import { foremanUrl, vulnerabilityDisabled } from '../ForemanRhCloudHelpers';
|
|
3
3
|
|
|
4
4
|
global.URL_PREFIX = 'MY_TEST_URL_PREFIX.example.com';
|
|
5
5
|
|
|
@@ -34,21 +34,6 @@ const fixtures = {
|
|
|
34
34
|
}),
|
|
35
35
|
'vulnerabilityDisabled returns true for missing hostDetails': () =>
|
|
36
36
|
vulnerabilityDisabled({}),
|
|
37
|
-
'hasNoInsightsFacet returns false when insights_attributes is present': () =>
|
|
38
|
-
hasNoInsightsFacet({
|
|
39
|
-
response: {
|
|
40
|
-
insights_attributes: {
|
|
41
|
-
uuid: 'test-uuid',
|
|
42
|
-
insights_hits_count: 5,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
}),
|
|
46
|
-
'hasNoInsightsFacet returns true when insights_attributes is missing': () =>
|
|
47
|
-
hasNoInsightsFacet({
|
|
48
|
-
response: {},
|
|
49
|
-
}),
|
|
50
|
-
'hasNoInsightsFacet returns true when response is missing': () =>
|
|
51
|
-
hasNoInsightsFacet({}),
|
|
52
37
|
};
|
|
53
38
|
|
|
54
39
|
describe('ForemanRhCloud helpers', () =>
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`ForemanRhCloud helpers hasNoInsightsFacet returns false when insights_attributes is present 1`] = `false`;
|
|
4
|
-
|
|
5
|
-
exports[`ForemanRhCloud helpers hasNoInsightsFacet returns true when insights_attributes is missing 1`] = `true`;
|
|
6
|
-
|
|
7
|
-
exports[`ForemanRhCloud helpers hasNoInsightsFacet returns true when response is missing 1`] = `true`;
|
|
8
|
-
|
|
9
3
|
exports[`ForemanRhCloud helpers should return foreman Url 1`] = `"MY_TEST_URL_PREFIX.example.com/test_path"`;
|
|
10
4
|
|
|
11
5
|
exports[`ForemanRhCloud helpers vulnerabilityDisabled returns false for RHEL host with vulnerability enabled 1`] = `false`;
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: foreman_rh_cloud
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 13.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Foreman Red Hat Cloud team
|
|
@@ -43,14 +43,14 @@ dependencies:
|
|
|
43
43
|
requirements:
|
|
44
44
|
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version:
|
|
46
|
+
version: 4.14.0.rc1.1
|
|
47
47
|
type: :runtime
|
|
48
48
|
prerelease: false
|
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements:
|
|
51
51
|
- - ">="
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
|
-
version:
|
|
53
|
+
version: 4.14.0.rc1.1
|
|
54
54
|
- !ruby/object:Gem::Dependency
|
|
55
55
|
name: rdoc
|
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -99,7 +99,6 @@ files:
|
|
|
99
99
|
- app/controllers/api/v2/rh_cloud/cloud_request_controller.rb
|
|
100
100
|
- app/controllers/api/v2/rh_cloud/inventory_controller.rb
|
|
101
101
|
- app/controllers/concerns/foreman_rh_cloud/iop_smart_proxy_access.rb
|
|
102
|
-
- app/controllers/concerns/foreman_rh_cloud/registration_manager_extensions.rb
|
|
103
102
|
- app/controllers/concerns/insights_cloud/candlepin_cache.rb
|
|
104
103
|
- app/controllers/concerns/insights_cloud/client_authentication.rb
|
|
105
104
|
- app/controllers/concerns/insights_cloud/package_profile_upload_extensions.rb
|
|
@@ -140,6 +139,7 @@ files:
|
|
|
140
139
|
- app/services/foreman_rh_cloud/cloud_presence.rb
|
|
141
140
|
- app/services/foreman_rh_cloud/cloud_request.rb
|
|
142
141
|
- app/services/foreman_rh_cloud/cloud_request_forwarder.rb
|
|
142
|
+
- app/services/foreman_rh_cloud/gateway_request.rb
|
|
143
143
|
- app/services/foreman_rh_cloud/hit_remediations_retriever.rb
|
|
144
144
|
- app/services/foreman_rh_cloud/hits_uploader.rb
|
|
145
145
|
- app/services/foreman_rh_cloud/insights_api_forwarder.rb
|
|
@@ -185,17 +185,13 @@ files:
|
|
|
185
185
|
- db/seeds.d/50_job_templates.rb
|
|
186
186
|
- lib/foreman_inventory_upload.rb
|
|
187
187
|
- lib/foreman_inventory_upload/async/async_helpers.rb
|
|
188
|
-
- lib/foreman_inventory_upload/async/create_missing_insights_facets.rb
|
|
189
188
|
- lib/foreman_inventory_upload/async/delayed_start.rb
|
|
190
189
|
- lib/foreman_inventory_upload/async/generate_all_reports_job.rb
|
|
191
|
-
- lib/foreman_inventory_upload/async/generate_host_report.rb
|
|
192
190
|
- lib/foreman_inventory_upload/async/generate_report_job.rb
|
|
193
|
-
- lib/foreman_inventory_upload/async/host_inventory_report_job.rb
|
|
194
191
|
- lib/foreman_inventory_upload/async/progress_output.rb
|
|
195
192
|
- lib/foreman_inventory_upload/async/queue_for_upload_job.rb
|
|
196
193
|
- lib/foreman_inventory_upload/async/remove_insights_hosts_job.rb
|
|
197
194
|
- lib/foreman_inventory_upload/async/shell_process.rb
|
|
198
|
-
- lib/foreman_inventory_upload/async/single_host_report_job.rb
|
|
199
195
|
- lib/foreman_inventory_upload/async/upload_report_job.rb
|
|
200
196
|
- lib/foreman_inventory_upload/generators/archived_report.rb
|
|
201
197
|
- lib/foreman_inventory_upload/generators/fact_helpers.rb
|
|
@@ -262,11 +258,7 @@ files:
|
|
|
262
258
|
- test/factories/inventory_upload_factories.rb
|
|
263
259
|
- test/jobs/cloud_connector_announce_task_test.rb
|
|
264
260
|
- test/jobs/connector_playbook_execution_reporter_task_test.rb
|
|
265
|
-
- test/jobs/create_missing_insights_facets_test.rb
|
|
266
261
|
- test/jobs/exponential_backoff_test.rb
|
|
267
|
-
- test/jobs/generate_host_report_test.rb
|
|
268
|
-
- test/jobs/generate_report_job_test.rb
|
|
269
|
-
- test/jobs/host_inventory_report_job_test.rb
|
|
270
262
|
- test/jobs/insights_client_status_aging_test.rb
|
|
271
263
|
- test/jobs/insights_full_sync_test.rb
|
|
272
264
|
- test/jobs/insights_resolutions_sync_test.rb
|
|
@@ -275,9 +267,7 @@ files:
|
|
|
275
267
|
- test/jobs/inventory_hosts_sync_test.rb
|
|
276
268
|
- test/jobs/inventory_scheduled_sync_test.rb
|
|
277
269
|
- test/jobs/inventory_self_host_sync_test.rb
|
|
278
|
-
- test/jobs/queue_for_upload_job_test.rb
|
|
279
270
|
- test/jobs/remove_insights_hosts_job_test.rb
|
|
280
|
-
- test/jobs/single_host_report_job_test.rb
|
|
281
271
|
- test/jobs/upload_report_job_test.rb
|
|
282
272
|
- test/models/insights_client_report_status_test.rb
|
|
283
273
|
- test/test_plugin_helper.rb
|
|
@@ -285,7 +275,6 @@ files:
|
|
|
285
275
|
- test/unit/fact_helpers_test.rb
|
|
286
276
|
- test/unit/foreman_rh_cloud_self_host_test.rb
|
|
287
277
|
- test/unit/insights_facet_test.rb
|
|
288
|
-
- test/unit/lib/foreman_rh_cloud/registration_manager_extensions_test.rb
|
|
289
278
|
- test/unit/metadata_generator_test.rb
|
|
290
279
|
- test/unit/playbook_progress_generator_test.rb
|
|
291
280
|
- test/unit/rh_cloud_http_proxy_test.rb
|
|
@@ -629,7 +618,6 @@ files:
|
|
|
629
618
|
- webpack/InsightsHostDetailsTab/__tests__/InsightsTabIntegration.test.js
|
|
630
619
|
- webpack/InsightsHostDetailsTab/__tests__/InsightsTabReducer.test.js
|
|
631
620
|
- webpack/InsightsHostDetailsTab/__tests__/InsightsTabSelectors.test.js
|
|
632
|
-
- webpack/InsightsHostDetailsTab/__tests__/InsightsTotalRiskChart.test.js
|
|
633
621
|
- webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTab.test.js.snap
|
|
634
622
|
- webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabActions.test.js.snap
|
|
635
623
|
- webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabReducer.test.js.snap
|
|
@@ -722,11 +710,7 @@ test_files:
|
|
|
722
710
|
- test/factories/inventory_upload_factories.rb
|
|
723
711
|
- test/jobs/cloud_connector_announce_task_test.rb
|
|
724
712
|
- test/jobs/connector_playbook_execution_reporter_task_test.rb
|
|
725
|
-
- test/jobs/create_missing_insights_facets_test.rb
|
|
726
713
|
- test/jobs/exponential_backoff_test.rb
|
|
727
|
-
- test/jobs/generate_host_report_test.rb
|
|
728
|
-
- test/jobs/generate_report_job_test.rb
|
|
729
|
-
- test/jobs/host_inventory_report_job_test.rb
|
|
730
714
|
- test/jobs/insights_client_status_aging_test.rb
|
|
731
715
|
- test/jobs/insights_full_sync_test.rb
|
|
732
716
|
- test/jobs/insights_resolutions_sync_test.rb
|
|
@@ -735,9 +719,7 @@ test_files:
|
|
|
735
719
|
- test/jobs/inventory_hosts_sync_test.rb
|
|
736
720
|
- test/jobs/inventory_scheduled_sync_test.rb
|
|
737
721
|
- test/jobs/inventory_self_host_sync_test.rb
|
|
738
|
-
- test/jobs/queue_for_upload_job_test.rb
|
|
739
722
|
- test/jobs/remove_insights_hosts_job_test.rb
|
|
740
|
-
- test/jobs/single_host_report_job_test.rb
|
|
741
723
|
- test/jobs/upload_report_job_test.rb
|
|
742
724
|
- test/models/insights_client_report_status_test.rb
|
|
743
725
|
- test/test_plugin_helper.rb
|
|
@@ -745,7 +727,6 @@ test_files:
|
|
|
745
727
|
- test/unit/fact_helpers_test.rb
|
|
746
728
|
- test/unit/foreman_rh_cloud_self_host_test.rb
|
|
747
729
|
- test/unit/insights_facet_test.rb
|
|
748
|
-
- test/unit/lib/foreman_rh_cloud/registration_manager_extensions_test.rb
|
|
749
730
|
- test/unit/metadata_generator_test.rb
|
|
750
731
|
- test/unit/playbook_progress_generator_test.rb
|
|
751
732
|
- test/unit/rh_cloud_http_proxy_test.rb
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
module ForemanRhCloud
|
|
2
|
-
module RegistrationManagerExtensions
|
|
3
|
-
include ForemanRhCloud::CertAuth
|
|
4
|
-
|
|
5
|
-
def logger
|
|
6
|
-
Rails.logger
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def unregister_host(host, options = {})
|
|
10
|
-
organization_destroy = options.fetch(:organization_destroy, false)
|
|
11
|
-
|
|
12
|
-
# Reload to ensure we have fresh association data
|
|
13
|
-
host.reload
|
|
14
|
-
|
|
15
|
-
# Only delete from HBI in IoP mode (hosted mode uses async job for cleanup)
|
|
16
|
-
hbi_host_destroy(host) if ForemanRhCloud.with_iop_smart_proxy? && !organization_destroy && host.insights_facet&.uuid&.presence
|
|
17
|
-
host.insights&.destroy!
|
|
18
|
-
super(host, options)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def hbi_host_destroy(host)
|
|
22
|
-
uuid = host.insights_facet.uuid
|
|
23
|
-
logger.debug "Unregistering host #{uuid} from HBI"
|
|
24
|
-
execute_cloud_request(
|
|
25
|
-
organization: host.organization,
|
|
26
|
-
method: :delete,
|
|
27
|
-
url: ForemanInventoryUpload.host_by_id_url(uuid),
|
|
28
|
-
headers: {
|
|
29
|
-
content_type: :json,
|
|
30
|
-
}
|
|
31
|
-
)
|
|
32
|
-
rescue RestClient::NotFound
|
|
33
|
-
Rails.logger.warn(_("Attempted to destroy HBI host %s, but host does not exist in HBI") % uuid)
|
|
34
|
-
rescue StandardError => e
|
|
35
|
-
# TODO: Improve error handling - don't break registration if HBI delete fails
|
|
36
|
-
Rails.logger.error(format(_("Failed to destroy HBI host %s: %s"), uuid, e.message))
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
module ForemanInventoryUpload
|
|
2
|
-
module Async
|
|
3
|
-
class CreateMissingInsightsFacets < ::Actions::EntryAction
|
|
4
|
-
def plan(organization_id)
|
|
5
|
-
plan_self(organization_id: organization_id)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def run
|
|
9
|
-
organization = ::Organization.find(input[:organization_id])
|
|
10
|
-
hosts_without_facets = ::ForemanInventoryUpload::Generators::Queries.for_org(organization, hosts_query: 'null? insights_uuid')
|
|
11
|
-
facet_count = 0
|
|
12
|
-
hosts_without_facets.each do |batch|
|
|
13
|
-
facets = batch.pluck(:id, 'katello_subscription_facets.uuid').map do |host_id, uuid|
|
|
14
|
-
{
|
|
15
|
-
host_id: host_id,
|
|
16
|
-
uuid: uuid,
|
|
17
|
-
}
|
|
18
|
-
end
|
|
19
|
-
# We don't need to validate the facets here as we create the necessary fields.
|
|
20
|
-
# rubocop:disable Rails/SkipsModelValidations
|
|
21
|
-
InsightsFacet.upsert_all(facets, unique_by: :host_id) unless facets.empty?
|
|
22
|
-
# rubocop:enable Rails/SkipsModelValidations
|
|
23
|
-
facet_count += facets.size
|
|
24
|
-
end
|
|
25
|
-
output[:result] = facet_count.zero? ? _("There were no missing Insights facets") : format(_("Missing Insights facets created: %s"), facet_count)
|
|
26
|
-
Rails.logger.debug output[:result]
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
module ForemanInventoryUpload
|
|
2
|
-
module Async
|
|
3
|
-
class GenerateHostReport < ::Actions::EntryAction
|
|
4
|
-
def plan(base_folder, organization_id, filter)
|
|
5
|
-
plan_self(
|
|
6
|
-
base_folder: base_folder,
|
|
7
|
-
organization_id: organization_id,
|
|
8
|
-
filter: filter
|
|
9
|
-
)
|
|
10
|
-
input[:target] = File.join(base_folder, ForemanInventoryUpload.facts_archive_name(input[:organization_id], input[:filter]))
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def run
|
|
14
|
-
archived_report_generator = ForemanInventoryUpload::Generators::ArchivedReport.new(input[:target])
|
|
15
|
-
archived_report_generator.render(organization: input[:organization_id], filter: input[:filter])
|
|
16
|
-
output[:result] = "Generated #{input[:target]} for organization id #{input[:organization_id]}"
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
module ForemanInventoryUpload
|
|
2
|
-
module Async
|
|
3
|
-
class HostInventoryReportJob < ::Actions::EntryAction
|
|
4
|
-
def plan(base_folder, organization_id, hosts_filter = "", upload = true)
|
|
5
|
-
sequence do
|
|
6
|
-
plan_action(
|
|
7
|
-
GenerateHostReport,
|
|
8
|
-
base_folder,
|
|
9
|
-
organization_id,
|
|
10
|
-
hosts_filter
|
|
11
|
-
)
|
|
12
|
-
if upload
|
|
13
|
-
plan_action(
|
|
14
|
-
QueueForUploadJob,
|
|
15
|
-
base_folder,
|
|
16
|
-
ForemanInventoryUpload.facts_archive_name(organization_id, hosts_filter),
|
|
17
|
-
organization_id
|
|
18
|
-
)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
if ForemanRhCloud.with_iop_smart_proxy?
|
|
22
|
-
plan_action(
|
|
23
|
-
CreateMissingInsightsFacets,
|
|
24
|
-
organization_id
|
|
25
|
-
)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def humanized_name
|
|
31
|
-
_("Host inventory report job")
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def organization_id
|
|
35
|
-
input[:organization_id]
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
module ForemanInventoryUpload
|
|
2
|
-
module Async
|
|
3
|
-
class SingleHostReportJob < HostInventoryReportJob
|
|
4
|
-
def plan(base_folder, organization_id, host_id)
|
|
5
|
-
input[:host_id] = host_id
|
|
6
|
-
super(base_folder, organization_id, "id=#{input[:host_id]}")
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def hostname(host_id)
|
|
10
|
-
host = ::Host.find_by(id: host_id)
|
|
11
|
-
host&.name
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def humanized_name
|
|
15
|
-
hostname_result = hostname(input[:host_id])
|
|
16
|
-
hostname_result.present? ? format(_("Single-host report job for host %s"), hostname_result) : _("Single-host report job")
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
require 'test_plugin_helper'
|
|
2
|
-
require 'foreman_tasks/test_helpers'
|
|
3
|
-
|
|
4
|
-
class CreateMissingInsightsFacetsTest < ActiveSupport::TestCase
|
|
5
|
-
include Dynflow::Testing::Factories
|
|
6
|
-
include KatelloCVEHelper
|
|
7
|
-
|
|
8
|
-
setup do
|
|
9
|
-
User.current = User.find_by(login: 'secret_admin')
|
|
10
|
-
@cve = make_cve
|
|
11
|
-
@env = @cve.lifecycle_environment
|
|
12
|
-
@organization = @env.organization
|
|
13
|
-
|
|
14
|
-
# Create a host with subscription facet but no insights facet
|
|
15
|
-
@host_without_facet = FactoryBot.create(
|
|
16
|
-
:host,
|
|
17
|
-
:with_subscription,
|
|
18
|
-
:with_content,
|
|
19
|
-
content_view: @cve.content_view,
|
|
20
|
-
lifecycle_environment: @env,
|
|
21
|
-
organization: @organization
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
# Create a host with both subscription and insights facets
|
|
25
|
-
@host_with_facet = FactoryBot.create(
|
|
26
|
-
:host,
|
|
27
|
-
:with_subscription,
|
|
28
|
-
:with_content,
|
|
29
|
-
content_view: @cve.content_view,
|
|
30
|
-
lifecycle_environment: @env,
|
|
31
|
-
organization: @organization
|
|
32
|
-
)
|
|
33
|
-
@host_with_facet.build_insights(uuid: @host_with_facet.subscription_facet.uuid)
|
|
34
|
-
@host_with_facet.insights.save!
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
test 'creates insights facets for hosts without them' do
|
|
38
|
-
assert_nil @host_without_facet.insights
|
|
39
|
-
|
|
40
|
-
action = create_and_plan_action(
|
|
41
|
-
ForemanInventoryUpload::Async::CreateMissingInsightsFacets,
|
|
42
|
-
@organization.id
|
|
43
|
-
)
|
|
44
|
-
action = run_action(action)
|
|
45
|
-
|
|
46
|
-
@host_without_facet.reload
|
|
47
|
-
assert_not_nil @host_without_facet.insights
|
|
48
|
-
assert_equal @host_without_facet.subscription_facet.uuid, @host_without_facet.insights.uuid
|
|
49
|
-
assert_match(/Missing Insights facets created: 1/, action.output[:result])
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
test 'does not create duplicate facets for hosts that already have them' do
|
|
53
|
-
original_uuid = @host_with_facet.insights.uuid
|
|
54
|
-
original_id = @host_with_facet.insights.id
|
|
55
|
-
|
|
56
|
-
action = create_and_plan_action(
|
|
57
|
-
ForemanInventoryUpload::Async::CreateMissingInsightsFacets,
|
|
58
|
-
@organization.id
|
|
59
|
-
)
|
|
60
|
-
run_action(action)
|
|
61
|
-
|
|
62
|
-
@host_with_facet.reload
|
|
63
|
-
assert_equal original_id, @host_with_facet.insights.id
|
|
64
|
-
assert_equal original_uuid, @host_with_facet.insights.uuid
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
test 'handles organization with no missing facets' do
|
|
68
|
-
# Create insights facet for the host that was missing one
|
|
69
|
-
@host_without_facet.build_insights(uuid: @host_without_facet.subscription_facet.uuid)
|
|
70
|
-
@host_without_facet.insights.save!
|
|
71
|
-
|
|
72
|
-
action = create_and_plan_action(
|
|
73
|
-
ForemanInventoryUpload::Async::CreateMissingInsightsFacets,
|
|
74
|
-
@organization.id
|
|
75
|
-
)
|
|
76
|
-
action = run_action(action)
|
|
77
|
-
|
|
78
|
-
assert_match(/There were no missing Insights facets/, action.output[:result])
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
test 'creates multiple facets when multiple hosts are missing them' do
|
|
82
|
-
# Remove the insights facet from the host that has one
|
|
83
|
-
@host_with_facet.insights.destroy
|
|
84
|
-
@host_with_facet.reload
|
|
85
|
-
|
|
86
|
-
assert_nil @host_without_facet.insights
|
|
87
|
-
assert_nil @host_with_facet.insights
|
|
88
|
-
|
|
89
|
-
action = create_and_plan_action(
|
|
90
|
-
ForemanInventoryUpload::Async::CreateMissingInsightsFacets,
|
|
91
|
-
@organization.id
|
|
92
|
-
)
|
|
93
|
-
action = run_action(action)
|
|
94
|
-
|
|
95
|
-
@host_without_facet.reload
|
|
96
|
-
@host_with_facet.reload
|
|
97
|
-
assert_not_nil @host_without_facet.insights
|
|
98
|
-
assert_not_nil @host_with_facet.insights
|
|
99
|
-
# After the bug fix, the count should correctly show 2 hosts
|
|
100
|
-
assert_match(/Missing Insights facets created: 2/, action.output[:result])
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
test 'logs result message' do
|
|
104
|
-
Rails.logger.expects(:debug).with(regexp_matches(/Missing Insights facets created/))
|
|
105
|
-
|
|
106
|
-
action = create_and_plan_action(
|
|
107
|
-
ForemanInventoryUpload::Async::CreateMissingInsightsFacets,
|
|
108
|
-
@organization.id
|
|
109
|
-
)
|
|
110
|
-
run_action(action)
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
test 'correctly counts facets across multiple batches' do
|
|
114
|
-
# Remove existing insights facet
|
|
115
|
-
@host_with_facet.insights.destroy
|
|
116
|
-
@host_with_facet.reload
|
|
117
|
-
|
|
118
|
-
# Stub the batch size to force multiple batches with just 2 hosts
|
|
119
|
-
ForemanInventoryUpload.stubs(:slice_size).returns(1)
|
|
120
|
-
|
|
121
|
-
assert_nil @host_without_facet.insights
|
|
122
|
-
assert_nil @host_with_facet.insights
|
|
123
|
-
|
|
124
|
-
action = create_and_plan_action(
|
|
125
|
-
ForemanInventoryUpload::Async::CreateMissingInsightsFacets,
|
|
126
|
-
@organization.id
|
|
127
|
-
)
|
|
128
|
-
action = run_action(action)
|
|
129
|
-
|
|
130
|
-
@host_without_facet.reload
|
|
131
|
-
@host_with_facet.reload
|
|
132
|
-
assert_not_nil @host_without_facet.insights
|
|
133
|
-
assert_not_nil @host_with_facet.insights
|
|
134
|
-
# Count should be 2 even though processed in 2 separate batches
|
|
135
|
-
assert_match(/Missing Insights facets created: 2/, action.output[:result])
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
test 'handles error when InsightsFacet.upsert_all fails' do
|
|
139
|
-
# Stub upsert_all to raise an exception
|
|
140
|
-
InsightsFacet.stubs(:upsert_all).raises(StandardError.new('upsert failed'))
|
|
141
|
-
|
|
142
|
-
action = create_and_plan_action(
|
|
143
|
-
ForemanInventoryUpload::Async::CreateMissingInsightsFacets,
|
|
144
|
-
@organization.id
|
|
145
|
-
)
|
|
146
|
-
|
|
147
|
-
assert_raises(StandardError) do
|
|
148
|
-
run_action(action)
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
end
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
require 'test_plugin_helper'
|
|
2
|
-
require 'foreman_tasks/test_helpers'
|
|
3
|
-
|
|
4
|
-
class GenerateHostReportTest < ActiveSupport::TestCase
|
|
5
|
-
include Dynflow::Testing::Factories
|
|
6
|
-
include FolderIsolation
|
|
7
|
-
|
|
8
|
-
let(:organization) { FactoryBot.create(:organization) }
|
|
9
|
-
let(:base_folder) { @tmpdir }
|
|
10
|
-
let(:filter) { '' }
|
|
11
|
-
|
|
12
|
-
setup do
|
|
13
|
-
# Stub the ArchivedReport generator
|
|
14
|
-
@mock_generator = mock('archived_report_generator')
|
|
15
|
-
@mock_generator.stubs(:render)
|
|
16
|
-
ForemanInventoryUpload::Generators::ArchivedReport.stubs(:new).returns(@mock_generator)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
test 'plan sets target path correctly' do
|
|
20
|
-
expected_archive_name = ForemanInventoryUpload.facts_archive_name(organization.id, filter)
|
|
21
|
-
expected_target = File.join(base_folder, expected_archive_name)
|
|
22
|
-
|
|
23
|
-
action = create_and_plan_action(
|
|
24
|
-
ForemanInventoryUpload::Async::GenerateHostReport,
|
|
25
|
-
base_folder,
|
|
26
|
-
organization.id,
|
|
27
|
-
filter
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
assert_equal expected_target, action.input[:target]
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
test 'run generates report archive' do
|
|
34
|
-
expected_target = File.join(base_folder, ForemanInventoryUpload.facts_archive_name(organization.id, filter))
|
|
35
|
-
|
|
36
|
-
ForemanInventoryUpload::Generators::ArchivedReport.expects(:new).with(expected_target).returns(@mock_generator)
|
|
37
|
-
@mock_generator.expects(:render).with(organization: organization.id, filter: filter)
|
|
38
|
-
|
|
39
|
-
action = create_and_plan_action(
|
|
40
|
-
ForemanInventoryUpload::Async::GenerateHostReport,
|
|
41
|
-
base_folder,
|
|
42
|
-
organization.id,
|
|
43
|
-
filter
|
|
44
|
-
)
|
|
45
|
-
action = run_action(action)
|
|
46
|
-
|
|
47
|
-
assert_match(/Generated #{Regexp.escape(expected_target)} for organization id #{organization.id}/, action.output[:result])
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
test 'generates report with filter' do
|
|
51
|
-
filter_value = 'id=123'
|
|
52
|
-
expected_target = File.join(base_folder, ForemanInventoryUpload.facts_archive_name(organization.id, filter_value))
|
|
53
|
-
|
|
54
|
-
ForemanInventoryUpload::Generators::ArchivedReport.expects(:new).with(expected_target).returns(@mock_generator)
|
|
55
|
-
@mock_generator.expects(:render).with(organization: organization.id, filter: filter_value)
|
|
56
|
-
|
|
57
|
-
action = create_and_plan_action(
|
|
58
|
-
ForemanInventoryUpload::Async::GenerateHostReport,
|
|
59
|
-
base_folder,
|
|
60
|
-
organization.id,
|
|
61
|
-
filter_value
|
|
62
|
-
)
|
|
63
|
-
action = run_action(action)
|
|
64
|
-
|
|
65
|
-
assert_match(/organization id #{organization.id}/, action.output[:result])
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
test 'stores organization_id and filter in input' do
|
|
69
|
-
filter_value = 'name~test'
|
|
70
|
-
|
|
71
|
-
action = create_and_plan_action(
|
|
72
|
-
ForemanInventoryUpload::Async::GenerateHostReport,
|
|
73
|
-
base_folder,
|
|
74
|
-
organization.id,
|
|
75
|
-
filter_value
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
assert_equal organization.id, action.input[:organization_id]
|
|
79
|
-
assert_equal filter_value, action.input[:filter]
|
|
80
|
-
assert_equal base_folder, action.input[:base_folder]
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
test 'handles ArchivedReport generator failure' do
|
|
84
|
-
expected_target = File.join(base_folder, ForemanInventoryUpload.facts_archive_name(organization.id, filter))
|
|
85
|
-
|
|
86
|
-
ForemanInventoryUpload::Generators::ArchivedReport.expects(:new).with(expected_target).returns(@mock_generator)
|
|
87
|
-
@mock_generator.expects(:render).with(organization: organization.id, filter: filter).raises(StandardError.new('Report generation failed'))
|
|
88
|
-
|
|
89
|
-
action = create_and_plan_action(
|
|
90
|
-
ForemanInventoryUpload::Async::GenerateHostReport,
|
|
91
|
-
base_folder,
|
|
92
|
-
organization.id,
|
|
93
|
-
filter
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
assert_raises(StandardError) do
|
|
97
|
-
run_action(action)
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|