foreman_rh_cloud 4.0.24 → 4.0.24.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b73f3b045ed5bcbba051801155232d62a0884b30da8e461328a17e509fe0f0ec
4
- data.tar.gz: 2cc1a0c73e193de7d26b368e9a78760ee302f78ecafeef6c27e18165293d0d2d
3
+ metadata.gz: 5de90e40ec6d14cf5483a2f92e46c61488c01a921a89feaa8194015f09c6fd0d
4
+ data.tar.gz: 3ac8ba217d2356211e25c1f1de144ad72578ba0be29116ce1d611817302fc097
5
5
  SHA512:
6
- metadata.gz: 2eb0bb9cdb4d2aefa66acec328c98467a7db33de69e0256f966cca0f929756fb9100a5880d8d9a03f358cfafaf6e5aa32cf9896125c0eab8e3de9b9ebbb09269
7
- data.tar.gz: 12e435965a84de5c538e98463fcdacbacd70eefd692822782cdb5ec4ed1e9f91e6d31f65466cffaa4b415c4491ff62e393a1e2f716f4542b03e5911fe6a34b97
6
+ metadata.gz: 051caa1c8e5d69a8dad5aa77570b79854854d5ae10f810afe2f57dc6d0f2be0a8de1090caab8ceb0a3faea06b2cb42bad3beda18097792b62e191caa6bb3b41d
7
+ data.tar.gz: 5f53fcc4bfdcc134afe56d19ac8a6c46822b2a6aeab832296eb0c7ffbe462d3a0510f2aaf2d0548f4b0f212f2b44e893fb12a04dace6c35fdc039071a7dd70b2
@@ -76,9 +76,11 @@ module InsightsCloud::Api
76
76
  return unless request.path == '/redhat_access/r/insights/platform/ingress/v1/upload' ||
77
77
  request.path.include?('/redhat_access/r/insights/uploads/')
78
78
 
79
- data = @cloud_response.code.to_s.start_with?('2')
80
- host_status = @host.get_status(InsightsClientReportStatus)
81
- host_status.update(reported_at: Time.now.utc, status: host_status.to_status(data: data))
79
+ return unless @cloud_response.code.to_s.start_with?('2')
80
+
81
+ # create insights status if it wasn't there in the first place and refresh its reporting date
82
+ @host.get_status(InsightsClientReportStatus).refresh!
83
+ @host.refresh_global_status!
82
84
  end
83
85
  end
84
86
  end
@@ -1,14 +1,11 @@
1
1
  class InsightsClientReportStatus < HostStatus::Status
2
2
  REPORT_INTERVAL = 48.hours
3
3
 
4
- REPORTING = 0 # host_registration_insights = true & getting data
5
- NO_REPORT = 1 # host_registration_insights = true & not getting data
6
- NOT_MANAGED = 2 # host_registration_insights = false
7
- NOT_MANAGED_WITH_DATA = 3 # host_registration_insights = false & getting data
4
+ REPORTING = 0
5
+ NO_REPORT = 1
8
6
 
9
7
  scope :stale, -> { where.not(reported_at: (Time.now - REPORT_INTERVAL)..Time.now) }
10
8
  scope :reporting, -> { where(status: REPORTING) }
11
- scope :not_managed_with_data, -> { where(status: NOT_MANAGED_WITH_DATA) }
12
9
 
13
10
  def self.status_name
14
11
  N_('Insights')
@@ -20,10 +17,6 @@ class InsightsClientReportStatus < HostStatus::Status
20
17
  N_('Reporting')
21
18
  when NO_REPORT
22
19
  N_('Not reporting')
23
- when NOT_MANAGED
24
- N_('Not reporting (not set by registration)')
25
- when NOT_MANAGED_WITH_DATA
26
- N_('Reporting (not set by registration)')
27
20
  end
28
21
  end
29
22
 
@@ -33,20 +26,16 @@ class InsightsClientReportStatus < HostStatus::Status
33
26
  ::HostStatus::Global::OK
34
27
  when NO_REPORT
35
28
  ::HostStatus::Global::ERROR
36
- when NOT_MANAGED
37
- ::HostStatus::Global::OK
38
- when NOT_MANAGED_WITH_DATA
39
- ::HostStatus::Global::WARN
40
29
  end
41
30
  end
42
31
 
43
- def to_status(data: false)
44
- if insights_param
45
- return REPORTING if data
46
- return in_interval? ? REPORTING : NO_REPORT
47
- end
32
+ def to_status
33
+ in_interval? ? REPORTING : NO_REPORT
34
+ end
48
35
 
49
- data ? NOT_MANAGED_WITH_DATA : NOT_MANAGED
36
+ # prevent creation of the status on global refresh, but show it if the record already exists
37
+ def relevant?(_options = {})
38
+ persisted?
50
39
  end
51
40
 
52
41
  private
@@ -55,8 +44,4 @@ class InsightsClientReportStatus < HostStatus::Status
55
44
  return false unless reported_at
56
45
  (Time.now.utc - reported_at).to_i < REPORT_INTERVAL.to_i
57
46
  end
58
-
59
- def insights_param
60
- host.host_params_hash.dig('host_registration_insights', :value)
61
- end
62
47
  end
@@ -0,0 +1,17 @@
1
+ module ForemanRhCloud
2
+ class InsightsStatusCleaner
3
+ def clean(host_search)
4
+ host_ids = Host.search_for(host_search).pluck(:id)
5
+
6
+ # delete all insights status records for the hosts
7
+ deleted_count = InsightsClientReportStatus.where(host_id: host_ids).delete_all
8
+
9
+ # refresh global status
10
+ Host.where(id: host_ids).preload(:host_statuses).find_in_batches do |hosts|
11
+ hosts.each { |host| host.refresh_global_status! }
12
+ end
13
+
14
+ deleted_count
15
+ end
16
+ end
17
+ end
@@ -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
@@ -93,8 +93,6 @@ module ForemanRhCloud
93
93
  register_custom_status InventorySync::InventoryStatus
94
94
  register_custom_status InsightsClientReportStatus
95
95
 
96
- subscribe 'host_created.event.foreman', ForemanRhCloud::InsightsSubscriber
97
-
98
96
  describe_host do
99
97
  overview_buttons_provider :insights_host_overview_buttons
100
98
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '4.0.24'.freeze
2
+ VERSION = '4.0.24.1'.freeze
3
3
  end
@@ -4,9 +4,15 @@ module InsightsCloud
4
4
  include ::Actions::RecurringAction
5
5
 
6
6
  def run
7
- # update all stale records to "not reporting" counterpart
8
- InsightsClientReportStatus.stale.reporting.update_all(status: InsightsClientReportStatus::NO_REPORT)
9
- InsightsClientReportStatus.stale.not_managed_with_data.update_all(status: InsightsClientReportStatus::NOT_MANAGED)
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
10
16
  end
11
17
 
12
18
  def logger
@@ -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": "4.0.24",
3
+ "version": "4.0.24.1",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -16,18 +16,18 @@ class InsightsClientStatusAgingTest < ActiveSupport::TestCase
16
16
  end
17
17
 
18
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::NOT_MANAGED, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)
22
- InsightsClientReportStatus.find_or_initialize_by(host_id: @host4.id).update(status: InsightsClientReportStatus::NOT_MANAGED_WITH_DATA, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)
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
23
 
24
24
  ForemanTasks.sync_task(InsightsCloud::Async::InsightsClientStatusAging)
25
25
 
26
26
  @hosts.each(&:reload)
27
27
 
28
- assert_equal InsightsClientReportStatus::NO_REPORT, @host1.get_status(InsightsClientReportStatus).status
28
+ assert_equal InsightsClientReportStatus::REPORTING, @host1.get_status(InsightsClientReportStatus).status
29
29
  assert_equal InsightsClientReportStatus::NO_REPORT, @host2.get_status(InsightsClientReportStatus).status
30
- assert_equal InsightsClientReportStatus::NOT_MANAGED, @host3.get_status(InsightsClientReportStatus).status
31
- assert_equal InsightsClientReportStatus::NOT_MANAGED, @host4.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
32
  end
33
33
  end
@@ -1,77 +1,75 @@
1
1
  require 'test_plugin_helper'
2
2
 
3
3
  class InsightsClientReportStatusTest < ActiveSupport::TestCase
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
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
76
74
  end
77
75
  end
@@ -0,0 +1,31 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class InsightsStatusCleanerTest < ActiveSupport::TestCase
4
+ setup do
5
+ @host1 = FactoryBot.create(:host)
6
+ @host2 = FactoryBot.create(:host)
7
+
8
+ InsightsClientReportStatus.find_or_initialize_by(host_id: @host1.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL + 1.day)
9
+ InsightsClientReportStatus.find_or_initialize_by(host_id: @host2.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL + 1.day)
10
+
11
+ @host1.refresh_global_status!
12
+ @host2.refresh_global_status!
13
+ end
14
+
15
+ test 'Cleans hosts by search condition' do
16
+ assert_equal HostStatus::Global::ERROR, @host1.global_status
17
+ assert_equal HostStatus::Global::ERROR, @host2.global_status
18
+
19
+ instance = ForemanRhCloud::InsightsStatusCleaner.new
20
+ actual_count = instance.clean("name = #{@host1.name}")
21
+
22
+ @host1.reload
23
+ @host2.refresh_global_status!
24
+
25
+ assert_equal 1, actual_count
26
+ assert_equal HostStatus::Global::OK, @host1.global_status
27
+ assert_equal HostStatus::Global::ERROR, @host2.global_status
28
+ assert InsightsClientReportStatus.where(host_id: @host1.id).empty?
29
+ refute InsightsClientReportStatus.where(host_id: @host2.id).empty?
30
+ end
31
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_rh_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.24
4
+ version: 4.0.24.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Red Hat Cloud team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-20 00:00:00.000000000 Z
11
+ date: 2021-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katello
@@ -178,9 +178,9 @@ files:
178
178
  - app/services/foreman_rh_cloud/cloud_connector.rb
179
179
  - app/services/foreman_rh_cloud/cloud_request.rb
180
180
  - app/services/foreman_rh_cloud/cloud_request_forwarder.rb
181
+ - app/services/foreman_rh_cloud/insights_status_cleaner.rb
181
182
  - app/services/foreman_rh_cloud/remediations_retriever.rb
182
183
  - app/services/foreman_rh_cloud/template_renderer_helper.rb
183
- - app/subscribers/foreman_rh_cloud/insights_subscriber.rb
184
184
  - app/views/hosts/_insights_tab.html.erb
185
185
  - app/views/job_templates/rh_cloud_remediations.erb
186
186
  - app/views/layouts/foreman_rh_cloud/application.html.erb
@@ -198,6 +198,7 @@ files:
198
198
  - db/migrate/20210214000002_add_rule_id_to_hits.foreman_rh_cloud.rb
199
199
  - db/migrate/20210307000001_add_unique_to_insights_facet.foreman_rh_cloud.rb
200
200
  - db/migrate/20210404000001_change_resolutions.foreman_rh_cloud.rb
201
+ - db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb
201
202
  - db/seeds.d/179_ui_notifications.rb
202
203
  - db/seeds.d/50_job_templates.rb
203
204
  - lib/foreman_inventory_upload.rb
@@ -269,6 +270,7 @@ files:
269
270
  - test/unit/rh_cloud_http_proxy_test.rb
270
271
  - test/unit/services/foreman_rh_cloud/branch_info_test.rb
271
272
  - test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb
273
+ - test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb
272
274
  - test/unit/services/foreman_rh_cloud/remediations_retriever_test.rb
273
275
  - test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb
274
276
  - test/unit/shell_process_job_test.rb
@@ -699,6 +701,7 @@ test_files:
699
701
  - test/unit/rh_cloud_http_proxy_test.rb
700
702
  - test/unit/services/foreman_rh_cloud/branch_info_test.rb
701
703
  - test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb
704
+ - test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb
702
705
  - test/unit/services/foreman_rh_cloud/remediations_retriever_test.rb
703
706
  - test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb
704
707
  - test/unit/shell_process_job_test.rb
@@ -1,9 +0,0 @@
1
- module ForemanRhCloud
2
- class InsightsSubscriber < ::Foreman::BaseSubscriber
3
- def call(*args)
4
- host = args.first.payload[:object]
5
- host_status = host.get_status(InsightsClientReportStatus)
6
- host_status.update(status: host_status.to_status)
7
- end
8
- end
9
- end