foreman_rh_cloud 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +619 -0
  3. data/README.md +38 -0
  4. data/Rakefile +47 -0
  5. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +39 -0
  6. data/app/controllers/foreman_inventory_upload/react_controller.rb +7 -0
  7. data/app/controllers/foreman_inventory_upload/reports_controller.rb +30 -0
  8. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +31 -0
  9. data/app/helpers/foreman_inventory_upload_helper.rb +13 -0
  10. data/app/views/foreman_inventory_upload/layouts/react.html.erb +16 -0
  11. data/config/routes.rb +10 -0
  12. data/lib/foreman_inventory_upload.rb +51 -0
  13. data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +19 -0
  14. data/lib/foreman_inventory_upload/async/generate_report_job.rb +37 -0
  15. data/lib/foreman_inventory_upload/async/progress_output.rb +61 -0
  16. data/lib/foreman_inventory_upload/async/queue_for_upload_job.rb +47 -0
  17. data/lib/foreman_inventory_upload/async/shell_process.rb +36 -0
  18. data/lib/foreman_inventory_upload/async/upload_report_job.rb +58 -0
  19. data/lib/foreman_inventory_upload/generators/archived_report.rb +53 -0
  20. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +18 -0
  21. data/lib/foreman_inventory_upload/generators/json_stream.rb +55 -0
  22. data/lib/foreman_inventory_upload/generators/metadata.rb +36 -0
  23. data/lib/foreman_inventory_upload/generators/queries.rb +61 -0
  24. data/lib/foreman_inventory_upload/generators/slice.rb +147 -0
  25. data/lib/foreman_inventory_upload/scripts/uploader.sh.erb +44 -0
  26. data/lib/foreman_rh_cloud.rb +4 -0
  27. data/lib/foreman_rh_cloud/engine.rb +62 -0
  28. data/lib/foreman_rh_cloud/version.rb +3 -0
  29. data/lib/tasks/foreman_rh_cloud_tasks.rake +37 -0
  30. data/lib/tasks/generator.rake +29 -0
  31. data/locale/Makefile +60 -0
  32. data/locale/en/foreman_rh_cloud.po +19 -0
  33. data/locale/foreman_rh_cloud.pot +19 -0
  34. data/locale/gemspec.rb +2 -0
  35. data/package.json +125 -0
  36. data/test/controllers/accounts_controller_test.rb +25 -0
  37. data/test/controllers/reports_controller_test.rb +21 -0
  38. data/test/controllers/uploads_controller_test.rb +21 -0
  39. data/test/factories/inventory_upload_factories.rb +88 -0
  40. data/test/test_plugin_helper.rb +26 -0
  41. data/test/unit/archived_report_generator_test.rb +61 -0
  42. data/test/unit/metadata_generator_test.rb +40 -0
  43. data/test/unit/shell_process_job_test.rb +27 -0
  44. data/test/unit/slice_generator_test.rb +177 -0
  45. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +37 -0
  46. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.js +74 -0
  47. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.stories.js +18 -0
  48. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +65 -0
  49. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListConstants.js +9 -0
  50. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListHelper.js +0 -0
  51. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +55 -0
  52. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +8 -0
  53. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/EmptyState.fixtures.js +0 -0
  54. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/EmptyState.js +16 -0
  55. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/EmptyStateHelper.js +0 -0
  56. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/EmptyState.test.js +13 -0
  57. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/__snapshots__/EmptyState.test.js.snap +26 -0
  58. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/emptyState.scss +7 -0
  59. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/index.js +1 -0
  60. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/ErrorState.fixtures.js +0 -0
  61. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/ErrorState.js +23 -0
  62. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/ErrorStateHelper.js +0 -0
  63. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/__tests__/ErrorState.test.js +13 -0
  64. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/__tests__/__snapshots__/ErrorState.test.js.snap +20 -0
  65. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/errorState.scss +18 -0
  66. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/index.js +1 -0
  67. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItem.fixtures.js +1 -0
  68. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItem.js +41 -0
  69. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItemHelper.js +0 -0
  70. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/ListItem.test.js +13 -0
  71. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/__snapshots__/ListItem.test.js.snap +50 -0
  72. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/index.js +1 -0
  73. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/listItem.scss +0 -0
  74. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/ListItemStatus.fixtures.js +7 -0
  75. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/ListItemStatus.js +43 -0
  76. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/ListItemStatusHelper.js +29 -0
  77. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/ListItemStatus.test.js +14 -0
  78. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/__snapshots__/ListItemStatus.test.js.snap +78 -0
  79. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/index.js +1 -0
  80. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/listItemStatus.scss +16 -0
  81. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountList.test.js +13 -0
  82. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +20 -0
  83. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListIntegration.test.js +14 -0
  84. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +60 -0
  85. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +26 -0
  86. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountList.test.js.snap +44 -0
  87. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +47 -0
  88. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +69 -0
  89. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +46 -0
  90. data/webpack/ForemanInventoryUpload/Components/AccountList/accountList.scss +9 -0
  91. data/webpack/ForemanInventoryUpload/Components/AccountList/index.js +27 -0
  92. data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.fixtures.js +50 -0
  93. data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.js +145 -0
  94. data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.stories.js +19 -0
  95. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardActions.js +87 -0
  96. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardConstants.js +9 -0
  97. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardHelper.js +0 -0
  98. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardReducer.js +68 -0
  99. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardSelectors.js +17 -0
  100. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/Dashboard.test.js +25 -0
  101. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardActions.test.js +39 -0
  102. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardIntegration.test.js +16 -0
  103. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardReducer.test.js +64 -0
  104. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardSelectors.test.js +45 -0
  105. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/__snapshots__/Dashboard.test.js.snap +35 -0
  106. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/__snapshots__/DashboardActions.test.js.snap +76 -0
  107. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/__snapshots__/DashboardReducer.test.js.snap +44 -0
  108. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/__snapshots__/DashboardSelectors.test.js.snap +42 -0
  109. data/webpack/ForemanInventoryUpload/Components/Dashboard/dashboard.scss +0 -0
  110. data/webpack/ForemanInventoryUpload/Components/Dashboard/index.js +34 -0
  111. data/webpack/ForemanInventoryUpload/Components/FileDownload/FileDownload.fixtures.js +0 -0
  112. data/webpack/ForemanInventoryUpload/Components/FileDownload/FileDownload.js +22 -0
  113. data/webpack/ForemanInventoryUpload/Components/FileDownload/FileDownloadHelper.js +0 -0
  114. data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/FileDownload.test.js +13 -0
  115. data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/__snapshots__/FileDownload.test.js.snap +25 -0
  116. data/webpack/ForemanInventoryUpload/Components/FileDownload/fileDownload.scss +3 -0
  117. data/webpack/ForemanInventoryUpload/Components/FileDownload/index.js +1 -0
  118. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModal.fixtures.js +0 -0
  119. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModal.js +50 -0
  120. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModalHelper.js +0 -0
  121. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/FullScreenModal.test.js +13 -0
  122. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/__snapshots__/FullScreenModal.test.js.snap +64 -0
  123. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/fullScreenModal.scss +18 -0
  124. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/index.js +1 -0
  125. data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.fixtures.js +10 -0
  126. data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.js +83 -0
  127. data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainerHelper.js +0 -0
  128. data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/NavContainer.test.js +26 -0
  129. data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/__snapshots__/NavContainer.test.js.snap +89 -0
  130. data/webpack/ForemanInventoryUpload/Components/NavContainer/index.js +1 -0
  131. data/webpack/ForemanInventoryUpload/Components/NavContainer/navContainer.scss +7 -0
  132. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.fixtures.js +16 -0
  133. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.js +57 -0
  134. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerateHelper.js +0 -0
  135. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/__tests__/ReportGenerate.test.js +14 -0
  136. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/__tests__/__snapshots__/ReportGenerate.test.js.snap +45 -0
  137. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/index.js +1 -0
  138. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/reportGenerate.scss +0 -0
  139. data/webpack/ForemanInventoryUpload/Components/ReportUpload/ReportUpload.fixtures.js +18 -0
  140. data/webpack/ForemanInventoryUpload/Components/ReportUpload/ReportUpload.js +53 -0
  141. data/webpack/ForemanInventoryUpload/Components/ReportUpload/ReportUploadHelper.js +0 -0
  142. data/webpack/ForemanInventoryUpload/Components/ReportUpload/__tests__/ReportUpload.test.js +14 -0
  143. data/webpack/ForemanInventoryUpload/Components/ReportUpload/__tests__/__snapshots__/ReportUpload.test.js.snap +45 -0
  144. data/webpack/ForemanInventoryUpload/Components/ReportUpload/index.js +1 -0
  145. data/webpack/ForemanInventoryUpload/Components/ReportUpload/reportUpload.scss +0 -0
  146. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRun.fixtures.js +3 -0
  147. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRun.js +27 -0
  148. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRunHelper.js +0 -0
  149. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/ScheduledRun.test.js +14 -0
  150. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/__snapshots__/ScheduledRun.test.js.snap +25 -0
  151. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/index.js +1 -0
  152. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/scheduledRun.scss +11 -0
  153. data/webpack/ForemanInventoryUpload/Components/StatusChart/StatusChart.fixtures.js +0 -0
  154. data/webpack/ForemanInventoryUpload/Components/StatusChart/StatusChart.js +56 -0
  155. data/webpack/ForemanInventoryUpload/Components/StatusChart/StatusChartHelper.js +0 -0
  156. data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/StatusChart.test.js +13 -0
  157. data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/__snapshots__/StatusChart.test.js.snap +74 -0
  158. data/webpack/ForemanInventoryUpload/Components/StatusChart/index.js +1 -0
  159. data/webpack/ForemanInventoryUpload/Components/StatusChart/statusChart.scss +8 -0
  160. data/webpack/ForemanInventoryUpload/Components/TabBody/TabBody.fixtures.js +0 -0
  161. data/webpack/ForemanInventoryUpload/Components/TabBody/TabBody.js +31 -0
  162. data/webpack/ForemanInventoryUpload/Components/TabBody/TabBodyHelper.js +0 -0
  163. data/webpack/ForemanInventoryUpload/Components/TabBody/__tests__/TabBody.test.js +13 -0
  164. data/webpack/ForemanInventoryUpload/Components/TabBody/__tests__/__snapshots__/TabBody.test.js.snap +19 -0
  165. data/webpack/ForemanInventoryUpload/Components/TabBody/index.js +1 -0
  166. data/webpack/ForemanInventoryUpload/Components/TabBody/tabBody.scss +3 -0
  167. data/webpack/ForemanInventoryUpload/Components/TabContainer/TabContainer.fixtures.js +0 -0
  168. data/webpack/ForemanInventoryUpload/Components/TabContainer/TabContainer.js +24 -0
  169. data/webpack/ForemanInventoryUpload/Components/TabContainer/TabContainerHelper.js +0 -0
  170. data/webpack/ForemanInventoryUpload/Components/TabContainer/__tests__/TabContainer.test.js +13 -0
  171. data/webpack/ForemanInventoryUpload/Components/TabContainer/__tests__/__snapshots__/TabContainer.test.js.snap +18 -0
  172. data/webpack/ForemanInventoryUpload/Components/TabContainer/index.js +1 -0
  173. data/webpack/ForemanInventoryUpload/Components/TabContainer/tabContainer.scss +8 -0
  174. data/webpack/ForemanInventoryUpload/Components/TabFooter/TabFooter.fixtures.js +0 -0
  175. data/webpack/ForemanInventoryUpload/Components/TabFooter/TabFooter.js +19 -0
  176. data/webpack/ForemanInventoryUpload/Components/TabFooter/TabFooterHelper.js +0 -0
  177. data/webpack/ForemanInventoryUpload/Components/TabFooter/__tests__/TabFooter.test.js +13 -0
  178. data/webpack/ForemanInventoryUpload/Components/TabFooter/__tests__/__snapshots__/TabFooter.test.js.snap +12 -0
  179. data/webpack/ForemanInventoryUpload/Components/TabFooter/index.js +1 -0
  180. data/webpack/ForemanInventoryUpload/Components/TabFooter/tabFooter.scss +0 -0
  181. data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeader.fixtures.js +0 -0
  182. data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeader.js +47 -0
  183. data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeaderHelper.js +0 -0
  184. data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/TabHeader.test.js +13 -0
  185. data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/__snapshots__/TabHeader.test.js.snap +43 -0
  186. data/webpack/ForemanInventoryUpload/Components/TabHeader/index.js +1 -0
  187. data/webpack/ForemanInventoryUpload/Components/TabHeader/tabHeader.scss +21 -0
  188. data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.fixtures.js +10 -0
  189. data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +112 -0
  190. data/webpack/ForemanInventoryUpload/Components/Terminal/TerminalHelper.js +6 -0
  191. data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/Terminal.test.js +35 -0
  192. data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/__snapshots__/Terminal.test.js.snap +98 -0
  193. data/webpack/ForemanInventoryUpload/Components/Terminal/index.js +1 -0
  194. data/webpack/ForemanInventoryUpload/Components/Terminal/terminal.scss +31 -0
  195. data/webpack/ForemanInventoryUpload/ForemanInventoryUpload.js +15 -0
  196. data/webpack/ForemanInventoryUpload/ForemanInventoryUpload.test.js +10 -0
  197. data/webpack/ForemanInventoryUpload/ForemanInventoryUploadReducers.js +12 -0
  198. data/webpack/ForemanInventoryUpload/ForemanInventoryUploadSelectors.js +4 -0
  199. data/webpack/ForemanInventoryUpload/__snapshots__/ForemanInventoryUpload.test.js.snap +16 -0
  200. data/webpack/ForemanInventoryUpload/index.js +1 -0
  201. data/webpack/__mocks__/foremanReact/API.js +7 -0
  202. data/webpack/__mocks__/foremanReact/common/I18n.js +5 -0
  203. data/webpack/__mocks__/foremanReact/common/helpers.js +3 -0
  204. data/webpack/index.js +18 -0
  205. data/webpack/stories/ForemanInventoryUploadReducers.js +3 -0
  206. data/webpack/stories/configureStore.js +15 -0
  207. data/webpack/stories/decorators/index.js +1 -0
  208. data/webpack/stories/decorators/withCardsDecorator.js +14 -0
  209. data/webpack/stories/index.js +10 -0
  210. data/webpack/stories/index.scss +7 -0
  211. data/webpack/test_setup.js +6 -0
  212. metadata +318 -0
@@ -0,0 +1,21 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class ReportsControllerTest < ActionController::TestCase
4
+ tests ForemanInventoryUpload::ReportsController
5
+
6
+ test 'Returns latest report generation status' do
7
+ progress_output = mock('progress_output')
8
+ test_org = FactoryBot.create(:organization)
9
+ ForemanInventoryUpload::Async::ProgressOutput
10
+ .expects(:get)
11
+ .with(ForemanInventoryUpload::Async::GenerateReportJob.output_label(test_org.id))
12
+ .returns(progress_output)
13
+ progress_output.expects(:full_output).returns('test output')
14
+
15
+ get :last, params: { organization_id: test_org.id }, session: set_session_user
16
+
17
+ assert_response :success
18
+ actual = JSON.parse(response.body)
19
+ assert_equal 'test output', actual['output']
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class UploadsControllerTest < ActionController::TestCase
4
+ tests ForemanInventoryUpload::UploadsController
5
+
6
+ test 'Returns latest upload status' do
7
+ progress_output = mock('progress_output')
8
+ test_org = FactoryBot.create(:organization)
9
+ ForemanInventoryUpload::Async::ProgressOutput
10
+ .expects(:get)
11
+ .with(ForemanInventoryUpload::Async::UploadReportJob.output_label(test_org.id))
12
+ .returns(progress_output)
13
+ progress_output.expects(:full_output).returns('test output')
14
+
15
+ get :last, params: { organization_id: test_org.id }, session: set_session_user
16
+
17
+ assert_response :success
18
+ actual = JSON.parse(response.body)
19
+ assert_equal 'test output', actual['output']
20
+ end
21
+ end
@@ -0,0 +1,88 @@
1
+ # redefine katello factories, as long as katello is not compatible with dynamic properties
2
+ FactoryBot.define do
3
+ factory :katello_organization, :class => "Organization" do
4
+ type {"Organization"}
5
+ sequence(:name) { |n| "Organization#{n}" }
6
+ sequence(:label) { |n| "org#{n}" }
7
+ sequence(:id) { |n| n }
8
+
9
+ trait :acme_corporation do
10
+ name {"ACME_Corporation"}
11
+ type {"Organization"}
12
+ description {"This is the first Organization."}
13
+ label {"acme_corporation_label"}
14
+ end
15
+
16
+ trait :with_library do
17
+ association :library, :factory => :katello_library
18
+ end
19
+
20
+ factory :acme_corporation, :traits => [:acme_corporation]
21
+ end
22
+ end
23
+
24
+ FactoryBot.define do
25
+ factory :katello_content_view, :class => Katello::ContentView do
26
+ sequence(:name) { |n| "Database#{n}" }
27
+ description {"This content view is for database content"}
28
+ association :organization, :factory => :katello_organization
29
+
30
+ trait :composite do
31
+ composite {true}
32
+ end
33
+ end
34
+ end
35
+
36
+ FactoryBot.define do
37
+ factory :katello_k_t_environment, :aliases => [:katello_environment], :class => Katello::KTEnvironment do
38
+ sequence(:name) { |n| "Environment#{n}" }
39
+ sequence(:label) { |n| "environment#{n}" }
40
+ association :organization, :factory => :katello_organization
41
+ end
42
+ end
43
+
44
+ FactoryBot.define do
45
+ factory :katello_content_facets, :aliases => [:content_facet], :class => ::Katello::Host::ContentFacet do
46
+ sequence(:uuid) { |n| "uuid-#{n}" }
47
+ end
48
+ end
49
+
50
+ FactoryBot.define do
51
+ factory :katello_subscription_facets, :aliases => [:subscription_facet], :class => ::Katello::Host::SubscriptionFacet do
52
+ sequence(:uuid) { |n| "uuid-#{n}-#{rand(500)}" }
53
+ facts { {'memory.memtotal' => "12 GB"} }
54
+ end
55
+ end
56
+
57
+ FactoryBot.define do
58
+ factory :katello_pool, :class => Katello::Pool do
59
+ active {true}
60
+ end_date {Date.today + 1.year}
61
+ end
62
+ end
63
+
64
+ FactoryBot.modify do
65
+ factory :host do
66
+ transient do
67
+ content_view {nil}
68
+ lifecycle_environment {nil}
69
+ content_source {nil}
70
+ end
71
+
72
+ trait :with_content do
73
+ association :content_facet, :factory => :content_facet, :strategy => :build
74
+
75
+ after(:build) do |host, evaluator|
76
+ if host.content_facet
77
+ host.content_facet.content_view = evaluator.content_view if evaluator.content_view
78
+ host.content_facet.lifecycle_environment = evaluator.lifecycle_environment if evaluator.lifecycle_environment
79
+ host.content_facet.content_source = evaluator.content_source if evaluator.content_source
80
+ end
81
+ end
82
+ end
83
+
84
+ trait :with_subscription do
85
+ association :subscription_facet, :factory => :subscription_facet, :strategy => :build
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,26 @@
1
+ # This calls the main test_helper in Foreman-core
2
+ require 'test_helper'
3
+
4
+ # Add plugin to FactoryBot's paths
5
+ FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
6
+ # FactoryBot.definition_file_paths << "#{Katello::Engine.root}/test/factories"
7
+ FactoryBot.reload
8
+
9
+ module FolderIsolation
10
+ extend ActiveSupport::Concern
11
+
12
+ included do
13
+ setup do
14
+ @tmpdir = Dir.mktmpdir(self.class.name.underscore)
15
+
16
+ ForemanInventoryUpload.stubs(:base_folder).returns(@tmpdir)
17
+ ForemanInventoryUpload.instance_variable_set(:@outputs_folder, nil)
18
+ ForemanInventoryUpload.instance_variable_set(:@uploads_folders, nil)
19
+ end
20
+
21
+ teardown do
22
+ FileUtils.remove_entry @tmpdir
23
+ ForemanInventoryUpload.unstub(:base_folder)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,61 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class ArchivedReportGeneratorTest < 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.subscription_facet.pools << FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
20
+ end
21
+
22
+ def interesting_facts
23
+ [
24
+ 'dmi::system::uuid',
25
+ 'virt::uuid',
26
+ 'cpu::cpu(s)',
27
+ 'cpu::cpu_socket(s)',
28
+ 'cpu::core(s)_per_socket',
29
+ 'memory::memtotal',
30
+ 'dmi::bios::vendor',
31
+ 'dmi::bios::version',
32
+ 'dmi::bios::relase_date',
33
+ 'distribution::name',
34
+ 'uname::release',
35
+ 'lscpu::flags',
36
+ ]
37
+ end
38
+
39
+ def fact_names
40
+ @fact_names ||= Hash[
41
+ interesting_facts.map do |fact|
42
+ [fact, FactoryBot.create(:fact_name, name: fact, type: 'Katello::RhsmFactName')]
43
+ end
44
+ ]
45
+ end
46
+
47
+ test 'generates a report for a single host' do
48
+ batches = Host.where(id: @host.id).in_batches
49
+ test_org = FactoryBot.create(:organization)
50
+
51
+ ForemanInventoryUpload::Generators::Queries.expects(:for_org).with(test_org.id).returns(batches)
52
+ Dir.mktmpdir do |tmpdir|
53
+ target = File.join(tmpdir, 'test.tar.gz')
54
+ generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
55
+ generator.render(organization: test_org.id)
56
+
57
+ files = Dir["#{tmpdir}/*"]
58
+ assert_equal "#{tmpdir}/test.tar.gz", files.first
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,40 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class MetadataGeneratorTest < ActiveSupport::TestCase
4
+ setup do
5
+ end
6
+
7
+ test 'generates an empty report' do
8
+ generator = ForemanInventoryUpload::Generators::Metadata.new
9
+
10
+ json_str = generator.render do
11
+ end
12
+ actual = JSON.parse(json_str.join("\n"))
13
+
14
+ assert_not_nil actual['report_id']
15
+ assert_equal 'Satellite', actual['source']
16
+ assert_equal({}, actual['report_slices'])
17
+ end
18
+
19
+ test 'generates a report for a single slice' do
20
+ generator = ForemanInventoryUpload::Generators::Metadata.new
21
+
22
+ json_str = generator.render do |gen|
23
+ gen.add_slice('test_123', 1, true)
24
+ gen.add_slice('test_1234', 2, false)
25
+ gen.add_slice('test_12345', 3, false)
26
+ end
27
+
28
+ actual = JSON.parse(json_str.join("\n"))
29
+
30
+ assert_not_nil actual['report_id']
31
+ assert_equal 'Satellite', actual['source']
32
+ assert_not_nil(slices = actual['report_slices'])
33
+ assert_not_nil(slice = slices['test_123'])
34
+ assert_equal 1, slice['number_hosts']
35
+ assert_not_nil(slice = slices['test_1234'])
36
+ assert_equal 2, slice['number_hosts']
37
+ assert_not_nil(slice = slices['test_12345'])
38
+ assert_equal 3, slice['number_hosts']
39
+ end
40
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class ShellProcessJobTest < ActiveSupport::TestCase
4
+ class TestProcessJob < ForemanInventoryUpload::Async::ShellProcess
5
+ def command
6
+ 'echo testing env: $testenv'
7
+ end
8
+
9
+ def env
10
+ super.merge(
11
+ 'testenv' => 'test_val'
12
+ )
13
+ end
14
+ end
15
+
16
+ include FolderIsolation
17
+
18
+ test 'Runs a process with environment vars' do
19
+ label = Foreman.uuid
20
+ TestProcessJob.perform_now(label)
21
+
22
+ progress_output = ForemanInventoryUpload::Async::ProgressOutput.get(label)
23
+
24
+ assert_match(/test_val/, progress_output.full_output)
25
+ assert_match(/exit 0/, progress_output.status)
26
+ end
27
+ end
@@ -0,0 +1,177 @@
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.subscription_facet.pools << FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
20
+ end
21
+
22
+ def interesting_facts
23
+ [
24
+ 'dmi::system::uuid',
25
+ 'virt::uuid',
26
+ 'cpu::cpu(s)',
27
+ 'cpu::cpu_socket(s)',
28
+ 'cpu::core(s)_per_socket',
29
+ 'memory::memtotal',
30
+ 'dmi::bios::vendor',
31
+ 'dmi::bios::version',
32
+ 'dmi::bios::relase_date',
33
+ 'distribution::name',
34
+ 'uname::release',
35
+ 'lscpu::flags',
36
+ ]
37
+ end
38
+
39
+ def fact_names
40
+ @fact_names ||= Hash[
41
+ interesting_facts.map do |fact|
42
+ [fact, FactoryBot.create(:fact_name, name: fact, type: 'Katello::RhsmFactName')]
43
+ end
44
+ ]
45
+ end
46
+
47
+ test 'generates a report for a single host' do
48
+ batch = Host.where(id: @host.id).in_batches.first
49
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
50
+
51
+ json_str = generator.render
52
+ actual = JSON.parse(json_str.join("\n"))
53
+
54
+ assert_equal 'slice_123', actual['report_slice_id']
55
+ assert_not_nil(actual_host = actual['hosts'].first)
56
+ assert_equal @host.name, actual_host['display_name']
57
+ assert_equal @host.fqdn, actual_host['fqdn']
58
+ assert_equal '1234', actual_host['account']
59
+ end
60
+
61
+ test 'generates a report with satellite facts' do
62
+ Foreman.expects(:instance_id).twice.returns('satellite-id')
63
+ batch = Host.where(id: @host.id).in_batches.first
64
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice-123')
65
+
66
+ json_str = generator.render
67
+ actual = JSON.parse(json_str.join("\n"))
68
+
69
+ facts = actual['hosts'].first['facts'].first
70
+ assert_equal 'satellite', facts['namespace']
71
+ satellite_facts = facts['facts']
72
+ assert_equal 'satellite-id', satellite_facts['satellite_instance_id']
73
+ assert_equal @host.organization_id, satellite_facts['organization_id']
74
+
75
+ instance_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'satellite_instance_id'}
76
+ assert_not_nil instance_id_tag
77
+ assert_equal 'satellite-id', instance_id_tag['value']
78
+
79
+ org_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'organization_id'}
80
+ assert_not_nil org_id_tag
81
+ assert_equal @host.organization_id, org_id_tag['value']
82
+
83
+ version = satellite_facts['satellite_version']
84
+ if defined?(ForemanThemeSatellite)
85
+ assert_equal ForemanThemeSatellite::SATELLITE_VERSION, version
86
+ else
87
+ assert_nil version
88
+ end
89
+ end
90
+
91
+ test 'generates a report for a host with hypervisor' do
92
+ hypervisor_host = FactoryBot.create(
93
+ :host,
94
+ :with_subscription,
95
+ :with_content,
96
+ content_view: @host.content_view,
97
+ lifecycle_environment: @host.lifecycle_environment,
98
+ organization: @host.organization
99
+ )
100
+
101
+ @host.subscription_facet.hypervisor_host = hypervisor_host
102
+ @host.save!
103
+
104
+ batch = Host.where(id: @host.id).in_batches.first
105
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
106
+
107
+ json_str = generator.render
108
+ actual = JSON.parse(json_str.join("\n"))
109
+
110
+ assert_equal 'slice_123', actual['report_slice_id']
111
+ assert_not_nil(actual_host = actual['hosts'].first)
112
+ assert_equal @host.name, actual_host['display_name']
113
+ assert_equal @host.fqdn, actual_host['fqdn']
114
+ assert_not_nil(host_facts = actual_host['facts']&.first)
115
+ assert_equal 'satellite', host_facts['namespace']
116
+ assert_not_nil(fact_values = host_facts['facts'])
117
+ assert_equal hypervisor_host.name, fact_values['virtual_host_name']
118
+ assert_equal hypervisor_host.subscription_facet.uuid, fact_values['virtual_host_uuid']
119
+ end
120
+
121
+ test 'generates a report with system purpose' do
122
+ @host.subscription_facet.purpose_usage = 'test_usage'
123
+ @host.subscription_facet.purpose_role = 'test_role'
124
+ @host.subscription_facet.save!
125
+
126
+ batch = Host.where(id: @host.id).in_batches.first
127
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
128
+
129
+ json_str = generator.render
130
+ actual = JSON.parse(json_str.join("\n"))
131
+
132
+ assert_equal 'slice_123', actual['report_slice_id']
133
+ assert_not_nil(actual_host = actual['hosts'].first)
134
+ assert_equal @host.name, actual_host['display_name']
135
+ assert_equal @host.fqdn, actual_host['fqdn']
136
+ assert_not_nil(host_facts = actual_host['facts']&.first)
137
+ assert_equal 'satellite', host_facts['namespace']
138
+ assert_not_nil(fact_values = host_facts['facts'])
139
+ assert_equal 'test_usage', fact_values['system_purpose_usage']
140
+ assert_equal 'test_role', fact_values['system_purpose_role']
141
+ end
142
+
143
+ test 'skips hosts without subscription' do
144
+ a_host = FactoryBot.create(
145
+ :host,
146
+ organization: @host.organization
147
+ )
148
+
149
+ # make a_host last
150
+ batch = Host.where(id: [@host.id, a_host.id]).order(:name).in_batches.first
151
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
152
+
153
+ json_str = generator.render
154
+ actual = JSON.parse(json_str.join("\n"))
155
+
156
+ assert_equal 'slice_123', actual['report_slice_id']
157
+ assert_not_nil(actual_host = actual['hosts'].first)
158
+ assert_equal @host.name, actual_host['display_name']
159
+ assert_equal @host.fqdn, actual_host['fqdn']
160
+ assert_equal '1234', actual_host['account']
161
+ end
162
+
163
+ test 'shows system_memory_bytes in bytes' do
164
+ FactoryBot.create(:fact_value, fact_name: fact_names['memory::memtotal'], value: '1', host: @host)
165
+
166
+ batch = Host.where(id: @host.id).in_batches.first
167
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
168
+
169
+ json_str = generator.render
170
+ actual = JSON.parse(json_str.join("\n"))
171
+
172
+ assert_equal 'slice_123', actual['report_slice_id']
173
+ assert_not_nil(actual_host = actual['hosts'].first)
174
+ assert_not_nil(actual_profile = actual_host['system_profile'])
175
+ assert_equal 1024, actual_profile['system_memory_bytes']
176
+ end
177
+ end