foreman_rh_cloud 1.0.5 → 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -0
  3. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +2 -6
  4. data/app/controllers/foreman_rh_cloud/react_controller.rb +8 -0
  5. data/app/models/setting/rh_cloud.rb +1 -0
  6. data/app/views/foreman_rh_cloud/react/inventory_upload.html.erb +1 -0
  7. data/app/views/{foreman_inventory_upload/layouts/react.html.erb → layouts/foreman_rh_cloud/application.html.erb} +2 -2
  8. data/config/routes.rb +4 -1
  9. data/lib/foreman_inventory_upload/async/async_helpers.rb +13 -0
  10. data/lib/foreman_inventory_upload/async/shell_process.rb +3 -1
  11. data/lib/foreman_inventory_upload/async/upload_report_job.rb +1 -5
  12. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +56 -0
  13. data/lib/foreman_inventory_upload/generators/queries.rb +6 -0
  14. data/lib/foreman_inventory_upload/generators/slice.rb +14 -9
  15. data/lib/foreman_rh_cloud/engine.rb +17 -5
  16. data/lib/foreman_rh_cloud/version.rb +1 -1
  17. data/package.json +20 -100
  18. data/test/factories/inventory_upload_factories.rb +13 -13
  19. data/test/unit/archived_report_generator_test.rb +1 -0
  20. data/test/unit/fact_helpers_test.rb +29 -0
  21. data/test/unit/slice_generator_test.rb +206 -20
  22. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +6 -2
  23. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.js +13 -10
  24. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.stories.js +5 -14
  25. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +3 -2
  26. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListHelper.js +10 -0
  27. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +1 -1
  28. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/EmptyResults.js +15 -0
  29. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/EmptyResults.test.js +13 -0
  30. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/__snapshots__/EmptyResults.test.js.snap +18 -0
  31. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/emptyResults.scss +7 -0
  32. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/index.js +1 -0
  33. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/EmptyState.test.js +1 -1
  34. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/__tests__/ErrorState.test.js +1 -1
  35. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItem.js +1 -4
  36. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/ListItem.test.js +1 -1
  37. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/ListItemStatus.test.js +1 -1
  38. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountList.test.js +2 -1
  39. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +1 -1
  40. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListHelper.test.js +12 -0
  41. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListIntegration.test.js +2 -2
  42. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +1 -1
  43. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +8 -9
  44. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountList.test.js.snap +2 -3
  45. data/webpack/ForemanInventoryUpload/Components/AccountList/index.js +2 -0
  46. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherActions.js +4 -1
  47. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcher.test.js +1 -1
  48. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcherActions.test.js +1 -1
  49. data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.fixtures.js +13 -9
  50. data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.stories.js +5 -15
  51. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardActions.js +4 -3
  52. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardSelectors.js +1 -1
  53. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/Dashboard.test.js +1 -2
  54. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardActions.test.js +17 -5
  55. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardIntegration.test.js +2 -2
  56. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardReducer.test.js +1 -1
  57. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardSelectors.test.js +4 -3
  58. data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/FileDownload.test.js +1 -1
  59. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/FullScreenModal.test.js +1 -1
  60. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/Components/ClearButton/ClearButton.js +26 -0
  61. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/Components/ClearButton/index.js +1 -0
  62. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.fixtures.js +2 -0
  63. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.js +39 -0
  64. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterActions.js +16 -0
  65. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterConstants.js +3 -0
  66. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js +36 -0
  67. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterSelectors.js +7 -0
  68. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilter.test.js +14 -0
  69. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterActions.test.js +14 -0
  70. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterReducer.test.js +35 -0
  71. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterSelectors.test.js +21 -0
  72. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilter.test.js.snap +25 -0
  73. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterActions.test.js.snap +17 -0
  74. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterReducer.test.js.snap +25 -0
  75. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterSelectors.test.js.snap +9 -0
  76. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +31 -0
  77. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/integration.test.js +18 -0
  78. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/index.js +17 -0
  79. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/inventoryFilter.scss +28 -0
  80. data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.fixtures.js +5 -2
  81. data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/NavContainer.test.js +1 -2
  82. data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/__snapshots__/NavContainer.test.js.snap +1 -1
  83. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js +12 -3
  84. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/PageHeader.test.js +1 -1
  85. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap +11 -2
  86. data/webpack/ForemanInventoryUpload/Components/PageHeader/pageHeader.scss +3 -0
  87. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/__tests__/ReportGenerate.test.js +1 -1
  88. data/webpack/ForemanInventoryUpload/Components/ReportUpload/__tests__/ReportUpload.test.js +1 -1
  89. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/ScheduledRun.test.js +1 -1
  90. data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/StatusChart.test.js +1 -1
  91. data/webpack/ForemanInventoryUpload/Components/TabBody/__tests__/TabBody.test.js +1 -1
  92. data/webpack/ForemanInventoryUpload/Components/TabContainer/__tests__/TabContainer.test.js +1 -1
  93. data/webpack/ForemanInventoryUpload/Components/TabFooter/__tests__/TabFooter.test.js +1 -1
  94. data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/TabHeader.test.js +1 -1
  95. data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +1 -1
  96. data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/Terminal.test.js +1 -2
  97. data/webpack/ForemanInventoryUpload/ForemanInventoryConstants.js +3 -0
  98. data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +4 -0
  99. data/webpack/ForemanInventoryUpload/ForemanInventoryUpload.js +16 -8
  100. data/webpack/ForemanInventoryUpload/ForemanInventoryUploadReducers.js +4 -4
  101. data/webpack/ForemanInventoryUpload/__tests__/ForemanInventoryHelpers.test.js +9 -0
  102. data/webpack/ForemanInventoryUpload/{ForemanInventoryUpload.test.js → __tests__/ForemanInventoryUpload.test.js} +2 -2
  103. data/webpack/ForemanInventoryUpload/__tests__/__snapshots__/ForemanInventoryHelpers.test.js.snap +3 -0
  104. data/webpack/ForemanInventoryUpload/{__snapshots__ → __tests__/__snapshots__}/ForemanInventoryUpload.test.js.snap +0 -0
  105. data/webpack/ForemanRhCloudHelpers.js +6 -0
  106. data/webpack/ForemanRhCloudReducers.js +8 -0
  107. data/webpack/ForemanRhCloudSelectors.js +3 -0
  108. data/webpack/ForemanRhCloudTestHelpers.js +5 -0
  109. data/webpack/__mocks__/foremanReact/components/Layout/LayoutConstants.js +1 -0
  110. data/webpack/__tests__/ForemanRhCloudHelpers.test.js +11 -0
  111. data/webpack/__tests__/ForemanRhCloudSelectors.test.js +17 -0
  112. data/webpack/__tests__/ForemanRhCloudTestHelpers.test.js +10 -0
  113. data/webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap +3 -0
  114. data/webpack/__tests__/__snapshots__/ForemanRhCloudSelectors.test.js.snap +15 -0
  115. data/webpack/__tests__/__snapshots__/ForemanRhCloudTestHelpers.test.js.snap +11 -0
  116. data/webpack/index.js +1 -1
  117. metadata +52 -14
  118. data/app/controllers/foreman_inventory_upload/react_controller.rb +0 -7
  119. data/webpack/ForemanInventoryUpload/ForemanInventoryUploadSelectors.js +0 -4
  120. data/webpack/stories/ForemanInventoryUploadReducers.js +0 -3
  121. data/webpack/stories/configureStore.js +0 -15
  122. data/webpack/stories/decorators/index.js +0 -1
  123. data/webpack/stories/decorators/withCardsDecorator.js +0 -14
  124. data/webpack/stories/index.js +0 -10
  125. data/webpack/stories/index.scss +0 -7
  126. data/webpack/test_setup.js +0 -6
@@ -1,16 +1,16 @@
1
1
  # redefine katello factories, as long as katello is not compatible with dynamic properties
2
2
  FactoryBot.define do
3
3
  factory :katello_organization, :class => "Organization" do
4
- type {"Organization"}
4
+ type { "Organization" }
5
5
  sequence(:name) { |n| "Organization#{n}" }
6
6
  sequence(:label) { |n| "org#{n}" }
7
7
  sequence(:id) { |n| n }
8
8
 
9
9
  trait :acme_corporation do
10
- name {"ACME_Corporation"}
11
- type {"Organization"}
12
- description {"This is the first Organization."}
13
- label {"acme_corporation_label"}
10
+ name { "ACME_Corporation" }
11
+ type { "Organization" }
12
+ description { "This is the first Organization." }
13
+ label { "acme_corporation_label" }
14
14
  end
15
15
 
16
16
  trait :with_library do
@@ -24,11 +24,11 @@ end
24
24
  FactoryBot.define do
25
25
  factory :katello_content_view, :class => Katello::ContentView do
26
26
  sequence(:name) { |n| "Database#{n}" }
27
- description {"This content view is for database content"}
27
+ description { "This content view is for database content" }
28
28
  association :organization, :factory => :katello_organization
29
29
 
30
30
  trait :composite do
31
- composite {true}
31
+ composite { true }
32
32
  end
33
33
  end
34
34
  end
@@ -50,23 +50,23 @@ end
50
50
  FactoryBot.define do
51
51
  factory :katello_subscription_facets, :aliases => [:subscription_facet], :class => ::Katello::Host::SubscriptionFacet do
52
52
  sequence(:uuid) { |n| "uuid-#{n}-#{rand(500)}" }
53
- facts { {'memory.memtotal' => "12 GB"} }
53
+ facts { { 'memory.memtotal' => "12 GB" } }
54
54
  end
55
55
  end
56
56
 
57
57
  FactoryBot.define do
58
58
  factory :katello_pool, :class => Katello::Pool do
59
- active {true}
60
- end_date {Date.today + 1.year}
59
+ active { true }
60
+ end_date { Date.today + 1.year }
61
61
  end
62
62
  end
63
63
 
64
64
  FactoryBot.modify do
65
65
  factory :host do
66
66
  transient do
67
- content_view {nil}
68
- lifecycle_environment {nil}
69
- content_source {nil}
67
+ content_view { nil }
68
+ lifecycle_environment { nil }
69
+ content_source { nil }
70
70
  end
71
71
 
72
72
  trait :with_content do
@@ -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.subscription_facet.pools << FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
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,12 @@ class ReportGeneratorTest < ActiveSupport::TestCase
37
37
  'distribution::name',
38
38
  'distribution::version',
39
39
  'distribution::id',
40
+ 'virt::is_guest',
41
+ 'dmi::system::manufacturer',
42
+ 'dmi::system::product_name',
43
+ 'dmi::chassis::asset_tag',
44
+ 'insights_client::obfuscate_hostname_enabled',
45
+ 'insights_client::hostname',
40
46
  ]
41
47
  end
42
48
 
@@ -50,14 +56,65 @@ class ReportGeneratorTest < ActiveSupport::TestCase
50
56
 
51
57
  test 'generates a report for a single host' do
52
58
  batch = Host.where(id: @host.id).in_batches.first
53
- generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
59
+ generator = create_generator(batch)
60
+
61
+ json_str = generator.render
62
+ actual = JSON.parse(json_str.join("\n"))
63
+
64
+ assert_equal 'slice_123', actual['report_slice_id']
65
+ assert_not_nil(actual_host = actual['hosts'].first)
66
+ assert_equal @host.fqdn, actual_host['fqdn']
67
+ assert_equal '1234', actual_host['account']
68
+ assert_equal 1, generator.hosts_count
69
+ end
70
+
71
+ test 'obfuscates fqdn when instructed by insights-client' do
72
+ FactoryBot.create(:fact_value, fact_name: fact_names['insights_client::obfuscate_hostname_enabled'], value: 'true', host: @host)
73
+ FactoryBot.create(:fact_value, fact_name: fact_names['insights_client::hostname'], value: 'obfuscated_name', host: @host)
74
+
75
+ batch = Host.where(id: @host.id).in_batches.first
76
+ generator = create_generator(batch)
77
+
78
+ json_str = generator.render
79
+ actual = JSON.parse(json_str.join("\n"))
80
+
81
+ assert_equal 'slice_123', actual['report_slice_id']
82
+ assert_not_nil(actual_host = actual['hosts'].first)
83
+ assert_equal 'obfuscated_name', actual_host['fqdn']
84
+ assert_equal '1234', actual_host['account']
85
+ assert_equal 1, generator.hosts_count
86
+ end
87
+
88
+ test 'obfuscates fqdn when setting set' do
89
+ FactoryBot.create(:setting, :name => 'obfuscate_inventory_hostnames', :value => true)
90
+
91
+ batch = Host.where(id: @host.id).in_batches.first
92
+ generator = create_generator(batch)
93
+
94
+ json_str = generator.render
95
+ actual = JSON.parse(json_str.join("\n"))
96
+
97
+ obfuscated_fqdn = Base64.urlsafe_encode64(Digest::SHA1.digest(@host.fqdn), padding: false)
98
+
99
+ assert_equal 'slice_123', actual['report_slice_id']
100
+ assert_not_nil(actual_host = actual['hosts'].first)
101
+ assert_equal obfuscated_fqdn, actual_host['fqdn']
102
+ assert_equal '1234', actual_host['account']
103
+ assert_equal 1, generator.hosts_count
104
+ end
105
+
106
+ test 'does not obfuscate fqdn when insights-client sets to false' do
107
+ FactoryBot.create(:fact_value, fact_name: fact_names['insights_client::obfuscate_hostname_enabled'], value: 'false', host: @host)
108
+ FactoryBot.create(:fact_value, fact_name: fact_names['insights_client::hostname'], value: 'obfuscated_name', host: @host)
109
+
110
+ batch = Host.where(id: @host.id).in_batches.first
111
+ generator = create_generator(batch)
54
112
 
55
113
  json_str = generator.render
56
114
  actual = JSON.parse(json_str.join("\n"))
57
115
 
58
116
  assert_equal 'slice_123', actual['report_slice_id']
59
117
  assert_not_nil(actual_host = actual['hosts'].first)
60
- assert_equal @host.name, actual_host['display_name']
61
118
  assert_equal @host.fqdn, actual_host['fqdn']
62
119
  assert_equal '1234', actual_host['account']
63
120
  assert_equal 1, generator.hosts_count
@@ -66,7 +123,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
66
123
  test 'generates a report with satellite facts' do
67
124
  Foreman.expects(:instance_id).twice.returns('satellite-id')
68
125
  batch = Host.where(id: @host.id).in_batches.first
69
- generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice-123')
126
+ generator = create_generator(batch)
70
127
 
71
128
  json_str = generator.render
72
129
  actual = JSON.parse(json_str.join("\n"))
@@ -77,11 +134,11 @@ class ReportGeneratorTest < ActiveSupport::TestCase
77
134
  assert_equal 'satellite-id', satellite_facts['satellite_instance_id']
78
135
  assert_equal @host.organization_id, satellite_facts['organization_id']
79
136
 
80
- instance_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'satellite_instance_id'}
137
+ instance_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'satellite_instance_id' }
81
138
  assert_not_nil instance_id_tag
82
139
  assert_equal 'satellite-id', instance_id_tag['value']
83
140
 
84
- org_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'organization_id'}
141
+ org_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'organization_id' }
85
142
  assert_not_nil org_id_tag
86
143
  assert_equal @host.organization_id.to_s, org_id_tag['value']
87
144
 
@@ -107,14 +164,13 @@ class ReportGeneratorTest < ActiveSupport::TestCase
107
164
  @host.save!
108
165
 
109
166
  batch = Host.where(id: @host.id).in_batches.first
110
- generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
167
+ generator = create_generator(batch)
111
168
 
112
169
  json_str = generator.render
113
170
  actual = JSON.parse(json_str.join("\n"))
114
171
 
115
172
  assert_equal 'slice_123', actual['report_slice_id']
116
173
  assert_not_nil(actual_host = actual['hosts'].first)
117
- assert_equal @host.name, actual_host['display_name']
118
174
  assert_equal @host.fqdn, actual_host['fqdn']
119
175
  assert_not_nil(host_facts = actual_host['facts']&.first)
120
176
  assert_equal 'satellite', host_facts['namespace']
@@ -129,14 +185,13 @@ class ReportGeneratorTest < ActiveSupport::TestCase
129
185
  @host.subscription_facet.save!
130
186
 
131
187
  batch = Host.where(id: @host.id).in_batches.first
132
- generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
188
+ generator = create_generator(batch)
133
189
 
134
190
  json_str = generator.render
135
191
  actual = JSON.parse(json_str.join("\n"))
136
192
 
137
193
  assert_equal 'slice_123', actual['report_slice_id']
138
194
  assert_not_nil(actual_host = actual['hosts'].first)
139
- assert_equal @host.name, actual_host['display_name']
140
195
  assert_equal @host.fqdn, actual_host['fqdn']
141
196
  assert_not_nil(host_facts = actual_host['facts']&.first)
142
197
  assert_equal 'satellite', host_facts['namespace']
@@ -145,6 +200,22 @@ class ReportGeneratorTest < ActiveSupport::TestCase
145
200
  assert_equal 'test_role', fact_values['system_purpose_role']
146
201
  end
147
202
 
203
+ test 'generates a report for a golden ticket' do
204
+ batch = Host.where(id: @host.id).in_batches.first
205
+ generator = create_generator(batch) do |generator|
206
+ generator.stubs(:golden_ticket?).returns(true)
207
+ end
208
+
209
+ json_str = generator.render
210
+ actual = JSON.parse(json_str.join("\n"))
211
+
212
+ assert_equal 'slice_123', actual['report_slice_id']
213
+ assert_not_nil(actual_host = actual['hosts'].first)
214
+ assert_equal @host.fqdn, actual_host['fqdn']
215
+ assert_equal '1234', actual_host['account']
216
+ assert_equal 1, generator.hosts_count
217
+ end
218
+
148
219
  test 'skips hosts without subscription' do
149
220
  a_host = FactoryBot.create(
150
221
  :host,
@@ -153,14 +224,13 @@ class ReportGeneratorTest < ActiveSupport::TestCase
153
224
 
154
225
  # make a_host last
155
226
  batch = Host.where(id: [@host.id, a_host.id]).order(:name).in_batches.first
156
- generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
227
+ generator = create_generator(batch)
157
228
 
158
229
  json_str = generator.render
159
230
  actual = JSON.parse(json_str.join("\n"))
160
231
 
161
232
  assert_equal 'slice_123', actual['report_slice_id']
162
233
  assert_not_nil(actual_host = actual['hosts'].first)
163
- assert_equal @host.name, actual_host['display_name']
164
234
  assert_equal @host.fqdn, actual_host['fqdn']
165
235
  assert_equal '1234', actual_host['account']
166
236
  assert_equal 1, generator.hosts_count
@@ -170,7 +240,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
170
240
  FactoryBot.create(:fact_value, fact_name: fact_names['memory::memtotal'], value: '1', host: @host)
171
241
 
172
242
  batch = Host.where(id: @host.id).in_batches.first
173
- generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
243
+ generator = create_generator(batch)
174
244
 
175
245
  json_str = generator.render
176
246
  actual = JSON.parse(json_str.join("\n"))
@@ -182,15 +252,14 @@ class ReportGeneratorTest < ActiveSupport::TestCase
182
252
  end
183
253
 
184
254
  test 'reports an account for hosts with multiple pools' do
185
- first_pool = @host.subscription_facet.pools.first
255
+ first_pool = @host.organization.pools.first
186
256
  second_pool = FactoryBot.create(:katello_pool, account_number: nil, cp_id: 2)
187
- @host.subscription_facet.pools = []
188
- @host.subscription_facet.save!
189
- @host.subscription_facet.pools << first_pool
190
- @host.subscription_facet.pools << second_pool
257
+ new_org = FactoryBot.create(:organization, pools: [first_pool, second_pool])
258
+ @host.organization = new_org
259
+ @host.save!
191
260
 
192
261
  batch = Host.where(id: @host.id).in_batches.first
193
- generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
262
+ generator = create_generator(batch)
194
263
 
195
264
  json_str = generator.render
196
265
  actual = JSON.parse(json_str.join("\n"))
@@ -207,7 +276,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
207
276
  FactoryBot.create(:fact_value, fact_name: fact_names['distribution::id'], value: 'TestId', host: @host)
208
277
 
209
278
  batch = Host.where(id: @host.id).in_batches.first
210
- generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
279
+ generator = create_generator(batch)
211
280
 
212
281
  json_str = generator.render
213
282
  actual = JSON.parse(json_str.join("\n"))
@@ -217,4 +286,121 @@ class ReportGeneratorTest < ActiveSupport::TestCase
217
286
  assert_not_nil(actual_profile = actual_host['system_profile'])
218
287
  assert_equal 'Red Hat Test Linux 7.1 (TestId)', actual_profile['os_release']
219
288
  end
289
+
290
+ test 'sets infrastructure_type to "virtual" based on virt.is_guest fact' do
291
+ FactoryBot.create(:fact_value, fact_name: fact_names['virt::is_guest'], value: true, host: @host)
292
+
293
+ batch = Host.where(id: @host.id).in_batches.first
294
+ generator = create_generator(batch)
295
+
296
+ json_str = generator.render
297
+ actual = JSON.parse(json_str.join("\n"))
298
+
299
+ assert_equal 'slice_123', actual['report_slice_id']
300
+ assert_not_nil(actual_host = actual['hosts'].first)
301
+ assert_not_nil(actual_profile = actual_host['system_profile'])
302
+ assert_equal 'virtual', actual_profile['infrastructure_type']
303
+ end
304
+
305
+ test 'sets infrastructure_type to "physical" based on virt.is_guest fact' do
306
+ FactoryBot.create(:fact_value, fact_name: fact_names['virt::is_guest'], value: false, host: @host)
307
+
308
+ batch = Host.where(id: @host.id).in_batches.first
309
+ generator = create_generator(batch)
310
+
311
+ json_str = generator.render
312
+ actual = JSON.parse(json_str.join("\n"))
313
+
314
+ assert_equal 'slice_123', actual['report_slice_id']
315
+ assert_not_nil(actual_host = actual['hosts'].first)
316
+ assert_not_nil(actual_profile = actual_host['system_profile'])
317
+ assert_equal 'physical', actual_profile['infrastructure_type']
318
+ end
319
+
320
+ test 'Identifies Amazon cloud provider' do
321
+ FactoryBot.create(:fact_value, fact_name: fact_names['dmi::bios::version'], value: 'Test Amazon version', host: @host)
322
+
323
+ batch = Host.where(id: @host.id).in_batches.first
324
+ generator = create_generator(batch)
325
+
326
+ json_str = generator.render
327
+ actual = JSON.parse(json_str.join("\n"))
328
+
329
+ assert_equal 'slice_123', actual['report_slice_id']
330
+ assert_not_nil(actual_host = actual['hosts'].first)
331
+ assert_not_nil(actual_profile = actual_host['system_profile'])
332
+ assert_equal 'aws', actual_profile['cloud_provider']
333
+ end
334
+
335
+ test 'Identifies Google cloud provider' do
336
+ FactoryBot.create(:fact_value, fact_name: fact_names['dmi::bios::version'], value: 'Test Google version', host: @host)
337
+
338
+ batch = Host.where(id: @host.id).in_batches.first
339
+ generator = create_generator(batch)
340
+
341
+ json_str = generator.render
342
+ actual = JSON.parse(json_str.join("\n"))
343
+
344
+ assert_equal 'slice_123', actual['report_slice_id']
345
+ assert_not_nil(actual_host = actual['hosts'].first)
346
+ assert_not_nil(actual_profile = actual_host['system_profile'])
347
+ assert_equal 'google', actual_profile['cloud_provider']
348
+ end
349
+
350
+ test 'Identifies Azure cloud provider' do
351
+ FactoryBot.create(:fact_value, fact_name: fact_names['dmi::chassis::asset_tag'], value: '7783-7084-3265-9085-8269-3286-77', host: @host)
352
+
353
+ batch = Host.where(id: @host.id).in_batches.first
354
+ generator = create_generator(batch)
355
+
356
+ json_str = generator.render
357
+ actual = JSON.parse(json_str.join("\n"))
358
+
359
+ assert_equal 'slice_123', actual['report_slice_id']
360
+ assert_not_nil(actual_host = actual['hosts'].first)
361
+ assert_not_nil(actual_profile = actual_host['system_profile'])
362
+ assert_equal 'azure', actual_profile['cloud_provider']
363
+ end
364
+
365
+ test 'Identifies Alibaba cloud provider via manufacturer' do
366
+ FactoryBot.create(:fact_value, fact_name: fact_names['dmi::system::manufacturer'], value: 'Test Alibaba Cloud version', host: @host)
367
+
368
+ batch = Host.where(id: @host.id).in_batches.first
369
+ generator = create_generator(batch)
370
+
371
+ json_str = generator.render
372
+ actual = JSON.parse(json_str.join("\n"))
373
+
374
+ assert_equal 'slice_123', actual['report_slice_id']
375
+ assert_not_nil(actual_host = actual['hosts'].first)
376
+ assert_not_nil(actual_profile = actual_host['system_profile'])
377
+ assert_equal 'alibaba', actual_profile['cloud_provider']
378
+ end
379
+
380
+ test 'Identifies Alibaba cloud provider via product name' do
381
+ FactoryBot.create(:fact_value, fact_name: fact_names['dmi::system::product_name'], value: 'Test Alibaba Cloud ECS product', host: @host)
382
+
383
+ batch = Host.where(id: @host.id).in_batches.first
384
+ generator = create_generator(batch)
385
+
386
+ json_str = generator.render
387
+ actual = JSON.parse(json_str.join("\n"))
388
+
389
+ assert_equal 'slice_123', actual['report_slice_id']
390
+ assert_not_nil(actual_host = actual['hosts'].first)
391
+ assert_not_nil(actual_profile = actual_host['system_profile'])
392
+ assert_equal 'alibaba', actual_profile['cloud_provider']
393
+ end
394
+
395
+ private
396
+
397
+ def create_generator(batch, name = 'slice_123')
398
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], name)
399
+ if block_given?
400
+ yield(generator)
401
+ else
402
+ generator.stubs(:golden_ticket?).returns(false)
403
+ end
404
+ generator
405
+ end
220
406
  end
@@ -1,6 +1,6 @@
1
1
  import { noop } from 'patternfly-react';
2
2
 
3
- export const API_SUCCESS_RESPONSE = {
3
+ export const accounts = {
4
4
  Account1: {
5
5
  label: 'test_org1',
6
6
  upload_report_status: 'running',
@@ -18,7 +18,9 @@ export const API_SUCCESS_RESPONSE = {
18
18
  },
19
19
  };
20
20
 
21
- export const accounts = API_SUCCESS_RESPONSE;
21
+ export const accountIDs = Object.keys(accounts);
22
+
23
+ export const API_SUCCESS_RESPONSE = accounts;
22
24
 
23
25
  export const pollingProcessID = 0;
24
26
 
@@ -30,6 +32,8 @@ export const processStatusName = 'upload_report_status';
30
32
 
31
33
  export const autoUploadEnabled = true;
32
34
 
35
+ export const filterTerm = 'some_filter';
36
+
33
37
  export const props = {
34
38
  accounts,
35
39
  fetchAccountsStatus: noop,