foreman_rh_cloud 0.9.5 → 0.9.6
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/lib/foreman_inventory_upload/async/async_helpers.rb +13 -0
- data/lib/foreman_inventory_upload/async/shell_process.rb +3 -1
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +13 -0
- data/lib/foreman_inventory_upload/generators/queries.rb +1 -0
- data/lib/foreman_inventory_upload/generators/slice.rb +12 -8
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/test/unit/archived_report_generator_test.rb +1 -0
- data/test/unit/fact_helpers_test.rb +29 -0
- data/test/unit/slice_generator_test.rb +72 -18
- data/test/unit/slice_generator_test.rb.orig +280 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7eee1b8b134db1bd55e2d737aab48dd46a97a8b97a5e8cd077ffe6381f13187
|
4
|
+
data.tar.gz: 6d00068cd4e2ca0cf50ccf45d5eff5ba6546b8c45638c53c3ac3a3703c974812
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66a8870e7e6950cfbfeab6ee4f1f98718bcc7ac4dbd5ac8a38c5ba5165c9d9e577e4f459092eb2b121fd388dddd3c9aa8b225e069645a248a5a43db7ab79ebed
|
7
|
+
data.tar.gz: 48820898171bca9808a0dedd1d0f494cd7407a40e668fde73d8e33b4a311812609b9c37ec0bd99f7244a431fcd8cf93243607e041884549aa63270ae14c0fe85
|
@@ -3,11 +3,13 @@ require 'open3'
|
|
3
3
|
module ForemanInventoryUpload
|
4
4
|
module Async
|
5
5
|
class ShellProcess < ::ApplicationJob
|
6
|
+
include AsyncHelpers
|
7
|
+
|
6
8
|
def perform(instance_label)
|
7
9
|
klass_name = self.class.name
|
8
10
|
logger.debug("Starting #{klass_name} with label #{instance_label}")
|
9
11
|
progress_output = ProgressOutput.register(instance_label)
|
10
|
-
Open3.popen2e(env, command) do |_stdin, stdout_stderr, wait_thread|
|
12
|
+
Open3.popen2e(hash_to_s(env), command) do |_stdin, stdout_stderr, wait_thread|
|
11
13
|
progress_output.status = "Running in pid #{wait_thread.pid}"
|
12
14
|
|
13
15
|
stdout_stderr.each do |out_line|
|
@@ -13,6 +13,19 @@ module ForemanInventoryUpload
|
|
13
13
|
def kilobytes_to_bytes(kilobytes)
|
14
14
|
kilobytes * 1024
|
15
15
|
end
|
16
|
+
|
17
|
+
def account_id(organization)
|
18
|
+
@organization_accounts ||= {}
|
19
|
+
@organization_accounts[organization.id] ||= organization.pools.where.not(account_number: nil).pluck(:account_number).first
|
20
|
+
end
|
21
|
+
|
22
|
+
def golden_ticket?(organization)
|
23
|
+
result = organization.try(:golden_ticket?)
|
24
|
+
result = organization.content_access_mode == 'org_environment' if result.nil?
|
25
|
+
|
26
|
+
@organization_golden_tickets ||= {}
|
27
|
+
@organization_golden_tickets[organization.id] ||= result
|
28
|
+
end
|
16
29
|
end
|
17
30
|
end
|
18
31
|
end
|
@@ -26,7 +26,7 @@ module ForemanInventoryUpload
|
|
26
26
|
@stream.array_field('hosts', :last) do
|
27
27
|
first = true
|
28
28
|
hosts_batch.each do |host|
|
29
|
-
next unless host&.subscription_facet
|
29
|
+
next unless host&.subscription_facet
|
30
30
|
@stream.comma unless first
|
31
31
|
if report_host(host)
|
32
32
|
first = false
|
@@ -39,11 +39,10 @@ module ForemanInventoryUpload
|
|
39
39
|
|
40
40
|
def report_host(host)
|
41
41
|
@stream.object do
|
42
|
-
@stream.simple_field('display_name', host.name)
|
43
42
|
@stream.simple_field('fqdn', host.fqdn)
|
44
|
-
@stream.simple_field('account', host.
|
45
|
-
@stream.simple_field('subscription_manager_id', host.subscription_facet
|
46
|
-
@stream.simple_field('satellite_id', host.subscription_facet
|
43
|
+
@stream.simple_field('account', account_id(host.organization).to_s)
|
44
|
+
@stream.simple_field('subscription_manager_id', host.subscription_facet&.uuid)
|
45
|
+
@stream.simple_field('satellite_id', host.subscription_facet&.uuid)
|
47
46
|
@stream.simple_field('bios_uuid', fact_value(host, 'dmi::system::uuid'))
|
48
47
|
@stream.simple_field('vm_uuid', fact_value(host, 'virt::uuid'))
|
49
48
|
@stream.array_field('ip_addresses') do
|
@@ -123,6 +122,10 @@ module ForemanInventoryUpload
|
|
123
122
|
@stream.simple_field('subscription_status', host.subscription_status_label)
|
124
123
|
@stream.simple_field('katello_agent_running', host.content_facet&.katello_agent_installed?)
|
125
124
|
@stream.simple_field('satellite_managed', true)
|
125
|
+
@stream.simple_field(
|
126
|
+
'infrastructure_type',
|
127
|
+
ActiveModel::Type::Boolean.new.cast(fact_value(host, 'virt::is_guest')) ? 'virtual' : 'physical'
|
128
|
+
)
|
126
129
|
unless (installed_products = host.subscription_facet&.installed_products).empty?
|
127
130
|
@stream.array_field('installed_products') do
|
128
131
|
@stream.raw(installed_products.map do |product|
|
@@ -143,15 +146,16 @@ module ForemanInventoryUpload
|
|
143
146
|
end
|
144
147
|
|
145
148
|
def report_satellite_facts(host)
|
146
|
-
@stream.simple_field('virtual_host_name', host.subscription_facet
|
147
|
-
@stream.simple_field('virtual_host_uuid', host.subscription_facet
|
149
|
+
@stream.simple_field('virtual_host_name', host.subscription_facet&.hypervisor_host&.name)
|
150
|
+
@stream.simple_field('virtual_host_uuid', host.subscription_facet&.hypervisor_host&.subscription_facet&.uuid)
|
148
151
|
if defined?(ForemanThemeSatellite)
|
149
152
|
@stream.simple_field('satellite_version', ForemanThemeSatellite::SATELLITE_VERSION)
|
150
153
|
end
|
151
154
|
@stream.simple_field('system_purpose_usage', host.subscription_facet.purpose_usage)
|
152
155
|
@stream.simple_field('system_purpose_role', host.subscription_facet.purpose_role)
|
153
156
|
@stream.simple_field('distribution_version', fact_value(host, 'distribution::version'))
|
154
|
-
@stream.simple_field('satellite_instance_id', Foreman.
|
157
|
+
@stream.simple_field('satellite_instance_id', Foreman.try(:instance_id))
|
158
|
+
@stream.simple_field('is_simple_content_access', golden_ticket?(host.organization))
|
155
159
|
@stream.simple_field('organization_id', host.organization_id, :last)
|
156
160
|
end
|
157
161
|
|
@@ -49,6 +49,7 @@ class ArchivedReportGeneratorTest < ActiveSupport::TestCase
|
|
49
49
|
test_org = FactoryBot.create(:organization)
|
50
50
|
|
51
51
|
ForemanInventoryUpload::Generators::Queries.expects(:for_org).with(test_org.id).returns(batches)
|
52
|
+
ForemanInventoryUpload::Generators::Slice.any_instance.stubs(:golden_ticket?).returns(false)
|
52
53
|
Dir.mktmpdir do |tmpdir|
|
53
54
|
target = File.join(tmpdir, 'test.tar.gz')
|
54
55
|
generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class FactHelpersTest < ActiveSupport::TestCase
|
4
|
+
class FactsHelpersTestStub
|
5
|
+
include ForemanInventoryUpload::Generators::FactHelpers
|
6
|
+
end
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@instance = FactsHelpersTestStub.new
|
10
|
+
|
11
|
+
@org = FactoryBot.create(:organization)
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'golden_ticket uses golden_ticket method when defined' do
|
15
|
+
@org.expects(:golden_ticket?).returns(true)
|
16
|
+
|
17
|
+
actual = @instance.golden_ticket?(@org)
|
18
|
+
|
19
|
+
assert actual
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'golden_ticket uses content_access_mode method when golden_ticket not defined' do
|
23
|
+
@org.expects(:content_access_mode).returns('org_environment')
|
24
|
+
|
25
|
+
actual = @instance.golden_ticket?(@org)
|
26
|
+
|
27
|
+
assert actual
|
28
|
+
end
|
29
|
+
end
|
@@ -16,7 +16,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
16
16
|
organization: env.organization
|
17
17
|
)
|
18
18
|
|
19
|
-
@host.
|
19
|
+
@host.organization.pools << FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
|
20
20
|
|
21
21
|
ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
|
22
22
|
end
|
@@ -37,6 +37,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
37
37
|
'distribution::name',
|
38
38
|
'distribution::version',
|
39
39
|
'distribution::id',
|
40
|
+
'virt::is_guest',
|
40
41
|
]
|
41
42
|
end
|
42
43
|
|
@@ -50,14 +51,13 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
50
51
|
|
51
52
|
test 'generates a report for a single host' do
|
52
53
|
batch = Host.where(id: @host.id).in_batches.first
|
53
|
-
generator =
|
54
|
+
generator = create_generator(batch)
|
54
55
|
|
55
56
|
json_str = generator.render
|
56
57
|
actual = JSON.parse(json_str.join("\n"))
|
57
58
|
|
58
59
|
assert_equal 'slice_123', actual['report_slice_id']
|
59
60
|
assert_not_nil(actual_host = actual['hosts'].first)
|
60
|
-
assert_equal @host.name, actual_host['display_name']
|
61
61
|
assert_equal @host.fqdn, actual_host['fqdn']
|
62
62
|
assert_equal '1234', actual_host['account']
|
63
63
|
assert_equal 1, generator.hosts_count
|
@@ -66,7 +66,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
66
66
|
test 'generates a report with satellite facts' do
|
67
67
|
Foreman.expects(:instance_id).twice.returns('satellite-id')
|
68
68
|
batch = Host.where(id: @host.id).in_batches.first
|
69
|
-
generator =
|
69
|
+
generator = create_generator(batch)
|
70
70
|
|
71
71
|
json_str = generator.render
|
72
72
|
actual = JSON.parse(json_str.join("\n"))
|
@@ -107,14 +107,13 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
107
107
|
@host.save!
|
108
108
|
|
109
109
|
batch = Host.where(id: @host.id).in_batches.first
|
110
|
-
generator =
|
110
|
+
generator = create_generator(batch)
|
111
111
|
|
112
112
|
json_str = generator.render
|
113
113
|
actual = JSON.parse(json_str.join("\n"))
|
114
114
|
|
115
115
|
assert_equal 'slice_123', actual['report_slice_id']
|
116
116
|
assert_not_nil(actual_host = actual['hosts'].first)
|
117
|
-
assert_equal @host.name, actual_host['display_name']
|
118
117
|
assert_equal @host.fqdn, actual_host['fqdn']
|
119
118
|
assert_not_nil(host_facts = actual_host['facts']&.first)
|
120
119
|
assert_equal 'satellite', host_facts['namespace']
|
@@ -129,14 +128,13 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
129
128
|
@host.subscription_facet.save!
|
130
129
|
|
131
130
|
batch = Host.where(id: @host.id).in_batches.first
|
132
|
-
generator =
|
131
|
+
generator = create_generator(batch)
|
133
132
|
|
134
133
|
json_str = generator.render
|
135
134
|
actual = JSON.parse(json_str.join("\n"))
|
136
135
|
|
137
136
|
assert_equal 'slice_123', actual['report_slice_id']
|
138
137
|
assert_not_nil(actual_host = actual['hosts'].first)
|
139
|
-
assert_equal @host.name, actual_host['display_name']
|
140
138
|
assert_equal @host.fqdn, actual_host['fqdn']
|
141
139
|
assert_not_nil(host_facts = actual_host['facts']&.first)
|
142
140
|
assert_equal 'satellite', host_facts['namespace']
|
@@ -145,6 +143,22 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
145
143
|
assert_equal 'test_role', fact_values['system_purpose_role']
|
146
144
|
end
|
147
145
|
|
146
|
+
test 'generates a report for a golden ticket' do
|
147
|
+
batch = Host.where(id: @host.id).in_batches.first
|
148
|
+
generator = create_generator(batch) do |generator|
|
149
|
+
generator.stubs(:golden_ticket?).returns(true)
|
150
|
+
end
|
151
|
+
|
152
|
+
json_str = generator.render
|
153
|
+
actual = JSON.parse(json_str.join("\n"))
|
154
|
+
|
155
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
156
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
157
|
+
assert_equal @host.fqdn, actual_host['fqdn']
|
158
|
+
assert_equal '1234', actual_host['account']
|
159
|
+
assert_equal 1, generator.hosts_count
|
160
|
+
end
|
161
|
+
|
148
162
|
test 'skips hosts without subscription' do
|
149
163
|
a_host = FactoryBot.create(
|
150
164
|
:host,
|
@@ -153,14 +167,13 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
153
167
|
|
154
168
|
# make a_host last
|
155
169
|
batch = Host.where(id: [@host.id, a_host.id]).order(:name).in_batches.first
|
156
|
-
generator =
|
170
|
+
generator = create_generator(batch)
|
157
171
|
|
158
172
|
json_str = generator.render
|
159
173
|
actual = JSON.parse(json_str.join("\n"))
|
160
174
|
|
161
175
|
assert_equal 'slice_123', actual['report_slice_id']
|
162
176
|
assert_not_nil(actual_host = actual['hosts'].first)
|
163
|
-
assert_equal @host.name, actual_host['display_name']
|
164
177
|
assert_equal @host.fqdn, actual_host['fqdn']
|
165
178
|
assert_equal '1234', actual_host['account']
|
166
179
|
assert_equal 1, generator.hosts_count
|
@@ -170,7 +183,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
170
183
|
FactoryBot.create(:fact_value, fact_name: fact_names['memory::memtotal'], value: '1', host: @host)
|
171
184
|
|
172
185
|
batch = Host.where(id: @host.id).in_batches.first
|
173
|
-
generator =
|
186
|
+
generator = create_generator(batch)
|
174
187
|
|
175
188
|
json_str = generator.render
|
176
189
|
actual = JSON.parse(json_str.join("\n"))
|
@@ -182,15 +195,14 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
182
195
|
end
|
183
196
|
|
184
197
|
test 'reports an account for hosts with multiple pools' do
|
185
|
-
first_pool = @host.
|
198
|
+
first_pool = @host.organization.pools.first
|
186
199
|
second_pool = FactoryBot.create(:katello_pool, account_number: nil, cp_id: 2)
|
187
|
-
|
188
|
-
@host.
|
189
|
-
@host.
|
190
|
-
@host.subscription_facet.pools << second_pool
|
200
|
+
new_org = FactoryBot.create(:organization, pools: [first_pool, second_pool])
|
201
|
+
@host.organization = new_org
|
202
|
+
@host.save!
|
191
203
|
|
192
204
|
batch = Host.where(id: @host.id).in_batches.first
|
193
|
-
generator =
|
205
|
+
generator = create_generator(batch)
|
194
206
|
|
195
207
|
json_str = generator.render
|
196
208
|
actual = JSON.parse(json_str.join("\n"))
|
@@ -207,7 +219,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
207
219
|
FactoryBot.create(:fact_value, fact_name: fact_names['distribution::id'], value: 'TestId', host: @host)
|
208
220
|
|
209
221
|
batch = Host.where(id: @host.id).in_batches.first
|
210
|
-
generator =
|
222
|
+
generator = create_generator(batch)
|
211
223
|
|
212
224
|
json_str = generator.render
|
213
225
|
actual = JSON.parse(json_str.join("\n"))
|
@@ -217,4 +229,46 @@ class ReportGeneratorTest < ActiveSupport::TestCase
|
|
217
229
|
assert_not_nil(actual_profile = actual_host['system_profile'])
|
218
230
|
assert_equal 'Red Hat Test Linux 7.1 (TestId)', actual_profile['os_release']
|
219
231
|
end
|
232
|
+
|
233
|
+
test 'sets infrastructure_type to "virtual" based on virt.is_guest fact' do
|
234
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['virt::is_guest'], value: true, host: @host)
|
235
|
+
|
236
|
+
batch = Host.where(id: @host.id).in_batches.first
|
237
|
+
generator = create_generator(batch)
|
238
|
+
|
239
|
+
json_str = generator.render
|
240
|
+
actual = JSON.parse(json_str.join("\n"))
|
241
|
+
|
242
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
243
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
244
|
+
assert_not_nil(actual_profile = actual_host['system_profile'])
|
245
|
+
assert_equal 'virtual', actual_profile['infrastructure_type']
|
246
|
+
end
|
247
|
+
|
248
|
+
test 'sets infrastructure_type to "physical" based on virt.is_guest fact' do
|
249
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['virt::is_guest'], value: false, host: @host)
|
250
|
+
|
251
|
+
batch = Host.where(id: @host.id).in_batches.first
|
252
|
+
generator = create_generator(batch)
|
253
|
+
|
254
|
+
json_str = generator.render
|
255
|
+
actual = JSON.parse(json_str.join("\n"))
|
256
|
+
|
257
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
258
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
259
|
+
assert_not_nil(actual_profile = actual_host['system_profile'])
|
260
|
+
assert_equal 'physical', actual_profile['infrastructure_type']
|
261
|
+
end
|
262
|
+
|
263
|
+
private
|
264
|
+
|
265
|
+
def create_generator(batch, name = 'slice_123')
|
266
|
+
generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], name)
|
267
|
+
if block_given?
|
268
|
+
yield(generator)
|
269
|
+
else
|
270
|
+
generator.stubs(:golden_ticket?).returns(false)
|
271
|
+
end
|
272
|
+
generator
|
273
|
+
end
|
220
274
|
end
|
@@ -0,0 +1,280 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class ReportGeneratorTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
User.current = User.find_by(login: 'secret_admin')
|
6
|
+
|
7
|
+
env = FactoryBot.create(:katello_k_t_environment)
|
8
|
+
cv = env.content_views << FactoryBot.create(:katello_content_view, organization: env.organization)
|
9
|
+
|
10
|
+
@host = FactoryBot.create(
|
11
|
+
:host,
|
12
|
+
:with_subscription,
|
13
|
+
:with_content,
|
14
|
+
content_view: cv.first,
|
15
|
+
lifecycle_environment: env,
|
16
|
+
organization: env.organization
|
17
|
+
)
|
18
|
+
|
19
|
+
@host.organization.pools << FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
|
20
|
+
|
21
|
+
ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
|
22
|
+
end
|
23
|
+
|
24
|
+
def interesting_facts
|
25
|
+
[
|
26
|
+
'dmi::system::uuid',
|
27
|
+
'virt::uuid',
|
28
|
+
'cpu::cpu(s)',
|
29
|
+
'cpu::cpu_socket(s)',
|
30
|
+
'cpu::core(s)_per_socket',
|
31
|
+
'memory::memtotal',
|
32
|
+
'dmi::bios::vendor',
|
33
|
+
'dmi::bios::version',
|
34
|
+
'dmi::bios::relase_date',
|
35
|
+
'uname::release',
|
36
|
+
'lscpu::flags',
|
37
|
+
'distribution::name',
|
38
|
+
'distribution::version',
|
39
|
+
'distribution::id',
|
40
|
+
'virt::is_guest',
|
41
|
+
]
|
42
|
+
end
|
43
|
+
|
44
|
+
def fact_names
|
45
|
+
@fact_names ||= Hash[
|
46
|
+
interesting_facts.map do |fact|
|
47
|
+
[fact, FactoryBot.create(:fact_name, name: fact, type: 'Katello::RhsmFactName')]
|
48
|
+
end
|
49
|
+
]
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'generates a report for a single host' do
|
53
|
+
batch = Host.where(id: @host.id).in_batches.first
|
54
|
+
generator = create_generator(batch)
|
55
|
+
|
56
|
+
json_str = generator.render
|
57
|
+
actual = JSON.parse(json_str.join("\n"))
|
58
|
+
|
59
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
60
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
61
|
+
assert_equal @host.name, actual_host['display_name']
|
62
|
+
assert_equal @host.fqdn, actual_host['fqdn']
|
63
|
+
assert_equal '1234', actual_host['account']
|
64
|
+
assert_equal 1, generator.hosts_count
|
65
|
+
end
|
66
|
+
|
67
|
+
test 'generates a report with satellite facts' do
|
68
|
+
Foreman.expects(:instance_id).twice.returns('satellite-id')
|
69
|
+
batch = Host.where(id: @host.id).in_batches.first
|
70
|
+
generator = create_generator(batch)
|
71
|
+
|
72
|
+
json_str = generator.render
|
73
|
+
actual = JSON.parse(json_str.join("\n"))
|
74
|
+
|
75
|
+
facts = actual['hosts'].first['facts'].first
|
76
|
+
assert_equal 'satellite', facts['namespace']
|
77
|
+
satellite_facts = facts['facts']
|
78
|
+
assert_equal 'satellite-id', satellite_facts['satellite_instance_id']
|
79
|
+
assert_equal @host.organization_id, satellite_facts['organization_id']
|
80
|
+
|
81
|
+
instance_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'satellite_instance_id' }
|
82
|
+
assert_not_nil instance_id_tag
|
83
|
+
assert_equal 'satellite-id', instance_id_tag['value']
|
84
|
+
|
85
|
+
org_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'organization_id' }
|
86
|
+
assert_not_nil org_id_tag
|
87
|
+
assert_equal @host.organization_id.to_s, org_id_tag['value']
|
88
|
+
|
89
|
+
version = satellite_facts['satellite_version']
|
90
|
+
if defined?(ForemanThemeSatellite)
|
91
|
+
assert_equal ForemanThemeSatellite::SATELLITE_VERSION, version
|
92
|
+
else
|
93
|
+
assert_nil version
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
test 'generates a report for a host with hypervisor' do
|
98
|
+
hypervisor_host = FactoryBot.create(
|
99
|
+
:host,
|
100
|
+
:with_subscription,
|
101
|
+
:with_content,
|
102
|
+
content_view: @host.content_view,
|
103
|
+
lifecycle_environment: @host.lifecycle_environment,
|
104
|
+
organization: @host.organization
|
105
|
+
)
|
106
|
+
|
107
|
+
@host.subscription_facet.hypervisor_host = hypervisor_host
|
108
|
+
@host.save!
|
109
|
+
|
110
|
+
batch = Host.where(id: @host.id).in_batches.first
|
111
|
+
generator = create_generator(batch)
|
112
|
+
|
113
|
+
json_str = generator.render
|
114
|
+
actual = JSON.parse(json_str.join("\n"))
|
115
|
+
|
116
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
117
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
118
|
+
assert_equal @host.name, actual_host['display_name']
|
119
|
+
assert_equal @host.fqdn, actual_host['fqdn']
|
120
|
+
assert_not_nil(host_facts = actual_host['facts']&.first)
|
121
|
+
assert_equal 'satellite', host_facts['namespace']
|
122
|
+
assert_not_nil(fact_values = host_facts['facts'])
|
123
|
+
assert_equal hypervisor_host.name, fact_values['virtual_host_name']
|
124
|
+
assert_equal hypervisor_host.subscription_facet.uuid, fact_values['virtual_host_uuid']
|
125
|
+
end
|
126
|
+
|
127
|
+
test 'generates a report with system purpose' do
|
128
|
+
@host.subscription_facet.purpose_usage = 'test_usage'
|
129
|
+
@host.subscription_facet.purpose_role = 'test_role'
|
130
|
+
@host.subscription_facet.save!
|
131
|
+
|
132
|
+
batch = Host.where(id: @host.id).in_batches.first
|
133
|
+
generator = create_generator(batch)
|
134
|
+
|
135
|
+
json_str = generator.render
|
136
|
+
actual = JSON.parse(json_str.join("\n"))
|
137
|
+
|
138
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
139
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
140
|
+
assert_equal @host.name, actual_host['display_name']
|
141
|
+
assert_equal @host.fqdn, actual_host['fqdn']
|
142
|
+
assert_not_nil(host_facts = actual_host['facts']&.first)
|
143
|
+
assert_equal 'satellite', host_facts['namespace']
|
144
|
+
assert_not_nil(fact_values = host_facts['facts'])
|
145
|
+
assert_equal 'test_usage', fact_values['system_purpose_usage']
|
146
|
+
assert_equal 'test_role', fact_values['system_purpose_role']
|
147
|
+
end
|
148
|
+
|
149
|
+
test 'generates a report for a golden ticket' do
|
150
|
+
batch = Host.where(id: @host.id).in_batches.first
|
151
|
+
generator = create_generator(batch) do |generator|
|
152
|
+
generator.stubs(:golden_ticket?).returns(true)
|
153
|
+
end
|
154
|
+
|
155
|
+
json_str = generator.render
|
156
|
+
actual = JSON.parse(json_str.join("\n"))
|
157
|
+
|
158
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
159
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
160
|
+
assert_equal @host.name, actual_host['display_name']
|
161
|
+
assert_equal @host.fqdn, actual_host['fqdn']
|
162
|
+
assert_equal '1234', actual_host['account']
|
163
|
+
assert_equal 1, generator.hosts_count
|
164
|
+
end
|
165
|
+
|
166
|
+
test 'skips hosts without subscription' do
|
167
|
+
a_host = FactoryBot.create(
|
168
|
+
:host,
|
169
|
+
organization: @host.organization
|
170
|
+
)
|
171
|
+
|
172
|
+
# make a_host last
|
173
|
+
batch = Host.where(id: [@host.id, a_host.id]).order(:name).in_batches.first
|
174
|
+
generator = create_generator(batch)
|
175
|
+
|
176
|
+
json_str = generator.render
|
177
|
+
actual = JSON.parse(json_str.join("\n"))
|
178
|
+
|
179
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
180
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
181
|
+
assert_equal @host.name, actual_host['display_name']
|
182
|
+
assert_equal @host.fqdn, actual_host['fqdn']
|
183
|
+
assert_equal '1234', actual_host['account']
|
184
|
+
assert_equal 1, generator.hosts_count
|
185
|
+
end
|
186
|
+
|
187
|
+
test 'shows system_memory_bytes in bytes' do
|
188
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['memory::memtotal'], value: '1', host: @host)
|
189
|
+
|
190
|
+
batch = Host.where(id: @host.id).in_batches.first
|
191
|
+
generator = create_generator(batch)
|
192
|
+
|
193
|
+
json_str = generator.render
|
194
|
+
actual = JSON.parse(json_str.join("\n"))
|
195
|
+
|
196
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
197
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
198
|
+
assert_not_nil(actual_profile = actual_host['system_profile'])
|
199
|
+
assert_equal 1024, actual_profile['system_memory_bytes']
|
200
|
+
end
|
201
|
+
|
202
|
+
test 'reports an account for hosts with multiple pools' do
|
203
|
+
first_pool = @host.organization.pools.first
|
204
|
+
second_pool = FactoryBot.create(:katello_pool, account_number: nil, cp_id: 2)
|
205
|
+
new_org = FactoryBot.create(:organization, pools: [first_pool, second_pool])
|
206
|
+
@host.organization = new_org
|
207
|
+
@host.save!
|
208
|
+
|
209
|
+
batch = Host.where(id: @host.id).in_batches.first
|
210
|
+
generator = create_generator(batch)
|
211
|
+
|
212
|
+
json_str = generator.render
|
213
|
+
actual = JSON.parse(json_str.join("\n"))
|
214
|
+
|
215
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
216
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
217
|
+
assert_not_nil(actual_host['account'])
|
218
|
+
assert_not_empty(actual_host['account'])
|
219
|
+
end
|
220
|
+
|
221
|
+
test 'Generates os_release with version and id' do
|
222
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['distribution::name'], value: 'Red Hat Test Linux', host: @host)
|
223
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['distribution::version'], value: '7.1', host: @host)
|
224
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['distribution::id'], value: 'TestId', host: @host)
|
225
|
+
|
226
|
+
batch = Host.where(id: @host.id).in_batches.first
|
227
|
+
generator = create_generator(batch)
|
228
|
+
|
229
|
+
json_str = generator.render
|
230
|
+
actual = JSON.parse(json_str.join("\n"))
|
231
|
+
|
232
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
233
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
234
|
+
assert_not_nil(actual_profile = actual_host['system_profile'])
|
235
|
+
assert_equal 'Red Hat Test Linux 7.1 (TestId)', actual_profile['os_release']
|
236
|
+
end
|
237
|
+
|
238
|
+
<<<<<<< HEAD
|
239
|
+
test 'sets infrastructure_type to "virtual" based on virt.is_guest fact' do
|
240
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['virt::is_guest'], value: true, host: @host)
|
241
|
+
|
242
|
+
batch = Host.where(id: @host.id).in_batches.first
|
243
|
+
generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
|
244
|
+
|
245
|
+
json_str = generator.render
|
246
|
+
actual = JSON.parse(json_str.join("\n"))
|
247
|
+
|
248
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
249
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
250
|
+
assert_not_nil(actual_profile = actual_host['system_profile'])
|
251
|
+
assert_equal 'virtual', actual_profile['infrastructure_type']
|
252
|
+
end
|
253
|
+
|
254
|
+
test 'sets infrastructure_type to "physical" based on virt.is_guest fact' do
|
255
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['virt::is_guest'], value: false, host: @host)
|
256
|
+
|
257
|
+
batch = Host.where(id: @host.id).in_batches.first
|
258
|
+
generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
|
259
|
+
|
260
|
+
json_str = generator.render
|
261
|
+
actual = JSON.parse(json_str.join("\n"))
|
262
|
+
|
263
|
+
assert_equal 'slice_123', actual['report_slice_id']
|
264
|
+
assert_not_nil(actual_host = actual['hosts'].first)
|
265
|
+
assert_not_nil(actual_profile = actual_host['system_profile'])
|
266
|
+
assert_equal 'physical', actual_profile['infrastructure_type']
|
267
|
+
=======
|
268
|
+
private
|
269
|
+
|
270
|
+
def create_generator(batch, name = 'slice_123')
|
271
|
+
generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], name)
|
272
|
+
if block_given?
|
273
|
+
yield(generator)
|
274
|
+
else
|
275
|
+
generator.stubs(:golden_ticket?).returns(false)
|
276
|
+
end
|
277
|
+
generator
|
278
|
+
>>>>>>> Add support fo golden ticket
|
279
|
+
end
|
280
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_rh_cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Foreman Red Hat Cloud team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: katello
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- app/views/foreman_inventory_upload/layouts/react.html.erb
|
86
86
|
- config/routes.rb
|
87
87
|
- lib/foreman_inventory_upload.rb
|
88
|
+
- lib/foreman_inventory_upload/async/async_helpers.rb
|
88
89
|
- lib/foreman_inventory_upload/async/generate_all_reports_job.rb
|
89
90
|
- lib/foreman_inventory_upload/async/generate_report_job.rb
|
90
91
|
- lib/foreman_inventory_upload/async/progress_output.rb
|
@@ -114,9 +115,11 @@ files:
|
|
114
115
|
- test/factories/inventory_upload_factories.rb
|
115
116
|
- test/test_plugin_helper.rb
|
116
117
|
- test/unit/archived_report_generator_test.rb
|
118
|
+
- test/unit/fact_helpers_test.rb
|
117
119
|
- test/unit/metadata_generator_test.rb
|
118
120
|
- test/unit/shell_process_job_test.rb
|
119
121
|
- test/unit/slice_generator_test.rb
|
122
|
+
- test/unit/slice_generator_test.rb.orig
|
120
123
|
- webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js
|
121
124
|
- webpack/ForemanInventoryUpload/Components/AccountList/AccountList.js
|
122
125
|
- webpack/ForemanInventoryUpload/Components/AccountList/AccountList.stories.js
|
@@ -329,5 +332,7 @@ test_files:
|
|
329
332
|
- test/factories/inventory_upload_factories.rb
|
330
333
|
- test/unit/shell_process_job_test.rb
|
331
334
|
- test/unit/metadata_generator_test.rb
|
335
|
+
- test/unit/slice_generator_test.rb.orig
|
336
|
+
- test/unit/fact_helpers_test.rb
|
332
337
|
- test/unit/archived_report_generator_test.rb
|
333
338
|
- test/unit/slice_generator_test.rb
|