foreman_rh_cloud 3.0.26 → 4.0.21.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_inventory_upload/reports_controller.rb +1 -3
  3. data/app/controllers/foreman_inventory_upload/tasks_controller.rb +13 -5
  4. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +4 -4
  5. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +3 -6
  6. data/app/controllers/insights_cloud/hits_controller.rb +3 -7
  7. data/app/models/insights_client_report_status.rb +22 -11
  8. data/app/services/foreman_rh_cloud/cloud_auth.rb +0 -16
  9. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +14 -11
  10. data/app/services/foreman_rh_cloud/remediations_retriever.rb +4 -6
  11. data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +9 -0
  12. data/config/Gemfile.lock.gh_test +95 -93
  13. data/config/routes.rb +1 -20
  14. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +0 -19
  15. data/lib/foreman_inventory_upload/generators/queries.rb +0 -1
  16. data/lib/foreman_inventory_upload/generators/slice.rb +5 -6
  17. data/lib/foreman_inventory_upload/generators/tags.rb +1 -3
  18. data/lib/foreman_inventory_upload.rb +1 -9
  19. data/lib/foreman_rh_cloud/engine.rb +10 -17
  20. data/lib/foreman_rh_cloud/version.rb +1 -1
  21. data/lib/insights_cloud/async/insights_full_sync.rb +14 -9
  22. data/lib/insights_cloud/async/insights_resolutions_sync.rb +6 -13
  23. data/lib/insights_cloud/async/insights_rules_sync.rb +9 -13
  24. data/lib/inventory_sync/async/host_result.rb +0 -4
  25. data/lib/inventory_sync/async/inventory_full_sync.rb +1 -7
  26. data/lib/inventory_sync/async/inventory_hosts_sync.rb +2 -21
  27. data/lib/inventory_sync/async/inventory_scheduled_sync.rb +0 -12
  28. data/lib/inventory_sync/async/query_inventory_job.rb +5 -6
  29. data/lib/tasks/insights.rake +0 -15
  30. data/lib/tasks/rh_cloud_inventory.rake +1 -8
  31. data/package.json +1 -1
  32. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +0 -41
  33. data/test/factories/inventory_upload_factories.rb +1 -1
  34. data/test/jobs/insights_full_sync_test.rb +0 -1
  35. data/test/jobs/insights_resolutions_sync_test.rb +1 -11
  36. data/test/jobs/insights_rules_sync_test.rb +0 -1
  37. data/test/jobs/inventory_full_sync_test.rb +0 -10
  38. data/test/models/insights_client_report_status_test.rb +72 -70
  39. data/test/test_plugin_helper.rb +0 -2
  40. data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +3 -4
  41. data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +0 -1
  42. data/test/unit/slice_generator_test.rb +27 -70
  43. data/test/unit/tags_generator_test.rb +0 -41
  44. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +0 -11
  45. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +0 -11
  46. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +63 -28
  47. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +3 -2
  48. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +19 -19
  49. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +14 -14
  50. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +0 -1
  51. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +0 -14
  52. data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +13 -20
  53. data/webpack/InsightsCloudSync/InsightsCloudSync.js +1 -4
  54. data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +20 -44
  55. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +0 -2
  56. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +2 -2
  57. data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +7 -11
  58. metadata +4 -30
  59. data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +0 -50
  60. data/app/controllers/concerns/inventory_upload/report_actions.rb +0 -26
  61. data/app/controllers/concerns/inventory_upload/task_actions.rb +0 -25
  62. data/app/helpers/foreman_insights_deprecations_helper.rb +0 -9
  63. data/app/helpers/foreman_insights_host_helper.rb +0 -19
  64. data/app/overrides/old_plugin_deprecation.rb +0 -20
  65. data/app/services/foreman_rh_cloud/cloud_request.rb +0 -14
  66. data/app/services/foreman_rh_cloud/insights_status_cleaner.rb +0 -17
  67. data/config/package-lock.json.plugin +0 -32774
  68. data/db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb +0 -6
  69. data/lib/insights_cloud/async/insights_client_status_aging.rb +0 -23
  70. data/lib/inventory_sync/async/inventory_self_host_sync.rb +0 -39
  71. data/test/controllers/inventory_upload/api/inventory_controller_test.rb +0 -53
  72. data/test/jobs/insights_client_status_aging_test.rb +0 -33
  73. data/test/jobs/inventory_hosts_sync_test.rb +0 -268
  74. data/test/jobs/inventory_scheduled_sync_test.rb +0 -22
  75. data/test/jobs/inventory_self_host_sync_test.rb +0 -104
  76. data/test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb +0 -31
  77. data/webpack/common/ForemanTasks/ForemanTasksActions.js +0 -64
  78. data/webpack/common/ForemanTasks/ForemanTasksHelpers.js +0 -7
  79. data/webpack/common/ForemanTasks/index.js +0 -1
@@ -6,17 +6,8 @@ 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
-
14
- # since the tasks are not connected, we need to force sequence execution here
15
- # to make sure we don't run resolutions until we synced all our rules
16
- sequence do
17
- plan_self
18
- plan_resolutions
19
- end
9
+ plan_self
10
+ plan_resolutions
20
11
  end
21
12
 
22
13
  def plan_resolutions
@@ -46,9 +37,14 @@ module InsightsCloud
46
37
  private
47
38
 
48
39
  def query_insights_rules(offset)
49
- rules_response = execute_cloud_request(
40
+ rules_response = RestClient::Request.execute(
50
41
  method: :get,
51
- url: InsightsCloud.rules_url(offset: offset)
42
+ url: InsightsCloud.rules_url(offset: offset),
43
+ verify_ssl: ForemanRhCloud.verify_ssl_method,
44
+ proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
45
+ headers: {
46
+ Authorization: "Bearer #{rh_credentials}",
47
+ }
52
48
  )
53
49
 
54
50
  JSON.parse(rules_response)
@@ -1,8 +1,6 @@
1
1
  module InventorySync
2
2
  module Async
3
3
  class HostResult
4
- attr_reader :uuid_by_fqdn
5
-
6
4
  def initialize(result)
7
5
  @total = result['total']
8
6
  @count = result['count']
@@ -10,7 +8,6 @@ module InventorySync
10
8
  @per_page = result['per_page']
11
9
  @sub_ids = result["results"].map { |host| host['subscription_manager_id'] }
12
10
  @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']] }]
14
11
  end
15
12
 
16
13
  def status_hashes
@@ -22,7 +19,6 @@ module InventorySync
22
19
  host_id: host_id,
23
20
  status: InventorySync::InventoryStatus::SYNC,
24
21
  reported_at: DateTime.current,
25
- type: InventorySync::InventoryStatus.name,
26
22
  }
27
23
  end
28
24
  end.compact
@@ -5,11 +5,6 @@ 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
-
13
8
  plan_self(organization_id: organization.id)
14
9
  end
15
10
 
@@ -29,7 +24,6 @@ module InventorySync
29
24
 
30
25
  logger.debug("Synced hosts amount: #{host_statuses[:sync]}")
31
26
  logger.debug("Disconnected hosts amount: #{host_statuses[:disconnect]}")
32
- output[:host_statuses] = host_statuses
33
27
  end
34
28
 
35
29
  def update_statuses_batch
@@ -59,7 +53,7 @@ module InventorySync
59
53
  end
60
54
 
61
55
  def host_statuses
62
- @host_statuses ||= {
56
+ output[:host_statuses] ||= {
63
57
  sync: 0,
64
58
  disconnect: 0,
65
59
  }
@@ -4,17 +4,6 @@ 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
-
18
7
  def setup_facet_transaction
19
8
  InsightsFacet.transaction do
20
9
  yield
@@ -31,22 +20,14 @@ module InventorySync
31
20
  private
32
21
 
33
22
  def add_missing_insights_facets(uuids_hash)
34
- existing_facets = InsightsFacet.where(host_id: uuids_hash.keys).pluck(:host_id, :uuid)
35
- missing_facets = uuids_hash.except(*existing_facets.map(&:first)).map do |host_id, uuid|
23
+ existing_facets = InsightsFacet.where(host_id: uuids_hash.keys).pluck(:host_id)
24
+ missing_facets = uuids_hash.except(*existing_facets).map do |host_id, uuid|
36
25
  {
37
26
  host_id: host_id,
38
27
  uuid: uuid,
39
28
  }
40
29
  end
41
30
  InsightsFacet.create(missing_facets)
42
-
43
- existing_facets.select { |host_id, uuid| uuid.empty? }.each do |host_id, _uuid|
44
- InsightsFacet.where(host_id: host_id).update_all(uuid: uuids_hash[host_id])
45
- end
46
- end
47
-
48
- def plan_self_host_sync
49
- plan_action InventorySync::Async::InventorySelfHostSync
50
31
  end
51
32
  end
52
33
  end
@@ -4,14 +4,6 @@ module InventorySync
4
4
  include ::Actions::RecurringAction
5
5
 
6
6
  def plan
7
- unless Setting[:allow_auto_inventory_upload]
8
- logger.debug(
9
- 'The scheduled process is disabled due to the "allow_auto_inventory_upload"
10
- setting being set to false.'
11
- )
12
- return
13
- end
14
-
15
7
  Organization.unscoped.each do |org|
16
8
  plan_org_sync(org)
17
9
  end
@@ -20,10 +12,6 @@ module InventorySync
20
12
  def plan_org_sync(org)
21
13
  plan_action InventoryFullSync, org
22
14
  end
23
-
24
- def logger
25
- action_logger
26
- end
27
15
  end
28
16
  end
29
17
  end
@@ -29,10 +29,13 @@ module InventorySync
29
29
  private
30
30
 
31
31
  def query_inventory(page = 1)
32
- hosts_inventory_response = execute_cloud_request(
32
+ hosts_inventory_response = RestClient::Request.execute(
33
33
  method: :get,
34
- url: request_url,
34
+ url: ForemanInventoryUpload.inventory_export_url,
35
+ verify_ssl: ForemanRhCloud.verify_ssl_method,
36
+ proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
35
37
  headers: {
38
+ Authorization: "Bearer #{rh_credentials}",
36
39
  params: {
37
40
  per_page: 100,
38
41
  page: page,
@@ -46,10 +49,6 @@ module InventorySync
46
49
  def logger
47
50
  action_logger
48
51
  end
49
-
50
- def request_url
51
- ForemanInventoryUpload.inventory_export_url
52
- end
53
52
  end
54
53
  end
55
54
  end
@@ -4,19 +4,4 @@ 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
22
7
  end
@@ -23,15 +23,8 @@ namespace :rh_cloud_inventory do
23
23
  organizations = [ENV['organization_id']]
24
24
  base_folder = ENV['target'] || Dir.pwd
25
25
 
26
- unless File.writable?(base_folder)
27
- puts "#{base_folder} is not writable by the current process"
28
- base_folder = Dir.mktmpdir
29
- puts "Using #{base_folder} for the output"
30
- end
31
-
32
- if portal_user.empty? && organizations.empty?
26
+ unless portal_user || organizations.empty?
33
27
  puts "Must specify either portal_user or organization_id"
34
- return
35
28
  end
36
29
 
37
30
  User.as_anonymous_admin do
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "3.0.26",
3
+ "version": "4.0.21.1",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,39 +11,6 @@ module InsightsCloud::Api
11
11
  host = FactoryBot.create(:host, :with_subscription, :organization => org)
12
12
  User.current = ::Katello::CpConsumerUser.new(:uuid => host.subscription_facet.uuid, :login => host.subscription_facet.uuid)
13
13
  InsightsCloud::Api::MachineTelemetriesController.any_instance.stubs(:upstream_owner).returns({ 'uuid' => 'abcdefg' })
14
-
15
- @cert1 = "-----BEGIN CERTIFICATE-----\r\n" +
16
- "MIIFdDCCA1ygAwIBAgIJAM5Uqykb3EAtMA0GCSqGSIb3DQEBCwUAME8xCzAJBgNV\r\n" +
17
- "BAYTAklMMREwDwYDVQQIDAhUZWwgQXZpdjEUMBIGA1UECgwLVGhlIEZvcmVtYW4x\r\n" +
18
- "FzAVBgNVBAMMDnRoZWZvcmVtYW4ub3JnMB4XDTE4MDMyNDEyMzYyOFoXDTI4MDMy\r\n" +
19
- "MTEyMzYyOFowTzELMAkGA1UEBhMCSUwxETAPBgNVBAgMCFRlbCBBdml2MRQwEgYD\r\n" +
20
- "VQQKDAtUaGUgRm9yZW1hbjEXMBUGA1UEAwwOdGhlZm9yZW1hbi5vcmcwggIiMA0G\r\n" +
21
- "CSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDF04/s4h+BgHPG1HDZ/sDlYq925pkc\r\n" +
22
- "RTVAfnE2EXDAmZ6W4Q9ueDY65MHe3ZWO5Dg72kNSP2sK9kRI7Dk5CAFOgyw1rH8t\r\n" +
23
- "Hd1+0xp/lv6e4SvSYghxIL68vFe0ftKkm1usqejBM5ZTgKr7JCI+XSIN36F65Kde\r\n" +
24
- "c+vxwBnayuhP04r9/aaE/709SXML4eRVYW8I3qFy9FPtUOm+bY8U2PIv5fHayqbG\r\n" +
25
- "cL/4t3+MCtMhHJsLzdBXya+1P5t+HcKjUNlmwoUF961YAktVuEFloGd0RMRlqF3/\r\n" +
26
- "itU3QNlXgA5QBIciE5VPr/PiqgMC3zgd5avjF4OribZ+N9AATLiQMW78il5wSfcc\r\n" +
27
- "kQjU9ChOLrzku455vQ8KE4bc0qvpCWGfUah6MvL9JB+TQkRl/8kxl0b9ZinIvJDH\r\n" +
28
- "ynVMb4cB/TDEjrjOfzn9mWLH0ZJqjmc2bER/G12WQxOaYLxdVwRStD3Yh6PtiFWu\r\n" +
29
- "sXOk19UOTVkeuvGFVtvzLfEwQ1lDEo7+VBQz8FG/HBu2Hpq3IwCFrHuicikwjQJk\r\n" +
30
- "nfturgD0rBOKEc1qWNZRCvovYOLL6ihvv5Orujsx5ZCHOAtnVNxkvIlFt2RS45LF\r\n" +
31
- "MtPJyhAc6SjitllfUEirxprsbmeSZqrIfzcGaEhgOSnyik1WMv6bYiqPfBg8Fzjh\r\n" +
32
- "vOCbtiDNPmvgOwIDAQABo1MwUTAdBgNVHQ4EFgQUtkAgQopsTtG9zSG3MgW2IxHD\r\n" +
33
- "MDwwHwYDVR0jBBgwFoAUtkAgQopsTtG9zSG3MgW2IxHDMDwwDwYDVR0TAQH/BAUw\r\n" +
34
- "AwEB/zANBgkqhkiG9w0BAQsFAAOCAgEAJq7iN+ZroRBweNhvUobxs75bLIV6tNn1\r\n" +
35
- "MdNHDRA+hezwf+gxHZhFyaAHfTpst2/9leK5Qe5Zd6gZLr3E5/8ppQuRod72H39B\r\n" +
36
- "vxMlG5zxDss0WMo3vZeKZbTY6QhXi/lY2IZ6OGV4feSvCsYxn27GTjjrRUSLFeHH\r\n" +
37
- "JVemCwCDMavaE3+OIY4v2P4FcG+MjUvfOB9ahI24TWL7YgrsNVmJjCILq+EeUj0t\r\n" +
38
- "Gde1SXVyLkqt7PoxHRJAE0BCEMJSnjxaVB329acJgeehBUxjj4CCPqtDxtbz9HEH\r\n" +
39
- "mOKfNdaKpFor+DUeEKUWVGnr9U9xOaC+Ws+oX7MIEUCDM7p2ob4JwcjnFs1jZgHh\r\n" +
40
- "Hwig+i7doTlc701PvKWO96fuNHK3B3/jTb1fVvSZ49O/RvY1VWODdUdxWmXGHNh3\r\n" +
41
- "LoR8tSPEb46lC2DXGaIQumqQt8PnBG+vL1qkQa1SGTV7dJ8TTbxbv0S+sS+igkk9\r\n" +
42
- "zsIEK8Ea3Ep935cXximz0faAAKHSA+It+xHLAyDtqy2KaAEBgGsBuuWlUfK6TaP3\r\n" +
43
- "Gwdjct3y4yYUO45lUsUfHqX8vk/4ttW5zYeDiW+HArJz+9VUXNbEdury4kGuHgBj\r\n" +
44
- "xHD4Bsul65+hHZ9QywKU26F1A6TLkYpQ2rk/Dx9LGICM4m4IlHjWJPFsQdtkyOor\r\n" +
45
- "osxMtcaZZ1E=\r\n" +
46
- "-----END CERTIFICATE-----"
47
14
  end
48
15
 
49
16
  test "should respond with response from cloud" do
@@ -63,14 +30,6 @@ module InsightsCloud::Api
63
30
  ::ForemanRhCloud::CloudRequestForwarder.any_instance.expects(:execute_cloud_request).with do |opts|
64
31
  opts[:headers][:content_type] == 'application/json'
65
32
  end.returns(res)
66
- InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:candlepin_id_cert)
67
- .returns(
68
- {
69
- cert: @cert1,
70
- key: OpenSSL::PKey::RSA.new(1024).to_pem,
71
- }
72
- )
73
- InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:cp_owner_id).returns('123')
74
33
 
75
34
  post :forward_request, as: :json, params: { "path" => "static/v1/test", "machine_telemetry" => {"foo" => "bar"} }
76
35
  assert_equal @body, @response.body
@@ -49,7 +49,7 @@ end
49
49
 
50
50
  FactoryBot.define do
51
51
  factory :katello_subscription_facets, :aliases => [:subscription_facet], :class => ::Katello::Host::SubscriptionFacet do
52
- sequence(:uuid) { |n| "00000000-%<n>04d-%<r>04d-0000-000000000000" % {n: n, r: rand(500)} }
52
+ sequence(:uuid) { |n| "uuid-#{n}-#{rand(500)}" }
53
53
  facts { { 'memory.memtotal' => "12 GB" } }
54
54
  end
55
55
  end
@@ -7,7 +7,6 @@ class InsightsFullSyncTest < ActiveSupport::TestCase
7
7
  setup do
8
8
  InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_rules_sync)
9
9
  InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_notifications)
10
- FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
11
10
 
12
11
  uuid1 = 'accdf444-5628-451d-bf3e-cf909ad72756'
13
12
  @host1 = FactoryBot.create(:host, :managed, name: 'host1')
@@ -1,4 +1,4 @@
1
- require 'test_plugin_helper'
1
+ require 'test_helper'
2
2
  require 'foreman_tasks/test_helpers'
3
3
 
4
4
  class InsightsResolutionsSyncTest < ActiveSupport::TestCase
@@ -63,7 +63,6 @@ class InsightsResolutionsSyncTest < ActiveSupport::TestCase
63
63
  }
64
64
 
65
65
  @rule = FactoryBot.create(:insights_rule, rule_id: 'network_tcp_connection_hang|NETWORK_TCP_CONNECTION_HANG_WARN')
66
- FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
67
66
  end
68
67
 
69
68
  test 'Resolutions data is replaced with data from cloud' do
@@ -75,13 +74,4 @@ class InsightsResolutionsSyncTest < ActiveSupport::TestCase
75
74
  assert_equal 5, InsightsResolution.all.count
76
75
  assert_equal 2, @rule.resolutions.count
77
76
  end
78
-
79
- test 'Skips pinging the cloud if no rule ids were found' do
80
- InsightsCloud::Async::InsightsResolutionsSync.any_instance.expects(:query_insights_resolutions).never
81
- InsightsRule.all.delete_all
82
-
83
- ForemanTasks.sync_task(InsightsCloud::Async::InsightsResolutionsSync)
84
-
85
- assert_equal 0, InsightsResolution.all.count
86
- end
87
77
  end
@@ -112,7 +112,6 @@ class InsightsRulesSyncTest < ActiveSupport::TestCase
112
112
  @hit = FactoryBot.create(:insights_hit, host_id: @host.id)
113
113
 
114
114
  InsightsCloud::Async::InsightsRulesSync.any_instance.stubs(:plan_resolutions)
115
- FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
116
115
  end
117
116
 
118
117
  test 'Hits data is replaced with data from cloud' do
@@ -242,7 +242,6 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
242
242
  end
243
243
 
244
244
  test 'Host status should be SYNC for inventory hosts' do
245
- FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'TEST TOKEN')
246
245
  InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
247
246
 
248
247
  ForemanTasks.sync_task(InventorySync::Async::InventoryFullSync, @host2.organization)
@@ -254,7 +253,6 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
254
253
  end
255
254
 
256
255
  test 'Host status should be DISCONNECT for hosts that are not returned from cloud' do
257
- FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'TEST TOKEN')
258
256
  InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
259
257
  FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
260
258
 
@@ -263,12 +261,4 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
263
261
 
264
262
  assert_equal InventorySync::InventoryStatus::DISCONNECT, InventorySync::InventoryStatus.where(host_id: @host1.id).first.status
265
263
  end
266
-
267
- test 'Task should be aborted if token is not present' do
268
- FactoryBot.create(:setting, name: 'rh_cloud_token', value: '')
269
-
270
- InventorySync::Async::InventoryFullSync.any_instance.expects(:plan_self).never
271
-
272
- ForemanTasks.sync_task(InventorySync::Async::InventoryFullSync, @host1.organization)
273
- end
274
264
  end
@@ -1,75 +1,77 @@
1
1
  require 'test_plugin_helper'
2
2
 
3
3
  class InsightsClientReportStatusTest < ActiveSupport::TestCase
4
- setup do
5
- @host = FactoryBot.create(:host, :managed)
6
- end
7
-
8
- test 'fresh host does not have insights status' do
9
- @host.reload
10
-
11
- refute @host.host_statuses.where(type: 'InsightsClientReportStatus').exists?
12
- insights_status = @host.get_status(InsightsClientReportStatus)
13
- refute insights_status.relevant?
14
- end
15
-
16
- test 'host can refresh all its statuses' do
17
- @host.refresh_statuses
18
- @host.reload
19
-
20
- refute @host.host_statuses.where(type: 'InsightsClientReportStatus').exists?
21
- end
22
-
23
- test 'host with correct report status sets global status to OK' do
24
- global_status = @host.get_status(HostStatus.find_status_by_humanized_name('Global'))
25
- # Status has to be OK before action
26
- assert_equal HostStatus::Global::OK, global_status.status
27
-
28
- # force create record
29
- @host.get_status(InsightsClientReportStatus).refresh!
30
- # now refresh should work
31
- @host.refresh_statuses([InsightsClientReportStatus])
32
-
33
- @host.reload
34
- global_status = @host.get_status(HostStatus.find_status_by_humanized_name('Global'))
35
- # Status has to be OK after the action too
36
- assert_equal HostStatus::Global::OK, global_status.status
37
-
38
- insights_status = @host.get_status(InsightsClientReportStatus)
39
- # assert the status would be displayed
40
- assert insights_status.relevant?
41
- end
42
-
43
- test 'host will return to OK once the status is refreshed' do
44
- global_status = @host.get_status(HostStatus.find_status_by_humanized_name('Global'))
45
- # Status has to be OK before action
46
- assert_equal HostStatus::Global::OK, global_status.status
47
-
48
- insights_status = @host.get_status(InsightsClientReportStatus)
49
- insights_status.status = InsightsClientReportStatus::NO_REPORT
50
- insights_status.save!
51
- @host.refresh_global_status!
52
- global_status = @host.global_status
53
- assert_equal HostStatus::Global::ERROR, global_status
54
-
55
- @host.refresh_statuses([InsightsClientReportStatus])
56
-
57
- @host.reload
58
- # Status has to be OK after the action too
59
- assert_equal HostStatus::Global::OK, @host.global_status
60
- end
61
-
62
- test 'host with stale status would set global to ERROR' do
63
- global_status = @host.get_status(HostStatus.find_status_by_humanized_name('Global'))
64
- # Status has to be OK before action
65
- assert_equal HostStatus::Global::OK, global_status.status
66
-
67
- insights_status = @host.get_status(InsightsClientReportStatus)
68
- insights_status.status = InsightsClientReportStatus::NO_REPORT
69
- insights_status.save!
70
- @host.refresh_global_status!
71
- @host.reload
72
-
73
- assert_equal HostStatus::Global::ERROR, @host.global_status
4
+ describe 'to_status' do
5
+ let(:host) { FactoryBot.create(:host, :managed) }
6
+
7
+ setup do
8
+ CommonParameter.where(name: 'host_registration_insights').destroy_all
9
+ end
10
+
11
+ test 'host_registration_insights = true & is getting data' do
12
+ FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
13
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
14
+
15
+ assert_equal 0, host_status.to_status(data: true)
16
+ end
17
+
18
+ test 'host_registration_insights = true & no data in less than 48 hours' do
19
+ FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
20
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
21
+ host_status.update(reported_at: 1.day.ago)
22
+ assert_equal 0, host_status.to_status
23
+ end
24
+
25
+ test 'host_registration_insights = true & no data in more than 48 hours' do
26
+ FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
27
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
28
+ host_status.update(reported_at: 3.days.ago)
29
+ assert_equal 1, host_status.to_status
30
+ end
31
+
32
+ test 'host_registration_insights = false & no data' do
33
+ FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false)
34
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
35
+ assert_equal 2, host_status.to_status
36
+ end
37
+
38
+ test 'host_registration_insights = false & getting data' do
39
+ FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false)
40
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
41
+ assert_equal 3, host_status.to_status(data: true)
42
+ end
43
+
44
+ test 'host_registration_insights = nil & is getting data' do
45
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
46
+ assert_equal 3, host_status.to_status(data: true)
47
+ end
48
+
49
+ test 'host_registration_insights = nil & no data in less than 48 hours' do
50
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
51
+ host_status.update(reported_at: 1.day.ago)
52
+ assert_equal 2, host_status.to_status
53
+ end
54
+
55
+ test 'host_registration_insights = nil & no data in more than 48 hours' do
56
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
57
+ host_status.update(reported_at: 3.days.ago)
58
+ assert_equal 2, host_status.to_status
59
+ end
60
+
61
+ test 'override param on host level from `false` to `true`' do
62
+ FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false)
63
+ FactoryBot.create(:host_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true, host: host)
64
+
65
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
66
+ assert_equal 0, host_status.to_status(data: true)
67
+ end
68
+
69
+ test 'override param on host level from `true` to `false`' do
70
+ FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
71
+ FactoryBot.create(:host_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false, host: host)
72
+
73
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
74
+ assert_equal 2, host_status.to_status
75
+ end
74
76
  end
75
77
  end
@@ -2,8 +2,6 @@
2
2
  require 'test_helper'
3
3
 
4
4
  # Add plugin to FactoryBot's paths
5
- FactoryBot.definition_file_paths << "#{ForemanTasks::Engine.root}/test/factories"
6
- FactoryBot.definition_file_paths << "#{ForemanRemoteExecution::Engine.root}/test/factories"
7
5
  FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
8
6
  # FactoryBot.definition_file_paths << "#{Katello::Engine.root}/test/factories"
9
7
  FactoryBot.reload
@@ -42,13 +42,12 @@ class CloudRequestForwarderTest < ActiveSupport::TestCase
42
42
  test 'should prepare correct cloud url' do
43
43
  paths = {
44
44
  "/redhat_access/r/insights/platform/module-update-router/v1/channel?module=insights-core" => "https://cert.cloud.redhat.com/api/module-update-router/v1/channel?module=insights-core",
45
- "/redhat_access/r/insights/v1/static/release/insights-core.egg" => "https://cert-api.access.redhat.com/r/insights/v1/static/release/insights-core.egg",
46
- "/redhat_access/r/insights/v1/static/uploader.v2.json" => "https://cert-api.access.redhat.com/r/insights/v1/static/uploader.v2.json",
47
- "/redhat_access/r/insights/v1/static/uploader.v2.json.asc" => "https://cert-api.access.redhat.com/r/insights/v1/static/uploader.v2.json.asc",
45
+ "/redhat_access/r/insights/v1/static/release/insights-core.egg" => "https://cloud.redhat.com/api/v1/static/release/insights-core.egg",
46
+ "/redhat_access/r/insights/v1/static/uploader.v2.json" => "https://cloud.redhat.com/api/v1/static/uploader.v2.json",
47
+ "/redhat_access/r/insights/v1/static/uploader.v2.json.asc" => "https://cloud.redhat.com/api/v1/static/uploader.v2.json.asc",
48
48
  "/redhat_access/r/insights/platform/inventory/v1/hosts" => "https://cert.cloud.redhat.com/api/inventory/v1/hosts",
49
49
  "/redhat_access/r/insights/platform/ingress/v1/upload" => "https://cert.cloud.redhat.com/api/ingress/v1/upload",
50
50
  "/redhat_access/r/insights/uploads/67200803-132b-474b-a6f9-37be74185df4" => "https://cert-api.access.redhat.com/r/insights/uploads/67200803-132b-474b-a6f9-37be74185df4",
51
- "/redhat_access/r/insights/" => "https://cert.cloud.redhat.com/api/apicast-tests/ping",
52
51
  }
53
52
 
54
53
  paths.each do |key, value|
@@ -8,7 +8,6 @@ class TemplateRendererHelperTest < ActiveSupport::TestCase
8
8
  response.stubs(:body).returns('TEST PLAYBOOK')
9
9
  ForemanRhCloud::RemediationsRetriever.any_instance.stubs(:query_playbook).returns(response)
10
10
  @host1 = FactoryBot.create(:host)
11
- FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
12
11
  end
13
12
 
14
13
  test 'Generates a playbook for hit and remediation' do