foreman_rh_cloud 4.0.23 → 4.0.25.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_inventory_upload/cloud_status_controller.rb +26 -0
  3. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +15 -7
  4. data/app/controllers/insights_cloud/hits_controller.rb +0 -1
  5. data/app/models/insights_client_report_status.rb +11 -22
  6. data/app/services/foreman_rh_cloud/cloud_auth.rb +4 -0
  7. data/app/services/foreman_rh_cloud/cloud_ping_service.rb +83 -0
  8. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +1 -9
  9. data/app/services/foreman_rh_cloud/insights_status_cleaner.rb +17 -0
  10. data/app/services/foreman_rh_cloud/remediations_retriever.rb +5 -0
  11. data/config/Gemfile.lock.gh_test +0 -8
  12. data/config/rh_cert-api_chain.pem +74 -0
  13. data/config/routes.rb +2 -0
  14. data/db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb +6 -0
  15. data/lib/foreman_inventory_upload.rb +9 -1
  16. data/lib/foreman_inventory_upload/generators/queries.rb +1 -16
  17. data/lib/foreman_inventory_upload/generators/slice.rb +1 -0
  18. data/lib/foreman_inventory_upload/generators/tags.rb +3 -1
  19. data/lib/foreman_rh_cloud.rb +4 -0
  20. data/lib/foreman_rh_cloud/engine.rb +14 -12
  21. data/lib/foreman_rh_cloud/version.rb +1 -1
  22. data/lib/insights_cloud.rb +4 -0
  23. data/lib/insights_cloud/async/insights_client_status_aging.rb +23 -0
  24. data/lib/insights_cloud/async/insights_full_sync.rb +5 -0
  25. data/lib/insights_cloud/async/insights_resolutions_sync.rb +9 -0
  26. data/lib/insights_cloud/async/insights_rules_sync.rb +5 -0
  27. data/lib/inventory_sync/async/host_result.rb +4 -0
  28. data/lib/inventory_sync/async/inventory_full_sync.rb +5 -0
  29. data/lib/inventory_sync/async/inventory_hosts_sync.rb +15 -0
  30. data/lib/inventory_sync/async/inventory_self_host_sync.rb +39 -0
  31. data/lib/inventory_sync/async/query_inventory_job.rb +5 -1
  32. data/lib/tasks/insights.rake +15 -0
  33. data/lib/tasks/rh_cloud_inventory.rake +2 -9
  34. data/package.json +2 -2
  35. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +45 -0
  36. data/test/controllers/inventory_upload/cloud_status_controller_test.rb +44 -0
  37. data/test/jobs/insights_client_status_aging_test.rb +33 -0
  38. data/test/jobs/insights_full_sync_test.rb +1 -0
  39. data/test/jobs/insights_resolutions_sync_test.rb +1 -0
  40. data/test/jobs/insights_rules_sync_test.rb +1 -0
  41. data/test/jobs/inventory_full_sync_test.rb +10 -0
  42. data/test/jobs/inventory_hosts_sync_test.rb +3 -0
  43. data/test/jobs/inventory_self_host_sync_test.rb +104 -0
  44. data/test/models/insights_client_report_status_test.rb +70 -72
  45. data/test/test_plugin_helper.rb +53 -0
  46. data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +6 -37
  47. data/test/unit/services/foreman_rh_cloud/cloud_status_service_test.rb +66 -0
  48. data/test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb +31 -0
  49. data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +1 -0
  50. data/test/unit/slice_generator_test.rb +15 -0
  51. data/test/unit/tags_generator_test.rb +41 -0
  52. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/EmptyState.js +1 -1
  53. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/__snapshots__/EmptyState.test.js.snap +1 -2
  54. data/webpack/ForemanInventoryUpload/Components/FileDownload/FileDownload.js +3 -1
  55. data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/__snapshots__/FileDownload.test.js.snap +2 -1
  56. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.js +1 -2
  57. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterConstants.js +3 -1
  58. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.scss +0 -4
  59. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageTitle.js +12 -0
  60. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageTitle.test.js.snap +10 -0
  61. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudPingModal/index.js +144 -0
  62. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudPingModal/index.scss +5 -0
  63. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +2 -2
  64. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Modal.js +1 -1
  65. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Toast.js +2 -2
  66. data/webpack/ForemanInventoryUpload/Components/StatusChart/StatusChart.js +4 -3
  67. data/webpack/ForemanInventoryUpload/ForemanInventoryConstants.js +2 -0
  68. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/InventoryAutoUpload.js +3 -1
  69. data/webpack/InsightsCloudSync/Components/InsightsHeader/InsightsHeader.scss +5 -1
  70. data/webpack/InsightsCloudSync/Components/InsightsHeader/index.js +6 -4
  71. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettings.js +9 -5
  72. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettings.test.js.snap +6 -6
  73. data/webpack/InsightsCloudSync/Components/InsightsSettings/insightsSettings.scss +0 -14
  74. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +4 -22
  75. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableConstants.js +25 -4
  76. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableSelectors.js +0 -3
  77. data/webpack/InsightsCloudSync/Components/InsightsTable/Pagination.js +51 -0
  78. data/webpack/InsightsCloudSync/Components/InsightsTable/SelectAllAlert.js +1 -1
  79. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +3 -68
  80. data/webpack/InsightsCloudSync/Components/InsightsTable/table.scss +10 -0
  81. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js +11 -10
  82. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +14 -0
  83. data/webpack/InsightsCloudSync/Components/RemediationModal/index.js +0 -2
  84. data/webpack/InsightsCloudSync/Components/ToolbarDropdown.js +32 -0
  85. data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/InsightsHeader.test.js.snap +5 -4
  86. data/webpack/InsightsCloudSync/InsightsCloudSync.js +17 -13
  87. data/webpack/InsightsCloudSync/InsightsCloudSync.scss +82 -2
  88. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +15 -6
  89. data/webpack/InsightsHostDetailsTab/InsightsTab.js +3 -2
  90. data/webpack/InsightsHostDetailsTab/InsightsTab.scss +4 -4
  91. data/webpack/InsightsHostDetailsTab/components/ListItem/ListItem.js +9 -7
  92. data/webpack/common/Switcher/SwitcherPF4.js +1 -1
  93. data/webpack/common/Switcher/SwitcherPF4.scss +6 -7
  94. data/webpack/common/Switcher/__tests__/__snapshots__/SwitcherPF4.test.js.snap +1 -1
  95. metadata +23 -24
  96. data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +0 -9
  97. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/InsightsSyncSwitcher.fixtures.js +0 -1
  98. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/InsightsSyncSwitcher.js +0 -45
  99. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/__tests__/InsightsSyncSwitcher.test.js +0 -17
  100. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/__tests__/__snapshots__/InsightsSyncSwitcher.test.js.snap +0 -38
  101. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/index.js +0 -1
  102. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/insightsSyncSwitcher.scss +0 -3
  103. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +0 -59
@@ -49,6 +49,7 @@ module ForemanInventoryUpload
49
49
  @stream.simple_field('satellite_id', uuid_value!(host.subscription_facet&.uuid))
50
50
  @stream.simple_field('bios_uuid', bios_uuid(host))
51
51
  @stream.simple_field('vm_uuid', uuid_value(fact_value(host, 'virt::uuid')))
52
+ @stream.simple_field('insights_id', uuid_value(fact_value(host, 'insights_id')))
52
53
  report_ip_addresses(host, host_ips_cache)
53
54
  report_mac_addresses(host)
54
55
  @stream.object_field('system_profile') do
@@ -19,7 +19,9 @@ module ForemanInventoryUpload
19
19
  def generate_parameters
20
20
  return [] unless Setting[:include_parameter_tags]
21
21
 
22
- (@host.host_inherited_params_objects || []).map { |item| [item.name, item.value] }
22
+ (@host.host_inherited_params_objects || [])
23
+ .map { |item| [item.name, item.value] }
24
+ .select { |_name, value| value.present? || value.is_a?(FalseClass) }
23
25
  end
24
26
 
25
27
  private
@@ -100,4 +100,8 @@ module ForemanRhCloud
100
100
  def self.foreman_host
101
101
  @foreman_host ||= ::Host.unscoped.friendly.find(ENV['SATELLITE_RH_CLOUD_FOREMAN_HOST'] || ::SmartProxy.default_capsule.name)
102
102
  end
103
+
104
+ def self.legacy_insights_ca
105
+ "#{ForemanRhCloud::Engine.root}/config/rh_cert-api_chain.pem"
106
+ end
103
107
  end
@@ -1,11 +1,22 @@
1
1
  require 'katello'
2
- require 'redhat_access'
3
2
  require 'foreman_ansible'
4
3
 
5
4
  module ForemanRhCloud
6
5
  class Engine < ::Rails::Engine
7
6
  engine_name 'foreman_rh_cloud'
8
7
 
8
+ def self.register_scheduled_task(task_class, cronline)
9
+ return if ForemanTasks::RecurringLogic.joins(:tasks)
10
+ .merge(ForemanTasks::Task.where(label: task_class.name))
11
+ .exists?
12
+
13
+ User.as_anonymous_admin do
14
+ recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline(cronline)
15
+ recurring_logic.save!
16
+ recurring_logic.start(task_class)
17
+ end
18
+ end
19
+
9
20
  initializer 'foreman_rh_cloud.load_default_settings', :before => :load_config_initializers do
10
21
  require_dependency File.expand_path('../../app/models/setting/rh_cloud.rb', __dir__)
11
22
  end
@@ -81,8 +92,6 @@ module ForemanRhCloud
81
92
  register_custom_status InventorySync::InventoryStatus
82
93
  register_custom_status InsightsClientReportStatus
83
94
 
84
- subscribe 'host_created.event.foreman', ForemanRhCloud::InsightsSubscriber
85
-
86
95
  describe_host do
87
96
  overview_buttons_provider :insights_host_overview_buttons
88
97
  end
@@ -138,15 +147,8 @@ module ForemanRhCloud
138
147
  # skip object creation when admin user is not present, for example in test DB
139
148
  if User.unscoped.find_by_login(User::ANONYMOUS_ADMIN).present?
140
149
  ::ForemanTasks.dynflow.config.on_init(false) do |world|
141
- unless ForemanTasks::RecurringLogic.joins(:tasks).merge(
142
- ForemanTasks::Task.where(label: 'InventorySync::Async::InventoryScheduledSync')
143
- ).exists?
144
- User.as_anonymous_admin do
145
- recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline("0 0 * * *")
146
- recurring_logic.save!
147
- recurring_logic.start(InventorySync::Async::InventoryScheduledSync)
148
- end
149
- end
150
+ ForemanRhCloud::Engine.register_scheduled_task(InventorySync::Async::InventoryScheduledSync, '0 0 * * *')
151
+ ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsClientStatusAging, '0 0 * * *')
150
152
  end
151
153
  end
152
154
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '4.0.23'.freeze
2
+ VERSION = '4.0.25.1'.freeze
3
3
  end
@@ -28,4 +28,8 @@ module InsightsCloud
28
28
  def self.remediation_rule_id(rule_id)
29
29
  "advisor:#{rule_id}"
30
30
  end
31
+
32
+ def self.enable_client_param
33
+ 'host_registration_insights'
34
+ end
31
35
  end
@@ -0,0 +1,23 @@
1
+ module InsightsCloud
2
+ module Async
3
+ class InsightsClientStatusAging < ::Actions::EntryAction
4
+ include ::Actions::RecurringAction
5
+
6
+ def run
7
+ host_ids = InsightsClientReportStatus.stale.reporting.pluck(:host_id)
8
+
9
+ # update all stale records
10
+ InsightsClientReportStatus.where(host_id: host_ids).update_all(status: InsightsClientReportStatus::NO_REPORT)
11
+
12
+ # refresh global status
13
+ Host.where(id: host_ids).preload(:host_statuses).find_in_batches do |hosts|
14
+ hosts.each { |host| host.refresh_global_status! }
15
+ end
16
+ end
17
+
18
+ def logger
19
+ action_logger
20
+ end
21
+ end
22
+ end
23
+ end
@@ -6,6 +6,11 @@ module InsightsCloud
6
6
  include ::ForemanRhCloud::CloudAuth
7
7
 
8
8
  def plan
9
+ unless cloud_auth_available?
10
+ logger.debug('Cloud authentication is not available, skipping insights sync')
11
+ return
12
+ end
13
+
9
14
  sequence do
10
15
  # This can be turned off when we enable automatic status syncs
11
16
  # This step will query cloud inventory to retrieve inventory uuids for each host
@@ -7,6 +7,15 @@ module InsightsCloud
7
7
 
8
8
  RULE_ID_REGEX = /[^:]*:(?<id>.*)/
9
9
 
10
+ def plan
11
+ unless cloud_auth_available?
12
+ logger.debug('Cloud authentication is not available, skipping resolutions sync')
13
+ return
14
+ end
15
+
16
+ plan_self
17
+ end
18
+
10
19
  def run
11
20
  InsightsResolution.transaction do
12
21
  InsightsResolution.delete_all
@@ -6,6 +6,11 @@ module InsightsCloud
6
6
  include ::ForemanRhCloud::CloudAuth
7
7
 
8
8
  def plan
9
+ unless cloud_auth_available?
10
+ logger.debug('Cloud authentication is not available, skipping rules sync')
11
+ return
12
+ end
13
+
9
14
  plan_self
10
15
  plan_resolutions
11
16
  end
@@ -1,6 +1,8 @@
1
1
  module InventorySync
2
2
  module Async
3
3
  class HostResult
4
+ attr_reader :uuid_by_fqdn
5
+
4
6
  def initialize(result)
5
7
  @total = result['total']
6
8
  @count = result['count']
@@ -8,6 +10,7 @@ module InventorySync
8
10
  @per_page = result['per_page']
9
11
  @sub_ids = result["results"].map { |host| host['subscription_manager_id'] }
10
12
  @uuid_by_sub_id = Hash[result["results"].map { |host| [host['subscription_manager_id'], host['id']] }]
13
+ @uuid_by_fqdn = Hash[result["results"].map { |host| [host['fqdn'].downcase, host['id']] }]
11
14
  end
12
15
 
13
16
  def status_hashes
@@ -19,6 +22,7 @@ module InventorySync
19
22
  host_id: host_id,
20
23
  status: InventorySync::InventoryStatus::SYNC,
21
24
  reported_at: DateTime.current,
25
+ type: InventorySync::InventoryStatus.name,
22
26
  }
23
27
  end
24
28
  end.compact
@@ -5,6 +5,11 @@ module InventorySync
5
5
  set_callback :step, :around, :update_statuses_batch
6
6
 
7
7
  def plan(organization)
8
+ unless cloud_auth_available?
9
+ logger.debug('Cloud authentication is not available, skipping inventory hosts sync')
10
+ return
11
+ end
12
+
8
13
  plan_self(organization_id: organization.id)
9
14
  end
10
15
 
@@ -4,6 +4,17 @@ module InventorySync
4
4
  set_callback :iteration, :around, :setup_facet_transaction
5
5
  set_callback :step, :around, :create_facets
6
6
 
7
+ def plan
8
+ unless cloud_auth_available?
9
+ logger.debug('Cloud authentication is not available, skipping inventory hosts sync')
10
+ return
11
+ end
12
+
13
+ # by default the tasks will be executed concurrently
14
+ plan_self
15
+ plan_self_host_sync
16
+ end
17
+
7
18
  def setup_facet_transaction
8
19
  InsightsFacet.transaction do
9
20
  yield
@@ -33,6 +44,10 @@ module InventorySync
33
44
  InsightsFacet.where(host_id: host_id).update_all(uuid: uuids_hash[host_id])
34
45
  end
35
46
  end
47
+
48
+ def plan_self_host_sync
49
+ plan_action InventorySync::Async::InventorySelfHostSync
50
+ end
36
51
  end
37
52
  end
38
53
  end
@@ -0,0 +1,39 @@
1
+ module InventorySync
2
+ module Async
3
+ class InventorySelfHostSync < QueryInventoryJob
4
+ set_callback :step, :around, :create_facets
5
+
6
+ def plan
7
+ unless cloud_auth_available?
8
+ logger.debug('Cloud authentication is not available, skipping self host sync')
9
+ return
10
+ end
11
+
12
+ plan_self
13
+ end
14
+
15
+ def create_facets
16
+ # get the results from the event
17
+ results = yield
18
+
19
+ add_missing_insights_facet(results.uuid_by_fqdn) unless results.uuid_by_fqdn.empty?
20
+ results
21
+ end
22
+
23
+ private
24
+
25
+ def add_missing_insights_facet(uuids_hash)
26
+ facet = InsightsFacet.find_or_create_by(host_id: ForemanRhCloud.foreman_host.id) do |facet|
27
+ facet.uuid = uuids_hash.values.first
28
+ end
29
+
30
+ # fix empty uuid in case the facet already exists
31
+ facet.update(uuid: uuids_hash.values.first) unless facet.uuid
32
+ end
33
+
34
+ def request_url
35
+ ForemanInventoryUpload.inventory_self_url
36
+ end
37
+ end
38
+ end
39
+ end
@@ -31,7 +31,7 @@ module InventorySync
31
31
  def query_inventory(page = 1)
32
32
  hosts_inventory_response = execute_cloud_request(
33
33
  method: :get,
34
- url: ForemanInventoryUpload.inventory_export_url,
34
+ url: request_url,
35
35
  headers: {
36
36
  params: {
37
37
  per_page: 100,
@@ -46,6 +46,10 @@ module InventorySync
46
46
  def logger
47
47
  action_logger
48
48
  end
49
+
50
+ def request_url
51
+ ForemanInventoryUpload.inventory_export_url
52
+ end
49
53
  end
50
54
  end
51
55
  end
@@ -4,4 +4,19 @@ namespace :rh_cloud_insights do
4
4
  ForemanTasks.sync_task(InsightsCloud::Async::InsightsFullSync)
5
5
  puts "Synchronized Insights hosts hits data"
6
6
  end
7
+
8
+ desc "Remove insights client report statuses by searching on host criteria"
9
+ task clean_statuses: [:environment] do
10
+ hosts_search = ENV['SEARCH']
11
+
12
+ if hosts_search.empty?
13
+ puts 'Must specify SEARCH= criteria for hosts search'
14
+ next
15
+ end
16
+
17
+ cleaner = ForemanRhCloud::InsightsStatusCleaner.new
18
+ deleted_count = cleaner.clean(hosts_search)
19
+
20
+ puts "Deleted #{deleted_count} insights statuses"
21
+ end
7
22
  end
@@ -19,7 +19,6 @@ namespace :rh_cloud_inventory do
19
19
  end
20
20
  desc 'Generate inventory report to be sent to Red Hat cloud'
21
21
  task generate: :environment do
22
- portal_user = ENV['portal_user']
23
22
  organizations = [ENV['organization_id']]
24
23
  base_folder = ENV['target'] || Dir.pwd
25
24
 
@@ -29,18 +28,12 @@ namespace :rh_cloud_inventory do
29
28
  puts "Using #{base_folder} for the output"
30
29
  end
31
30
 
32
- if portal_user.empty? && organizations.empty?
33
- puts "Must specify either portal_user or organization_id"
31
+ if organizations.empty?
32
+ puts "Must specify organization_id"
34
33
  return
35
34
  end
36
35
 
37
36
  User.as_anonymous_admin do
38
- if portal_user
39
- puts "Generating report for all organizations associated with #{portal_user}"
40
- base_folder = File.join(base_folder, portal_user)
41
- organizations = ForemanInventoryUpload::Generators::Queries.organizations_for_user(portal_user).pluck(:id)
42
- end
43
-
44
37
  organizations.each do |organization|
45
38
  target = File.join(base_folder, ForemanInventoryUpload.facts_archive_name(organization))
46
39
  archived_report_generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "4.0.23",
3
+ "version": "4.0.25.1",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -45,4 +45,4 @@
45
45
  "jed": "~1.1.1",
46
46
  "react-intl": "~2.8.0"
47
47
  }
48
- }
48
+ }
@@ -2,6 +2,10 @@ require 'test_plugin_helper'
2
2
 
3
3
  module InsightsCloud::Api
4
4
  class MachineTelemetriesControllerTest < ActionController::TestCase
5
+ setup do
6
+ FactoryBot.create(:common_parameter, name: InsightsCloud.enable_client_param, key_type: 'boolean', value: true)
7
+ end
8
+
5
9
  context '#forward_request' do
6
10
  setup do
7
11
  @body = 'Cloud response body'
@@ -11,6 +15,39 @@ module InsightsCloud::Api
11
15
  host = FactoryBot.create(:host, :with_subscription, :organization => org)
12
16
  User.current = ::Katello::CpConsumerUser.new(:uuid => host.subscription_facet.uuid, :login => host.subscription_facet.uuid)
13
17
  InsightsCloud::Api::MachineTelemetriesController.any_instance.stubs(:upstream_owner).returns({ 'uuid' => 'abcdefg' })
18
+
19
+ @cert1 = "-----BEGIN CERTIFICATE-----\r\n" +
20
+ "M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HD4Bsul65+hHZ9QywKU26F1A6TLkYpQ2rk/Dx9LGICM4m4IlHjWJPFsQdtkyOor\r\n" +
49
+ "osxMtcaZZ1E=\r\n" +
50
+ "-----END CERTIFICATE-----"
14
51
  end
15
52
 
16
53
  test "should respond with response from cloud" do
@@ -30,6 +67,14 @@ module InsightsCloud::Api
30
67
  ::ForemanRhCloud::CloudRequestForwarder.any_instance.expects(:execute_cloud_request).with do |opts|
31
68
  opts[:headers][:content_type] == 'application/json'
32
69
  end.returns(res)
70
+ InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:candlepin_id_cert)
71
+ .returns(
72
+ {
73
+ cert: @cert1,
74
+ key: OpenSSL::PKey::RSA.new(1024).to_pem,
75
+ }
76
+ )
77
+ InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:cp_owner_id).returns('123')
33
78
 
34
79
  post :forward_request, as: :json, params: { "path" => "static/v1/test", "machine_telemetry" => {"foo" => "bar"} }
35
80
  assert_equal @body, @response.body
@@ -0,0 +1,44 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class CloudStatusControllerTest < ActionController::TestCase
4
+ include MockCerts
5
+ tests ForemanInventoryUpload::CloudStatusController
6
+
7
+ test 'return ping status hash for each organization' do
8
+ organizations = FactoryBot.create_list(:organization, 2)
9
+ user = users(:admin)
10
+ User.stubs(:current).returns(user)
11
+ user.stubs(:my_organizations).returns(organizations)
12
+
13
+ ForemanRhCloud::CloudPingService::TokenPing.any_instance.expects(:execute_cloud_request).returns(
14
+ RestClient::Response.new('TEST RESPONSE')
15
+ )
16
+
17
+ setup_certs_expectation do
18
+ ForemanRhCloud::CloudPingService::CertPing.any_instance.expects(:candlepin_id_cert).with { |actual| actual.id == organizations[0].id }
19
+ end
20
+ ForemanRhCloud::CloudPingService::CertPing.any_instance.expects(:execute_cloud_request).returns(
21
+ RestClient::Response.new('TEST RESPONSE ORG 0')
22
+ )
23
+
24
+ setup_certs_expectation do
25
+ ForemanRhCloud::CloudPingService::CertPing.any_instance.expects(:candlepin_id_cert).with { |actual| actual.id == organizations[1].id }
26
+ end
27
+
28
+ ForemanRhCloud::CloudPingService::CertPing.any_instance.expects(:execute_cloud_request).returns(
29
+ RestClient::Response.new('TEST RESPONSE ORG 1')
30
+ )
31
+
32
+ get :index, session: set_session_user
33
+
34
+ assert_response :success
35
+ actual = JSON.parse(response.body)
36
+ assert_not_nil (actual_ping = actual['ping'])
37
+ assert actual_ping['token_auth']['success']
38
+ assert_nil actual_ping['token_auth']['error']
39
+ assert actual_ping['cert_auth'][0]['success']
40
+ assert_nil actual_ping['cert_auth'][0]['error']
41
+ assert actual_ping['cert_auth'][1]['success']
42
+ assert_nil actual_ping['cert_auth'][1]['error']
43
+ end
44
+ end