foreman_rh_cloud 3.0.24 → 3.0.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +5 -3
  3. data/app/models/insights_client_report_status.rb +8 -23
  4. data/app/services/foreman_rh_cloud/cloud_auth.rb +4 -0
  5. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +10 -0
  6. data/app/services/foreman_rh_cloud/insights_status_cleaner.rb +17 -0
  7. data/app/services/foreman_rh_cloud/remediations_retriever.rb +5 -0
  8. data/config/Gemfile.lock.gh_test +93 -95
  9. data/config/database.yml.example +2 -2
  10. data/config/routes.rb +1 -1
  11. data/db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb +6 -0
  12. data/lib/foreman_inventory_upload/generators/tags.rb +3 -1
  13. data/lib/foreman_rh_cloud/engine.rb +0 -2
  14. data/lib/foreman_rh_cloud/version.rb +1 -1
  15. data/lib/foreman_rh_cloud.rb +12 -1
  16. data/lib/insights_cloud/async/insights_client_status_aging.rb +9 -3
  17. data/lib/insights_cloud/async/insights_full_sync.rb +5 -0
  18. data/lib/insights_cloud/async/insights_resolutions_sync.rb +12 -2
  19. data/lib/insights_cloud/async/insights_rules_sync.rb +11 -2
  20. data/lib/inventory_sync/async/inventory_full_sync.rb +5 -0
  21. data/lib/inventory_sync/async/inventory_hosts_sync.rb +5 -0
  22. data/lib/inventory_sync/async/inventory_self_host_sync.rb +9 -0
  23. data/lib/tasks/insights.rake +15 -0
  24. data/package.json +3 -3
  25. data/test/jobs/insights_client_status_aging_test.rb +7 -7
  26. data/test/jobs/insights_full_sync_test.rb +1 -0
  27. data/test/jobs/insights_resolutions_sync_test.rb +11 -1
  28. data/test/jobs/insights_rules_sync_test.rb +1 -0
  29. data/test/jobs/inventory_full_sync_test.rb +10 -0
  30. data/test/jobs/inventory_hosts_sync_test.rb +1 -0
  31. data/test/jobs/inventory_self_host_sync_test.rb +1 -0
  32. data/test/models/insights_client_report_status_test.rb +70 -72
  33. data/test/unit/foreman_rh_cloud_self_host_test.rb +28 -0
  34. data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +1 -0
  35. data/test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb +31 -0
  36. data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +1 -0
  37. data/test/unit/tags_generator_test.rb +41 -0
  38. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +14 -0
  39. metadata +9 -4
  40. data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +0 -9
@@ -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
@@ -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
 
@@ -5,6 +5,11 @@ module InventorySync
5
5
  set_callback :step, :around, :create_facets
6
6
 
7
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
+
8
13
  # by default the tasks will be executed concurrently
9
14
  plan_self
10
15
  plan_self_host_sync
@@ -3,6 +3,15 @@ module InventorySync
3
3
  class InventorySelfHostSync < QueryInventoryJob
4
4
  set_callback :step, :around, :create_facets
5
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
+
6
15
  def create_facets
7
16
  # get the results from the event
8
17
  results = yield
@@ -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.24",
3
+ "version": "3.0.28",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,7 +26,6 @@
26
26
  },
27
27
  "devDependencies": {
28
28
  "@babel/core": "~7.7.0",
29
- "@redhat-cloud-services/frontend-components": "^2.5.0",
30
29
  "@theforeman/builder": "~4.14.0",
31
30
  "@theforeman/stories": "~4.14.0",
32
31
  "@theforeman/test": "~4.14.0",
@@ -43,6 +42,7 @@
43
42
  },
44
43
  "dependencies": {
45
44
  "jed": "~1.1.1",
46
- "react-intl": "~2.8.0"
45
+ "react-intl": "~2.8.0",
46
+ "@redhat-cloud-services/frontend-components": "^2.5.0"
47
47
  }
48
48
  }
@@ -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
@@ -7,6 +7,7 @@ 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')
10
11
 
11
12
  uuid1 = 'accdf444-5628-451d-bf3e-cf909ad72756'
12
13
  @host1 = FactoryBot.create(:host, :managed, name: 'host1')
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require 'test_plugin_helper'
2
2
  require 'foreman_tasks/test_helpers'
3
3
 
4
4
  class InsightsResolutionsSyncTest < ActiveSupport::TestCase
@@ -63,6 +63,7 @@ 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')
66
67
  end
67
68
 
68
69
  test 'Resolutions data is replaced with data from cloud' do
@@ -74,4 +75,13 @@ class InsightsResolutionsSyncTest < ActiveSupport::TestCase
74
75
  assert_equal 5, InsightsResolution.all.count
75
76
  assert_equal 2, @rule.resolutions.count
76
77
  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
77
87
  end
@@ -112,6 +112,7 @@ 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')
115
116
  end
116
117
 
117
118
  test 'Hits data is replaced with data from cloud' do
@@ -242,6 +242,7 @@ 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')
245
246
  InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
246
247
 
247
248
  ForemanTasks.sync_task(InventorySync::Async::InventoryFullSync, @host2.organization)
@@ -253,6 +254,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
253
254
  end
254
255
 
255
256
  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')
256
258
  InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
257
259
  FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
258
260
 
@@ -261,4 +263,12 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
261
263
 
262
264
  assert_equal InventorySync::InventoryStatus::DISCONNECT, InventorySync::InventoryStatus.where(host_id: @host1.id).first.status
263
265
  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
264
274
  end
@@ -6,6 +6,7 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
6
6
 
7
7
  setup do
8
8
  User.current = User.find_by(login: 'secret_admin')
9
+ FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
9
10
 
10
11
  env = FactoryBot.create(:katello_k_t_environment)
11
12
  cv = env.content_views << FactoryBot.create(:katello_content_view, organization: env.organization)
@@ -6,6 +6,7 @@ class InventorySelfHostSyncTest < ActiveSupport::TestCase
6
6
 
7
7
  setup do
8
8
  User.current = User.find_by(login: 'secret_admin')
9
+ FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
9
10
 
10
11
  # this host would pass our plugin queries, so it could be uploaded to the cloud.
11
12
  @host1 = FactoryBot.create(:host)
@@ -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,28 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class ForemanRhCloudSelfHostTest < ActiveSupport::TestCase
4
+ setup do
5
+ # reset cached value
6
+ ForemanRhCloud.instance_variable_set(:@foreman_host, nil)
7
+ end
8
+
9
+ test 'finds host by fullname' do
10
+ @domain
11
+ @host = FactoryBot.create(:host, :managed)
12
+ ForemanRhCloud.expects(:foreman_host_name).returns(@host.name)
13
+
14
+ actual = ForemanRhCloud.foreman_host
15
+
16
+ assert_not_nil actual
17
+ end
18
+
19
+ test 'finds host by shortname' do
20
+ @host = FactoryBot.create(:host, :managed)
21
+ Host.where(name: @host.name).update_all(name: @host.shortname)
22
+ ForemanRhCloud.expects(:foreman_host_name).returns(@host.name)
23
+
24
+ actual = ForemanRhCloud.foreman_host
25
+
26
+ assert_not_nil actual
27
+ end
28
+ end
@@ -48,6 +48,7 @@ class CloudRequestForwarderTest < ActiveSupport::TestCase
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",
51
52
  }
52
53
 
53
54
  paths.each do |key, value|
@@ -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
@@ -8,6 +8,7 @@ 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')
11
12
  end
12
13
 
13
14
  test 'Generates a playbook for hit and remediation' do
@@ -62,6 +62,47 @@ class TagsGeneratorTest < ActiveSupport::TestCase
62
62
  assert_equal false, actual.key?('content_view')
63
63
  end
64
64
 
65
+ test 'generates parameter tags' do
66
+ FactoryBot.create(:setting, :name => 'include_parameter_tags', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => true)
67
+
68
+ @host.stubs(:host_inherited_params_objects).returns(
69
+ [
70
+ OpenStruct.new(name: 'bool_param', value: true),
71
+ OpenStruct.new(name: 'false_param', value: false),
72
+ OpenStruct.new(name: 'int_param', value: 1),
73
+ OpenStruct.new(name: 'empty_param', value: nil),
74
+ OpenStruct.new(name: 'empty_str_param', value: ''),
75
+ ]
76
+ )
77
+
78
+ generator = create_generator
79
+ actual = Hash[generator.generate_parameters]
80
+
81
+ assert_equal 3, actual.count
82
+ assert_equal true, actual['bool_param']
83
+ assert_equal false, actual['false_param']
84
+ assert_equal 1, actual['int_param']
85
+ end
86
+
87
+ test 'skips parameter tags if include_parameter_tags setting is off' do
88
+ FactoryBot.create(:setting, :name => 'include_parameter_tags', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => false)
89
+
90
+ @host.stubs(:host_inherited_params_objects).returns(
91
+ [
92
+ OpenStruct.new(name: 'bool_param', value: true),
93
+ OpenStruct.new(name: 'false_param', value: false),
94
+ OpenStruct.new(name: 'int_param', value: 1),
95
+ OpenStruct.new(name: 'empty_param', value: nil),
96
+ OpenStruct.new(name: 'empty_str_param', value: ''),
97
+ ]
98
+ )
99
+
100
+ generator = create_generator
101
+ actual = generator.generate_parameters.group_by { |key, value| key }
102
+
103
+ assert_equal 0, actual.count
104
+ end
105
+
65
106
  private
66
107
 
67
108
  def create_generator
@@ -6,4 +6,18 @@
6
6
  margin-top: 5px;
7
7
  }
8
8
  }
9
+
10
+ // applies to the backdrop parent of the modal
11
+ @at-root .pf-c-backdrop {
12
+ width: calc(100% - 200px) !important;
13
+ left: 200px !important;
14
+ }
15
+
16
+ // where the vertical nav breaks: https://github.com/theforeman/foreman/blob/3347fa49d500964f0209122d8d36c920d1feafcc/webpack/assets/javascripts/react_app/components/Layout/components/Toolbar/HeaderToolbar.scss#L26
17
+ @media (max-width: 768px) {
18
+ @at-root .pf-c-backdrop {
19
+ width: 100% !important;
20
+ left: 0 !important;
21
+ }
22
+ }
9
23
  }
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: 3.0.24
4
+ version: 3.0.28
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-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katello
@@ -180,9 +180,9 @@ files:
180
180
  - app/services/foreman_rh_cloud/cloud_connector.rb
181
181
  - app/services/foreman_rh_cloud/cloud_request.rb
182
182
  - app/services/foreman_rh_cloud/cloud_request_forwarder.rb
183
+ - app/services/foreman_rh_cloud/insights_status_cleaner.rb
183
184
  - app/services/foreman_rh_cloud/remediations_retriever.rb
184
185
  - app/services/foreman_rh_cloud/template_renderer_helper.rb
185
- - app/subscribers/foreman_rh_cloud/insights_subscriber.rb
186
186
  - app/views/hosts/_insights_tab.html.erb
187
187
  - app/views/job_templates/rh_cloud_remediations.erb
188
188
  - app/views/layouts/foreman_rh_cloud/application.html.erb
@@ -200,6 +200,7 @@ files:
200
200
  - db/migrate/20210214000002_add_rule_id_to_hits.foreman_rh_cloud.rb
201
201
  - db/migrate/20210307000001_add_unique_to_insights_facet.foreman_rh_cloud.rb
202
202
  - db/migrate/20210404000001_change_resolutions.foreman_rh_cloud.rb
203
+ - db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb
203
204
  - db/seeds.d/179_ui_notifications.rb
204
205
  - db/seeds.d/50_job_templates.rb
205
206
  - lib/foreman_inventory_upload.rb
@@ -266,11 +267,13 @@ files:
266
267
  - test/test_plugin_helper.rb
267
268
  - test/unit/archived_report_generator_test.rb
268
269
  - test/unit/fact_helpers_test.rb
270
+ - test/unit/foreman_rh_cloud_self_host_test.rb
269
271
  - test/unit/insights_facet_test.rb
270
272
  - test/unit/metadata_generator_test.rb
271
273
  - test/unit/rh_cloud_http_proxy_test.rb
272
274
  - test/unit/services/foreman_rh_cloud/branch_info_test.rb
273
275
  - test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb
276
+ - test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb
274
277
  - test/unit/services/foreman_rh_cloud/remediations_retriever_test.rb
275
278
  - test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb
276
279
  - test/unit/shell_process_job_test.rb
@@ -669,7 +672,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
669
672
  - !ruby/object:Gem::Version
670
673
  version: '0'
671
674
  requirements: []
672
- rubygems_version: 3.2.15
675
+ rubygems_version: 3.2.22
673
676
  signing_key:
674
677
  specification_version: 4
675
678
  summary: Summary of ForemanRhCloud.
@@ -696,11 +699,13 @@ test_files:
696
699
  - test/test_plugin_helper.rb
697
700
  - test/unit/archived_report_generator_test.rb
698
701
  - test/unit/fact_helpers_test.rb
702
+ - test/unit/foreman_rh_cloud_self_host_test.rb
699
703
  - test/unit/insights_facet_test.rb
700
704
  - test/unit/metadata_generator_test.rb
701
705
  - test/unit/rh_cloud_http_proxy_test.rb
702
706
  - test/unit/services/foreman_rh_cloud/branch_info_test.rb
703
707
  - test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb
708
+ - test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb
704
709
  - test/unit/services/foreman_rh_cloud/remediations_retriever_test.rb
705
710
  - test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb
706
711
  - 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