foreman_rh_cloud 2.0.11 → 3.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +2 -0
  3. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +18 -0
  4. data/app/helpers/foreman_inventory_upload_host_helper.rb +2 -10
  5. data/app/models/concerns/rh_cloud_host.rb +4 -1
  6. data/app/models/insights_hit.rb +1 -1
  7. data/app/models/setting/rh_cloud.rb +2 -0
  8. data/app/overrides/hosts_list.rb +1 -1
  9. data/app/services/foreman_rh_cloud/cloud_auth.rb +28 -0
  10. data/app/views/foreman_rh_cloud/react/insights_cloud.html.erb +1 -6
  11. data/app/views/foreman_rh_cloud/react/inventory_upload.html.erb +1 -1
  12. data/app/views/hosts/_insights_tab.html.erb +1 -7
  13. data/app/views/layouts/foreman_rh_cloud/application.html.erb +0 -1
  14. data/config/routes.rb +2 -0
  15. data/db/migrate/20201007115752_add_hits_count_to_insights_facets_table.foreman_rh_cloud.rb +5 -0
  16. data/db/migrate/20201007121540_setup_hits_count_cache.foreman_rh_cloud.rb +10 -0
  17. data/lib/foreman_inventory_upload/async/upload_report_job.rb +2 -32
  18. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +35 -0
  19. data/lib/foreman_inventory_upload/generators/json_stream.rb +7 -2
  20. data/lib/foreman_inventory_upload/generators/queries.rb +2 -0
  21. data/lib/foreman_inventory_upload/generators/slice.rb +27 -25
  22. data/lib/foreman_rh_cloud.rb +55 -0
  23. data/lib/foreman_rh_cloud/engine.rb +6 -4
  24. data/lib/foreman_rh_cloud/version.rb +1 -1
  25. data/lib/insights_cloud/async/insights_full_sync.rb +5 -24
  26. data/lib/inventory_sync/async/inventory_full_sync.rb +3 -22
  27. data/lib/tasks/rh_cloud_inventory.rake +12 -10
  28. data/package.json +1 -1
  29. data/test/unit/fact_helpers_test.rb +22 -0
  30. data/test/unit/insights_facet_test.rb +7 -0
  31. data/test/unit/rh_cloud_http_proxy_test.rb +65 -0
  32. data/test/unit/slice_generator_test.rb +147 -2
  33. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +14 -1
  34. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +22 -18
  35. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +16 -0
  36. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +6 -0
  37. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +7 -0
  38. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +12 -8
  39. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +9 -0
  40. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +19 -0
  41. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +11 -0
  42. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +6 -0
  43. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.fixtures.js +2 -0
  44. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.js +1 -1
  45. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherActions.js +10 -11
  46. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherConstants.js +0 -1
  47. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcherActions.test.js +12 -2
  48. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcher.test.js.snap +1 -1
  49. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcherActions.test.js.snap +17 -0
  50. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcher.fixtures.js +1 -0
  51. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcher.js +30 -0
  52. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcherActions.js +29 -0
  53. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcherConstants.js +1 -0
  54. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/ExcludePackagesSwitcher.test.js +13 -0
  55. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/ExcludePackagesSwitcherActions.test.js +21 -0
  56. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/ExcludePackagesSwitcher.test.js.snap +38 -0
  57. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/ExcludePackagesSwitcherActions.test.js.snap +31 -0
  58. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/integration.test.js.snap +41 -0
  59. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/integration.test.js +36 -0
  60. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/excludePackagesSwitcher.scss +3 -0
  61. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/index.js +20 -0
  62. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.fixtures.js +2 -1
  63. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.js +1 -0
  64. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.scss +3 -0
  65. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherActions.js +10 -11
  66. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherConstants.js +0 -2
  67. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcherActions.test.js +12 -2
  68. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcherActions.test.js.snap +18 -1
  69. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.js +4 -0
  70. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettings.test.js.snap +2 -0
  71. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcher.fixtures.js +1 -0
  72. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcher.js +29 -0
  73. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcherActions.js +29 -0
  74. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcherConstants.js +1 -0
  75. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/IpsObfuscationSwitcher.test.js +13 -0
  76. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/IpsObfuscationSwitcherActions.test.js +21 -0
  77. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/__snapshots__/IpsObfuscationSwitcher.test.js.snap +38 -0
  78. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/__snapshots__/IpsObfuscationSwitcherActions.test.js.snap +31 -0
  79. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/index.js +20 -0
  80. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButton.js +8 -2
  81. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +9 -11
  82. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonConstants.js +1 -1
  83. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonReducer.js +2 -2
  84. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonActions.test.js +18 -0
  85. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonReducer.test.js +1 -8
  86. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonActions.test.js.snap +62 -0
  87. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonReducer.test.js.snap +0 -7
  88. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Modal.js +2 -2
  89. data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeader.js +6 -1
  90. data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +2 -4
  91. data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +8 -0
  92. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/InventoryAutoUpload.js +92 -0
  93. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/InventoryAutoUpload.test.js +17 -0
  94. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/__snapshots__/InventoryAutoUpload.test.js.snap +106 -0
  95. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/components/AdvancedSettings/AdvancedSettings.js +60 -0
  96. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/components/AdvancedSettings/index.js +28 -0
  97. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/index.js +22 -0
  98. data/webpack/ForemanRhCloudFills.js +23 -0
  99. data/webpack/ForemanRhCloudPages.js +6 -1
  100. data/webpack/ForemanRhCloudReducers.js +10 -1
  101. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsActions.js +17 -20
  102. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsConstants.js +0 -6
  103. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsReducer.js +0 -4
  104. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js +16 -0
  105. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsReducer.test.js +1 -24
  106. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsActions.test.js.snap +38 -4
  107. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsReducer.test.js.snap +0 -14
  108. data/webpack/InsightsCloudSync/InsightsCloudSync.js +3 -5
  109. data/webpack/InsightsCloudSync/InsightsCloudSync.test.js +1 -3
  110. data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +10 -11
  111. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +0 -2
  112. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +1 -1
  113. data/webpack/InsightsHostDetailsTab/InsightsTab.js +13 -13
  114. data/webpack/InsightsHostDetailsTab/InsightsTab.scss +2 -2
  115. data/webpack/InsightsHostDetailsTab/InsightsTabActions.js +9 -8
  116. data/webpack/InsightsHostDetailsTab/InsightsTabConstants.js +0 -1
  117. data/webpack/InsightsHostDetailsTab/InsightsTabReducer.js +2 -9
  118. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTab.fixtures.js +12 -14
  119. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabActions.test.js +7 -1
  120. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabReducer.test.js +0 -9
  121. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTab.test.js.snap +26 -22
  122. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabActions.test.js.snap +38 -2
  123. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabReducer.test.js.snap +10 -19
  124. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabSelectors.test.js.snap +10 -12
  125. data/webpack/__mocks__/foremanReact/common/MountingService.js +1 -0
  126. data/webpack/common/Switcher/index.js +79 -0
  127. data/webpack/global_index.js +5 -0
  128. data/webpack/index.js +4 -14
  129. metadata +54 -20
  130. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/hostObfuscationSwitcher.scss +0 -0
  131. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/SubscriptionsPageExtensionActions.js +0 -34
  132. data/webpack/subscriptions_extension_index.js +0 -8
@@ -13,6 +13,7 @@ module ForemanRhCloud
13
13
  config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
14
14
  config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
15
15
  config.autoload_paths += Dir["#{config.root}/app/overrides"]
16
+ config.autoload_paths += Dir["#{config.root}/app/services"]
16
17
  config.autoload_paths += Dir["#{config.root}/lib"]
17
18
 
18
19
  config.eager_load_paths += Dir["#{config.root}/lib"]
@@ -26,7 +27,7 @@ module ForemanRhCloud
26
27
 
27
28
  initializer 'foreman_rh_cloud.register_plugin', :before => :finisher_hook do |_app|
28
29
  Foreman::Plugin.register :foreman_rh_cloud do
29
- requires_foreman '> 1.24'
30
+ requires_foreman '>= 2.3'
30
31
 
31
32
  # Add permissions
32
33
  security_block :foreman_rh_cloud do
@@ -54,8 +55,8 @@ module ForemanRhCloud
54
55
 
55
56
  # Adding a sub menu after hosts menu
56
57
  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
58
+ menu :top_menu, :inventory_upload, caption: N_('Inventory Upload'), url_hash: { controller: :'foreman_rh_cloud/react', action: :inventory_upload }, parent: :configure_menu
59
+ menu :top_menu, :insights_hits_import, caption: N_('Insights'), url_hash: { controller: :'foreman_rh_cloud/react', action: :insights_cloud }, parent: :configure_menu
59
60
 
60
61
  register_facet InsightsFacet, :insights do
61
62
  configure_host do
@@ -63,7 +64,7 @@ module ForemanRhCloud
63
64
  end
64
65
  end
65
66
 
66
- register_global_js_file 'subscriptions_extension'
67
+ register_global_js_file 'global'
67
68
 
68
69
  register_custom_status(InventorySync::InventoryStatus)
69
70
 
@@ -71,6 +72,7 @@ module ForemanRhCloud
71
72
  context.add_pagelet :main_tabs,
72
73
  partial: 'hosts/insights_tab',
73
74
  name: _('Insights'),
75
+ id: 'insights',
74
76
  onlyif: proc { |host| host.insights }
75
77
  end
76
78
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '2.0.11'.freeze
2
+ VERSION = '3.0.14'.freeze
3
3
  end
@@ -3,6 +3,8 @@ require 'rest-client'
3
3
  module InsightsCloud
4
4
  module Async
5
5
  class InsightsFullSync < ::ApplicationJob
6
+ include ::ForemanRhCloud::CloudAuth
7
+
6
8
  def perform
7
9
  hits = query_insights_hits
8
10
 
@@ -16,10 +18,6 @@ module InsightsCloud
16
18
  Foreman::Logging.logger('background')
17
19
  end
18
20
 
19
- def rh_credentials
20
- @rh_credentials ||= query_refresh_token
21
- end
22
-
23
21
  private
24
22
 
25
23
  def query_insights_hits
@@ -27,6 +25,7 @@ module InsightsCloud
27
25
  method: :get,
28
26
  url: InsightsCloud.hits_export_url,
29
27
  verify_ssl: ForemanRhCloud.verify_ssl_method,
28
+ proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
30
29
  headers: {
31
30
  Authorization: "Bearer #{rh_credentials}",
32
31
  }
@@ -35,24 +34,6 @@ module InsightsCloud
35
34
  JSON.parse(hits_response)
36
35
  end
37
36
 
38
- def query_refresh_token
39
- token_response = RestClient::Request.execute(
40
- method: :post,
41
- url: ForemanRhCloud.authentication_url,
42
- verify_ssl: ForemanRhCloud.verify_ssl_method,
43
- payload: {
44
- grant_type: 'refresh_token',
45
- client_id: 'rhsm-api',
46
- refresh_token: Setting[:rh_cloud_token],
47
- }
48
- )
49
-
50
- JSON.parse(token_response)['access_token']
51
- rescue RestClient::ExceptionWithResponse => e
52
- Foreman::Logging.exception('Unable to authenticate using rh_cloud_token setting', e)
53
- raise ::Foreman::WrappedException.new(e, N_('Unable to authenticate using rh_cloud_token setting'))
54
- end
55
-
56
37
  def setup_host_names(host_names)
57
38
  @host_ids = Hash[
58
39
  Host.unscoped.where(name: host_names).pluck(:name, :id)
@@ -65,8 +46,6 @@ module InsightsCloud
65
46
 
66
47
  def replace_hits_data(hits)
67
48
  InsightsHit.transaction do
68
- InsightsHit.delete_all
69
- InsightsHit.create(hits.map { |hits_hash| to_model_hash(hits_hash) }.compact)
70
49
  # create new facets for hosts that are missing one
71
50
  hosts_with_existing_facets = InsightsFacet.where(host_id: @host_ids.values).pluck(:host_id)
72
51
  InsightsFacet.create(
@@ -79,6 +58,8 @@ module InsightsCloud
79
58
  end
80
59
  end.compact
81
60
  )
61
+ InsightsHit.delete_all
62
+ InsightsHit.create(hits.map { |hits_hash| to_model_hash(hits_hash) }.compact)
82
63
  end
83
64
  end
84
65
 
@@ -3,6 +3,8 @@ require 'rest-client'
3
3
  module InventorySync
4
4
  module Async
5
5
  class InventoryFullSync < ::ApplicationJob
6
+ include ::ForemanRhCloud::CloudAuth
7
+
6
8
  def perform(organization)
7
9
  @organization = organization
8
10
  @subscribed_hosts_ids = Set.new(
@@ -37,10 +39,6 @@ module InventorySync
37
39
  @host_statuses
38
40
  end
39
41
 
40
- def rh_credentials
41
- @rh_credentials ||= query_refresh_token
42
- end
43
-
44
42
  private
45
43
 
46
44
  def update_hosts_status(status_hashes, touched)
@@ -65,6 +63,7 @@ module InventorySync
65
63
  method: :get,
66
64
  url: ForemanInventoryUpload.inventory_export_url,
67
65
  verify_ssl: ForemanRhCloud.verify_ssl_method,
66
+ proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
68
67
  headers: {
69
68
  Authorization: "Bearer #{rh_credentials}",
70
69
  params: {
@@ -76,24 +75,6 @@ module InventorySync
76
75
 
77
76
  JSON.parse(hosts_inventory_response)
78
77
  end
79
-
80
- def query_refresh_token
81
- token_response = RestClient::Request.execute(
82
- method: :post,
83
- url: ForemanRhCloud.authentication_url,
84
- verify_ssl: ForemanRhCloud.verify_ssl_method,
85
- payload: {
86
- grant_type: 'refresh_token',
87
- client_id: 'rhsm-api',
88
- refresh_token: Setting[:rh_cloud_token],
89
- }
90
- )
91
-
92
- JSON.parse(token_response)['access_token']
93
- rescue RestClient::ExceptionWithResponse => e
94
- Foreman::Logging.exception('Unable to authenticate using rh_cloud_token setting', e)
95
- raise ::Foreman::WrappedException.new(e, N_('Unable to authenticate using rh_cloud_token setting'))
96
- end
97
78
  end
98
79
  end
99
80
  end
@@ -12,17 +12,19 @@ namespace :rh_cloud_inventory do
12
12
  puts "Must specify either portal_user or organization_id"
13
13
  end
14
14
 
15
- if portal_user
16
- puts "Generating report for all organizations associated with #{portal_user}"
17
- base_folder = File.join(base_folder, portal_user)
18
- organizations = ForemanInventoryUpload::Generators::Queries.organizations_for_user(portal_user).pluck(:id)
19
- end
15
+ User.as_anonymous_admin do
16
+ if portal_user
17
+ puts "Generating report for all organizations associated with #{portal_user}"
18
+ base_folder = File.join(base_folder, portal_user)
19
+ organizations = ForemanInventoryUpload::Generators::Queries.organizations_for_user(portal_user).pluck(:id)
20
+ end
20
21
 
21
- organizations.each do |organization|
22
- target = File.join(base_folder, ForemanInventoryUpload.facts_archive_name(organization))
23
- archived_report_generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
24
- archived_report_generator.render(organization: organization)
25
- puts "Successfully generated #{target} for organization id #{organization}"
22
+ organizations.each do |organization|
23
+ target = File.join(base_folder, ForemanInventoryUpload.facts_archive_name(organization))
24
+ archived_report_generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
25
+ archived_report_generator.render(organization: organization)
26
+ puts "Successfully generated #{target} for organization id #{organization}"
27
+ end
26
28
  end
27
29
  end
28
30
  end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "2.0.11",
3
+ "version": "3.0.14",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,4 +26,26 @@ class FactHelpersTest < ActiveSupport::TestCase
26
26
 
27
27
  assert actual
28
28
  end
29
+
30
+ test 'obfuscates ips with insights-client data' do
31
+ host = mock('host')
32
+ @instance.expects(:fact_value).with(host, 'insights_client::ips').returns(
33
+ '[{"obfuscated": "10.230.230.1", "original": "224.0.0.1"}, {"obfuscated": "10.230.230.2", "original": "224.0.0.251"}]'
34
+ )
35
+
36
+ actual = @instance.obfuscated_ips(host)
37
+
38
+ assert_equal '10.230.230.1', actual['224.0.0.1']
39
+ assert_equal '10.230.230.3', actual['224.0.0.2']
40
+ end
41
+
42
+ test 'obfuscates ips without insights-client data' do
43
+ host = mock('host')
44
+ @instance.expects(:fact_value).with(host, 'insights_client::ips').returns(nil)
45
+
46
+ actual = @instance.obfuscated_ips(host)
47
+
48
+ assert_equal '10.230.230.1', actual['224.0.0.1']
49
+ assert_equal '10.230.230.2', actual['224.0.0.2']
50
+ end
29
51
  end
@@ -3,6 +3,7 @@ require 'test_plugin_helper'
3
3
  class InsightsFacetTest < ActiveSupport::TestCase
4
4
  setup do
5
5
  @host = FactoryBot.create(:host, :with_insights_hits)
6
+ InsightsFacet.reset_counters(@host.insights.id, :hits_count)
6
7
  end
7
8
 
8
9
  test 'host with hits can be deleted' do
@@ -13,4 +14,10 @@ class InsightsFacetTest < ActiveSupport::TestCase
13
14
  actual_host = Host.find_by_id(host_id)
14
15
  assert_nil actual_host
15
16
  end
17
+
18
+ test 'search host by recommendations_count' do
19
+ FactoryBot.create(:host) # create another host with no recommendations
20
+
21
+ assert_equal 1, Host.search_for('insights_recommendations_count = 1').count
22
+ end
16
23
  end
@@ -0,0 +1,65 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class RhCloudHttpProxyTest < ActiveSupport::TestCase
4
+ setup do
5
+ @global_content_proxy_mock = 'http://global:content@localhost:8888'
6
+ @global_foreman_proxy_mock = 'http://global:foreman@localhost:8888'
7
+ @katello_cdn_proxy_mock = {
8
+ host: 'localhost',
9
+ port: '8888',
10
+ user: 'katello',
11
+ password: 'cdn',
12
+ scheme: 'http',
13
+ }
14
+ @katello_cdn_proxy_string_mock = 'http://katello:cdn@localhost:8888'
15
+ end
16
+
17
+ test 'selects global content proxy' do
18
+ setup_global_content_proxy
19
+ setup_global_foreman_proxy
20
+ setup_cdn_proxy do
21
+ assert_equal @global_content_proxy_mock, ForemanRhCloud.proxy_setting
22
+ end
23
+ end
24
+
25
+ test 'selects cdn proxy' do
26
+ setup_global_foreman_proxy
27
+ setup_cdn_proxy do
28
+ assert_equal @katello_cdn_proxy_string_mock, ForemanRhCloud.proxy_setting
29
+ end
30
+ end
31
+
32
+ test 'selects global foreman proxy' do
33
+ setup_global_foreman_proxy
34
+
35
+ assert_equal @global_foreman_proxy_mock, ForemanRhCloud.proxy_setting
36
+ end
37
+
38
+ def setup_global_content_proxy
39
+ http_proxy = FactoryBot.create(:http_proxy, url: @global_content_proxy_mock)
40
+ HttpProxy.stubs(:default_global_content_proxy).returns(http_proxy)
41
+ end
42
+
43
+ def setup_global_foreman_proxy
44
+ FactoryBot.create(:setting, :name => 'http_proxy', :value => @global_foreman_proxy_mock)
45
+ end
46
+
47
+ def setup_cdn_proxy
48
+ old_cdn_setting = SETTINGS[:katello][:cdn_proxy]
49
+ SETTINGS[:katello][:cdn_proxy] = @katello_cdn_proxy_mock
50
+ yield
51
+ ensure
52
+ SETTINGS[:katello][:cdn_proxy] = old_cdn_setting
53
+ end
54
+
55
+ test 'transform proxy scheme test' do
56
+ mock_http_proxy = 'http://user:password@localhost:8888'
57
+ mock_https_proxy = 'https://user:password@localhost:8888'
58
+
59
+ transformed_http_uri = URI.parse(ForemanRhCloud.transform_scheme(mock_http_proxy))
60
+ transformed_https_uri = URI.parse(ForemanRhCloud.transform_scheme(mock_https_proxy))
61
+
62
+ assert_equal 'proxy', transformed_http_uri.scheme
63
+ assert_equal 'proxys', transformed_https_uri.scheme
64
+ end
65
+ end
@@ -1,6 +1,6 @@
1
1
  require 'test_plugin_helper'
2
2
 
3
- class ReportGeneratorTest < ActiveSupport::TestCase
3
+ class SliceGeneratorTest < ActiveSupport::TestCase
4
4
  setup do
5
5
  User.current = User.find_by(login: 'secret_admin')
6
6
 
@@ -44,6 +44,8 @@ class ReportGeneratorTest < ActiveSupport::TestCase
44
44
  'dmi::chassis::asset_tag',
45
45
  'insights_client::obfuscate_hostname_enabled',
46
46
  'insights_client::hostname',
47
+ 'insights_client::obfuscate_ip_enabled',
48
+ 'insights_client::ips',
47
49
  ]
48
50
  end
49
51
 
@@ -69,10 +71,62 @@ class ReportGeneratorTest < ActiveSupport::TestCase
69
71
  assert_equal @host.fqdn, actual_host['fqdn']
70
72
  assert_equal '1234', actual_host['account']
71
73
  assert_equal 1, generator.hosts_count
74
+ assert_not_nil(actual_system_profile = actual_host['system_profile'])
75
+ assert_nil actual_system_profile['number_of_cpus']
76
+ assert_nil actual_system_profile['number_of_sockets']
77
+ assert_nil actual_system_profile['cores_per_socket']
78
+ assert_nil actual_system_profile['system_memory_bytes']
79
+ assert_nil actual_system_profile['os_release']
80
+ assert_not_nil(actual_network_interfaces = actual_system_profile['network_interfaces'])
81
+ assert_not_nil(actual_nic = actual_network_interfaces.first)
82
+ refute actual_nic.key?('mtu')
83
+ refute actual_nic.key?('mac_address')
84
+ refute actual_nic.key?('name')
85
+ end
86
+
87
+ test 'hosts report fields should be present if fact exist' do
88
+ FactoryBot.create(:fact_value, fact_name: fact_names['cpu::cpu(s)'], value: '4', host: @host)
89
+ FactoryBot.create(:fact_value, fact_name: fact_names['cpu::cpu_socket(s)'], value: '2', host: @host)
90
+ FactoryBot.create(:fact_value, fact_name: fact_names['cpu::core(s)_per_socket'], value: '1', host: @host)
91
+
92
+ batch = Host.where(id: @host.id).in_batches.first
93
+ generator = create_generator(batch)
94
+
95
+ json_str = generator.render
96
+ actual = JSON.parse(json_str.join("\n"))
97
+
98
+ assert_equal 'slice_123', actual['report_slice_id']
99
+ assert_not_nil(actual_host = actual['hosts'].first)
100
+ assert_not_nil(actual_system_profile = actual_host['system_profile'])
101
+ assert_equal 4, actual_system_profile['number_of_cpus']
102
+ assert_equal 2, actual_system_profile['number_of_sockets']
103
+ assert_equal 1, actual_system_profile['cores_per_socket']
72
104
  end
73
105
 
74
106
  test 'generates ip_address and mac_address fields' do
75
- @host.interfaces << FactoryBot.build(:nic_managed)
107
+ nic = FactoryBot.build(:nic_managed)
108
+ nic.attrs['mtu'] = '1500'
109
+ @host.interfaces << nic
110
+ batch = Host.where(id: @host.id).in_batches.first
111
+ generator = create_generator(batch)
112
+
113
+ json_str = generator.render
114
+ actual = JSON.parse(json_str.join("\n"))
115
+
116
+ assert_equal 'slice_123', actual['report_slice_id']
117
+ assert_not_nil(actual_host = actual['hosts'].first)
118
+ assert_equal @host.interfaces.where.not(ip: nil).first.ip, actual_host['ip_addresses'].first
119
+ assert_equal @host.interfaces.where.not(mac: nil).first.mac, actual_host['mac_addresses'].first
120
+ assert_equal @host.fqdn, actual_host['fqdn']
121
+ assert_equal '1234', actual_host['account']
122
+ assert_equal 1, generator.hosts_count
123
+ end
124
+
125
+ test 'generates nic fields' do
126
+ ip6 = Array.new(4) { '%x' % rand(16**4) }.join(':') + '::' + '5'
127
+ nic = FactoryBot.build(:nic_managed, ip6: ip6)
128
+ nic.attrs['mtu'] = '1500'
129
+ @host.interfaces << nic
76
130
  batch = Host.where(id: @host.id).in_batches.first
77
131
  generator = create_generator(batch)
78
132
 
@@ -83,6 +137,66 @@ class ReportGeneratorTest < ActiveSupport::TestCase
83
137
  assert_not_nil(actual_host = actual['hosts'].first)
84
138
  assert_equal @host.interfaces.where.not(ip: nil).first.ip, actual_host['ip_addresses'].first
85
139
  assert_equal @host.interfaces.where.not(mac: nil).first.mac, actual_host['mac_addresses'].first
140
+ assert_not_nil(actual_system_profile = actual_host['system_profile'])
141
+ assert_not_nil(actual_network_interfaces = actual_system_profile['network_interfaces'])
142
+ assert_not_nil(actual_nic = actual_network_interfaces.first)
143
+ assert_equal nic.ip, actual_nic['ipv4_addresses'].first
144
+ assert_equal nic.ip6, actual_nic['ipv6_addresses'].first
145
+ assert_equal 1500, actual_nic['mtu']
146
+ assert_equal nic.mac, actual_nic['mac_address']
147
+ assert_equal nic.identifier, actual_nic['name']
148
+ assert_equal @host.fqdn, actual_host['fqdn']
149
+ assert_equal '1234', actual_host['account']
150
+ assert_equal 1, generator.hosts_count
151
+ end
152
+
153
+ test 'generates obfuscated ip_address fields without inisghts-client' do
154
+ FactoryBot.create(:setting, :name => 'obfuscate_inventory_ips', :value => true)
155
+
156
+ @host.interfaces << FactoryBot.build(:nic_managed)
157
+ batch = Host.where(id: @host.id).in_batches.first
158
+ generator = create_generator(batch)
159
+
160
+ json_str = generator.render
161
+ actual = JSON.parse(json_str.join("\n"))
162
+
163
+ assert_equal 'slice_123', actual['report_slice_id']
164
+ assert_not_nil(actual_host = actual['hosts'].first)
165
+ assert_equal '10.230.230.1', actual_host['ip_addresses'].first
166
+ assert_not_nil(actual_system_profile = actual_host['system_profile'])
167
+ assert_not_nil(actual_network_interfaces = actual_system_profile['network_interfaces'])
168
+ assert_not_nil(actual_nic = actual_network_interfaces.first)
169
+ assert_equal '10.230.230.1', actual_nic['ipv4_addresses'].first
170
+ assert_equal @host.fqdn, actual_host['fqdn']
171
+ assert_equal '1234', actual_host['account']
172
+ assert_equal 1, generator.hosts_count
173
+ end
174
+
175
+ test 'generates obfuscated ip_address fields with inisghts-client' do
176
+ nic = FactoryBot.build(:nic_managed)
177
+ @host.interfaces << nic
178
+
179
+ FactoryBot.create(:fact_value, fact_name: fact_names['insights_client::obfuscate_ip_enabled'], value: 'true', host: @host)
180
+ FactoryBot.create(
181
+ :fact_value,
182
+ fact_name: fact_names['insights_client::ips'],
183
+ value: "[{\"obfuscated\": \"10.230.230.100\", \"original\": \"#{nic.ip}\"}]",
184
+ host: @host
185
+ )
186
+
187
+ batch = Host.where(id: @host.id).in_batches.first
188
+ generator = create_generator(batch)
189
+
190
+ json_str = generator.render
191
+ actual = JSON.parse(json_str.join("\n"))
192
+
193
+ assert_equal 'slice_123', actual['report_slice_id']
194
+ assert_not_nil(actual_host = actual['hosts'].first)
195
+ assert_equal '10.230.230.100', actual_host['ip_addresses'].first
196
+ assert_not_nil(actual_system_profile = actual_host['system_profile'])
197
+ assert_not_nil(actual_network_interfaces = actual_system_profile['network_interfaces'])
198
+ assert_not_nil(actual_nic = actual_network_interfaces.first)
199
+ assert_equal '10.230.230.100', actual_nic['ipv4_addresses'].first
86
200
  assert_equal @host.fqdn, actual_host['fqdn']
87
201
  assert_equal '1234', actual_host['account']
88
202
  assert_equal 1, generator.hosts_count
@@ -147,6 +261,10 @@ class ReportGeneratorTest < ActiveSupport::TestCase
147
261
  end
148
262
 
149
263
  test 'generates a report with satellite facts' do
264
+ hostgroup = FactoryBot.create(:hostgroup)
265
+ @host.hostgroup = hostgroup
266
+ @host.save!
267
+
150
268
  Foreman.expects(:instance_id).twice.returns('satellite-id')
151
269
  batch = Host.where(id: @host.id).in_batches.first
152
270
  generator = create_generator(batch)
@@ -166,6 +284,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
166
284
  assert_tag(@host.content_view.name, actual_host, 'content_view')
167
285
  assert_tag(@host.location.name, actual_host, 'location')
168
286
  assert_tag(@host.organization.name, actual_host, 'organization')
287
+ assert_tag(@host.hostgroup.name, actual_host, 'hostgroup')
169
288
 
170
289
  assert_equal false, satellite_facts['is_hostname_obfuscated']
171
290
 
@@ -444,6 +563,32 @@ class ReportGeneratorTest < ActiveSupport::TestCase
444
563
  assert_equal 'alibaba', actual_profile['cloud_provider']
445
564
  end
446
565
 
566
+ test 'include packages installed in the report' do
567
+ FactoryBot.create(:setting, :name => 'exclude_installed_packages', :value => false)
568
+ installed_package = ::Katello::InstalledPackage.create(name: 'test-package', nvrea: 'test-package-1.0.x86_64', nvra: 'test-package-1.0.x86_64')
569
+
570
+ another_host = FactoryBot.create(
571
+ :host,
572
+ :with_subscription,
573
+ :with_content,
574
+ content_view: @host.content_view,
575
+ lifecycle_environment: @host.lifecycle_environment,
576
+ organization: @host.organization,
577
+ installed_packages: [installed_package]
578
+ )
579
+
580
+ batch = Host.where(id: another_host.id).in_batches.first
581
+ generator = create_generator(batch)
582
+
583
+ json_str = generator.render
584
+ actual = JSON.parse(json_str.join("\n"))
585
+
586
+ assert_equal 'slice_123', actual['report_slice_id']
587
+ assert_not_nil(actual_host = actual['hosts'].first)
588
+ assert_not_nil(actual_profile = actual_host['system_profile'])
589
+ assert_not_nil(actual_profile['installed_packages'])
590
+ end
591
+
447
592
  private
448
593
 
449
594
  def create_generator(batch, name = 'slice_123')