foreman_rh_cloud 1.0.4 → 1.0.8
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/accounts_controller.rb +4 -6
- data/app/controllers/foreman_inventory_upload/uploads_controller.rb +33 -7
- data/app/controllers/foreman_rh_cloud/react_controller.rb +11 -0
- data/app/controllers/insights_cloud/tasks_controller.rb +8 -0
- data/app/helpers/foreman_inventory_upload_host_helper.rb +11 -0
- data/app/models/insights_facet.rb +3 -0
- data/app/models/insights_hit.rb +6 -0
- data/app/models/setting/rh_cloud.rb +15 -0
- data/app/overrides/hosts_list.rb +13 -0
- data/app/views/foreman_rh_cloud/react/insights_cloud.html.erb +1 -0
- data/app/views/foreman_rh_cloud/react/inventory_upload.html.erb +1 -0
- data/app/views/{foreman_inventory_upload/layouts/react.html.erb → layouts/foreman_rh_cloud/application.html.erb} +2 -2
- data/config/routes.rb +12 -1
- data/db/migrate/20191215104806_create_insights_hits.foreman_inventory_upload.rb +14 -0
- data/db/migrate/20191216062008_create_insights_facets.foreman_inventory_upload.rb +7 -0
- data/lib/foreman_inventory_upload.rb +12 -0
- data/lib/foreman_inventory_upload/async/async_helpers.rb +13 -0
- data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +8 -0
- data/lib/foreman_inventory_upload/async/shell_process.rb +3 -1
- data/lib/foreman_inventory_upload/generators/archived_report.rb +6 -3
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +56 -0
- data/lib/foreman_inventory_upload/generators/queries.rb +7 -0
- data/lib/foreman_inventory_upload/generators/slice.rb +34 -12
- data/lib/foreman_inventory_upload/notifications/manifest_import_success_notification_override.rb +19 -0
- data/lib/foreman_rh_cloud/engine.rb +33 -5
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud.rb +15 -0
- data/lib/insights_cloud/async/insights_full_sync.rb +92 -0
- data/test/controllers/accounts_controller_test.rb +8 -3
- data/test/controllers/uploads_controller_test.rb +13 -0
- data/test/jobs/insights_full_sync_test.rb +62 -0
- data/test/unit/archived_report_generator_test.rb +1 -0
- data/test/unit/fact_helpers_test.rb +29 -0
- data/test/unit/slice_generator_test.rb +249 -13
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +14 -2
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.js +13 -10
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +6 -3
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListHelper.js +10 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +16 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +10 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/EmptyResults.js +15 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/EmptyResults.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/__snapshots__/EmptyResults.test.js.snap +18 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/emptyResults.scss +7 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItem.js +1 -4
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountList.test.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +8 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListHelper.test.js +12 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListIntegration.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +22 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +20 -8
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountList.test.js.snap +2 -3
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +20 -2
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +20 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +8 -2
- data/webpack/ForemanInventoryUpload/Components/AccountList/index.js +2 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.fixtures.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.js +32 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherActions.js +30 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherConstants.js +2 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcher.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcherActions.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcher.test.js.snap +38 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcherActions.test.js.snap +14 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/autoUploadSwitcher.scss +3 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/index.js +17 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardActions.js +4 -3
- data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardSelectors.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardActions.test.js +2 -3
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardIntegration.test.js +2 -1
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardSelectors.test.js +3 -2
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.fixtures.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.js +29 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherActions.js +30 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherConstants.js +3 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcher.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcherActions.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcher.test.js.snap +38 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcherActions.test.js.snap +14 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/hostObfuscationSwitcher.scss +0 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/index.js +20 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/Components/ClearButton/ClearButton.js +26 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/Components/ClearButton/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.fixtures.js +2 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.js +39 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterActions.js +16 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterConstants.js +3 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js +36 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterSelectors.js +7 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilter.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterActions.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterReducer.test.js +35 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterSelectors.test.js +21 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilter.test.js.snap +25 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterActions.test.js.snap +17 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterReducer.test.js.snap +25 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterSelectors.test.js.snap +9 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +31 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/integration.test.js +18 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/index.js +17 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/inventoryFilter.scss +28 -0
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.js +15 -0
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/InventorySettings.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettings.test.js.snap +13 -0
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/inventorySettings.scss +15 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js +40 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/PageHeader.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap +61 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/DocsButton.js +17 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/__tests__/DocsButton.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/__tests__/__snapshots__/DocsButton.test.js.snap +20 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/HistoryButton.js +18 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/__tests__/HistoryButton.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/__tests__/__snapshots__/HistoryButton.test.js.snap +21 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +24 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/PageDescription.test.js +11 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +17 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/ToolbarButtons.test.js +12 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/__snapshots__/ToolbarButtons.test.js.snap +10 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/toolbarButtons.scss +7 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/pageHeader.scss +3 -0
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRun.fixtures.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRun.js +4 -2
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/ScheduledRun.test.js +0 -1
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/__snapshots__/ScheduledRun.test.js.snap +0 -2
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/index.js +12 -1
- data/webpack/ForemanInventoryUpload/Components/TabBody/__tests__/__snapshots__/TabBody.test.js.snap +1 -1
- data/webpack/ForemanInventoryUpload/ForemanInventoryConstants.js +7 -0
- data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +12 -0
- data/webpack/ForemanInventoryUpload/ForemanInventoryUpload.js +18 -9
- data/webpack/ForemanInventoryUpload/ForemanInventoryUploadReducers.js +4 -4
- data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/SubscriptionsPageExtensionActions.js +34 -0
- data/webpack/ForemanInventoryUpload/__tests__/ForemanInventoryHelpers.test.js +12 -0
- data/webpack/ForemanInventoryUpload/{ForemanInventoryUpload.test.js → __tests__/ForemanInventoryUpload.test.js} +1 -1
- data/webpack/ForemanInventoryUpload/__tests__/__snapshots__/ForemanInventoryHelpers.test.js.snap +5 -0
- data/webpack/ForemanInventoryUpload/{__snapshots__ → __tests__/__snapshots__}/ForemanInventoryUpload.test.js.snap +6 -5
- data/webpack/ForemanRhCloudHelpers.js +6 -0
- data/webpack/ForemanRhCloudReducers.js +10 -0
- data/webpack/ForemanRhCloudSelectors.js +5 -0
- data/webpack/ForemanRhCloudTestHelpers.js +6 -0
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +26 -0
- data/webpack/InsightsCloudSync/InsightsCloudSync.test.js +13 -0
- data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +23 -0
- data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +6 -0
- data/webpack/InsightsCloudSync/InsightsCloudSyncHelpers.js +3 -0
- data/webpack/InsightsCloudSync/InsightsCloudSyncReducers.js +3 -0
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +25 -0
- data/webpack/InsightsCloudSync/__tests__/InsightsCloudSyncHelpers.test.js +11 -0
- data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncHelpers.test.js.snap +3 -0
- data/webpack/InsightsCloudSync/index.js +17 -0
- data/webpack/__mocks__/foremanReact/components/Layout/LayoutConstants.js +1 -0
- data/webpack/__tests__/ForemanRhCloudHelpers.test.js +11 -0
- data/webpack/__tests__/ForemanRhCloudSelectors.test.js +19 -0
- data/webpack/__tests__/ForemanRhCloudTestHelpers.test.js +10 -0
- data/webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap +3 -0
- data/webpack/__tests__/__snapshots__/ForemanRhCloudSelectors.test.js.snap +24 -0
- data/webpack/__tests__/__snapshots__/ForemanRhCloudTestHelpers.test.js.snap +14 -0
- data/webpack/index.js +8 -1
- data/webpack/subscriptions_extension_index.js +8 -0
- metadata +124 -7
- data/app/controllers/foreman_inventory_upload/react_controller.rb +0 -7
- data/webpack/ForemanInventoryUpload/ForemanInventoryUploadSelectors.js +0 -4
data/lib/foreman_inventory_upload/notifications/manifest_import_success_notification_override.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module ForemanInventoryUpload
|
2
|
+
module Notifications
|
3
|
+
module ManifestImportSuccessNotificationOverride
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def actions
|
7
|
+
{
|
8
|
+
:links => [
|
9
|
+
{
|
10
|
+
:href => Rails.application.routes.url_helpers.foreman_rh_cloud_inventory_upload_path,
|
11
|
+
:title => _('Enable inventory upload'),
|
12
|
+
:external => false,
|
13
|
+
},
|
14
|
+
],
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -5,6 +5,10 @@ module ForemanRhCloud
|
|
5
5
|
class Engine < ::Rails::Engine
|
6
6
|
engine_name 'foreman_rh_cloud'
|
7
7
|
|
8
|
+
initializer 'foreman_rh_cloud.load_default_settings', :before => :load_config_initializers do
|
9
|
+
require_dependency File.expand_path('../../app/models/setting/rh_cloud.rb', __dir__)
|
10
|
+
end
|
11
|
+
|
8
12
|
config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
|
9
13
|
config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
|
10
14
|
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
|
@@ -26,17 +30,41 @@ module ForemanRhCloud
|
|
26
30
|
|
27
31
|
# Add permissions
|
28
32
|
security_block :foreman_rh_cloud do
|
29
|
-
permission
|
33
|
+
permission(
|
34
|
+
:generate_foreman_rh_cloud,
|
35
|
+
'foreman_inventory_upload/reports': [:generate]
|
36
|
+
)
|
37
|
+
permission(
|
38
|
+
:view_foreman_rh_cloud,
|
39
|
+
'foreman_inventory_upload/accounts': [:index],
|
40
|
+
'foreman_inventory_upload/reports': [:last],
|
41
|
+
'foreman_inventory_upload/uploads': [:auto_upload, :download_file, :last],
|
42
|
+
'foreman_rh_cloud/react': [:inventory_upload]
|
43
|
+
)
|
30
44
|
end
|
31
45
|
|
32
|
-
|
33
|
-
|
46
|
+
plugin_permissions = [:view_foreman_rh_cloud, :generate_foreman_rh_cloud]
|
47
|
+
|
48
|
+
role 'ForemanRhCloud', plugin_permissions, 'Role granting permissions to view the hosts inventory,
|
49
|
+
generate a report, upload it to the cloud and download it locally'
|
50
|
+
|
51
|
+
add_permissions_to_default_roles Role::ORG_ADMIN => plugin_permissions,
|
52
|
+
Role::MANAGER => plugin_permissions,
|
53
|
+
Role::SYSTEM_ADMIN => plugin_permissions
|
34
54
|
|
35
55
|
# Adding a sub menu after hosts menu
|
36
|
-
|
37
|
-
|
56
|
+
divider :top_menu, caption: N_('RH Cloud'), parent: :configure_menu
|
57
|
+
menu :top_menu, :inventory_upload, :caption => N_('Inventory Upload'), :url_hash => { controller: :'foreman_rh_cloud/react', :action => :inventory_upload}, parent: :configure_menu
|
58
|
+
menu :top_menu, :insights_hits_import, :caption => N_('Insights'), :url_hash => { controller: :'foreman_rh_cloud/react', :action => :insights_cloud }, parent: :configure_menu
|
59
|
+
|
60
|
+
register_facet InsightsFacet, :insights do
|
61
|
+
configure_host
|
38
62
|
end
|
63
|
+
|
64
|
+
register_global_js_file 'subscriptions_extension'
|
39
65
|
end
|
66
|
+
|
67
|
+
::Katello::UINotifications::Subscriptions::ManifestImportSuccess.include ForemanInventoryUpload::Notifications::ManifestImportSuccessNotificationOverride if defined?(Katello)
|
40
68
|
end
|
41
69
|
|
42
70
|
initializer "foreman_rh_cloud.set_dynflow.config.on_init", :before => :finisher_hook do |_app|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module InsightsCloud
|
2
|
+
def self.base_url
|
3
|
+
# for testing set ENV to 'https://ci.cloud.redhat.com'
|
4
|
+
@base_url ||= ENV['SATELLITE_INSIGHTS_CLOUD_URL'] || 'https://cloud.redhat.com'
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.authentication_url
|
8
|
+
# https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token
|
9
|
+
@authentication_url ||= ENV['SATELLITE_INSIGHTS_CLOUD_SSO_URL'] || 'https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token'
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.hits_export_url
|
13
|
+
base_url + '/api/insights/v1/export/hits/'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module InsightsCloud
|
4
|
+
module Async
|
5
|
+
class InsightsFullSync < ::ApplicationJob
|
6
|
+
def perform(organization)
|
7
|
+
@organization = organization
|
8
|
+
|
9
|
+
hits = query_insights_hits
|
10
|
+
|
11
|
+
host_names = hits.map { |hit| hit['hostname'] }.uniq
|
12
|
+
setup_host_names(host_names)
|
13
|
+
|
14
|
+
replace_hits_data(hits)
|
15
|
+
end
|
16
|
+
|
17
|
+
def logger
|
18
|
+
Foreman::Logging.logger('background')
|
19
|
+
end
|
20
|
+
|
21
|
+
def rh_credentials
|
22
|
+
@rh_credentials ||= query_refresh_token
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def query_insights_hits
|
28
|
+
hits_response = RestClient::Request.execute(
|
29
|
+
method: :get,
|
30
|
+
url: InsightsCloud.hits_export_url,
|
31
|
+
verify_ssl: ENV['SATELLITE_INSIGHTS_CLOUD_URL'] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER,
|
32
|
+
headers: {
|
33
|
+
Authorization: "Bearer #{rh_credentials}",
|
34
|
+
}
|
35
|
+
)
|
36
|
+
|
37
|
+
JSON.parse(hits_response)
|
38
|
+
end
|
39
|
+
|
40
|
+
def query_refresh_token
|
41
|
+
token_response = RestClient::Request.execute(
|
42
|
+
method: :post,
|
43
|
+
url: InsightsCloud.authentication_url,
|
44
|
+
verify_ssl: ENV['SATELLITE_INSIGHTS_CLOUD_URL'] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER,
|
45
|
+
payload: {
|
46
|
+
grant_type: 'refresh_token',
|
47
|
+
client_id: 'rhsm-api',
|
48
|
+
refresh_token: Setting[:rh_cloud_token],
|
49
|
+
}
|
50
|
+
)
|
51
|
+
|
52
|
+
JSON.parse(token_response)['access_token']
|
53
|
+
rescue RestClient::ExceptionWithResponse => e
|
54
|
+
Foreman::Logging.exception('Unable to authenticate using rh_cloud_token setting', e)
|
55
|
+
raise ::Foreman::WrappedException.new(e, N_('Unable to authenticate using rh_cloud_token setting'))
|
56
|
+
end
|
57
|
+
|
58
|
+
def setup_host_names(host_names)
|
59
|
+
@host_ids = Hash[
|
60
|
+
Host.where(name: host_names).pluck(:name, :id)
|
61
|
+
]
|
62
|
+
end
|
63
|
+
|
64
|
+
def host_id(host_name)
|
65
|
+
@host_ids[host_name]
|
66
|
+
end
|
67
|
+
|
68
|
+
def replace_hits_data(hits)
|
69
|
+
InsightsHit.transaction do
|
70
|
+
InsightsHit.delete_all
|
71
|
+
InsightsHit.create(hits.map { |hits_hash| to_model_hash(hits_hash) })
|
72
|
+
# create new facets for hosts that are missing one
|
73
|
+
hosts_with_existing_facets = InsightsFacet.where(host_id: @host_ids.values).pluck(:host_id)
|
74
|
+
InsightsFacet.create((@host_ids.values - hosts_with_existing_facets).map { |id| {host_id: id} })
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def to_model_hash(hit_hash)
|
79
|
+
{
|
80
|
+
host_id: host_id(hit_hash['hostname']),
|
81
|
+
last_seen: DateTime.parse(hit_hash['last_seen']),
|
82
|
+
publish_date: DateTime.parse(hit_hash['publish_date']),
|
83
|
+
title: hit_hash['title'],
|
84
|
+
solution_url: hit_hash['solution_url'],
|
85
|
+
total_risk: hit_hash['total_risk'].to_i,
|
86
|
+
likelihood: hit_hash['likelihood'].to_i,
|
87
|
+
results_url: hit_hash['results_url'],
|
88
|
+
}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -14,12 +14,17 @@ class AccountsControllerTest < ActionController::TestCase
|
|
14
14
|
upload_label = ForemanInventoryUpload::Async::UploadReportJob.output_label(test_org.id)
|
15
15
|
upload_output = ForemanInventoryUpload::Async::ProgressOutput.register(upload_label)
|
16
16
|
upload_output.status = 'upload_status_test'
|
17
|
+
FactoryBot.create(:setting, :name => 'allow_auto_inventory_upload', :value => true)
|
18
|
+
assert_equal true, Setting[:allow_auto_inventory_upload]
|
17
19
|
|
18
20
|
get :index, session: set_session_user
|
19
21
|
|
20
22
|
assert_response :success
|
21
|
-
actual = JSON.parse(response.body)
|
22
|
-
|
23
|
-
assert_equal '
|
23
|
+
actual = JSON.parse(response.body)
|
24
|
+
actual_account_statuses = actual['accounts'][test_org.id.to_s]
|
25
|
+
assert_equal 'generate_status_test', actual_account_statuses['generate_report_status']
|
26
|
+
assert_equal 'upload_status_test', actual_account_statuses['upload_report_status']
|
27
|
+
|
28
|
+
assert_equal true, actual['autoUploadEnabled']
|
24
29
|
end
|
25
30
|
end
|
@@ -18,4 +18,17 @@ class UploadsControllerTest < ActionController::TestCase
|
|
18
18
|
actual = JSON.parse(response.body)
|
19
19
|
assert_equal 'test output', actual['output']
|
20
20
|
end
|
21
|
+
|
22
|
+
test 'should update allow_auto_inventory_upload setting' do
|
23
|
+
FactoryBot.create(:setting, :name => 'allow_auto_inventory_upload', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => false)
|
24
|
+
|
25
|
+
assert_equal false, Setting[:allow_auto_inventory_upload]
|
26
|
+
|
27
|
+
post :auto_upload, params: { value: true }, session: set_session_user
|
28
|
+
|
29
|
+
assert_response :success
|
30
|
+
actual = JSON.parse(response.body)
|
31
|
+
assert_equal true, actual['autoUploadEnabled']
|
32
|
+
assert_equal true, Setting[:allow_auto_inventory_upload]
|
33
|
+
end
|
21
34
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class InsightsFullSyncTest < ActiveJob::TestCase
|
4
|
+
setup do
|
5
|
+
@host1 = FactoryBot.create(:host, :managed, name: 'host1')
|
6
|
+
@host2 = FactoryBot.create(:host, :managed, name: 'host2')
|
7
|
+
|
8
|
+
hits_json = <<-HITS_JSON
|
9
|
+
[
|
10
|
+
{
|
11
|
+
"hostname": "#{@host1.name}",
|
12
|
+
"rhel_version": "7.5",
|
13
|
+
"uuid": "accdf444-5628-451d-bf3e-cf909ad72756",
|
14
|
+
"last_seen": "2019-11-22T08:41:42.447244Z",
|
15
|
+
"title": "New Ansible Engine packages are inaccessible when dedicated Ansible repo is not enabled",
|
16
|
+
"solution_url": "",
|
17
|
+
"total_risk": 2,
|
18
|
+
"likelihood": 2,
|
19
|
+
"publish_date": "2018-04-16T10:03:16Z",
|
20
|
+
"results_url": "https://cloud.redhat.com/insights/overview/stability/ansible_deprecated_repo%7CANSIBLE_DEPRECATED_REPO/accdf444-5628-451d-bf3e-cf909ad72756/"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"hostname": "#{@host1.name}",
|
24
|
+
"rhel_version": "7.5",
|
25
|
+
"uuid": "accdf444-5628-451d-bf3e-cf909ad72756",
|
26
|
+
"last_seen": "2019-11-22T08:41:42.447244Z",
|
27
|
+
"title": "CPU vulnerable to side-channel attacks using Microarchitectural Data Sampling (CVE-2018-12130, CVE-2018-12126, CVE-2018-12127, CVE-2019-11091)",
|
28
|
+
"solution_url": "https://access.redhat.com/node/4134081",
|
29
|
+
"total_risk": 2,
|
30
|
+
"likelihood": 2,
|
31
|
+
"publish_date": "2019-05-14T17:00:00Z",
|
32
|
+
"results_url": "https://cloud.redhat.com/insights/overview/security/CVE_2018_12130_cpu_kernel%7CCVE_2018_12130_CPU_KERNEL_NEED_UPDATE/accdf444-5628-451d-bf3e-cf909ad72756/"
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"hostname": "#{@host2.name}",
|
36
|
+
"rhel_version": "7.5",
|
37
|
+
"uuid": "accdf444-5628-451d-bf3e-cf909ad72757",
|
38
|
+
"last_seen": "2019-11-22T08:41:42.447244Z",
|
39
|
+
"title": "CPU vulnerable to side-channel attacks using L1 Terminal Fault (CVE-2018-3620)",
|
40
|
+
"solution_url": "https://access.redhat.com/node/3560291",
|
41
|
+
"total_risk": 2,
|
42
|
+
"likelihood": 2,
|
43
|
+
"publish_date": "2018-08-14T17:00:00Z",
|
44
|
+
"results_url": "https://cloud.redhat.com/insights/overview/security/CVE_2018_3620_cpu_kernel%7CCVE_2018_3620_CPU_KERNEL_NEED_UPDATE/accdf444-5628-451d-bf3e-cf909ad72756/"
|
45
|
+
}
|
46
|
+
]
|
47
|
+
HITS_JSON
|
48
|
+
@hits = JSON.parse(hits_json)
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'Hits data is replaced with data from cloud' do
|
52
|
+
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).returns(@hits)
|
53
|
+
|
54
|
+
InsightsCloud::Async::InsightsFullSync.perform_now(@host1.organization)
|
55
|
+
|
56
|
+
@host1.reload
|
57
|
+
@host2.reload
|
58
|
+
|
59
|
+
assert_equal 2, @host1.insights.hits.count
|
60
|
+
assert_equal 1, @host2.insights.hits.count
|
61
|
+
end
|
62
|
+
end
|
@@ -49,6 +49,7 @@ class ArchivedReportGeneratorTest < ActiveSupport::TestCase
|
|
49
49
|
test_org = FactoryBot.create(:organization)
|
50
50
|
|
51
51
|
ForemanInventoryUpload::Generators::Queries.expects(:for_org).with(test_org.id).returns(batches)
|
52
|
+
ForemanInventoryUpload::Generators::Slice.any_instance.stubs(:golden_ticket?).returns(false)
|
52
53
|
Dir.mktmpdir do |tmpdir|
|
53
54
|
target = File.join(tmpdir, 'test.tar.gz')
|
54
55
|
generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class FactHelpersTest < ActiveSupport::TestCase
|
4
|
+
class FactsHelpersTestStub
|
5
|
+
include ForemanInventoryUpload::Generators::FactHelpers
|
6
|
+
end
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@instance = FactsHelpersTestStub.new
|
10
|
+
|
11
|
+
@org = FactoryBot.create(:organization)
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'golden_ticket uses golden_ticket method when defined' do
|
15
|
+
@org.expects(:golden_ticket?).returns(true)
|
16
|
+
|
17
|
+
actual = @instance.golden_ticket?(@org)
|
18
|
+
|
19
|
+
assert actual
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'golden_ticket uses content_access_mode method when golden_ticket not defined' do
|
23
|
+
@org.expects(:content_access_mode).returns('org_environment')
|
24
|
+
|
25
|
+
actual = @instance.golden_ticket?(@org)
|
26
|
+
|
27
|
+
assert actual
|
28
|
+
end
|
29
|
+
end
|
@@ -16,7 +16,9 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
16
16
|
organization: env.organization
|
17
17
|
)
|
18
18
|
|
19
|
-
@host.
|
19
|
+
@host.organization.pools << FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
|
20
|
+
|
21
|
+
ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
|
20
22
|
end
|
21
23
|
|
22
24
|
def interesting_facts
|
@@ -30,9 +32,17 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
30
32
|
'dmi::bios::vendor',
|
31
33
|
'dmi::bios::version',
|
32
34
|
'dmi::bios::relase_date',
|
33
|
-
'distribution::name',
|
34
35
|
'uname::release',
|
35
36
|
'lscpu::flags',
|
37
|
+
'distribution::name',
|
38
|
+
'distribution::version',
|
39
|
+
'distribution::id',
|
40
|
+
'virt::is_guest',
|
41
|
+
'dmi::system::manufacturer',
|
42
|
+
'dmi::system::product_name',
|
43
|
+
'dmi::chassis::asset_tag',
|
44
|
+
'insights_client::obfuscate_hostname_enabled',
|
45
|
+
'insights_client::hostname',
|
36
46
|
]
|
37
47
|
end
|
38
48
|
|
@@ -46,22 +56,80 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
46
56
|
|
47
57
|
test 'generates a report for a single host' do
|
48
58
|
batch = Host.where(id: @host.id).in_batches.first
|
49
|
-
generator =
|
59
|
+
generator = create_generator(batch)
|
50
60
|
|
51
61
|
json_str = generator.render
|
52
62
|
actual = JSON.parse(json_str.join("\n"))
|
53
63
|
|
54
64
|
assert_equal 'slice_123', actual['report_slice_id']
|
55
65
|
assert_not_nil(actual_host = actual['hosts'].first)
|
56
|
-
assert_equal @host.name, actual_host['display_name']
|
57
66
|
assert_equal @host.fqdn, actual_host['fqdn']
|
58
67
|
assert_equal '1234', actual_host['account']
|
68
|
+
assert_equal 1, generator.hosts_count
|
69
|
+
end
|
70
|
+
|
71
|
+
test 'obfuscates fqdn when instructed by insights-client' do
|
72
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['insights_client::obfuscate_hostname_enabled'], value: 'true', host: @host)
|
73
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['insights_client::hostname'], value: 'obfuscated_name', host: @host)
|
74
|
+
|
75
|
+
batch = Host.where(id: @host.id).in_batches.first
|
76
|
+
generator = create_generator(batch)
|
77
|
+
|
78
|
+
json_str = generator.render
|
79
|
+
actual = JSON.parse(json_str.join("\n"))
|
80
|
+
|
81
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
82
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
83
|
+
assert_equal 'obfuscated_name', actual_host['fqdn']
|
84
|
+
assert_equal '1234', actual_host['account']
|
85
|
+
assert_not_nil(actual_facts = actual_host['facts'].first['facts'])
|
86
|
+
assert_equal true, actual_facts['is_hostname_obfuscated']
|
87
|
+
assert_equal 1, generator.hosts_count
|
88
|
+
end
|
89
|
+
|
90
|
+
test 'obfuscates fqdn when setting set' do
|
91
|
+
FactoryBot.create(:setting, :name => 'obfuscate_inventory_hostnames', :value => true)
|
92
|
+
|
93
|
+
batch = Host.where(id: @host.id).in_batches.first
|
94
|
+
generator = create_generator(batch)
|
95
|
+
|
96
|
+
json_str = generator.render
|
97
|
+
actual = JSON.parse(json_str.join("\n"))
|
98
|
+
|
99
|
+
obfuscated_fqdn = Digest::SHA1.hexdigest(@host.fqdn)
|
100
|
+
|
101
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
102
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
103
|
+
assert_equal obfuscated_fqdn, actual_host['fqdn']
|
104
|
+
assert_equal '1234', actual_host['account']
|
105
|
+
assert_not_nil(actual_facts = actual_host['facts'].first['facts'])
|
106
|
+
assert_equal true, actual_facts['is_hostname_obfuscated']
|
107
|
+
assert_equal 1, generator.hosts_count
|
108
|
+
end
|
109
|
+
|
110
|
+
test 'does not obfuscate fqdn when insights-client sets to false' do
|
111
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['insights_client::obfuscate_hostname_enabled'], value: 'false', host: @host)
|
112
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['insights_client::hostname'], value: 'obfuscated_name', host: @host)
|
113
|
+
|
114
|
+
batch = Host.where(id: @host.id).in_batches.first
|
115
|
+
generator = create_generator(batch)
|
116
|
+
|
117
|
+
json_str = generator.render
|
118
|
+
actual = JSON.parse(json_str.join("\n"))
|
119
|
+
|
120
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
121
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
122
|
+
assert_equal @host.fqdn, actual_host['fqdn']
|
123
|
+
assert_equal '1234', actual_host['account']
|
124
|
+
assert_not_nil(actual_facts = actual_host['facts'].first['facts'])
|
125
|
+
assert_equal false, actual_facts['is_hostname_obfuscated']
|
126
|
+
assert_equal 1, generator.hosts_count
|
59
127
|
end
|
60
128
|
|
61
129
|
test 'generates a report with satellite facts' do
|
62
130
|
Foreman.expects(:instance_id).twice.returns('satellite-id')
|
63
131
|
batch = Host.where(id: @host.id).in_batches.first
|
64
|
-
generator =
|
132
|
+
generator = create_generator(batch)
|
65
133
|
|
66
134
|
json_str = generator.render
|
67
135
|
actual = JSON.parse(json_str.join("\n"))
|
@@ -78,7 +146,8 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
78
146
|
|
79
147
|
org_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'organization_id'}
|
80
148
|
assert_not_nil org_id_tag
|
81
|
-
assert_equal @host.organization_id, org_id_tag['value']
|
149
|
+
assert_equal @host.organization_id.to_s, org_id_tag['value']
|
150
|
+
assert_equal false, satellite_facts['is_hostname_obfuscated']
|
82
151
|
|
83
152
|
version = satellite_facts['satellite_version']
|
84
153
|
if defined?(ForemanThemeSatellite)
|
@@ -102,14 +171,13 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
102
171
|
@host.save!
|
103
172
|
|
104
173
|
batch = Host.where(id: @host.id).in_batches.first
|
105
|
-
generator =
|
174
|
+
generator = create_generator(batch)
|
106
175
|
|
107
176
|
json_str = generator.render
|
108
177
|
actual = JSON.parse(json_str.join("\n"))
|
109
178
|
|
110
179
|
assert_equal 'slice_123', actual['report_slice_id']
|
111
180
|
assert_not_nil(actual_host = actual['hosts'].first)
|
112
|
-
assert_equal @host.name, actual_host['display_name']
|
113
181
|
assert_equal @host.fqdn, actual_host['fqdn']
|
114
182
|
assert_not_nil(host_facts = actual_host['facts']&.first)
|
115
183
|
assert_equal 'satellite', host_facts['namespace']
|
@@ -124,14 +192,13 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
124
192
|
@host.subscription_facet.save!
|
125
193
|
|
126
194
|
batch = Host.where(id: @host.id).in_batches.first
|
127
|
-
generator =
|
195
|
+
generator = create_generator(batch)
|
128
196
|
|
129
197
|
json_str = generator.render
|
130
198
|
actual = JSON.parse(json_str.join("\n"))
|
131
199
|
|
132
200
|
assert_equal 'slice_123', actual['report_slice_id']
|
133
201
|
assert_not_nil(actual_host = actual['hosts'].first)
|
134
|
-
assert_equal @host.name, actual_host['display_name']
|
135
202
|
assert_equal @host.fqdn, actual_host['fqdn']
|
136
203
|
assert_not_nil(host_facts = actual_host['facts']&.first)
|
137
204
|
assert_equal 'satellite', host_facts['namespace']
|
@@ -140,6 +207,22 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
140
207
|
assert_equal 'test_role', fact_values['system_purpose_role']
|
141
208
|
end
|
142
209
|
|
210
|
+
test 'generates a report for a golden ticket' do
|
211
|
+
batch = Host.where(id: @host.id).in_batches.first
|
212
|
+
generator = create_generator(batch) do |generator|
|
213
|
+
generator.stubs(:golden_ticket?).returns(true)
|
214
|
+
end
|
215
|
+
|
216
|
+
json_str = generator.render
|
217
|
+
actual = JSON.parse(json_str.join("\n"))
|
218
|
+
|
219
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
220
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
221
|
+
assert_equal @host.fqdn, actual_host['fqdn']
|
222
|
+
assert_equal '1234', actual_host['account']
|
223
|
+
assert_equal 1, generator.hosts_count
|
224
|
+
end
|
225
|
+
|
143
226
|
test 'skips hosts without subscription' do
|
144
227
|
a_host = FactoryBot.create(
|
145
228
|
:host,
|
@@ -148,23 +231,23 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
148
231
|
|
149
232
|
# make a_host last
|
150
233
|
batch = Host.where(id: [@host.id, a_host.id]).order(:name).in_batches.first
|
151
|
-
generator =
|
234
|
+
generator = create_generator(batch)
|
152
235
|
|
153
236
|
json_str = generator.render
|
154
237
|
actual = JSON.parse(json_str.join("\n"))
|
155
238
|
|
156
239
|
assert_equal 'slice_123', actual['report_slice_id']
|
157
240
|
assert_not_nil(actual_host = actual['hosts'].first)
|
158
|
-
assert_equal @host.name, actual_host['display_name']
|
159
241
|
assert_equal @host.fqdn, actual_host['fqdn']
|
160
242
|
assert_equal '1234', actual_host['account']
|
243
|
+
assert_equal 1, generator.hosts_count
|
161
244
|
end
|
162
245
|
|
163
246
|
test 'shows system_memory_bytes in bytes' do
|
164
247
|
FactoryBot.create(:fact_value, fact_name: fact_names['memory::memtotal'], value: '1', host: @host)
|
165
248
|
|
166
249
|
batch = Host.where(id: @host.id).in_batches.first
|
167
|
-
generator =
|
250
|
+
generator = create_generator(batch)
|
168
251
|
|
169
252
|
json_str = generator.render
|
170
253
|
actual = JSON.parse(json_str.join("\n"))
|
@@ -174,4 +257,157 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
174
257
|
assert_not_nil(actual_profile = actual_host['system_profile'])
|
175
258
|
assert_equal 1024, actual_profile['system_memory_bytes']
|
176
259
|
end
|
260
|
+
|
261
|
+
test 'reports an account for hosts with multiple pools' do
|
262
|
+
first_pool = @host.organization.pools.first
|
263
|
+
second_pool = FactoryBot.create(:katello_pool, account_number: nil, cp_id: 2)
|
264
|
+
new_org = FactoryBot.create(:organization, pools: [first_pool, second_pool])
|
265
|
+
@host.organization = new_org
|
266
|
+
@host.save!
|
267
|
+
|
268
|
+
batch = Host.where(id: @host.id).in_batches.first
|
269
|
+
generator = create_generator(batch)
|
270
|
+
|
271
|
+
json_str = generator.render
|
272
|
+
actual = JSON.parse(json_str.join("\n"))
|
273
|
+
|
274
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
275
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
276
|
+
assert_not_nil(actual_host['account'])
|
277
|
+
assert_not_empty(actual_host['account'])
|
278
|
+
end
|
279
|
+
|
280
|
+
test 'Generates os_release with version and id' do
|
281
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['distribution::name'], value: 'Red Hat Test Linux', host: @host)
|
282
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['distribution::version'], value: '7.1', host: @host)
|
283
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['distribution::id'], value: 'TestId', host: @host)
|
284
|
+
|
285
|
+
batch = Host.where(id: @host.id).in_batches.first
|
286
|
+
generator = create_generator(batch)
|
287
|
+
|
288
|
+
json_str = generator.render
|
289
|
+
actual = JSON.parse(json_str.join("\n"))
|
290
|
+
|
291
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
292
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
293
|
+
assert_not_nil(actual_profile = actual_host['system_profile'])
|
294
|
+
assert_equal 'Red Hat Test Linux 7.1 (TestId)', actual_profile['os_release']
|
295
|
+
end
|
296
|
+
|
297
|
+
test 'sets infrastructure_type to "virtual" based on virt.is_guest fact' do
|
298
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['virt::is_guest'], value: true, host: @host)
|
299
|
+
|
300
|
+
batch = Host.where(id: @host.id).in_batches.first
|
301
|
+
generator = create_generator(batch)
|
302
|
+
|
303
|
+
json_str = generator.render
|
304
|
+
actual = JSON.parse(json_str.join("\n"))
|
305
|
+
|
306
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
307
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
308
|
+
assert_not_nil(actual_profile = actual_host['system_profile'])
|
309
|
+
assert_equal 'virtual', actual_profile['infrastructure_type']
|
310
|
+
end
|
311
|
+
|
312
|
+
test 'sets infrastructure_type to "physical" based on virt.is_guest fact' do
|
313
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['virt::is_guest'], value: false, host: @host)
|
314
|
+
|
315
|
+
batch = Host.where(id: @host.id).in_batches.first
|
316
|
+
generator = create_generator(batch)
|
317
|
+
|
318
|
+
json_str = generator.render
|
319
|
+
actual = JSON.parse(json_str.join("\n"))
|
320
|
+
|
321
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
322
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
323
|
+
assert_not_nil(actual_profile = actual_host['system_profile'])
|
324
|
+
assert_equal 'physical', actual_profile['infrastructure_type']
|
325
|
+
end
|
326
|
+
|
327
|
+
test 'Identifies Amazon cloud provider' do
|
328
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['dmi::bios::version'], value: 'Test Amazon version', host: @host)
|
329
|
+
|
330
|
+
batch = Host.where(id: @host.id).in_batches.first
|
331
|
+
generator = create_generator(batch)
|
332
|
+
|
333
|
+
json_str = generator.render
|
334
|
+
actual = JSON.parse(json_str.join("\n"))
|
335
|
+
|
336
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
337
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
338
|
+
assert_not_nil(actual_profile = actual_host['system_profile'])
|
339
|
+
assert_equal 'aws', actual_profile['cloud_provider']
|
340
|
+
end
|
341
|
+
|
342
|
+
test 'Identifies Google cloud provider' do
|
343
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['dmi::bios::version'], value: 'Test Google version', host: @host)
|
344
|
+
|
345
|
+
batch = Host.where(id: @host.id).in_batches.first
|
346
|
+
generator = create_generator(batch)
|
347
|
+
|
348
|
+
json_str = generator.render
|
349
|
+
actual = JSON.parse(json_str.join("\n"))
|
350
|
+
|
351
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
352
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
353
|
+
assert_not_nil(actual_profile = actual_host['system_profile'])
|
354
|
+
assert_equal 'google', actual_profile['cloud_provider']
|
355
|
+
end
|
356
|
+
|
357
|
+
test 'Identifies Azure cloud provider' do
|
358
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['dmi::chassis::asset_tag'], value: '7783-7084-3265-9085-8269-3286-77', host: @host)
|
359
|
+
|
360
|
+
batch = Host.where(id: @host.id).in_batches.first
|
361
|
+
generator = create_generator(batch)
|
362
|
+
|
363
|
+
json_str = generator.render
|
364
|
+
actual = JSON.parse(json_str.join("\n"))
|
365
|
+
|
366
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
367
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
368
|
+
assert_not_nil(actual_profile = actual_host['system_profile'])
|
369
|
+
assert_equal 'azure', actual_profile['cloud_provider']
|
370
|
+
end
|
371
|
+
|
372
|
+
test 'Identifies Alibaba cloud provider via manufacturer' do
|
373
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['dmi::system::manufacturer'], value: 'Test Alibaba Cloud version', host: @host)
|
374
|
+
|
375
|
+
batch = Host.where(id: @host.id).in_batches.first
|
376
|
+
generator = create_generator(batch)
|
377
|
+
|
378
|
+
json_str = generator.render
|
379
|
+
actual = JSON.parse(json_str.join("\n"))
|
380
|
+
|
381
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
382
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
383
|
+
assert_not_nil(actual_profile = actual_host['system_profile'])
|
384
|
+
assert_equal 'alibaba', actual_profile['cloud_provider']
|
385
|
+
end
|
386
|
+
|
387
|
+
test 'Identifies Alibaba cloud provider via product name' do
|
388
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['dmi::system::product_name'], value: 'Test Alibaba Cloud ECS product', host: @host)
|
389
|
+
|
390
|
+
batch = Host.where(id: @host.id).in_batches.first
|
391
|
+
generator = create_generator(batch)
|
392
|
+
|
393
|
+
json_str = generator.render
|
394
|
+
actual = JSON.parse(json_str.join("\n"))
|
395
|
+
|
396
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
397
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
398
|
+
assert_not_nil(actual_profile = actual_host['system_profile'])
|
399
|
+
assert_equal 'alibaba', actual_profile['cloud_provider']
|
400
|
+
end
|
401
|
+
|
402
|
+
private
|
403
|
+
|
404
|
+
def create_generator(batch, name = 'slice_123')
|
405
|
+
generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], name)
|
406
|
+
if block_given?
|
407
|
+
yield(generator)
|
408
|
+
else
|
409
|
+
generator.stubs(:golden_ticket?).returns(false)
|
410
|
+
end
|
411
|
+
generator
|
412
|
+
end
|
177
413
|
end
|