foreman_rh_cloud 4.0.36 → 5.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/concerns/inventory_upload/report_actions.rb +1 -1
- data/app/controllers/foreman_inventory_upload/reports_controller.rb +1 -1
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +5 -16
- data/app/models/setting/rh_cloud.rb +0 -1
- data/app/models/task_output_line.rb +2 -0
- data/app/models/task_output_status.rb +2 -0
- data/app/services/foreman_rh_cloud/cloud_ping_service.rb +1 -4
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +5 -16
- data/config/package-lock.json.plugin +10551 -7500
- data/db/migrate/20211027000001_create_task_output.foreman_rh_cloud.rb +18 -0
- data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +11 -7
- data/lib/foreman_inventory_upload/async/generate_report_job.rb +24 -12
- data/lib/foreman_inventory_upload/async/progress_output.rb +5 -28
- data/lib/foreman_inventory_upload/async/queue_for_upload_job.rb +20 -5
- data/lib/foreman_inventory_upload/async/shell_process.rb +17 -4
- data/lib/foreman_inventory_upload/async/upload_report_job.rb +22 -13
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +1 -3
- data/lib/foreman_inventory_upload/generators/queries.rb +0 -1
- data/lib/foreman_inventory_upload/generators/tags.rb +1 -8
- data/lib/foreman_rh_cloud/engine.rb +12 -22
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud/async/insights_scheduled_sync.rb +11 -7
- data/lib/inventory_sync/async/host_result.rb +5 -0
- data/lib/inventory_sync/async/inventory_full_sync.rb +9 -14
- data/lib/inventory_sync/async/inventory_hosts_sync.rb +6 -2
- data/lib/tasks/rh_cloud_inventory.rake +2 -2
- data/package.json +7 -12
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +0 -23
- data/test/controllers/inventory_upload/cloud_status_controller_test.rb +0 -2
- data/test/jobs/inventory_full_sync_test.rb +2 -28
- data/test/jobs/inventory_hosts_sync_test.rb +0 -15
- data/test/jobs/upload_report_job_test.rb +5 -3
- data/test/unit/fact_helpers_test.rb +2 -2
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +0 -19
- data/test/unit/services/foreman_rh_cloud/cloud_status_service_test.rb +0 -4
- data/test/unit/shell_process_job_test.rb +3 -1
- data/test/unit/slice_generator_test.rb +0 -12
- data/test/unit/tags_generator_test.rb +0 -15
- data/webpack/ForemanInventoryUpload/Components/AccountList/accountList.scss +8 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.scss +17 -4
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageTitle.js +29 -17
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageTitle.test.js.snap +58 -47
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudPingModal/index.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +12 -10
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +10 -10
- data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/__snapshots__/InventoryAutoUpload.test.js.snap +1 -1
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +4 -1
- data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +24 -13
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +1 -1
- data/webpack/__mocks__/foremanReact/components/Head.js +11 -0
- data/webpack/common/Switcher/__tests__/__snapshots__/SwitcherPF4.test.js.snap +1 -0
- metadata +7 -3
|
@@ -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 < ::
|
|
4
|
-
|
|
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
|
-
|
|
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
|
|
29
|
-
|
|
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
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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' =>
|
|
32
|
-
'organization_id' =>
|
|
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
|
-
|
|
19
|
+
TaskOutputLine.where(label: @label).order(:created_at).pluck(:line).join("\n")
|
|
27
20
|
end
|
|
28
21
|
|
|
29
22
|
def write_line(line)
|
|
30
|
-
|
|
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
|
-
|
|
40
|
-
rescue Errno::ENOENT
|
|
41
|
-
''
|
|
30
|
+
TaskOutputStatus.where(label: @label).pluck(:status).first || ''
|
|
42
31
|
end
|
|
43
32
|
|
|
44
33
|
def status=(status)
|
|
45
|
-
|
|
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 < ::
|
|
4
|
-
def
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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 < ::
|
|
5
|
+
class ShellProcess < ::Actions::EntryAction
|
|
6
6
|
include AsyncHelpers
|
|
7
7
|
|
|
8
|
-
def
|
|
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
|
-
|
|
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
|
|
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
|
|
10
|
+
def plan(filename, organization_id)
|
|
11
11
|
label = UploadReportJob.output_label(organization_id)
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
super(label, filename: filename, organization_id: organization_id)
|
|
13
|
+
end
|
|
14
14
|
|
|
15
|
+
def run
|
|
15
16
|
if Setting[:content_disconnected]
|
|
16
|
-
|
|
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
|
|
24
|
-
logger.info("Skipping organization '#{
|
|
25
|
-
|
|
26
|
-
progress_output.write_line("Skipping organization #{
|
|
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([
|
|
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
|
|
38
|
+
super
|
|
38
39
|
end
|
|
39
40
|
end
|
|
40
41
|
|
|
41
42
|
def command
|
|
42
|
-
['/bin/bash', File.join(File.dirname(
|
|
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' =>
|
|
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 =
|
|
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
|
-
|
|
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)
|
|
@@ -13,7 +13,7 @@ module ForemanInventoryUpload
|
|
|
13
13
|
organizations +
|
|
14
14
|
content_data +
|
|
15
15
|
satellite_server_data
|
|
16
|
-
).reject { |key, value| value.empty? }
|
|
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
|
|
@@ -6,18 +6,15 @@ module ForemanRhCloud
|
|
|
6
6
|
engine_name 'foreman_rh_cloud'
|
|
7
7
|
|
|
8
8
|
def self.register_scheduled_task(task_class, cronline)
|
|
9
|
-
ForemanTasks::RecurringLogic.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
recurring_logic.start(task_class)
|
|
18
|
-
end
|
|
9
|
+
return if ForemanTasks::RecurringLogic.joins(:tasks)
|
|
10
|
+
.merge(ForemanTasks::Task.where(label: task_class.name))
|
|
11
|
+
.exists?
|
|
12
|
+
|
|
13
|
+
User.as_anonymous_admin do
|
|
14
|
+
recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline(cronline)
|
|
15
|
+
recurring_logic.save!
|
|
16
|
+
recurring_logic.start(task_class)
|
|
19
17
|
end
|
|
20
|
-
rescue ActiveRecord::TransactionIsolationError
|
|
21
18
|
end
|
|
22
19
|
|
|
23
20
|
initializer 'foreman_rh_cloud.load_default_settings', :before => :load_config_initializers do
|
|
@@ -118,15 +115,6 @@ module ForemanRhCloud
|
|
|
118
115
|
::Host::Managed.include RhCloudHost
|
|
119
116
|
end
|
|
120
117
|
|
|
121
|
-
initializer "foreman_rh_cloud.set_dynflow.config.on_init", :before => :finisher_hook do |_app|
|
|
122
|
-
unless Rails.env.test?
|
|
123
|
-
ForemanTasks.dynflow.config.on_init do |world|
|
|
124
|
-
ForemanInventoryUpload::Async::GenerateAllReportsJob.spawn_if_missing(world)
|
|
125
|
-
InsightsCloud::Async::InsightsScheduledSync.spawn_if_missing(world)
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
118
|
rake_tasks do
|
|
131
119
|
Rake::Task['db:seed'].enhance do
|
|
132
120
|
ForemanRhCloud::Engine.load_seed
|
|
@@ -139,9 +127,9 @@ module ForemanRhCloud
|
|
|
139
127
|
Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
|
|
140
128
|
end
|
|
141
129
|
|
|
142
|
-
|
|
130
|
+
config.to_prepare do
|
|
143
131
|
# skip database manipulations while tables do not exist, like in migrations
|
|
144
|
-
if ActiveRecord::Base.connection.data_source_exists?(ForemanTasks::Task.table_name)
|
|
132
|
+
if ActiveRecord::Base.connection.data_source_exists?(ForemanTasks::Task.table_name) &&
|
|
145
133
|
RemoteExecutionFeature.register(
|
|
146
134
|
:rh_cloud_remediate_hosts,
|
|
147
135
|
N_('Apply Insights recommendations'),
|
|
@@ -151,7 +139,9 @@ module ForemanRhCloud
|
|
|
151
139
|
# skip object creation when admin user is not present, for example in test DB
|
|
152
140
|
if User.unscoped.find_by_login(User::ANONYMOUS_ADMIN).present?
|
|
153
141
|
::ForemanTasks.dynflow.config.on_init(false) do |world|
|
|
142
|
+
ForemanRhCloud::Engine.register_scheduled_task(ForemanInventoryUpload::Async::GenerateAllReportsJob, '0 0 * * *')
|
|
154
143
|
ForemanRhCloud::Engine.register_scheduled_task(InventorySync::Async::InventoryScheduledSync, '0 0 * * *')
|
|
144
|
+
ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsScheduledSync, '0 0 * * *')
|
|
155
145
|
ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsClientStatusAging, '0 0 * * *')
|
|
156
146
|
end
|
|
157
147
|
end
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
module InsightsCloud
|
|
2
2
|
module Async
|
|
3
|
-
class InsightsScheduledSync < ::
|
|
4
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
plan_full_sync
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def plan_full_sync
|
|
19
|
+
plan_action InsightsFullSync
|
|
16
20
|
end
|
|
17
21
|
|
|
18
|
-
def
|
|
19
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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": "
|
|
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": "~
|
|
25
|
+
"@theforeman/vendor": "~8.16.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "~7.7.0",
|
|
29
|
-
"@
|
|
30
|
-
"@theforeman/
|
|
31
|
-
"@theforeman/
|
|
32
|
-
"@theforeman/
|
|
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
|
}
|