foreman_rh_cloud 3.0.18.1 → 4.0.21.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -5
  3. data/app/controllers/foreman_inventory_upload/tasks_controller.rb +14 -3
  4. data/app/controllers/foreman_inventory_upload/uploads_settings_controller.rb +8 -0
  5. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +17 -7
  6. data/app/controllers/insights_cloud/hits_controller.rb +37 -0
  7. data/app/controllers/insights_cloud/settings_controller.rb +1 -1
  8. data/app/controllers/insights_cloud/tasks_controller.rb +1 -2
  9. data/app/models/insights_client_report_status.rb +58 -0
  10. data/app/models/insights_resolution.rb +1 -1
  11. data/app/models/inventory_sync/inventory_status.rb +6 -0
  12. data/app/models/setting/rh_cloud.rb +5 -5
  13. data/app/services/foreman_rh_cloud/cloud_connector.rb +1 -1
  14. data/app/services/foreman_rh_cloud/remediations_retriever.rb +78 -0
  15. data/app/services/foreman_rh_cloud/template_renderer_helper.rb +22 -0
  16. data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +9 -0
  17. data/app/views/job_templates/rh_cloud_remediations.erb +14 -0
  18. data/config/routes.rb +2 -1
  19. data/db/migrate/20210404000001_change_resolutions.foreman_rh_cloud.rb +10 -0
  20. data/db/seeds.d/179_ui_notifications.rb +11 -0
  21. data/db/seeds.d/50_job_templates.rb +14 -0
  22. data/lib/foreman_inventory_upload.rb +9 -0
  23. data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +8 -2
  24. data/lib/foreman_inventory_upload/generators/queries.rb +3 -2
  25. data/lib/foreman_inventory_upload/generators/slice.rb +1 -1
  26. data/lib/foreman_inventory_upload/generators/tags.rb +8 -6
  27. data/lib/foreman_inventory_upload/scripts/uploader.sh.erb +5 -1
  28. data/lib/foreman_rh_cloud.rb +18 -0
  29. data/lib/foreman_rh_cloud/engine.rb +36 -2
  30. data/lib/foreman_rh_cloud/version.rb +1 -1
  31. data/lib/insights_cloud.rb +12 -0
  32. data/lib/insights_cloud/async/insights_full_sync.rb +39 -24
  33. data/lib/insights_cloud/async/insights_generate_notifications.rb +58 -0
  34. data/lib/insights_cloud/async/insights_resolutions_sync.rb +69 -0
  35. data/lib/insights_cloud/async/insights_rules_sync.rb +13 -17
  36. data/lib/insights_cloud/async/insights_scheduled_sync.rb +1 -1
  37. data/lib/inventory_sync/async/host_result.rb +11 -6
  38. data/lib/inventory_sync/async/inventory_full_sync.rb +24 -41
  39. data/lib/inventory_sync/async/inventory_hosts_sync.rb +34 -0
  40. data/lib/inventory_sync/async/inventory_scheduled_sync.rb +17 -0
  41. data/lib/inventory_sync/async/query_inventory_job.rb +54 -0
  42. data/lib/tasks/insights.rake +4 -12
  43. data/lib/tasks/rh_cloud_inventory.rake +12 -4
  44. data/package.json +1 -1
  45. data/test/factories/insights_factories.rb +22 -0
  46. data/test/jobs/insights_full_sync_test.rb +28 -15
  47. data/test/jobs/insights_resolutions_sync_test.rb +77 -0
  48. data/test/jobs/insights_rules_sync_test.rb +8 -3
  49. data/test/jobs/inventory_full_sync_test.rb +185 -12
  50. data/test/models/insights_client_report_status_test.rb +77 -0
  51. data/test/unit/rh_cloud_http_proxy_test.rb +4 -4
  52. data/test/unit/services/foreman_rh_cloud/remediations_retriever_test.rb +49 -0
  53. data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +28 -0
  54. data/test/unit/slice_generator_test.rb +11 -2
  55. data/test/unit/tags_generator_test.rb +10 -0
  56. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModal.js +1 -1
  57. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/__snapshots__/FullScreenModal.test.js.snap +1 -1
  58. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/fullScreenModal.scss +14 -16
  59. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.js +1 -1
  60. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +0 -1
  61. data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/AdvancedSettingsConstants.js +5 -3
  62. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +15 -2
  63. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +13 -2
  64. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +81 -46
  65. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonConstants.js +3 -3
  66. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonSelectors.js +6 -12
  67. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonFixtures.js +1 -9
  68. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonSelectors.test.js +18 -27
  69. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonSelectors.test.js.snap +1 -16
  70. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +58 -0
  71. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/integrations.test.js +51 -0
  72. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/index.js +2 -5
  73. data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +1 -1
  74. data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/Terminal.test.js +1 -1
  75. data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/__snapshots__/Terminal.test.js.snap +2 -2
  76. data/webpack/ForemanInventoryUpload/Components/Terminal/terminal.scss +25 -27
  77. data/webpack/ForemanInventoryUpload/ForemanInventoryUploadReducers.js +0 -2
  78. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +1 -1
  79. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableSelectors.js +3 -0
  80. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +2 -0
  81. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +59 -0
  82. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationActions.js +12 -0
  83. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationHelpers.js +43 -0
  84. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js +101 -0
  85. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +9 -0
  86. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModalFooter.js +43 -0
  87. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationTableConstants.js +38 -0
  88. data/webpack/InsightsCloudSync/Components/RemediationModal/Resolutions.js +55 -0
  89. data/webpack/InsightsCloudSync/Components/RemediationModal/index.js +34 -0
  90. data/webpack/InsightsCloudSync/InsightsCloudSync.js +8 -3
  91. data/webpack/InsightsCloudSync/InsightsCloudSync.scss +5 -0
  92. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +9 -6
  93. data/webpack/__mocks__/foremanReact/redux/middlewares/IntervalMiddleware.js +4 -0
  94. data/webpack/{InsightsCloudSync/Components/InsightsTable/components → common/table}/EmptyState.js +0 -0
  95. data/webpack/common/table/helpers.js +7 -0
  96. metadata +56 -26
  97. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonReducer.js +0 -36
  98. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonActions.test.js +0 -31
  99. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonReducer.test.js +0 -26
  100. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonActions.test.js.snap +0 -98
  101. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonReducer.test.js.snap +0 -18
@@ -0,0 +1,77 @@
1
+ require 'test_plugin_helper'
2
+
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
76
+ end
77
+ end
@@ -2,16 +2,16 @@ require 'test_plugin_helper'
2
2
 
3
3
  class RhCloudHttpProxyTest < ActiveSupport::TestCase
4
4
  setup do
5
- @global_content_proxy_mock = 'http://global:content@localhost:8888'
6
- @global_foreman_proxy_mock = 'http://global:foreman@localhost:8888'
5
+ @global_content_proxy_mock = 'http://global:content@localhost:80'
6
+ @global_foreman_proxy_mock = 'http://global:foreman@localhost:80'
7
7
  @katello_cdn_proxy_mock = {
8
8
  host: 'localhost',
9
- port: '8888',
9
+ port: '80',
10
10
  user: 'katello',
11
11
  password: 'cdn',
12
12
  scheme: 'http',
13
13
  }
14
- @katello_cdn_proxy_string_mock = 'http://katello:cdn@localhost:8888'
14
+ @katello_cdn_proxy_string_mock = 'http://katello:cdn@localhost:80'
15
15
  end
16
16
 
17
17
  test 'selects global content proxy' do
@@ -0,0 +1,49 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class RemediationsRetrieverTest < ActiveSupport::TestCase
4
+ setup do
5
+ @host1 = FactoryBot.create(:host)
6
+ @host2 = FactoryBot.create(:host)
7
+ end
8
+ test 'groups hosts together' do
9
+ rule1 = FactoryBot.create(:insights_rule)
10
+ rule1_remediation1 = FactoryBot.create(:insights_resolution, rule_id: rule1.rule_id, resolution_type: 'fix')
11
+
12
+ FactoryBot.create(:insights_facet, uuid: 'HOST1', host_id: @host1.id)
13
+ host1_hit1 = FactoryBot.create(:insights_hit, rule_id: rule1.rule_id, host_id: @host1.id)
14
+
15
+ FactoryBot.create(:insights_facet, uuid: 'HOST2', host_id: @host2.id)
16
+ host2_hit1 = FactoryBot.create(:insights_hit, rule_id: rule1.rule_id, host_id: @host2.id)
17
+
18
+ pairs = [{'hit_id' => host1_hit1.id, 'resolution_id' => rule1_remediation1.id}, {'hit_id' => host2_hit1.id, 'resolution_id' => rule1_remediation1.id}]
19
+ retriever = ForemanRhCloud::RemediationsRetriever.new(pairs)
20
+
21
+ actual_request = retriever.send(:playbook_request)
22
+
23
+ assert_not_nil (issues = actual_request[:issues])
24
+ assert_not_nil (resolution = issues.first)
25
+ assert_equal 'fix', resolution[:resolution]
26
+ assert_equal "advisor:#{rule1.rule_id}", resolution[:id]
27
+ assert_same_elements ['HOST1', 'HOST2'], resolution[:systems]
28
+ end
29
+
30
+ test 'does not group different resolutions' do
31
+ rule1 = FactoryBot.create(:insights_rule)
32
+ rule1_remediation1 = FactoryBot.create(:insights_resolution, rule_id: rule1.rule_id, resolution_type: 'fix')
33
+ rule1_remediation2 = FactoryBot.create(:insights_resolution, rule_id: rule1.rule_id, resolution_type: 'panic')
34
+
35
+ FactoryBot.create(:insights_facet, uuid: 'HOST1', host_id: @host1.id)
36
+ host1_hit1 = FactoryBot.create(:insights_hit, rule_id: rule1.rule_id, host_id: @host1.id)
37
+
38
+ FactoryBot.create(:insights_facet, uuid: 'HOST2', host_id: @host2.id)
39
+ host2_hit1 = FactoryBot.create(:insights_hit, rule_id: rule1.rule_id, host_id: @host2.id)
40
+
41
+ pairs = [{'hit_id' => host1_hit1.id, 'resolution_id' => rule1_remediation1.id}, {'hit_id' => host2_hit1.id, 'resolution_id' => rule1_remediation2.id}]
42
+ retriever = ForemanRhCloud::RemediationsRetriever.new(pairs)
43
+
44
+ actual_request = retriever.send(:playbook_request)
45
+
46
+ assert_not_nil (issues = actual_request[:issues])
47
+ assert_equal 2, issues.count
48
+ end
49
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class TemplateRendererHelperTest < ActiveSupport::TestCase
4
+ include ForemanRhCloud::TemplateRendererHelper
5
+
6
+ setup do
7
+ response = mock('respone')
8
+ response.stubs(:body).returns('TEST PLAYBOOK')
9
+ ForemanRhCloud::RemediationsRetriever.any_instance.stubs(:query_playbook).returns(response)
10
+ @host1 = FactoryBot.create(:host)
11
+ end
12
+
13
+ test 'Generates a playbook for hit and remediation' do
14
+ rule = FactoryBot.create(:insights_rule)
15
+ hit = FactoryBot.create(:insights_hit, rule: rule, host_id: @host1.id)
16
+ remediation = FactoryBot.create(:insights_resolution, rule: rule)
17
+
18
+ pairs = [{hit_id: hit.id, remediation_id: remediation.id}].to_json
19
+
20
+ actual_playbook = remediations_playbook(pairs)
21
+
22
+ assert_equal 'TEST PLAYBOOK', actual_playbook
23
+ end
24
+
25
+ def template_logger
26
+ Logger.new(IO::NULL)
27
+ end
28
+ end
@@ -296,6 +296,13 @@ class SliceGeneratorTest < ActiveSupport::TestCase
296
296
  @host.hostgroup = hostgroup
297
297
  @host.save!
298
298
 
299
+ ForemanInventoryUpload::Generators::Tags.any_instance.expects(:generate_parameters).returns(
300
+ [
301
+ ['bool_param', true],
302
+ ['int_param', 1],
303
+ ]
304
+ )
305
+
299
306
  Foreman.expects(:instance_id).twice.returns('satellite-id')
300
307
  batch = Host.where(id: @host.id).in_batches.first
301
308
  generator = create_generator(batch)
@@ -316,6 +323,8 @@ class SliceGeneratorTest < ActiveSupport::TestCase
316
323
  assert_tag(@host.location.name, actual_host, 'location')
317
324
  assert_tag(@host.organization.name, actual_host, 'organization')
318
325
  assert_tag(@host.hostgroup.name, actual_host, 'hostgroup')
326
+ assert_tag('true', actual_host, 'bool_param', 'satellite_parameter')
327
+ assert_tag('1', actual_host, 'int_param', 'satellite_parameter')
319
328
 
320
329
  assert_equal false, satellite_facts['is_hostname_obfuscated']
321
330
 
@@ -632,8 +641,8 @@ class SliceGeneratorTest < ActiveSupport::TestCase
632
641
  generator
633
642
  end
634
643
 
635
- def assert_tag(expected_value, host, tag_id)
636
- actual_tag = host['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == tag_id }
644
+ def assert_tag(expected_value, host, tag_id, namespace = 'satellite')
645
+ actual_tag = host['tags'].find { |tag| tag['namespace'] == namespace && tag['key'] == tag_id }
637
646
  assert_not_nil actual_tag
638
647
  assert_equal expected_value, actual_tag['value']
639
648
  end
@@ -52,6 +52,16 @@ class TagsGeneratorTest < ActiveSupport::TestCase
52
52
  assert_equal @host.organization_id.to_s, actual['organization_id'].first.last
53
53
  end
54
54
 
55
+ test 'filters tags with empty values' do
56
+ generator = create_generator
57
+
58
+ @host.stubs(:content_view)
59
+
60
+ actual = generator.generate.group_by { |key, value| key }
61
+
62
+ assert_equal false, actual.key?('content_view')
63
+ end
64
+
55
65
  private
56
66
 
57
67
  def create_generator
@@ -12,7 +12,7 @@ const FullScreenModal = ({
12
12
  terminalProps,
13
13
  }) => (
14
14
  <Modal
15
- id="full-screen-terminal"
15
+ id="rh-cloud-inventory-full-screen-terminal"
16
16
  show={showFullScreen}
17
17
  onHide={toggleFullScreen}
18
18
  >
@@ -8,7 +8,7 @@ exports[`FullScreenModal rendering render without Props 1`] = `
8
8
  bsClass="modal"
9
9
  dialogComponentClass={[Function]}
10
10
  enforceFocus={true}
11
- id="full-screen-terminal"
11
+ id="rh-cloud-inventory-full-screen-terminal"
12
12
  keyboard={true}
13
13
  manager={
14
14
  ModalManager {
@@ -1,21 +1,19 @@
1
- .rh-cloud-inventory-page {
2
- #full-screen-terminal {
3
- .modal-dialog {
4
- width: 95%;
5
- height: 95%;
6
- margin: 30px 0 0 30px;
1
+ #rh-cloud-inventory-full-screen-terminal {
2
+ .modal-dialog {
3
+ width: 95%;
4
+ height: 95%;
5
+ margin: 30px 0 0 30px;
7
6
 
8
- .modal-body {
9
- padding: 0;
10
- display: flex;
11
- height: -webkit-fill-available;
12
- height: -moz-available;
13
- height: fill-available;
7
+ .modal-body {
8
+ padding: 0;
9
+ display: flex;
10
+ height: -webkit-fill-available;
11
+ height: -moz-available;
12
+ height: fill-available;
14
13
 
15
- .terminal {
16
- margin: 0 -20px;
17
- height: 100%;
18
- }
14
+ .rh-cloud-inventory-terminal {
15
+ margin: 0 -20px;
16
+ height: 100%;
19
17
  }
20
18
  }
21
19
  }
@@ -18,7 +18,7 @@ const InventoryFilter = ({
18
18
  const initialTerm =
19
19
  organization === __(ANY_ORGANIZATION) ? '' : organization;
20
20
  handleFilterChange(initialTerm);
21
- }, [organization]);
21
+ }, []);
22
22
 
23
23
  return (
24
24
  <form id="inventory_filter_form">
@@ -37,7 +37,6 @@ Object {
37
37
  "inventoryFilter": Object {
38
38
  "filterTerm": "some-org",
39
39
  },
40
- "inventorySync": Object {},
41
40
  },
42
41
  },
43
42
  },
@@ -3,7 +3,7 @@ import { translate as __ } from 'foremanReact/common/I18n';
3
3
  export const settingsDict = {
4
4
  autoUploadEnabled: {
5
5
  name: 'allow_auto_inventory_upload',
6
- label: __('Auto upload'),
6
+ label: __('Automatic inventory upload'),
7
7
  tooltip: __(
8
8
  'Enable automatic upload of your hosts inventory to the Red Hat cloud'
9
9
  ),
@@ -20,7 +20,9 @@ export const settingsDict = {
20
20
  },
21
21
  excludePackagesEnabled: {
22
22
  name: 'exclude_installed_packages',
23
- label: __('Exclude Packages'),
24
- tooltip: __('Exclude packages from being uploaded to the Red Hat cloud'),
23
+ label: __('Exclude installed Packages'),
24
+ tooltip: __(
25
+ 'Exclude installed packages from being uploaded to the Red Hat cloud'
26
+ ),
25
27
  },
26
28
  };
@@ -10,14 +10,27 @@ export const PageDescription = () => (
10
10
  </p>
11
11
  <p>
12
12
  {__(
13
- 'In order to utilize these services, you can set the auto upload in the settings to "ON".'
13
+ 'You can toggle the Auto upload switch to the ON position to enable Satellite to automatically upload your host inventory once a day.'
14
14
  )}
15
15
  </p>
16
16
  <p>
17
17
  {__(
18
- 'You can also trigger the upload manually by opening the relevant organization card, and clicking on the "Restart" button'
18
+ 'Click Restart to upload your host inventory to Red Hat Insights. Perform this step for each organization from which you want to manually upload a host inventory.'
19
19
  )}
20
20
  </p>
21
+ <p>
22
+ {__(
23
+ 'Enabling inventory uploads is required by subscription watch. For more information about subscription watch see link:'
24
+ )}
25
+ &nbsp;
26
+ <a
27
+ href="https://access.redhat.com/documentation/en-us/subscription_central/2020-04/html/getting_started_with_subscription_watch/assembly-about-subscriptionwatch"
28
+ target="_blank"
29
+ rel="noopener noreferrer"
30
+ >
31
+ About subscription watch
32
+ </a>
33
+ </p>
21
34
  </div>
22
35
  );
23
36
 
@@ -8,10 +8,21 @@ exports[`PageDescription rendering render without Props 1`] = `
8
8
  Red Hat Insights is a set of cloud services which provide unified subscription reporting, predictive analysis and remediation of issues through this Satellite instance.
9
9
  </p>
10
10
  <p>
11
- In order to utilize these services, you can set the auto upload in the settings to "ON".
11
+ You can toggle the Auto upload switch to the ON position to enable Satellite to automatically upload your host inventory once a day.
12
12
  </p>
13
13
  <p>
14
- You can also trigger the upload manually by opening the relevant organization card, and clicking on the "Restart" button
14
+ Click Restart to upload your host inventory to Red Hat Insights. Perform this step for each organization from which you want to manually upload a host inventory.
15
+ </p>
16
+ <p>
17
+ Enabling inventory uploads is required by subscription watch. For more information about subscription watch see link:
18
+  
19
+ <a
20
+ href="https://access.redhat.com/documentation/en-us/subscription_central/2020-04/html/getting_started_with_subscription_watch/assembly-about-subscriptionwatch"
21
+ rel="noopener noreferrer"
22
+ target="_blank"
23
+ >
24
+ About subscription watch
25
+ </a>
15
26
  </p>
16
27
  </div>
17
28
  `;
@@ -1,57 +1,92 @@
1
1
  import React from 'react';
2
- import { API } from 'foremanReact/redux/API';
2
+ import { get, post } from 'foremanReact/redux/API';
3
+ import { withInterval } from 'foremanReact/redux/middlewares/IntervalMiddleware';
3
4
  import { addToast } from 'foremanReact/redux/actions/toasts';
5
+ import { translate as __ } from 'foremanReact/common/I18n';
4
6
  import { inventoryUrl } from '../../../../ForemanInventoryHelpers';
5
7
  import Toast from './components/Toast';
6
8
  import {
7
- INVENTORY_SYNC_REQUEST,
8
- INVENTORY_SYNC_SUCCESS,
9
- INVENTORY_SYNC_ERROR,
9
+ INVENTORY_SYNC,
10
+ INVENTORY_SYNC_TASK_UPDATE,
10
11
  } from './SyncButtonConstants';
12
+ import { foremanUrl } from '../../../../../ForemanRhCloudHelpers';
11
13
 
12
- export const handleSync = () => async dispatch => {
13
- dispatch({
14
- type: INVENTORY_SYNC_REQUEST,
15
- payload: {},
16
- });
17
- try {
18
- const {
19
- data: { syncHosts, disconnectHosts },
20
- } = await API.post(inventoryUrl('tasks'));
21
- dispatch({
22
- type: INVENTORY_SYNC_SUCCESS,
23
- payload: {
24
- syncHosts,
25
- disconnectHosts,
26
- },
27
- });
28
-
29
- dispatch(
30
- addToast({
31
- sticky: true,
32
- type: 'success',
33
- message: (
34
- <Toast syncHosts={syncHosts} disconnectHosts={disconnectHosts} />
35
- ),
36
- })
37
- );
38
- } catch ({
39
- message,
40
- response: { data: { message: toastMessage } = {} } = {},
41
- }) {
42
- dispatch({
43
- type: INVENTORY_SYNC_ERROR,
44
- payload: {
45
- error: message,
14
+ export const handleSync = () => dispatch => {
15
+ dispatch(
16
+ post({
17
+ key: INVENTORY_SYNC,
18
+ url: inventoryUrl('tasks'),
19
+ handleSuccess: ({
20
+ data: {
21
+ task: { id },
22
+ },
23
+ }) => {
24
+ dispatch(getSyncTaskInterval(id));
25
+ return dispatch(
26
+ taskPageRefererToast(id, 'info', __('Inventory sync has started:'))
27
+ );
46
28
  },
47
- });
29
+ errorToast: inventorySyncErrorToast,
30
+ })
31
+ );
32
+ };
48
33
 
49
- dispatch(
50
- addToast({
51
- sticky: true,
52
- type: 'error',
53
- message: toastMessage || message,
34
+ export const getSyncTaskInterval = id => dispatch => {
35
+ dispatch(
36
+ withInterval(
37
+ get({
38
+ key: INVENTORY_SYNC_TASK_UPDATE,
39
+ url: inventoryUrl(`tasks/${id}`),
40
+ handleSuccess: ({ data: { result, output } }, stopTaskInterval) => {
41
+ if (result === 'success') {
42
+ const {
43
+ host_statuses: { sync, disconnect },
44
+ } = output;
45
+ dispatch(
46
+ addToast({
47
+ sticky: true,
48
+ type: 'success',
49
+ message: (
50
+ <Toast syncHosts={sync} disconnectHosts={disconnect} />
51
+ ),
52
+ })
53
+ );
54
+ }
55
+ if (result === 'error') {
56
+ dispatch(
57
+ taskPageRefererToast(
58
+ id,
59
+ 'error',
60
+ __('Inventory sync has failed:'),
61
+ true
62
+ )
63
+ );
64
+ }
65
+ stopTaskInterval();
66
+ },
67
+ errorToast: inventorySyncErrorToast,
54
68
  })
55
- );
56
- }
69
+ )
70
+ );
57
71
  };
72
+
73
+ const inventorySyncErrorToast = ({ message, response }) =>
74
+ `${__('Inventory sync has failed: ')} ${response.data?.message || message}`;
75
+
76
+ const taskPageRefererToast = (taskID, toastType, prefix, sticky = false) =>
77
+ addToast({
78
+ sticky,
79
+ type: toastType,
80
+ message: (
81
+ <span>
82
+ {prefix}{' '}
83
+ <a
84
+ target="_blank"
85
+ rel="noopener noreferrer"
86
+ href={foremanUrl(`/foreman_tasks/tasks/${taskID}`)}
87
+ >
88
+ {__('view the task page for more details')}
89
+ </a>
90
+ </span>
91
+ ),
92
+ });