foreman_inventory_upload 0.0.1.dev1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +1 -1
  3. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +39 -0
  4. data/app/controllers/foreman_inventory_upload/reports_controller.rb +13 -6
  5. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +4 -4
  6. data/app/helpers/foreman_inventory_upload_helper.rb +1 -1
  7. data/app/views/scripts/uploader.sh.erb +21 -10
  8. data/config/routes.rb +5 -5
  9. data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +19 -0
  10. data/lib/foreman_inventory_upload/async/generate_report_job.rb +13 -9
  11. data/lib/foreman_inventory_upload/async/progress_output.rb +1 -1
  12. data/lib/foreman_inventory_upload/async/queue_for_upload_job.rb +12 -17
  13. data/lib/foreman_inventory_upload/async/shell_process.rb +2 -1
  14. data/lib/foreman_inventory_upload/async/upload_report_job.rb +22 -17
  15. data/lib/foreman_inventory_upload/engine.rb +11 -1
  16. data/lib/foreman_inventory_upload/generators/archived_report.rb +2 -2
  17. data/lib/foreman_inventory_upload/generators/queries.rb +20 -11
  18. data/lib/foreman_inventory_upload/generators/slice.rb +26 -5
  19. data/lib/foreman_inventory_upload/version.rb +1 -1
  20. data/lib/foreman_inventory_upload.rb +15 -10
  21. data/lib/tasks/generator.rake +19 -5
  22. data/package.json +125 -0
  23. data/test/controllers/{statuses_controller_test.rb → accounts_controller_test.rb} +6 -7
  24. data/test/controllers/reports_controller_test.rb +3 -3
  25. data/test/controllers/uploads_controller_test.rb +3 -3
  26. data/test/unit/archived_report_generator_test.rb +4 -4
  27. data/test/unit/slice_generator_test.rb +75 -1
  28. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +37 -0
  29. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.js +74 -0
  30. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.stories.js +18 -0
  31. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +65 -0
  32. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListConstants.js +9 -0
  33. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListHelper.js +0 -0
  34. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +55 -0
  35. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +8 -0
  36. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/EmptyState.fixtures.js +0 -0
  37. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/EmptyState.js +16 -0
  38. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/EmptyStateHelper.js +0 -0
  39. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/EmptyState.test.js +13 -0
  40. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/__snapshots__/EmptyState.test.js.snap +26 -0
  41. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/emptyState.scss +7 -0
  42. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/index.js +1 -0
  43. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/ErrorState.fixtures.js +0 -0
  44. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/ErrorState.js +23 -0
  45. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/ErrorStateHelper.js +0 -0
  46. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/__tests__/ErrorState.test.js +13 -0
  47. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/__tests__/__snapshots__/ErrorState.test.js.snap +20 -0
  48. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/errorState.scss +18 -0
  49. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/index.js +1 -0
  50. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItem.fixtures.js +1 -0
  51. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItem.js +41 -0
  52. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItemHelper.js +0 -0
  53. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/ListItem.test.js +13 -0
  54. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/__snapshots__/ListItem.test.js.snap +50 -0
  55. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/index.js +1 -0
  56. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/listItem.scss +0 -0
  57. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/ListItemStatus.fixtures.js +7 -0
  58. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/ListItemStatus.js +43 -0
  59. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/ListItemStatusHelper.js +29 -0
  60. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/ListItemStatus.test.js +14 -0
  61. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/__snapshots__/ListItemStatus.test.js.snap +78 -0
  62. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/index.js +1 -0
  63. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/listItemStatus.scss +16 -0
  64. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountList.test.js +13 -0
  65. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +20 -0
  66. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListIntegration.test.js +14 -0
  67. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +60 -0
  68. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +26 -0
  69. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountList.test.js.snap +44 -0
  70. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +47 -0
  71. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +69 -0
  72. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +46 -0
  73. data/webpack/ForemanInventoryUpload/Components/AccountList/accountList.scss +9 -0
  74. data/webpack/ForemanInventoryUpload/Components/AccountList/index.js +27 -0
  75. data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.fixtures.js +50 -0
  76. data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.js +146 -0
  77. data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.stories.js +19 -0
  78. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardActions.js +87 -0
  79. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardConstants.js +9 -0
  80. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardHelper.js +0 -0
  81. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardReducer.js +68 -0
  82. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardSelectors.js +17 -0
  83. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/Dashboard.test.js +25 -0
  84. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardActions.test.js +39 -0
  85. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardIntegration.test.js +16 -0
  86. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardReducer.test.js +64 -0
  87. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardSelectors.test.js +45 -0
  88. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/__snapshots__/Dashboard.test.js.snap +36 -0
  89. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/__snapshots__/DashboardActions.test.js.snap +76 -0
  90. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/__snapshots__/DashboardReducer.test.js.snap +44 -0
  91. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/__snapshots__/DashboardSelectors.test.js.snap +42 -0
  92. data/webpack/ForemanInventoryUpload/Components/Dashboard/dashboard.scss +0 -0
  93. data/webpack/ForemanInventoryUpload/Components/Dashboard/index.js +34 -0
  94. data/webpack/ForemanInventoryUpload/Components/FileDownload/FileDownload.fixtures.js +0 -0
  95. data/webpack/ForemanInventoryUpload/Components/FileDownload/FileDownload.js +22 -0
  96. data/webpack/ForemanInventoryUpload/Components/FileDownload/FileDownloadHelper.js +0 -0
  97. data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/FileDownload.test.js +13 -0
  98. data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/__snapshots__/FileDownload.test.js.snap +25 -0
  99. data/webpack/ForemanInventoryUpload/Components/FileDownload/fileDownload.scss +3 -0
  100. data/webpack/ForemanInventoryUpload/Components/FileDownload/index.js +1 -0
  101. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModal.fixtures.js +0 -0
  102. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModal.js +50 -0
  103. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModalHelper.js +0 -0
  104. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/FullScreenModal.test.js +13 -0
  105. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/__snapshots__/FullScreenModal.test.js.snap +64 -0
  106. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/fullScreenModal.scss +10 -0
  107. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/index.js +1 -0
  108. data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.fixtures.js +10 -0
  109. data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.js +83 -0
  110. data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainerHelper.js +0 -0
  111. data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/NavContainer.test.js +26 -0
  112. data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/__snapshots__/NavContainer.test.js.snap +89 -0
  113. data/webpack/ForemanInventoryUpload/Components/NavContainer/index.js +1 -0
  114. data/webpack/ForemanInventoryUpload/Components/NavContainer/navContainer.scss +7 -0
  115. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.fixtures.js +16 -0
  116. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.js +57 -0
  117. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerateHelper.js +0 -0
  118. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/__tests__/ReportGenerate.test.js +14 -0
  119. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/__tests__/__snapshots__/ReportGenerate.test.js.snap +45 -0
  120. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/index.js +1 -0
  121. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/reportGenerate.scss +0 -0
  122. data/webpack/ForemanInventoryUpload/Components/ReportUpload/ReportUpload.fixtures.js +18 -0
  123. data/webpack/ForemanInventoryUpload/Components/ReportUpload/ReportUpload.js +57 -0
  124. data/webpack/ForemanInventoryUpload/Components/ReportUpload/ReportUploadHelper.js +0 -0
  125. data/webpack/ForemanInventoryUpload/Components/ReportUpload/__tests__/ReportUpload.test.js +14 -0
  126. data/webpack/ForemanInventoryUpload/Components/ReportUpload/__tests__/__snapshots__/ReportUpload.test.js.snap +45 -0
  127. data/webpack/ForemanInventoryUpload/Components/ReportUpload/index.js +1 -0
  128. data/webpack/ForemanInventoryUpload/Components/ReportUpload/reportUpload.scss +0 -0
  129. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRun.fixtures.js +3 -0
  130. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRun.js +27 -0
  131. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRunHelper.js +0 -0
  132. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/ScheduledRun.test.js +14 -0
  133. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/__snapshots__/ScheduledRun.test.js.snap +25 -0
  134. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/index.js +1 -0
  135. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/scheduledRun.scss +11 -0
  136. data/webpack/ForemanInventoryUpload/Components/StatusChart/StatusChart.fixtures.js +0 -0
  137. data/webpack/ForemanInventoryUpload/Components/StatusChart/StatusChart.js +56 -0
  138. data/webpack/ForemanInventoryUpload/Components/StatusChart/StatusChartHelper.js +0 -0
  139. data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/StatusChart.test.js +13 -0
  140. data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/__snapshots__/StatusChart.test.js.snap +74 -0
  141. data/webpack/ForemanInventoryUpload/Components/StatusChart/index.js +1 -0
  142. data/webpack/ForemanInventoryUpload/Components/StatusChart/statusChart.scss +8 -0
  143. data/webpack/ForemanInventoryUpload/Components/TabBody/TabBody.fixtures.js +0 -0
  144. data/webpack/ForemanInventoryUpload/Components/TabBody/TabBody.js +31 -0
  145. data/webpack/ForemanInventoryUpload/Components/TabBody/TabBodyHelper.js +0 -0
  146. data/webpack/ForemanInventoryUpload/Components/TabBody/__tests__/TabBody.test.js +13 -0
  147. data/webpack/ForemanInventoryUpload/Components/TabBody/__tests__/__snapshots__/TabBody.test.js.snap +19 -0
  148. data/webpack/ForemanInventoryUpload/Components/TabBody/index.js +1 -0
  149. data/webpack/ForemanInventoryUpload/Components/TabBody/tabBody.scss +3 -0
  150. data/webpack/ForemanInventoryUpload/Components/TabContainer/TabContainer.fixtures.js +0 -0
  151. data/webpack/ForemanInventoryUpload/Components/TabContainer/TabContainer.js +24 -0
  152. data/webpack/ForemanInventoryUpload/Components/TabContainer/TabContainerHelper.js +0 -0
  153. data/webpack/ForemanInventoryUpload/Components/TabContainer/__tests__/TabContainer.test.js +13 -0
  154. data/webpack/ForemanInventoryUpload/Components/TabContainer/__tests__/__snapshots__/TabContainer.test.js.snap +18 -0
  155. data/webpack/ForemanInventoryUpload/Components/TabContainer/index.js +1 -0
  156. data/webpack/ForemanInventoryUpload/Components/TabContainer/tabContainer.scss +8 -0
  157. data/webpack/ForemanInventoryUpload/Components/TabFooter/TabFooter.fixtures.js +0 -0
  158. data/webpack/ForemanInventoryUpload/Components/TabFooter/TabFooter.js +19 -0
  159. data/webpack/ForemanInventoryUpload/Components/TabFooter/TabFooterHelper.js +0 -0
  160. data/webpack/ForemanInventoryUpload/Components/TabFooter/__tests__/TabFooter.test.js +13 -0
  161. data/webpack/ForemanInventoryUpload/Components/TabFooter/__tests__/__snapshots__/TabFooter.test.js.snap +12 -0
  162. data/webpack/ForemanInventoryUpload/Components/TabFooter/index.js +1 -0
  163. data/webpack/ForemanInventoryUpload/Components/TabFooter/tabFooter.scss +0 -0
  164. data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeader.fixtures.js +0 -0
  165. data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeader.js +45 -0
  166. data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeaderHelper.js +0 -0
  167. data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/TabHeader.test.js +13 -0
  168. data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/__snapshots__/TabHeader.test.js.snap +53 -0
  169. data/webpack/ForemanInventoryUpload/Components/TabHeader/index.js +1 -0
  170. data/webpack/ForemanInventoryUpload/Components/TabHeader/tabHeader.scss +21 -0
  171. data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.fixtures.js +10 -0
  172. data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +112 -0
  173. data/webpack/ForemanInventoryUpload/Components/Terminal/TerminalHelper.js +6 -0
  174. data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/Terminal.test.js +35 -0
  175. data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/__snapshots__/Terminal.test.js.snap +98 -0
  176. data/webpack/ForemanInventoryUpload/Components/Terminal/index.js +1 -0
  177. data/webpack/ForemanInventoryUpload/Components/Terminal/terminal.scss +31 -0
  178. data/webpack/ForemanInventoryUpload/ForemanInventoryUpload.js +15 -0
  179. data/webpack/ForemanInventoryUpload/ForemanInventoryUpload.test.js +10 -0
  180. data/webpack/ForemanInventoryUpload/ForemanInventoryUploadReducers.js +12 -0
  181. data/webpack/ForemanInventoryUpload/ForemanInventoryUploadSelectors.js +4 -0
  182. data/webpack/ForemanInventoryUpload/__snapshots__/ForemanInventoryUpload.test.js.snap +16 -0
  183. data/webpack/ForemanInventoryUpload/index.js +1 -0
  184. data/webpack/__mocks__/foremanReact/API.js +7 -0
  185. data/webpack/__mocks__/foremanReact/common/I18n.js +5 -0
  186. data/webpack/__mocks__/foremanReact/common/helpers.js +3 -0
  187. data/webpack/index.js +18 -0
  188. data/webpack/stories/ForemanInventoryUploadReducers.js +3 -0
  189. data/webpack/stories/configureStore.js +15 -0
  190. data/webpack/stories/decorators/index.js +1 -0
  191. data/webpack/stories/decorators/withCardsDecorator.js +14 -0
  192. data/webpack/stories/index.js +10 -0
  193. data/webpack/stories/index.scss +7 -0
  194. data/webpack/test_setup.js +6 -0
  195. metadata +205 -9
  196. data/app/controllers/foreman_inventory_upload/statuses_controller.rb +0 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 42f516b5764fdf3d298592d73e3349a3aac827bb
4
- data.tar.gz: 68d8d1d23a8a455b4c7659ea4b4c18e082dd83e0
2
+ SHA256:
3
+ metadata.gz: a633e9716013237bbbcce5cba1748fad264cea4b4b965e5f19bb0f0be8d41e4e
4
+ data.tar.gz: 58de7c1e9666e4373fb44db980bacfb4392131bfddbd31a86123de34b1d456bd
5
5
  SHA512:
6
- metadata.gz: 63f68d4d635e776d3414f450f4a7174f9163c4160c20bb50eceb1bd09b6311bc415b5e66e4d31756f38eb2da89554428ff7ab81561274e322871d70f2a41dcaa
7
- data.tar.gz: 3df2740f66a0d01532d029c8ed1be571678504e8ab3e17e31a1992df01b1915191a5b1dc7788ac275a0e96ed17cac4b8fdd88caf723f06add20e747d90ee17e6
6
+ metadata.gz: 033077e27db0e59ec53895ab8038ff4da2c1cf8e223ebe7296dce00d7961e3d79edf5ac807b438e2eb0c71afb42a93bf9923d6aa1ce647a3df7323190c4dcf3d
7
+ data.tar.gz: ca759475503697dfe741a92b11d9beb8f8520056cb19aea59745d350103c56dded3f6641087b77448652bdfe06ead35c6916d6d356447bb8da31271699849eca
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
22
 
23
- APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
23
+ APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
24
24
 
25
25
  Bundler::GemHelper.install_tasks
26
26
 
@@ -0,0 +1,39 @@
1
+ module ForemanInventoryUpload
2
+ class AccountsController < ::ApplicationController
3
+ # override default "welcome screen behavior, since we don't have a model"
4
+ def welcome
5
+ true
6
+ end
7
+
8
+ def index
9
+ labels = Organization.all.pluck(:id, :name)
10
+
11
+ accounts = Hash[
12
+ labels.map do |id, label|
13
+ generate_report_status = status_for(id, ForemanInventoryUpload::Async::GenerateReportJob)
14
+ upload_report_status = status_for(id, ForemanInventoryUpload::Async::UploadReportJob)
15
+
16
+ [
17
+ id,
18
+ {
19
+ generate_report_status: generate_report_status,
20
+ upload_report_status: upload_report_status,
21
+ label: label,
22
+ },
23
+ ]
24
+ end
25
+ ]
26
+
27
+ render json: {
28
+ accounts: accounts,
29
+ }, status: :ok
30
+ end
31
+
32
+ private
33
+
34
+ def status_for(label, job_class)
35
+ label = job_class.output_label(label)
36
+ ForemanInventoryUpload::Async::ProgressOutput.get(label)&.status
37
+ end
38
+ end
39
+ end
@@ -1,22 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanInventoryUpload
2
4
  class ReportsController < ::ApplicationController
3
5
  def last
4
- label = ForemanInventoryUpload::Async::GenerateReportJob.output_label(params[:portal_user])
6
+ label = ForemanInventoryUpload::Async::GenerateReportJob.output_label(params[:organization_id])
5
7
  output = ForemanInventoryUpload::Async::ProgressOutput.get(label)&.full_output
8
+ task_label = ForemanInventoryUpload::Async::GenerateAllReportsJob.singleton_job_name
9
+ scheduled = ForemanTasks::Task.where(
10
+ :label => task_label,
11
+ :state => 'scheduled'
12
+ ).first&.start_at || nil
6
13
 
7
14
  render json: {
8
- output: output
15
+ output: output,
16
+ scheduled: scheduled,
9
17
  }, status: :ok
10
18
  end
11
19
 
12
20
  def generate
13
- portal_user = params[:portal_user]
21
+ organization_id = params[:organization_id]
14
22
 
15
- generated_file_name = File.join(ForemanInventoryUpload.base_folder, "#{portal_user}.tar.gz")
16
- ForemanInventoryUpload::Async::GenerateReportJob.perform_later(generated_file_name, portal_user)
23
+ ForemanInventoryUpload::Async::GenerateReportJob.perform_later(ForemanInventoryUpload.generated_reports_folder, organization_id)
17
24
 
18
25
  render json: {
19
- action_status: 'success'
26
+ action_status: 'success',
20
27
  }, status: :ok
21
28
  end
22
29
  end
@@ -1,17 +1,17 @@
1
1
  module ForemanInventoryUpload
2
2
  class UploadsController < ::ApplicationController
3
3
  def last
4
- label = ForemanInventoryUpload::Async::UploadReportJob.output_label(params[:portal_user])
4
+ label = ForemanInventoryUpload::Async::UploadReportJob.output_label(params[:organization_id])
5
5
  output = ForemanInventoryUpload::Async::ProgressOutput.get(label)&.full_output
6
6
 
7
7
  render json: {
8
- output: output
8
+ output: output,
9
9
  }, status: :ok
10
10
  end
11
11
 
12
12
  def download_file
13
- filename = 'hosts_report.tar.gz'
14
- path = Rails.root.join(ForemanInventoryUpload.uploads_folder(params[:portal_user]), filename)
13
+ filename = ForemanInventoryUpload.facts_archive_name(params[:organization_id])
14
+ path = Rails.root.join(ForemanInventoryUpload.uploads_folder, filename)
15
15
  unless File.exist? path
16
16
  return throw_flash_error(
17
17
  "Path doesn't exist: #{path}"
@@ -10,4 +10,4 @@ module ForemanInventoryUploadHelper
10
10
  end
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -1,28 +1,39 @@
1
1
  #! /bin/sh
2
2
 
3
3
  DEST=<%= @upload_url %>
4
- RH_USERNAME=<%= @rh_username %>
5
4
 
6
- if [ -z "$RH_USERNAME" ]
5
+ if [ -z "$FILES" ]
7
6
  then
8
- IFS= read -rp "Enter username: " RH_USERNAME
7
+ FILES=./*.tar.gz
9
8
  fi
10
9
 
11
- if [ -z "$RH_PASSWORD" ]
10
+ if [ -n "$CER_PATH" ]
12
11
  then
13
- IFS= read -rsp "Enter password: " RH_PASSWORD
14
- fi
12
+ AUTH_KEY="--cert"
13
+ AUTH_VAL="$CER_PATH"
14
+ else
15
+ if [ -z "$RH_USERNAME" ]
16
+ then
17
+ IFS= read -rp "Enter username: " RH_USERNAME
18
+ fi
15
19
 
16
- if [ -z "$FILES" ]
17
- then
18
- FILES=./*.tar.gz
20
+ if [ -z "$RH_PASSWORD" ]
21
+ then
22
+ IFS= read -rsp "Enter password: " RH_PASSWORD
23
+ fi
24
+
25
+ AUTH_KEY="-u"
26
+ AUTH_VAL="\"$RH_USERNAME\":\"$RH_PASSWORD\""
19
27
  fi
20
28
 
29
+ # /tmp/a b/x.pem
30
+ # curl --cert /tmp/a\ b/x.pem
31
+
21
32
  mkdir -p done
22
33
 
23
34
  for f in $FILES
24
35
  do
25
- curl -k -vvv -# --fail -F "file=@$f;type=application/vnd.redhat.qpc.tar+tgz" $DEST -u "$RH_USERNAME":"$RH_PASSWORD"
36
+ curl -k -vvv -# --fail -F "file=@$f;type=application/vnd.redhat.qpc.tar+tgz" $DEST "$AUTH_KEY" "$AUTH_VAL"
26
37
  if [ $? -eq 0 ]; then
27
38
  mv $f done/
28
39
  echo "Done: $f"
data/config/routes.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  Rails.application.routes.draw do
2
2
  namespace :foreman_inventory_upload do
3
3
  get 'index', to: 'react#index'
4
- get ':portal_user/reports/last', to: 'reports#last', constraints: { portal_user: %r{[^\/]+} }
5
- post ':portal_user/reports', to: 'reports#generate', constraints: { portal_user: %r{[^\/]+} }
6
- get ':portal_user/uploads/last', to: 'uploads#last', constraints: { portal_user: %r{[^\/]+} }
7
- get ':portal_user/uploads/file', to: 'uploads#download_file', constraints: { portal_user: %r{[^\/]+} }
8
- get 'statuses', to: 'statuses#index'
4
+ get ':organization_id/reports/last', to: 'reports#last', constraints: { organization_id: %r{[^\/]+} }
5
+ post ':organization_id/reports', to: 'reports#generate', constraints: { organization_id: %r{[^\/]+} }
6
+ get ':organization_id/uploads/last', to: 'uploads#last', constraints: { organization_id: %r{[^\/]+} }
7
+ get ':organization_id/uploads/file', to: 'uploads#download_file', constraints: { organization_id: %r{[^\/]+} }
8
+ get 'accounts', to: 'accounts#index'
9
9
  end
10
10
  end
@@ -0,0 +1,19 @@
1
+ module ForemanInventoryUpload
2
+ module Async
3
+ class GenerateAllReportsJob < ::ApplicationJob
4
+ def perform
5
+ organizations = Organization.unscoped.all
6
+
7
+ organizations.map do |organization|
8
+ GenerateReportJob.perform_later(ForemanInventoryUpload.generated_reports_folder, organization.id)
9
+ end
10
+ ensure
11
+ self.class.set(:wait => 24.hours).perform_later
12
+ end
13
+
14
+ def self.singleton_job_name
15
+ name
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,17 +1,21 @@
1
1
  module ForemanInventoryUpload
2
2
  module Async
3
3
  class GenerateReportJob < ShellProcess
4
- def self.output_label(portal_user)
5
- "report_for_#{portal_user}"
4
+ def self.output_label(label)
5
+ "report_for_#{label}"
6
6
  end
7
7
 
8
- def perform(result_file, portal_user)
9
- @result_file = result_file
10
- @portal_user = portal_user
8
+ def perform(base_folder, organization)
9
+ @base_folder = base_folder
10
+ @organization = organization
11
11
 
12
- super(GenerateReportJob.output_label(portal_user))
12
+ super(GenerateReportJob.output_label(organization))
13
13
 
14
- QueueForUploadJob.perform_later(result_file, portal_user)
14
+ QueueForUploadJob.perform_later(
15
+ base_folder,
16
+ ForemanInventoryUpload.facts_archive_name(organization),
17
+ organization
18
+ )
15
19
  end
16
20
 
17
21
  def command
@@ -20,8 +24,8 @@ module ForemanInventoryUpload
20
24
 
21
25
  def env
22
26
  super.merge(
23
- 'target' => @result_file,
24
- 'portal_user' => @portal_user
27
+ 'target' => @base_folder,
28
+ 'organization_id' => @organization
25
29
  )
26
30
  end
27
31
  end
@@ -50,7 +50,7 @@ module ForemanInventoryUpload
50
50
  private
51
51
 
52
52
  def file_mode
53
- @mode == :reader ? 'r' : 'w'
53
+ (@mode == :reader) ? 'r' : 'w'
54
54
  end
55
55
 
56
56
  def file_name(type = 'out')
@@ -1,21 +1,22 @@
1
1
  module ForemanInventoryUpload
2
2
  module Async
3
3
  class QueueForUploadJob < ::ApplicationJob
4
- def perform(report_file, portal_user)
5
- @portal_user = portal_user
4
+ def perform(base_folder, report_file, organization_id)
5
+ @base_folder = base_folder
6
+ @report_file = report_file
6
7
  logger.debug('Ensuring objects')
7
8
  ensure_ouput_folder
8
9
  ensure_output_script
9
10
  logger.debug("Copying #{report_file} to #{uploads_folder}")
10
- enqueued_file_name = File.join(uploads_folder, ForemanInventoryUpload.facts_archive_name)
11
- FileUtils.mv(report_file, enqueued_file_name)
11
+ enqueued_file_name = File.join(uploads_folder, report_file)
12
+ FileUtils.mv(File.join(base_folder, report_file), enqueued_file_name)
12
13
  logger.debug("Done copying #{report_file} to #{enqueued_file_name}")
13
14
 
14
- UploadReportJob.perform_later(enqueued_file_name, portal_user)
15
+ UploadReportJob.perform_later(enqueued_file_name, organization_id)
15
16
  end
16
17
 
17
18
  def uploads_folder
18
- @uploads_folder ||= ForemanInventoryUpload.uploads_folder(@portal_user)
19
+ @uploads_folder ||= ForemanInventoryUpload.uploads_folder
19
20
  end
20
21
 
21
22
  def script_file
@@ -29,17 +30,11 @@ module ForemanInventoryUpload
29
30
  def ensure_output_script
30
31
  return if File.exist?(script_file)
31
32
 
32
- script_source = File.join(ForemanInventoryUpload::Engine.root, 'app/views/scripts/uploader.sh.erb')
33
-
34
- template_src = Foreman::Renderer::Source::String.new(content: File.read(script_source))
35
- scope = Foreman::Renderer::Scope::Base.new(
36
- source: template_src,
37
- variables: {
38
- upload_url: ForemanInventoryUpload.upload_url,
39
- rh_username: @portal_user
40
- }
41
- )
42
- script_source = Foreman::Renderer.render(template_src, scope)
33
+ script_source_file = File.join(ForemanInventoryUpload::Engine.root, 'app/views/scripts/uploader.sh.erb')
34
+
35
+ script_source = File.read(script_source_file)
36
+ script_source.gsub!('<%= @upload_url %>', ForemanInventoryUpload.upload_url)
37
+
43
38
  File.write(script_file, script_source)
44
39
  FileUtils.chmod('+x', script_file)
45
40
  end
@@ -21,7 +21,8 @@ module ForemanInventoryUpload
21
21
  progress_output.close
22
22
  end
23
23
 
24
- def command; end
24
+ def command
25
+ end
25
26
 
26
27
  def env
27
28
  {}
@@ -1,15 +1,23 @@
1
+ require 'tempfile'
2
+
1
3
  module ForemanInventoryUpload
2
4
  module Async
3
5
  class UploadReportJob < ShellProcess
4
- def self.output_label(portal_user)
5
- "upload_for_#{portal_user}"
6
+ def self.output_label(label)
7
+ "upload_for_#{label}"
6
8
  end
7
9
 
8
- def perform(filename, portal_user)
9
- @portal_user = portal_user
10
+ def perform(filename, organization_id)
10
11
  @filename = filename
12
+ @organization = Organization.find(organization_id)
11
13
 
12
- super(UploadReportJob.output_label(portal_user))
14
+ Tempfile.create([@organization.name, '.pem']) do |cer_file|
15
+ cer_file.write(rh_credentials[:cert])
16
+ cer_file.write(rh_credentials[:key])
17
+ cer_file.flush
18
+ @cer_path = cer_file.path
19
+ super(UploadReportJob.output_label(organization_id))
20
+ end
13
21
  end
14
22
 
15
23
  def command
@@ -18,22 +26,19 @@ module ForemanInventoryUpload
18
26
 
19
27
  def env
20
28
  super.merge(
21
- 'RH_USERNAME' => rh_username,
22
- 'RH_PASSWORD' => rh_password,
23
- 'FILES' => @filename
29
+ 'FILES' => @filename,
30
+ 'CER_PATH' => @cer_path
24
31
  )
25
32
  end
26
33
 
27
34
  def rh_credentials
28
- @rh_credentials ||= RedhatAccess::TelemetryConfiguration.where(portal_user: @portal_user).last
29
- end
30
-
31
- def rh_username
32
- @portal_user
33
- end
34
-
35
- def rh_password
36
- rh_credentials.portal_password
35
+ @rh_credentials ||= begin
36
+ candlepin_id_certificate = @organization.owner_details['upstreamConsumer']['idCert']
37
+ {
38
+ cert: candlepin_id_certificate['cert'],
39
+ key: candlepin_id_certificate['key'],
40
+ }
41
+ end
37
42
  end
38
43
  end
39
44
  end
@@ -11,6 +11,8 @@ module ForemanInventoryUpload
11
11
  config.autoload_paths += Dir["#{config.root}/app/overrides"]
12
12
  config.autoload_paths += Dir["#{config.root}/lib"]
13
13
 
14
+ config.eager_load_paths += Dir["#{config.root}/lib"]
15
+
14
16
  # Add any db migrations
15
17
  initializer 'foreman_inventory_upload.load_app_instance_data' do |app|
16
18
  ForemanInventoryUpload::Engine.paths['db/migrate'].existent.each do |path|
@@ -32,7 +34,15 @@ module ForemanInventoryUpload
32
34
 
33
35
  # Adding a sub menu after hosts menu
34
36
  sub_menu :top_menu, :foreman_inventory_upload, :caption => N_('RH Inventory'), :icon => 'fa fa-cloud-upload' do
35
- menu :top_menu, :level1, :caption => N_('Manage'), :url_hash => { controller: :'foreman_inventory_upload/react', :action=>:index}
37
+ menu :top_menu, :level1, :caption => N_('Manage'), :url_hash => { controller: :'foreman_inventory_upload/react', :action => :index}
38
+ end
39
+ end
40
+ end
41
+
42
+ initializer "foreman_inventory_upload.set_dynflow.config.on_init", :before => :finisher_hook do |_app|
43
+ unless Rails.env.test?
44
+ ForemanTasks.dynflow.config.on_init do |world|
45
+ ForemanInventoryUpload::Async::GenerateAllReportsJob.spawn_if_missing(world)
36
46
  end
37
47
  end
38
48
  end
@@ -6,10 +6,10 @@ module ForemanInventoryUpload
6
6
  @logger = logger
7
7
  end
8
8
 
9
- def render(portal_user)
9
+ def render(organization:)
10
10
  Dir.mktmpdir do |tmpdir|
11
11
  @logger.info "Started generating hosts report in #{tmpdir}"
12
- host_batches = ForemanInventoryUpload::Generators::Queries.for_report(portal_user)
12
+ host_batches = ForemanInventoryUpload::Generators::Queries.for_org(organization)
13
13
  File.open(File.join(tmpdir, 'metadata.json'), 'w') do |metadata_out|
14
14
  metadata_generator = ForemanInventoryUpload::Generators::Metadata.new(metadata_out)
15
15
  metadata_generator.render do |inner_generator|
@@ -16,7 +16,8 @@ module ForemanInventoryUpload
16
16
  'dmi::bios::relase_date',
17
17
  'distribution::name',
18
18
  'uname::release',
19
- 'lscpu::flags'
19
+ 'lscpu::flags',
20
+ 'distribution::version',
20
21
  ]).pluck(:name, :id)
21
22
  ]
22
23
  end
@@ -31,21 +32,29 @@ module ForemanInventoryUpload
31
32
  :installed_packages,
32
33
  :content_facet,
33
34
  :host_statuses,
34
- subscription_facet: %i[pools installed_products]
35
+ subscription_facet: [:pools, :installed_products, :hypervisor_host]
35
36
  )
36
37
  .merge(fact_values)
37
38
  end
38
39
 
39
40
  def self.for_report(portal_user)
40
- org_ids = Organization
41
- .joins(:telemetry_configuration)
42
- .where(
43
- redhat_access_telemetry_configurations: {
44
- portal_user: portal_user,
45
- enable_telemetry: true
46
- }
47
- ).pluck(:id)
48
- for_slice(Host.where(organization_id: org_ids)).in_batches(of: 1_000)
41
+ org_ids = organizations_for_user(portal_user).pluck(:id)
42
+ for_slice(Host.unscoped.where(organization_id: org_ids)).in_batches(of: 1_000)
43
+ end
44
+
45
+ def self.for_org(organization_id)
46
+ for_slice(Host.unscoped.where(organization_id: organization_id)).in_batches(of: 1_000)
47
+ end
48
+
49
+ def self.organizations_for_user(portal_user)
50
+ Organization
51
+ .joins(:telemetry_configuration)
52
+ .where(
53
+ redhat_access_telemetry_configurations: {
54
+ portal_user: portal_user,
55
+ enable_telemetry: true,
56
+ }
57
+ )
49
58
  end
50
59
  end
51
60
  end
@@ -23,14 +23,14 @@ module ForemanInventoryUpload
23
23
  first = true
24
24
  hosts_batch.each do |host|
25
25
  @stream.comma unless first
26
- first = false
27
- report_host(host)
26
+ first = false if report_host(host)
28
27
  end
29
28
  end
30
29
  end
31
30
  end
32
31
 
33
32
  def report_host(host)
33
+ return nil unless host&.subscription_facet&.pools&.first
34
34
  @stream.object do
35
35
  @stream.simple_field('display_name', host.name)
36
36
  @stream.simple_field('fqdn', host.fqdn)
@@ -49,9 +49,17 @@ module ForemanInventoryUpload
49
49
  @stream.stringify_value(nic.mac) if nic.mac
50
50
  end.compact.join(', '))
51
51
  end
52
- @stream.object_field('system_profile', :last) do
52
+ @stream.object_field('system_profile') do
53
53
  report_system_profile(host)
54
54
  end
55
+ @stream.array_field('facts', :last) do
56
+ @stream.object do
57
+ @stream.simple_field('namespace', 'satellite')
58
+ @stream.object_field('facts', :last) do
59
+ report_satellite_facts(host)
60
+ end
61
+ end
62
+ end
55
63
  end
56
64
  end
57
65
 
@@ -67,7 +75,7 @@ module ForemanInventoryUpload
67
75
  'ipv6_addresses': [nic.ip6].compact,
68
76
  'mtu': nic.mtu,
69
77
  'mac_address': nic.mac,
70
- 'name': nic.identifier
78
+ 'name': nic.identifier,
71
79
  }.compact.to_json
72
80
  end.join(', '))
73
81
  end
@@ -92,7 +100,7 @@ module ForemanInventoryUpload
92
100
  @stream.raw(installed_products.map do |product|
93
101
  {
94
102
  'name': product.name,
95
- 'id': product.cp_product_id
103
+ 'id': product.cp_product_id,
96
104
  }.to_json
97
105
  end.join(', '))
98
106
  end
@@ -106,6 +114,19 @@ module ForemanInventoryUpload
106
114
  end
107
115
  end
108
116
 
117
+ def report_satellite_facts(host)
118
+ @stream.simple_field('virtual_host_name', host.subscription_facet.hypervisor_host&.name)
119
+ @stream.simple_field('virtual_host_uuid', host.subscription_facet.hypervisor_host&.subscription_facet&.uuid)
120
+ if defined?(ForemanThemeSatellite)
121
+ @stream.simple_field('satellite_version', ForemanThemeSatellite::SATELLITE_VERSION)
122
+ end
123
+ @stream.simple_field('system_purpose_usage', host.subscription_facet.purpose_usage)
124
+ @stream.simple_field('system_purpose_role', host.subscription_facet.purpose_role)
125
+ @stream.simple_field('distribution_version', fact_value(host, 'distribution::version'))
126
+ @stream.simple_field('satellite_instance_id', Foreman.respond_to?(:instance_id) ? Foreman.instance_id : nil)
127
+ @stream.simple_field('organization_id', host.organization_id, :last)
128
+ end
129
+
109
130
  def fact_value(host, fact_name)
110
131
  value_record = host.fact_values.find do |fact_value|
111
132
  fact_value.fact_name_id == ForemanInventoryUpload::Generators::Queries.fact_names[fact_name]
@@ -1,3 +1,3 @@
1
1
  module ForemanInventoryUpload
2
- VERSION = '0.0.1.dev1'.freeze
2
+ VERSION = '0.9.0'.freeze
3
3
  end
@@ -11,16 +11,20 @@ module ForemanInventoryUpload
11
11
  )
12
12
  end
13
13
 
14
- def self.uploads_folder(group)
15
- @uploads_folders ||= {}
16
- cache = @uploads_folders[group]
17
- return cache if cache
14
+ def self.uploads_folder
15
+ @uploads_folder ||= ensure_folder(
16
+ File.join(
17
+ ForemanInventoryUpload.base_folder,
18
+ 'uploads/'
19
+ )
20
+ )
21
+ end
18
22
 
19
- @uploads_folders[group] = ensure_folder(
23
+ def self.generated_reports_folder
24
+ @generated_reports_folder ||= ensure_folder(
20
25
  File.join(
21
26
  ForemanInventoryUpload.base_folder,
22
- 'uploads/',
23
- "#{group}/"
27
+ 'generated_reports/'
24
28
  )
25
29
  )
26
30
  end
@@ -33,12 +37,13 @@ module ForemanInventoryUpload
33
37
  'uploader.sh'
34
38
  end
35
39
 
36
- def self.facts_archive_name
37
- 'hosts_report.tar.gz'
40
+ def self.facts_archive_name(organization)
41
+ "report_for_#{organization}.tar.gz"
38
42
  end
39
43
 
40
44
  def self.upload_url
41
- 'https://ci.cloud.paas.psi.redhat.com/api/ingress/v1/upload'
45
+ # for testing set ENV to 'https://ci.cloud.redhat.com/api/ingress/v1/upload'
46
+ @upload_url ||= ENV['SATELLITE_INVENTORY_UPLOAD_URL'] || 'https://cloud.redhat.com/api/ingress/v1/upload'
42
47
  end
43
48
 
44
49
  def self.ensure_folder(folder)
@@ -4,12 +4,26 @@ namespace :foreman_inventory_upload do
4
4
  namespace :report do
5
5
  desc 'Generate inventory report to be sent to Red Hat cloud'
6
6
  task generate: :environment do
7
- target = ENV['target'] || ForemanInventoryUpload.facts_archive_name
8
- portal_user = ENV['portal_user'] || 'anonymous'
7
+ portal_user = ENV['portal_user']
8
+ organizations = [ENV['organization_id']]
9
+ base_folder = ENV['target'] || Dir.pwd
9
10
 
10
- archived_report_generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
11
- archived_report_generator.render(portal_user)
12
- puts "Successfully generated #{target} for #{portal_user}"
11
+ unless portal_user || organizations.empty?
12
+ puts "Must specify either portal_user or organization_id"
13
+ end
14
+
15
+ if portal_user
16
+ puts "Generating report for all organizations associated with #{portal_user}"
17
+ base_folder = File.join(base_folder, portal_user)
18
+ organizations = ForemanInventoryUpload::Generators::Queries.organizations_for_user(portal_user).pluck(:id)
19
+ end
20
+
21
+ organizations.each do |organization|
22
+ target = File.join(base_folder, ForemanInventoryUpload.facts_archive_name(organization))
23
+ archived_report_generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
24
+ archived_report_generator.render(organization: organization)
25
+ puts "Successfully generated #{target} for organization id #{organization}"
26
+ end
13
27
  end
14
28
  end
15
29
  end