foreman_rh_cloud 7.0.45 → 7.0.47
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/db/migrate/20221102110254_fix_rh_cloud_settings_category_to_dsl.rb +1 -1
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +12 -0
- data/lib/foreman_inventory_upload/generators/metadata.rb +4 -0
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb +27 -7
- data/lib/tasks/hybrid_cloud.rake +63 -0
- data/locale/foreman_rh_cloud.pot +1091 -8
- data/locale/gemspec.rb +1 -1
- data/package.json +1 -1
- data/test/jobs/connector_playbook_execution_reporter_task_test.rb +120 -37
- data/test/test_plugin_helper.rb +11 -0
- data/test/unit/archived_report_generator_test.rb +2 -0
- data/test/unit/metadata_generator_test.rb +25 -0
- metadata +7 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c5493c69d3f1918da42b12dfc523e6bf387203e1d1cdd057d6bea1e401caeef6
|
|
4
|
+
data.tar.gz: 7413d1788622b27285da6a7257928b57b79bb6de8660ca9f966edcbb4cc7ee00
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bf2220d31d2bc0b41291560ea0f25a8a88c33d73e281915ebe4534bf0a2fbd80be8f815776b38eade95366e92824179519decf91062f607a60c396e03a0387e2
|
|
7
|
+
data.tar.gz: 9d16b6f204bc3585e00b012e0fa47132ae4209fbaa85015c8db99ebce79aac167fa85374423366b2ff4ecd2cb725a20d7a5d52b61873f525b37ea7094e23fc7f
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
class FixRhCloudSettingsCategoryToDsl < ActiveRecord::Migration[6.0]
|
|
4
4
|
def up
|
|
5
|
-
Setting.where(category: 'Setting::RhCloud').update_all(category: 'Setting')
|
|
5
|
+
Setting.where(category: 'Setting::RhCloud').update_all(category: 'Setting') if column_exists?(:settings, :category)
|
|
6
6
|
end
|
|
7
7
|
end
|
|
@@ -109,6 +109,18 @@ module ForemanInventoryUpload
|
|
|
109
109
|
IPAddr.new(max_obfuscated + 1, Socket::AF_INET).to_s
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
+
def hostname_match
|
|
113
|
+
bash_hostname = `uname -n`.chomp
|
|
114
|
+
foreman_hostname = ForemanRhCloud.foreman_host&.name
|
|
115
|
+
if bash_hostname == foreman_hostname
|
|
116
|
+
fqdn(foreman_hostname)
|
|
117
|
+
elsif Setting[:obfuscate_inventory_hostnames]
|
|
118
|
+
obfuscate_fqdn(bash_hostname)
|
|
119
|
+
else
|
|
120
|
+
bash_hostname
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
112
124
|
def bios_uuid(host)
|
|
113
125
|
value = fact_value(host, 'dmi::system::uuid') || ''
|
|
114
126
|
uuid_value(value)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module ForemanInventoryUpload
|
|
2
2
|
module Generators
|
|
3
3
|
class Metadata
|
|
4
|
+
include FactHelpers
|
|
4
5
|
def initialize(output = [])
|
|
5
6
|
@stream = JsonStream.new(output)
|
|
6
7
|
end
|
|
@@ -28,6 +29,9 @@ module ForemanInventoryUpload
|
|
|
28
29
|
@stream.simple_field('report_id', Foreman.uuid)
|
|
29
30
|
@stream.simple_field('host_inventory_api_version', '1.0')
|
|
30
31
|
@stream.simple_field('source', 'Satellite')
|
|
32
|
+
@stream.simple_field('reporting_host_name', hostname_match)
|
|
33
|
+
@stream.simple_field('reporting_host_ips', host_ips(ForemanRhCloud.foreman_host))
|
|
34
|
+
@stream.simple_field('reporting_host_bios_uuid', bios_uuid(ForemanRhCloud.foreman_host))
|
|
31
35
|
@stream.simple_field('source_metadata', metadata)
|
|
32
36
|
@stream.object_field('report_slices', :last) do
|
|
33
37
|
yield(self)
|
|
@@ -43,7 +43,17 @@ module InsightsCloud
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def done?(current_status = invocation_status)
|
|
46
|
-
|
|
46
|
+
ActiveModel::Type::Boolean.new.cast(current_status[:task_state][:task_done_reported])
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def job_finished?
|
|
50
|
+
job_invocation.finished?
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def all_hosts_finished?(current_status)
|
|
54
|
+
current_status[:hosts_state].values.all? do |status|
|
|
55
|
+
ActiveModel::Type::Boolean.new.cast(status['report_done'] == true)
|
|
56
|
+
end
|
|
47
57
|
end
|
|
48
58
|
|
|
49
59
|
# noop, we don't want to do anything when the polling task starts
|
|
@@ -95,7 +105,11 @@ module InsightsCloud
|
|
|
95
105
|
end
|
|
96
106
|
|
|
97
107
|
def host_status(host)
|
|
98
|
-
external_task&.dig('invocation_status', host)
|
|
108
|
+
external_task&.dig('invocation_status', :hosts_state, host)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def task_done_state
|
|
112
|
+
ActiveModel::Type::Boolean.new.cast(external_task&.dig('invocation_status', :task_state, :task_done_reported))
|
|
99
113
|
end
|
|
100
114
|
|
|
101
115
|
def sequence(host)
|
|
@@ -111,13 +125,15 @@ module InsightsCloud
|
|
|
111
125
|
end
|
|
112
126
|
|
|
113
127
|
def invocation_status
|
|
114
|
-
Hash[job_invocation.targeting.hosts.map do |host|
|
|
128
|
+
hosts_state = Hash[job_invocation.targeting.hosts.map do |host|
|
|
115
129
|
next unless host.insights&.uuid
|
|
116
130
|
[
|
|
117
131
|
host.insights.uuid,
|
|
118
132
|
task_status(job_invocation.sub_task_for_host(host), host.insights.uuid),
|
|
119
133
|
]
|
|
120
134
|
end.compact]
|
|
135
|
+
|
|
136
|
+
{task_state: {task_done_reported: task_done_state}, hosts_state: hosts_state}
|
|
121
137
|
end
|
|
122
138
|
|
|
123
139
|
def task_status(host_task, host_name)
|
|
@@ -128,7 +144,7 @@ module InsightsCloud
|
|
|
128
144
|
{
|
|
129
145
|
'state' => host_task.state,
|
|
130
146
|
'output' => host_task.main_action.live_output.map { |line| line['output'] }.join("\n"),
|
|
131
|
-
'exit_status' => host_task.main_action.exit_status,
|
|
147
|
+
'exit_status' => ActiveModel::Type::Integer.new.cast(host_task.main_action.exit_status),
|
|
132
148
|
'sequence' => sequence(host_name),
|
|
133
149
|
'report_done' => host_done?(host_name),
|
|
134
150
|
}
|
|
@@ -138,9 +154,9 @@ module InsightsCloud
|
|
|
138
154
|
generator = InsightsCloud::Generators::PlaybookProgressGenerator.new(correlation_id)
|
|
139
155
|
all_hosts_success = true
|
|
140
156
|
|
|
141
|
-
invocation_status.each do |host_name, status|
|
|
157
|
+
invocation_status[:hosts_state].each do |host_name, status|
|
|
142
158
|
# skip host if the host already reported that it's finished
|
|
143
|
-
next if status['report_done']
|
|
159
|
+
next if ActiveModel::Type::Boolean.new.cast(status['report_done'])
|
|
144
160
|
|
|
145
161
|
unless status['state'] == 'unknown'
|
|
146
162
|
sequence = status['sequence']
|
|
@@ -154,7 +170,11 @@ module InsightsCloud
|
|
|
154
170
|
all_hosts_success &&= status['exit_status'] == 0
|
|
155
171
|
end
|
|
156
172
|
end
|
|
157
|
-
|
|
173
|
+
|
|
174
|
+
if (job_finished? || all_hosts_finished?(invocation_status))
|
|
175
|
+
generator.job_finished_message(all_hosts_success)
|
|
176
|
+
invocation_status[:task_state][:task_done_reported] = true
|
|
177
|
+
end
|
|
158
178
|
|
|
159
179
|
send_report(generator.generate)
|
|
160
180
|
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'io/console'
|
|
2
|
+
|
|
3
|
+
namespace :rh_cloud do |args|
|
|
4
|
+
desc 'Register Satellite Organization with Hybrid Cloud API. \
|
|
5
|
+
Specify org_id=x replace your organization ID with x. \
|
|
6
|
+
Specify SATELLITE_RH_CLOUD_URL=https://x with the Hybrid Cloud endpoint you are connecting to.'
|
|
7
|
+
task hybridcloud_register: [:environment] do
|
|
8
|
+
include ::ForemanRhCloud::CertAuth
|
|
9
|
+
include ::InsightsCloud::CandlepinCache
|
|
10
|
+
|
|
11
|
+
def logger
|
|
12
|
+
@logger ||= Logger.new(STDOUT)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def registrations_url
|
|
16
|
+
logger.warn("Custom url is not set, using the default one: #{ForemanRhCloud.base_url}") if ENV['SATELLITE_RH_CLOUD_URL'].empty?
|
|
17
|
+
ForemanRhCloud.base_url + '/api/identity/certificate/registrations'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
if ENV['org_id'].nil?
|
|
21
|
+
logger.error('ERROR: org_id needs to be specified.')
|
|
22
|
+
exit(1)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
organization = Organization.find_by(id: ENV['org_id'].to_i) # saw this coming in as a string, so making sure it gets passed as an integer.
|
|
26
|
+
|
|
27
|
+
@uid = cp_owner_id(organization)
|
|
28
|
+
logger.error('Organization provided does not have a manifest imported.') + exit(1) if @uid.nil?
|
|
29
|
+
|
|
30
|
+
puts 'Paste your token, output will be hidden.'
|
|
31
|
+
@token = STDIN.noecho(&:gets).chomp
|
|
32
|
+
logger.error('Token was not entered.') + exit(1) if @token.empty?
|
|
33
|
+
|
|
34
|
+
def headers
|
|
35
|
+
{
|
|
36
|
+
Authorization: "Bearer #{@token}"
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def payload
|
|
41
|
+
{
|
|
42
|
+
"uid": @uid
|
|
43
|
+
}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def method
|
|
47
|
+
:post
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
begin
|
|
51
|
+
response = execute_cloud_request(
|
|
52
|
+
organization: organization,
|
|
53
|
+
method: method,
|
|
54
|
+
url: registrations_url,
|
|
55
|
+
headers: headers,
|
|
56
|
+
payload: payload.to_json
|
|
57
|
+
)
|
|
58
|
+
logger.debug(response)
|
|
59
|
+
rescue Exception => ex
|
|
60
|
+
logger.error(ex)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|