foreman_rh_cloud 4.0.32 → 5.0.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) 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/models/setting/rh_cloud.rb +0 -1
  5. data/app/models/task_output_line.rb +2 -0
  6. data/app/models/task_output_status.rb +2 -0
  7. data/app/services/foreman_rh_cloud/cloud_ping_service.rb +1 -4
  8. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +1 -1
  9. data/config/package-lock.json.plugin +10551 -7500
  10. data/db/migrate/20211027000001_create_task_output.foreman_rh_cloud.rb +18 -0
  11. data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +11 -7
  12. data/lib/foreman_inventory_upload/async/generate_report_job.rb +24 -12
  13. data/lib/foreman_inventory_upload/async/progress_output.rb +5 -28
  14. data/lib/foreman_inventory_upload/async/queue_for_upload_job.rb +20 -5
  15. data/lib/foreman_inventory_upload/async/shell_process.rb +17 -4
  16. data/lib/foreman_inventory_upload/async/upload_report_job.rb +22 -13
  17. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +1 -3
  18. data/lib/foreman_inventory_upload/generators/queries.rb +0 -1
  19. data/lib/foreman_inventory_upload/generators/tags.rb +1 -8
  20. data/lib/foreman_rh_cloud/engine.rb +2 -10
  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/inventory_sync/async/host_result.rb +5 -0
  24. data/lib/inventory_sync/async/inventory_full_sync.rb +9 -14
  25. data/lib/inventory_sync/async/inventory_hosts_sync.rb +6 -2
  26. data/lib/tasks/rh_cloud_inventory.rake +2 -2
  27. data/package.json +7 -12
  28. data/test/controllers/inventory_upload/cloud_status_controller_test.rb +0 -2
  29. data/test/jobs/inventory_full_sync_test.rb +2 -28
  30. data/test/jobs/inventory_hosts_sync_test.rb +0 -15
  31. data/test/jobs/upload_report_job_test.rb +5 -3
  32. data/test/unit/fact_helpers_test.rb +2 -2
  33. data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +0 -19
  34. data/test/unit/services/foreman_rh_cloud/cloud_status_service_test.rb +0 -4
  35. data/test/unit/shell_process_job_test.rb +3 -1
  36. data/test/unit/slice_generator_test.rb +0 -12
  37. data/test/unit/tags_generator_test.rb +0 -15
  38. data/webpack/ForemanInventoryUpload/Components/AccountList/accountList.scss +8 -0
  39. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.scss +17 -4
  40. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageTitle.js +29 -17
  41. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageTitle.test.js.snap +58 -47
  42. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudPingModal/index.js +1 -1
  43. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +12 -10
  44. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +10 -10
  45. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/__snapshots__/InventoryAutoUpload.test.js.snap +1 -1
  46. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +4 -1
  47. data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +24 -13
  48. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +1 -1
  49. data/webpack/__mocks__/foremanReact/components/Head.js +11 -0
  50. data/webpack/common/Switcher/__tests__/__snapshots__/SwitcherPF4.test.js.snap +1 -0
  51. metadata +6 -3
  52. data/config/package-lock.json +0 -41822
@@ -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
@@ -104,9 +104,7 @@ module ForemanInventoryUpload
104
104
  end
105
105
 
106
106
  def obfuscate_ip(ip, ips_dict)
107
- max_obfuscated = ips_dict.values.map { |v| IPAddr.new(v).to_i }.max || IPAddr.new('10.230.230.0').to_i
108
-
109
- IPAddr.new(max_obfuscated + 1, Socket::AF_INET).to_s
107
+ "10.230.230.#{ips_dict.count + 1}"
110
108
  end
111
109
 
112
110
  def bios_uuid(host)
@@ -34,7 +34,6 @@ module ForemanInventoryUpload
34
34
 
35
35
  def self.for_slice(base)
36
36
  base
37
- .search_for("not params.#{InsightsCloud.enable_client_param} = f")
38
37
  .joins(:subscription_facet)
39
38
  .preload(
40
39
  :interfaces,
@@ -13,7 +13,7 @@ module ForemanInventoryUpload
13
13
  organizations +
14
14
  content_data +
15
15
  satellite_server_data
16
- ).reject { |key, value| value.empty? }.map { |key, value| [key, truncated_value(value)] }
16
+ ).reject { |key, value| value.empty? }
17
17
  end
18
18
 
19
19
  def generate_parameters
@@ -21,7 +21,6 @@ module ForemanInventoryUpload
21
21
 
22
22
  (@host.host_params || {})
23
23
  .select { |_name, value| value.present? || value.is_a?(FalseClass) }
24
- .map { |key, value| [key, truncated_value(value)] }
25
24
  end
26
25
 
27
26
  private
@@ -58,12 +57,6 @@ module ForemanInventoryUpload
58
57
  ['organization_id', @host.organization_id.to_s],
59
58
  ]
60
59
  end
61
-
62
- def truncated_value(value)
63
- return 'Original value exceeds 250 characters' if value.to_s.length > 250
64
-
65
- value
66
- end
67
60
  end
68
61
  end
69
62
  end
@@ -115,15 +115,6 @@ module ForemanRhCloud
115
115
  ::Host::Managed.include RhCloudHost
116
116
  end
117
117
 
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
118
  rake_tasks do
128
119
  Rake::Task['db:seed'].enhance do
129
120
  ForemanRhCloud::Engine.load_seed
@@ -139,7 +130,6 @@ module ForemanRhCloud
139
130
  config.to_prepare do
140
131
  # skip database manipulations while tables do not exist, like in migrations
141
132
  if ActiveRecord::Base.connection.data_source_exists?(ForemanTasks::Task.table_name) &&
142
-
143
133
  RemoteExecutionFeature.register(
144
134
  :rh_cloud_remediate_hosts,
145
135
  N_('Apply Insights recommendations'),
@@ -149,7 +139,9 @@ module ForemanRhCloud
149
139
  # skip object creation when admin user is not present, for example in test DB
150
140
  if User.unscoped.find_by_login(User::ANONYMOUS_ADMIN).present?
151
141
  ::ForemanTasks.dynflow.config.on_init(false) do |world|
142
+ ForemanRhCloud::Engine.register_scheduled_task(ForemanInventoryUpload::Async::GenerateAllReportsJob, '0 0 * * *')
152
143
  ForemanRhCloud::Engine.register_scheduled_task(InventorySync::Async::InventoryScheduledSync, '0 0 * * *')
144
+ ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsScheduledSync, '0 0 * * *')
153
145
  ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsClientStatusAging, '0 0 * * *')
154
146
  end
155
147
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '4.0.32'.freeze
2
+ VERSION = '5.0.28'.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
@@ -17,6 +17,7 @@ module InventorySync
17
17
  @sub_ids.map do |sub_id|
18
18
  host_id = host_id(sub_id)
19
19
  if host_id
20
+ touched << host_id
20
21
  {
21
22
  host_id: host_id,
22
23
  status: InventorySync::InventoryStatus::SYNC,
@@ -27,6 +28,10 @@ module InventorySync
27
28
  end.compact
28
29
  end
29
30
 
31
+ def touched
32
+ @touched ||= []
33
+ end
34
+
30
35
  def host_id(sub_id)
31
36
  hosts[sub_id]
32
37
  end
@@ -14,7 +14,11 @@ module InventorySync
14
14
  end
15
15
 
16
16
  def setup_statuses
17
- @subscribed_hosts_ids = Set.new(affected_host_ids)
17
+ @subscribed_hosts_ids = Set.new(
18
+ ForemanInventoryUpload::Generators::Queries.for_slice(
19
+ Host.unscoped.where(organization: input[:organization_id])
20
+ ).pluck(:id)
21
+ )
18
22
 
19
23
  InventorySync::InventoryStatus.transaction do
20
24
  InventorySync::InventoryStatus.where(host_id: @subscribed_hosts_ids).delete_all
@@ -31,10 +35,8 @@ module InventorySync
31
35
  def update_statuses_batch
32
36
  results = yield
33
37
 
34
- existing_hosts = results.status_hashes.select { |hash| @subscribed_hosts_ids.include?(hash[:host_id]) }
35
-
36
- update_hosts_status(existing_hosts)
37
- host_statuses[:sync] += existing_hosts.size
38
+ update_hosts_status(results.status_hashes, results.touched)
39
+ host_statuses[:sync] += results.touched.size
38
40
  end
39
41
 
40
42
  def rescue_strategy_for_self
@@ -43,10 +45,9 @@ module InventorySync
43
45
 
44
46
  private
45
47
 
46
- def update_hosts_status(status_hashes)
48
+ def update_hosts_status(status_hashes, touched)
47
49
  InventorySync::InventoryStatus.create(status_hashes)
48
- updated_ids = status_hashes.map { |hash| hash[:host_id] }
49
- @subscribed_hosts_ids.subtract(updated_ids)
50
+ @subscribed_hosts_ids.subtract(touched)
50
51
  end
51
52
 
52
53
  def add_missing_hosts_statuses(hosts_ids)
@@ -67,12 +68,6 @@ module InventorySync
67
68
  disconnect: 0,
68
69
  }
69
70
  end
70
-
71
- def affected_host_ids
72
- ForemanInventoryUpload::Generators::Queries.for_slice(
73
- Host.unscoped.where(organization: input[:organization_id])
74
- ).pluck(:id)
75
- end
76
71
  end
77
72
  end
78
73
  end
@@ -35,14 +35,18 @@ module InventorySync
35
35
  private
36
36
 
37
37
  def add_missing_insights_facets(uuids_hash)
38
- all_facets = uuids_hash.map do |host_id, uuid|
38
+ existing_facets = InsightsFacet.where(host_id: uuids_hash.keys).pluck(:host_id, :uuid)
39
+ missing_facets = uuids_hash.except(*existing_facets.map(&:first)).map do |host_id, uuid|
39
40
  {
40
41
  host_id: host_id,
41
42
  uuid: uuid,
42
43
  }
43
44
  end
45
+ InsightsFacet.create(missing_facets)
44
46
 
45
- InsightsFacet.upsert_all(all_facets, unique_by: :host_id) unless all_facets.empty?
47
+ existing_facets.select { |host_id, uuid| uuid.empty? }.each do |host_id, _uuid|
48
+ InsightsFacet.where(host_id: host_id).update_all(uuid: uuids_hash[host_id])
49
+ end
46
50
  end
47
51
 
48
52
  def plan_self_host_sync
@@ -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.32",
3
+ "version": "5.0.28",
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
  }
@@ -29,8 +29,6 @@ class CloudStatusControllerTest < ActionController::TestCase
29
29
  RestClient::Response.new('TEST RESPONSE ORG 1')
30
30
  )
31
31
 
32
- Katello::UpstreamConnectionChecker.any_instance.expects(:assert_connection).twice.returns(true)
33
-
34
32
  get :index, session: set_session_user
35
33
 
36
34
  assert_response :success