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 +4 -4
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +5 -3
- data/app/models/insights_client_report_status.rb +8 -23
- data/app/services/foreman_rh_cloud/insights_status_cleaner.rb +17 -0
- data/db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb +6 -0
- data/lib/foreman_rh_cloud/engine.rb +0 -2
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud/async/insights_client_status_aging.rb +9 -3
- data/lib/tasks/insights.rake +15 -0
- data/package.json +1 -1
- data/test/jobs/insights_client_status_aging_test.rb +7 -7
- data/test/models/insights_client_report_status_test.rb +70 -72
- data/test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb +31 -0
- metadata +6 -3
- data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5de90e40ec6d14cf5483a2f92e46c61488c01a921a89feaa8194015f09c6fd0d
|
4
|
+
data.tar.gz: 3ac8ba217d2356211e25c1f1de144ad72578ba0be29116ce1d611817302fc097
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
80
|
-
|
81
|
-
|
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
|
5
|
-
NO_REPORT = 1
|
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
|
44
|
-
|
45
|
-
|
46
|
-
return in_interval? ? REPORTING : NO_REPORT
|
47
|
-
end
|
32
|
+
def to_status
|
33
|
+
in_interval? ? REPORTING : NO_REPORT
|
34
|
+
end
|
48
35
|
|
49
|
-
|
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
|
@@ -4,9 +4,15 @@ module InsightsCloud
|
|
4
4
|
include ::Actions::RecurringAction
|
5
5
|
|
6
6
|
def run
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
data/lib/tasks/insights.rake
CHANGED
@@ -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
@@ -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
|
20
|
-
InsightsClientReportStatus.find_or_initialize_by(host_id: @host2.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL
|
21
|
-
InsightsClientReportStatus.find_or_initialize_by(host_id: @host3.id).update(status: InsightsClientReportStatus::
|
22
|
-
InsightsClientReportStatus.find_or_initialize_by(host_id: @host4.id).update(status: InsightsClientReportStatus::
|
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::
|
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::
|
31
|
-
assert_equal InsightsClientReportStatus::
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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-
|
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
|