foreman_rh_cloud 4.0.31 → 5.0.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/inventory_upload/report_actions.rb +1 -1
  3. data/app/controllers/foreman_inventory_upload/reports_controller.rb +1 -1
  4. data/app/controllers/insights_cloud/hits_controller.rb +1 -1
  5. data/app/models/insights_hit.rb +4 -0
  6. data/app/models/setting/rh_cloud.rb +0 -1
  7. data/app/models/task_output_line.rb +2 -0
  8. data/app/models/task_output_status.rb +2 -0
  9. data/config/Gemfile.lock.gh_test +204 -168
  10. data/config/package-lock.json.gh_test +14336 -7973
  11. data/config/package-lock.json.plugin +10551 -7500
  12. data/config/routes.rb +1 -1
  13. data/db/migrate/20211027000001_create_task_output.foreman_rh_cloud.rb +18 -0
  14. data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +11 -7
  15. data/lib/foreman_inventory_upload/async/generate_report_job.rb +24 -12
  16. data/lib/foreman_inventory_upload/async/progress_output.rb +5 -28
  17. data/lib/foreman_inventory_upload/async/queue_for_upload_job.rb +20 -5
  18. data/lib/foreman_inventory_upload/async/shell_process.rb +17 -4
  19. data/lib/foreman_inventory_upload/async/upload_report_job.rb +22 -13
  20. data/lib/foreman_rh_cloud/engine.rb +12 -11
  21. data/lib/foreman_rh_cloud/version.rb +1 -1
  22. data/lib/insights_cloud/async/insights_scheduled_sync.rb +11 -7
  23. data/lib/tasks/rh_cloud_inventory.rake +2 -2
  24. data/package.json +7 -12
  25. data/test/controllers/insights_sync/settings_controller_test.rb +2 -2
  26. data/test/controllers/uploads_settings_controller_test.rb +2 -2
  27. data/test/jobs/insights_full_sync_test.rb +2 -2
  28. data/test/jobs/insights_resolutions_sync_test.rb +1 -1
  29. data/test/jobs/insights_rules_sync_test.rb +2 -2
  30. data/test/jobs/inventory_full_sync_test.rb +3 -3
  31. data/test/jobs/inventory_hosts_sync_test.rb +1 -1
  32. data/test/jobs/inventory_scheduled_sync_test.rb +2 -2
  33. data/test/jobs/inventory_self_host_sync_test.rb +1 -1
  34. data/test/jobs/upload_report_job_test.rb +6 -4
  35. data/test/test_plugin_helper.rb +0 -2
  36. data/test/unit/rh_cloud_http_proxy_test.rb +1 -1
  37. data/test/unit/rh_cloud_permissions_test.rb +14 -0
  38. data/test/unit/services/foreman_rh_cloud/branch_info_test.rb +1 -1
  39. data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +1 -1
  40. data/test/unit/shell_process_job_test.rb +3 -1
  41. data/test/unit/slice_generator_test.rb +3 -3
  42. data/test/unit/tags_generator_test.rb +2 -2
  43. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +1 -1
  44. data/webpack/ForemanInventoryUpload/Components/AccountList/accountList.scss +8 -0
  45. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.js +3 -3
  46. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/index.js +0 -2
  47. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.scss +17 -4
  48. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageTitle.js +29 -17
  49. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageTitle.test.js.snap +58 -47
  50. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +12 -10
  51. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +10 -10
  52. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +1 -1
  53. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/__snapshots__/InventoryAutoUpload.test.js.snap +1 -1
  54. data/webpack/ForemanRhCloudFills.js +14 -0
  55. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsActions.js +1 -1
  56. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +22 -6
  57. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +23 -16
  58. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableConstants.js +49 -2
  59. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js +31 -14
  60. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +19 -2
  61. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +0 -1
  62. data/webpack/InsightsCloudSync/Components/InsightsTable/table.scss +11 -13
  63. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +0 -14
  64. data/webpack/InsightsCloudSync/Components/ToolbarDropdown.js +13 -0
  65. data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +24 -13
  66. data/webpack/InsightsCloudSync/InsightsCloudSyncHelpers.js +8 -0
  67. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +1 -1
  68. data/webpack/InsightsHostDetailsTab/InsightsTab.scss +4 -0
  69. data/webpack/InsightsHostDetailsTab/InsightsTabActions.js +1 -1
  70. data/webpack/InsightsHostDetailsTab/InsightsTabConstants.js +75 -0
  71. data/webpack/InsightsHostDetailsTab/InsightsTotalRiskChart.js +147 -0
  72. data/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js +103 -0
  73. data/webpack/__mocks__/foremanReact/Root/Context/ForemanContext.js +1 -0
  74. data/webpack/__mocks__/foremanReact/components/Head.js +11 -0
  75. data/webpack/__mocks__/foremanReact/{redux/actions/toasts.js → components/ToastsList/index.js} +0 -0
  76. data/webpack/common/DropdownToggle.js +24 -0
  77. data/webpack/common/ForemanTasks/ForemanTasksActions.js +1 -1
  78. data/webpack/common/Switcher/__tests__/__snapshots__/SwitcherPF4.test.js.snap +1 -0
  79. metadata +11 -3
  80. data/webpack/__mocks__/foremanReact/components/Layout/LayoutSelectors.js +0 -1
data/config/routes.rb CHANGED
@@ -18,7 +18,7 @@ Rails.application.routes.draw do
18
18
  namespace :insights_cloud do
19
19
  resources :tasks, only: [:create]
20
20
  resource :settings, only: [:show, :update]
21
- resources :hits, except: %i[show] do
21
+ resources :hits, only: [:index] do
22
22
  collection do
23
23
  get 'auto_complete_search'
24
24
  get 'resolutions', to: 'hits#resolutions'
@@ -0,0 +1,18 @@
1
+ class CreateTaskOutput < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :task_output_lines do |t|
4
+ t.string :label
5
+ t.string :line
6
+ t.timestamps
7
+
8
+ t.index :label
9
+ end
10
+
11
+ create_table :task_output_statuses do |t|
12
+ t.string :label
13
+ t.string :status
14
+
15
+ t.index :label, unique: true
16
+ end
17
+ end
18
+ end
@@ -1,7 +1,9 @@
1
1
  module ForemanInventoryUpload
2
2
  module Async
3
- class GenerateAllReportsJob < ::ApplicationJob
4
- def perform
3
+ class GenerateAllReportsJob < ::Actions::EntryAction
4
+ include ::Actions::RecurringAction
5
+
6
+ def plan
5
7
  unless Setting[:allow_auto_inventory_upload]
6
8
  logger.debug(
7
9
  'The scheduled process is disabled due to the "allow_auto_inventory_upload"
@@ -16,17 +18,19 @@ module ForemanInventoryUpload
16
18
  total_hosts = ForemanInventoryUpload::Generators::Queries.for_org(organization.id, use_batches: false).count
17
19
 
18
20
  if total_hosts <= ForemanInventoryUpload.max_org_size
19
- GenerateReportJob.perform_later(ForemanInventoryUpload.generated_reports_folder, organization.id)
21
+ plan_generate_report(ForemanInventoryUpload.generated_reports_folder, organization)
20
22
  else
21
23
  logger.info("Skipping automatic uploads for organization #{organization.name}, too many hosts (#{total_hosts}/#{ForemanInventoryUpload.max_org_size})")
22
24
  end
23
25
  end.compact
24
- ensure
25
- self.class.set(:wait => 24.hours).perform_later
26
26
  end
27
27
 
28
- def self.singleton_job_name
29
- name
28
+ def rescue_strategy_for_self
29
+ Dynflow::Action::Rescue::Fail
30
+ end
31
+
32
+ def plan_generate_report(folder, organization)
33
+ plan_action(ForemanInventoryUpload::Async::GenerateReportJob, folder, organization.id)
30
34
  end
31
35
  end
32
36
  end
@@ -5,17 +5,21 @@ module ForemanInventoryUpload
5
5
  "report_for_#{label}"
6
6
  end
7
7
 
8
- def perform(base_folder, organization)
9
- @base_folder = base_folder
10
- @organization = organization
8
+ def plan(base_folder, organization_id)
9
+ sequence do
10
+ super(
11
+ GenerateReportJob.output_label(organization_id),
12
+ organization_id: organization_id,
13
+ base_folder: base_folder
14
+ )
11
15
 
12
- super(GenerateReportJob.output_label(organization))
13
-
14
- QueueForUploadJob.perform_later(
15
- base_folder,
16
- ForemanInventoryUpload.facts_archive_name(organization),
17
- organization
18
- )
16
+ plan_action(
17
+ QueueForUploadJob,
18
+ base_folder,
19
+ ForemanInventoryUpload.facts_archive_name(organization_id),
20
+ organization_id
21
+ )
22
+ end
19
23
  end
20
24
 
21
25
  def rake_prefix
@@ -28,10 +32,18 @@ module ForemanInventoryUpload
28
32
 
29
33
  def env
30
34
  super.merge(
31
- 'target' => @base_folder,
32
- 'organization_id' => @organization
35
+ 'target' => base_folder,
36
+ 'organization_id' => organization_id
33
37
  )
34
38
  end
39
+
40
+ def base_folder
41
+ input[:base_folder]
42
+ end
43
+
44
+ def organization_id
45
+ input[:organization_id]
46
+ end
35
47
  end
36
48
  end
37
49
  end
@@ -6,6 +6,7 @@ module ForemanInventoryUpload
6
6
  end
7
7
 
8
8
  def self.register(label)
9
+ TaskOutputLine.where(label: @label).delete_all
9
10
  ProgressOutput.new(label, :writer)
10
11
  end
11
12
 
@@ -14,47 +15,23 @@ module ForemanInventoryUpload
14
15
  @mode = mode
15
16
  end
16
17
 
17
- def buffer
18
- @buffer ||= begin
19
- File.open(file_name, file_mode)
20
- rescue Errno::ENOENT
21
- StringIO.new
22
- end
23
- end
24
-
25
18
  def full_output
26
- buffer.read
19
+ TaskOutputLine.where(label: @label).order(:created_at).pluck(:line).join("\n")
27
20
  end
28
21
 
29
22
  def write_line(line)
30
- buffer << line
31
- buffer.fsync
23
+ TaskOutputLine.create!(label: @label, line: line)
32
24
  end
33
25
 
34
26
  def close
35
- @buffer&.close
36
27
  end
37
28
 
38
29
  def status
39
- File.read(file_name(:status))
40
- rescue Errno::ENOENT
41
- ''
30
+ TaskOutputStatus.where(label: @label).pluck(:status).first || ''
42
31
  end
43
32
 
44
33
  def status=(status)
45
- File.atomic_write(file_name(:status)) do |status_file|
46
- status_file.write(status)
47
- end
48
- end
49
-
50
- private
51
-
52
- def file_mode
53
- (@mode == :reader) ? 'r' : 'w'
54
- end
55
-
56
- def file_name(type = 'out')
57
- File.join(ForemanInventoryUpload.outputs_folder, "#{@label}.#{type}")
34
+ TaskOutputStatus.upsert({ label: @label, status: status }, unique_by: :label)
58
35
  end
59
36
  end
60
37
  end
@@ -1,9 +1,12 @@
1
1
  module ForemanInventoryUpload
2
2
  module Async
3
- class QueueForUploadJob < ::ApplicationJob
4
- def perform(base_folder, report_file, organization_id)
5
- @base_folder = base_folder
6
- @report_file = report_file
3
+ class QueueForUploadJob < ::Actions::EntryAction
4
+ def plan(base_folder, report_file, organization_id)
5
+ enqueue_task = plan_self(base_folder: base_folder, report_file: report_file)
6
+ plan_upload_report(enqueue_task.output[:enqueued_file_name], organization_id)
7
+ end
8
+
9
+ def run
7
10
  logger.debug('Ensuring objects')
8
11
  ensure_ouput_folder
9
12
  ensure_output_script
@@ -12,7 +15,7 @@ module ForemanInventoryUpload
12
15
  FileUtils.mv(File.join(base_folder, report_file), enqueued_file_name)
13
16
  logger.debug("Done copying #{report_file} to #{enqueued_file_name}")
14
17
 
15
- UploadReportJob.perform_later(enqueued_file_name, organization_id)
18
+ output[:enqueued_file_name] = enqueued_file_name
16
19
  end
17
20
 
18
21
  def uploads_folder
@@ -47,6 +50,18 @@ module ForemanInventoryUpload
47
50
  def logger
48
51
  Foreman::Logging.logger('background')
49
52
  end
53
+
54
+ def base_folder
55
+ input[:base_folder]
56
+ end
57
+
58
+ def report_file
59
+ input[:report_file]
60
+ end
61
+
62
+ def plan_upload_report(enqueued_file_name, organization_id)
63
+ plan_action(UploadReportJob, enqueued_file_name, organization_id)
64
+ end
50
65
  end
51
66
  end
52
67
  end
@@ -2,13 +2,18 @@ require 'open3'
2
2
 
3
3
  module ForemanInventoryUpload
4
4
  module Async
5
- class ShellProcess < ::ApplicationJob
5
+ class ShellProcess < ::Actions::EntryAction
6
6
  include AsyncHelpers
7
7
 
8
- def perform(instance_label)
8
+ def plan(instance_label, more_inputs = {})
9
+ inputs = more_inputs.merge(instance_label: instance_label)
10
+ plan_self(inputs)
11
+ end
12
+
13
+ def run
9
14
  klass_name = self.class.name
10
15
  logger.debug("Starting #{klass_name} with label #{instance_label}")
11
- progress_output_for(instance_label) do |progress_output|
16
+ progress_output do |progress_output|
12
17
  Open3.popen2e(hash_to_s(env), *preprocess_command(command)) do |_stdin, stdout_stderr, wait_thread|
13
18
  progress_output.status = "Running in pid #{wait_thread.pid}"
14
19
 
@@ -25,7 +30,7 @@ module ForemanInventoryUpload
25
30
  def command
26
31
  end
27
32
 
28
- def progress_output_for(instance_label)
33
+ def progress_output
29
34
  progress_output = ProgressOutput.register(instance_label)
30
35
  yield(progress_output)
31
36
  ensure
@@ -40,11 +45,19 @@ module ForemanInventoryUpload
40
45
  Foreman::Logging.logger('background')
41
46
  end
42
47
 
48
+ def rescue_strategy_for_self
49
+ Dynflow::Action::Rescue::Fail
50
+ end
51
+
43
52
  private
44
53
 
45
54
  def preprocess_command(command)
46
55
  command.kind_of?(Array) ? command : [command]
47
56
  end
57
+
58
+ def instance_label
59
+ input[:instance_label]
60
+ end
48
61
  end
49
62
  end
50
63
  end
@@ -7,44 +7,45 @@ module ForemanInventoryUpload
7
7
  "upload_for_#{label}"
8
8
  end
9
9
 
10
- def perform(filename, organization_id)
10
+ def plan(filename, organization_id)
11
11
  label = UploadReportJob.output_label(organization_id)
12
- @filename = filename
13
- @organization = Organization.find(organization_id)
12
+ super(label, filename: filename, organization_id: organization_id)
13
+ end
14
14
 
15
+ def run
15
16
  if Setting[:content_disconnected]
16
- progress_output_for(label) do |progress_output|
17
+ progress_output do |progress_output|
17
18
  progress_output.write_line('Upload was stopped since disconnected mode setting is enabled for content on this instance.')
18
19
  progress_output.status = "Task aborted, exit 1"
19
20
  end
20
21
  return
21
22
  end
22
23
 
23
- unless @organization.owner_details&.fetch('upstreamConsumer')&.fetch('idCert')
24
- logger.info("Skipping organization '#{@organization}', no candlepin certificate defined.")
25
- progress_output_for(label) do |progress_output|
26
- progress_output.write_line("Skipping organization #{@organization}, no candlepin certificate defined.")
24
+ unless organization.owner_details&.fetch('upstreamConsumer')&.fetch('idCert')
25
+ logger.info("Skipping organization '#{organization}', no candlepin certificate defined.")
26
+ progress_output do |progress_output|
27
+ progress_output.write_line("Skipping organization #{organization}, no candlepin certificate defined.")
27
28
  progress_output.status = "Task aborted, exit 1"
28
29
  end
29
30
  return
30
31
  end
31
32
 
32
- Tempfile.create([@organization.name, '.pem']) do |cer_file|
33
+ Tempfile.create([organization.name, '.pem']) do |cer_file|
33
34
  cer_file.write(rh_credentials[:cert])
34
35
  cer_file.write(rh_credentials[:key])
35
36
  cer_file.flush
36
37
  @cer_path = cer_file.path
37
- super(label)
38
+ super
38
39
  end
39
40
  end
40
41
 
41
42
  def command
42
- ['/bin/bash', File.join(File.dirname(@filename), ForemanInventoryUpload.upload_script_file)]
43
+ ['/bin/bash', File.join(File.dirname(filename), ForemanInventoryUpload.upload_script_file)]
43
44
  end
44
45
 
45
46
  def env
46
47
  env_vars = super.merge(
47
- 'FILES' => @filename,
48
+ 'FILES' => filename,
48
49
  'CER_PATH' => @cer_path
49
50
  )
50
51
 
@@ -58,13 +59,21 @@ module ForemanInventoryUpload
58
59
 
59
60
  def rh_credentials
60
61
  @rh_credentials ||= begin
61
- candlepin_id_certificate = @organization.owner_details['upstreamConsumer']['idCert']
62
+ candlepin_id_certificate = organization.owner_details['upstreamConsumer']['idCert']
62
63
  {
63
64
  cert: candlepin_id_certificate['cert'],
64
65
  key: candlepin_id_certificate['key'],
65
66
  }
66
67
  end
67
68
  end
69
+
70
+ def filename
71
+ input[:filename]
72
+ end
73
+
74
+ def organization
75
+ @organization ||= Organization.find(input[:organization_id])
76
+ end
68
77
  end
69
78
  end
70
79
  end
@@ -48,13 +48,22 @@ module ForemanRhCloud
48
48
  security_block :foreman_rh_cloud do
49
49
  permission(
50
50
  :generate_foreman_rh_cloud,
51
- 'foreman_inventory_upload/reports': [:generate]
51
+ 'foreman_inventory_upload/reports': [:generate],
52
+ 'foreman_inventory_upload/tasks': [:create],
53
+ 'api/v2/rh_cloud/inventory': [:sync_inventory_status, :download_file, :generate_report, :enable_cloud_connector],
54
+ 'foreman_inventory_upload/uploads': [:enable_cloud_connector],
55
+ 'foreman_inventory_upload/uploads_settings': [:set_advanced_setting],
56
+ 'insights_cloud/settings': [:save_token_and_sync, :update],
57
+ 'insights_cloud/tasks': [:create]
52
58
  )
53
59
  permission(
54
60
  :view_foreman_rh_cloud,
55
61
  'foreman_inventory_upload/accounts': [:index],
56
62
  'foreman_inventory_upload/reports': [:last],
57
63
  'foreman_inventory_upload/uploads': [:auto_upload, :show_auto_upload, :download_file, :last],
64
+ 'foreman_inventory_upload/tasks': [:show],
65
+ 'foreman_inventory_upload/cloud_status': [:index],
66
+ 'foreman_inventory_upload/uploads_settings': [:index],
58
67
  'react': [:index]
59
68
  )
60
69
  permission(
@@ -115,15 +124,6 @@ module ForemanRhCloud
115
124
  ::Host::Managed.include RhCloudHost
116
125
  end
117
126
 
118
- initializer "foreman_rh_cloud.set_dynflow.config.on_init", :before => :finisher_hook do |_app|
119
- unless Rails.env.test?
120
- ForemanTasks.dynflow.config.on_init do |world|
121
- ForemanInventoryUpload::Async::GenerateAllReportsJob.spawn_if_missing(world)
122
- InsightsCloud::Async::InsightsScheduledSync.spawn_if_missing(world)
123
- end
124
- end
125
- end
126
-
127
127
  rake_tasks do
128
128
  Rake::Task['db:seed'].enhance do
129
129
  ForemanRhCloud::Engine.load_seed
@@ -139,7 +139,6 @@ module ForemanRhCloud
139
139
  config.to_prepare do
140
140
  # skip database manipulations while tables do not exist, like in migrations
141
141
  if ActiveRecord::Base.connection.data_source_exists?(ForemanTasks::Task.table_name) &&
142
-
143
142
  RemoteExecutionFeature.register(
144
143
  :rh_cloud_remediate_hosts,
145
144
  N_('Apply Insights recommendations'),
@@ -149,7 +148,9 @@ module ForemanRhCloud
149
148
  # skip object creation when admin user is not present, for example in test DB
150
149
  if User.unscoped.find_by_login(User::ANONYMOUS_ADMIN).present?
151
150
  ::ForemanTasks.dynflow.config.on_init(false) do |world|
151
+ ForemanRhCloud::Engine.register_scheduled_task(ForemanInventoryUpload::Async::GenerateAllReportsJob, '0 0 * * *')
152
152
  ForemanRhCloud::Engine.register_scheduled_task(InventorySync::Async::InventoryScheduledSync, '0 0 * * *')
153
+ ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsScheduledSync, '0 0 * * *')
153
154
  ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsClientStatusAging, '0 0 * * *')
154
155
  end
155
156
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '4.0.31'.freeze
2
+ VERSION = '5.0.31'.freeze
3
3
  end
@@ -1,7 +1,9 @@
1
1
  module InsightsCloud
2
2
  module Async
3
- class InsightsScheduledSync < ::ApplicationJob
4
- def perform
3
+ class InsightsScheduledSync < ::Actions::EntryAction
4
+ include ::Actions::RecurringAction
5
+
6
+ def plan
5
7
  unless Setting[:allow_auto_insights_sync]
6
8
  logger.debug(
7
9
  'The scheduled process is disabled due to the "allow_auto_insights_sync"
@@ -10,13 +12,15 @@ module InsightsCloud
10
12
  return
11
13
  end
12
14
 
13
- ForemanTasks.async_task InsightsFullSync
14
- ensure
15
- self.class.set(:wait => 24.hours).perform_later
15
+ plan_full_sync
16
+ end
17
+
18
+ def plan_full_sync
19
+ plan_action InsightsFullSync
16
20
  end
17
21
 
18
- def self.singleton_job_name
19
- name
22
+ def rescue_strategy_for_self
23
+ Dynflow::Action::Rescue::Fail
20
24
  end
21
25
  end
22
26
  end
@@ -12,7 +12,7 @@ namespace :rh_cloud_inventory do
12
12
 
13
13
  User.as_anonymous_admin do
14
14
  organizations.each do |organization|
15
- ForemanInventoryUpload::Async::GenerateReportJob.perform_now(ForemanInventoryUpload.generated_reports_folder, organization.id)
15
+ ForemanTasks.async_task(ForemanInventoryUpload::Async::GenerateReportJob, ForemanInventoryUpload.generated_reports_folder, organization.id)
16
16
  puts "Generated and uploaded inventory report for organization '#{organization.name}'"
17
17
  end
18
18
  end
@@ -47,7 +47,7 @@ namespace :rh_cloud_inventory do
47
47
  base_folder = ENV['target'] || ForemanInventoryUpload.generated_reports_folder
48
48
  organization_id = ENV['organization_id']
49
49
  report_file = ForemanInventoryUpload.facts_archive_name(organization_id)
50
- ForemanInventoryUpload::Async::QueueForUploadJob.perform_now(base_folder, report_file, organization_id)
50
+ ForemanTasks.sync_task(ForemanInventoryUpload::Async::QueueForUploadJob, base_folder, report_file, organization_id)
51
51
  puts "Uploaded #{report_file}"
52
52
  end
53
53
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "4.0.31",
3
+ "version": "5.0.31",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,27 +22,22 @@
22
22
  "url": "http://projects.theforeman.org/projects/foreman_rh_cloud/issues"
23
23
  },
24
24
  "peerDependencies": {
25
- "@theforeman/vendor": "~4.14.0"
25
+ "@theforeman/vendor": "~8.16.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@babel/core": "~7.7.0",
29
- "@redhat-cloud-services/frontend-components": "^2.5.0",
30
- "@theforeman/builder": "~4.14.0",
31
- "@theforeman/stories": "~4.14.0",
32
- "@theforeman/test": "~4.14.0",
33
- "@theforeman/vendor-dev": "~4.14.0",
34
- "@theforeman/eslint-plugin-foreman": "~4.14.0",
29
+ "@theforeman/builder": "~8.16.0",
30
+ "@theforeman/stories": "~8.16.0",
31
+ "@theforeman/test": "~8.16.0",
32
+ "@theforeman/eslint-plugin-foreman": "~8.16.0",
35
33
  "babel-eslint": "~10.0.0",
36
34
  "eslint": "~6.7.2",
37
35
  "eslint-plugin-spellcheck": "~0.0.17",
36
+ "jed": "~1.1.1",
38
37
  "prettier": "~1.19.1",
39
38
  "stylelint": "~9.3.0",
40
39
  "stylelint-config-standard": "~18.0.0",
41
40
  "surge": "~0.20.3",
42
41
  "redux-mock-store": "~1.2.2"
43
- },
44
- "dependencies": {
45
- "jed": "~1.1.1",
46
- "react-intl": "~2.8.0"
47
42
  }
48
43
  }
@@ -4,7 +4,7 @@ class SettingsControllerTest < ActionController::TestCase
4
4
  tests InsightsCloud::SettingsController
5
5
 
6
6
  test 'should return allow_auto_insights_sync setting' do
7
- FactoryBot.create(:setting, :name => 'allow_auto_insights_sync', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => false)
7
+ Setting[:allow_auto_insights_sync] = false
8
8
 
9
9
  assert_equal false, Setting[:allow_auto_insights_sync]
10
10
 
@@ -16,7 +16,7 @@ class SettingsControllerTest < ActionController::TestCase
16
16
  end
17
17
 
18
18
  test 'should update allow_auto_insights_sync setting' do
19
- FactoryBot.create(:setting, :name => 'allow_auto_insights_sync', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => false)
19
+ Setting[:allow_auto_insights_sync] = false
20
20
 
21
21
  assert_equal false, Setting[:allow_auto_insights_sync]
22
22
 
@@ -4,7 +4,7 @@ class UploadsSettingsControllerTest < ActionController::TestCase
4
4
  tests ForemanInventoryUpload::UploadsSettingsController
5
5
 
6
6
  test 'should get upload inventory settings' do
7
- FactoryBot.create(:setting, :name => 'allow_auto_inventory_upload', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => true)
7
+ Setting[:allow_auto_inventory_upload] = true
8
8
 
9
9
  assert_equal true, Setting[:allow_auto_inventory_upload]
10
10
 
@@ -17,7 +17,7 @@ class UploadsSettingsControllerTest < ActionController::TestCase
17
17
  end
18
18
 
19
19
  test 'should update allow_auto_inventory_upload setting' do
20
- FactoryBot.create(:setting, :name => 'allow_auto_inventory_upload', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => false)
20
+ Setting[:allow_auto_inventory_upload] = false
21
21
 
22
22
  assert_equal false, Setting[:allow_auto_inventory_upload]
23
23
 
@@ -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 InsightsFullSyncTest < ActiveSupport::TestCase
@@ -7,7 +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
+ Setting[:rh_cloud_token] = 'MOCK_TOKEN'
11
11
 
12
12
  uuid1 = 'accdf444-5628-451d-bf3e-cf909ad72756'
13
13
  @host1 = FactoryBot.create(:host, :managed, name: 'host1')
@@ -63,7 +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
+ Setting[:rh_cloud_token] = 'MOCK_TOKEN'
67
67
  end
68
68
 
69
69
  test 'Resolutions data is replaced with data from cloud' do
@@ -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 InsightsRulesSyncTest < ActiveSupport::TestCase
@@ -112,7 +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
+ Setting[:rh_cloud_token] = 'MOCK_TOKEN'
116
116
  end
117
117
 
118
118
  test 'Hits data is replaced with data from cloud' do
@@ -254,7 +254,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
254
254
  end
255
255
 
256
256
  test 'Host status should be SYNC for inventory hosts' do
257
- FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'TEST TOKEN')
257
+ Setting[:rh_cloud_token] = 'TEST TOKEN'
258
258
  InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
259
259
 
260
260
  ForemanTasks.sync_task(InventorySync::Async::InventoryFullSync, @host2.organization)
@@ -266,7 +266,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
266
266
  end
267
267
 
268
268
  test 'Host status should be DISCONNECT for hosts that are not returned from cloud' do
269
- FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'TEST TOKEN')
269
+ Setting[:rh_cloud_token] = 'TEST TOKEN'
270
270
  InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
271
271
  FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
272
272
 
@@ -277,7 +277,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
277
277
  end
278
278
 
279
279
  test 'Task should be aborted if token is not present' do
280
- FactoryBot.create(:setting, name: 'rh_cloud_token', value: '')
280
+ Setting[:rh_cloud_token] = ''
281
281
 
282
282
  InventorySync::Async::InventoryFullSync.any_instance.expects(:plan_self).never
283
283
 
@@ -6,7 +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
+ Setting[:rh_cloud_token] = 'MOCK_TOKEN'
10
10
 
11
11
  env = FactoryBot.create(:katello_k_t_environment)
12
12
  cv = env.content_views << FactoryBot.create(:katello_content_view, organization: env.organization)
@@ -5,7 +5,7 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase
5
5
  include ForemanTasks::TestHelpers::WithInThreadExecutor
6
6
 
7
7
  test 'Schedules an execution if auto upload is enabled' do
8
- FactoryBot.create(:setting, :name => 'allow_auto_inventory_upload', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => true)
8
+ Setting[:allow_auto_inventory_upload] = true
9
9
 
10
10
  InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).times(Organization.unscoped.count)
11
11
 
@@ -13,7 +13,7 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase
13
13
  end
14
14
 
15
15
  test 'Skips execution if auto upload is disabled' do
16
- FactoryBot.create(:setting, :name => 'allow_auto_inventory_upload', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => false)
16
+ Setting[:allow_auto_inventory_upload] = false
17
17
 
18
18
  InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).never
19
19
 
@@ -6,7 +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
+ Setting[:rh_cloud_token] = 'MOCK_TOKEN'
10
10
 
11
11
  # this host would pass our plugin queries, so it could be uploaded to the cloud.
12
12
  @host1 = FactoryBot.create(:host)