foreman_rh_cloud 3.0.23 → 3.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +5 -3
  3. data/app/helpers/foreman_insights_deprecations_helper.rb +9 -0
  4. data/app/models/insights_client_report_status.rb +11 -22
  5. data/app/overrides/old_plugin_deprecation.rb +20 -0
  6. data/app/services/foreman_rh_cloud/cloud_auth.rb +4 -0
  7. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +10 -8
  8. data/app/services/foreman_rh_cloud/insights_status_cleaner.rb +17 -0
  9. data/app/services/foreman_rh_cloud/remediations_retriever.rb +5 -0
  10. data/config/Gemfile.lock.gh_test +93 -95
  11. data/config/routes.rb +1 -1
  12. data/db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb +6 -0
  13. data/lib/foreman_inventory_upload/generators/queries.rb +1 -0
  14. data/lib/foreman_inventory_upload/generators/slice.rb +1 -0
  15. data/lib/foreman_inventory_upload/generators/tags.rb +3 -1
  16. data/lib/foreman_inventory_upload.rb +9 -1
  17. data/lib/foreman_rh_cloud/engine.rb +14 -11
  18. data/lib/foreman_rh_cloud/version.rb +1 -1
  19. data/lib/insights_cloud/async/insights_client_status_aging.rb +23 -0
  20. data/lib/insights_cloud/async/insights_full_sync.rb +5 -0
  21. data/lib/insights_cloud/async/insights_resolutions_sync.rb +12 -2
  22. data/lib/insights_cloud/async/insights_rules_sync.rb +11 -2
  23. data/lib/inventory_sync/async/host_result.rb +4 -0
  24. data/lib/inventory_sync/async/inventory_full_sync.rb +5 -0
  25. data/lib/inventory_sync/async/inventory_hosts_sync.rb +15 -0
  26. data/lib/inventory_sync/async/inventory_self_host_sync.rb +39 -0
  27. data/lib/inventory_sync/async/query_inventory_job.rb +5 -1
  28. data/lib/tasks/insights.rake +15 -0
  29. data/package.json +1 -1
  30. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +41 -0
  31. data/test/jobs/insights_client_status_aging_test.rb +33 -0
  32. data/test/jobs/insights_full_sync_test.rb +1 -0
  33. data/test/jobs/insights_resolutions_sync_test.rb +11 -1
  34. data/test/jobs/insights_rules_sync_test.rb +1 -0
  35. data/test/jobs/inventory_full_sync_test.rb +10 -0
  36. data/test/jobs/inventory_hosts_sync_test.rb +3 -0
  37. data/test/jobs/inventory_self_host_sync_test.rb +104 -0
  38. data/test/models/insights_client_report_status_test.rb +70 -72
  39. data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +4 -3
  40. data/test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb +31 -0
  41. data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +1 -0
  42. data/test/unit/slice_generator_test.rb +15 -0
  43. data/test/unit/tags_generator_test.rb +41 -0
  44. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +14 -0
  45. metadata +15 -4
  46. data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +0 -9
data/config/routes.rb CHANGED
@@ -37,7 +37,7 @@ Rails.application.routes.draw do
37
37
  end
38
38
 
39
39
  scope '/r/insights' do
40
- match '/*path', :constraints => lambda { |req| !req.path.include?('view/api') }, to: 'machine_telemetries#forward_request', via: [:get, :post, :delete,:put, :patch]
40
+ match '(/*path)(/)', :constraints => lambda { |req| !req.path.include?('view/api') }, to: 'machine_telemetries#forward_request', via: [:get, :post, :delete,:put, :patch]
41
41
  end
42
42
  end
43
43
 
@@ -0,0 +1,6 @@
1
+ class RemoveOldInsightsStatuses < ActiveRecord::Migration[5.2]
2
+ def up
3
+ InsightsClientReportStatus.where(status: 2).update_all(status: InsightsClientReportStatus::NO_REPORT)
4
+ InsightsClientReportStatus.where(status: 3).update_all(status: InsightsClientReportStatus::REPORTING)
5
+ end
6
+ end
@@ -27,6 +27,7 @@ module ForemanInventoryUpload
27
27
  'insights_client::obfuscate_ip_enabled',
28
28
  'insights_client::hostname',
29
29
  'insights_client::ips',
30
+ 'insights_id',
30
31
  ]).pluck(:name, :id)
31
32
  ]
32
33
  end
@@ -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
@@ -70,8 +70,16 @@ module ForemanInventoryUpload
70
70
  folder
71
71
  end
72
72
 
73
+ def self.inventory_base_url
74
+ ForemanRhCloud.base_url + "/api/inventory/v1/hosts"
75
+ end
76
+
73
77
  def self.inventory_export_url
74
78
  tags = URI.encode("satellite/satellite_instance_id=#{Foreman.instance_id}")
75
- ForemanRhCloud.base_url + "/api/inventory/v1/hosts?tags=#{tags}"
79
+ inventory_base_url + "?tags=#{tags}"
80
+ end
81
+
82
+ def self.inventory_self_url
83
+ inventory_base_url + "?hostname_or_id=#{ForemanRhCloud.foreman_host.fqdn}"
76
84
  end
77
85
  end
@@ -6,6 +6,18 @@ module ForemanRhCloud
6
6
  class Engine < ::Rails::Engine
7
7
  engine_name 'foreman_rh_cloud'
8
8
 
9
+ def self.register_scheduled_task(task_class, cronline)
10
+ return if ForemanTasks::RecurringLogic.joins(:tasks)
11
+ .merge(ForemanTasks::Task.where(label: task_class.name))
12
+ .exists?
13
+
14
+ User.as_anonymous_admin do
15
+ recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline(cronline)
16
+ recurring_logic.save!
17
+ recurring_logic.start(task_class)
18
+ end
19
+ end
20
+
9
21
  initializer 'foreman_rh_cloud.load_default_settings', :before => :load_config_initializers do
10
22
  require_dependency File.expand_path('../../app/models/setting/rh_cloud.rb', __dir__)
11
23
  end
@@ -81,8 +93,6 @@ module ForemanRhCloud
81
93
  register_custom_status InventorySync::InventoryStatus
82
94
  register_custom_status InsightsClientReportStatus
83
95
 
84
- subscribe 'host_created.event.foreman', ForemanRhCloud::InsightsSubscriber
85
-
86
96
  describe_host do
87
97
  overview_buttons_provider :insights_host_overview_buttons
88
98
  end
@@ -138,15 +148,8 @@ module ForemanRhCloud
138
148
  # skip object creation when admin user is not present, for example in test DB
139
149
  if User.unscoped.find_by_login(User::ANONYMOUS_ADMIN).present?
140
150
  ::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
151
+ ForemanRhCloud::Engine.register_scheduled_task(InventorySync::Async::InventoryScheduledSync, '0 0 * * *')
152
+ ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsClientStatusAging, '0 0 * * *')
150
153
  end
151
154
  end
152
155
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '3.0.23'.freeze
2
+ VERSION = '3.0.26'.freeze
3
3
  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,11 +7,21 @@ 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
13
- api_response = query_insights_resolutions(relevant_rules)
14
- write_resolutions(api_response)
22
+ rule_ids = relevant_rules
23
+ api_response = query_insights_resolutions(rule_ids) unless rule_ids.empty?
24
+ write_resolutions(api_response) if api_response
15
25
  end
16
26
  end
17
27
 
@@ -6,8 +6,17 @@ module InsightsCloud
6
6
  include ::ForemanRhCloud::CloudAuth
7
7
 
8
8
  def plan
9
- plan_self
10
- plan_resolutions
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
11
20
  end
12
21
 
13
22
  def plan_resolutions
@@ -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
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "3.0.23",
3
+ "version": "3.0.26",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,6 +11,39 @@ 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-----"
14
47
  end
15
48
 
16
49
  test "should respond with response from cloud" do
@@ -30,6 +63,14 @@ module InsightsCloud::Api
30
63
  ::ForemanRhCloud::CloudRequestForwarder.any_instance.expects(:execute_cloud_request).with do |opts|
31
64
  opts[:headers][:content_type] == 'application/json'
32
65
  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')
33
74
 
34
75
  post :forward_request, as: :json, params: { "path" => "static/v1/test", "machine_telemetry" => {"foo" => "bar"} }
35
76
  assert_equal @body, @response.body
@@ -0,0 +1,33 @@
1
+ require 'test_plugin_helper'
2
+ require 'foreman_tasks/test_helpers'
3
+
4
+ class InsightsClientStatusAgingTest < ActiveSupport::TestCase
5
+ include ForemanTasks::TestHelpers::WithInThreadExecutor
6
+
7
+ setup do
8
+ User.current = User.find_by(login: 'secret_admin')
9
+
10
+ @host1 = FactoryBot.create(:host)
11
+ @host2 = FactoryBot.create(:host)
12
+ @host3 = FactoryBot.create(:host)
13
+ @host4 = FactoryBot.create(:host)
14
+
15
+ @hosts = [@host1, @host2, @host3, @host4]
16
+ end
17
+
18
+ test 'stale statuses should change' do
19
+ InsightsClientReportStatus.find_or_initialize_by(host_id: @host1.id).update(status: InsightsClientReportStatus::REPORTING, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL + 1.day)
20
+ InsightsClientReportStatus.find_or_initialize_by(host_id: @host2.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL + 1.day)
21
+ InsightsClientReportStatus.find_or_initialize_by(host_id: @host3.id).update(status: InsightsClientReportStatus::REPORTING, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)
22
+ InsightsClientReportStatus.find_or_initialize_by(host_id: @host4.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)
23
+
24
+ ForemanTasks.sync_task(InsightsCloud::Async::InsightsClientStatusAging)
25
+
26
+ @hosts.each(&:reload)
27
+
28
+ assert_equal InsightsClientReportStatus::REPORTING, @host1.get_status(InsightsClientReportStatus).status
29
+ assert_equal InsightsClientReportStatus::NO_REPORT, @host2.get_status(InsightsClientReportStatus).status
30
+ assert_equal InsightsClientReportStatus::NO_REPORT, @host3.get_status(InsightsClientReportStatus).status
31
+ assert_equal InsightsClientReportStatus::NO_REPORT, @host4.get_status(InsightsClientReportStatus).status
32
+ end
33
+ end