foreman_rh_cloud 2.0.4 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -0
  3. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +4 -6
  4. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +33 -7
  5. data/app/controllers/foreman_rh_cloud/react_controller.rb +11 -0
  6. data/app/controllers/insights_cloud/tasks_controller.rb +8 -0
  7. data/app/helpers/foreman_inventory_upload_host_helper.rb +11 -0
  8. data/app/models/insights_facet.rb +3 -0
  9. data/app/models/insights_hit.rb +6 -0
  10. data/app/models/setting/rh_cloud.rb +15 -0
  11. data/app/overrides/hosts_list.rb +13 -0
  12. data/app/views/foreman_rh_cloud/react/insights_cloud.html.erb +6 -0
  13. data/app/views/foreman_rh_cloud/react/inventory_upload.html.erb +1 -0
  14. data/app/views/{foreman_inventory_upload/layouts/react.html.erb → layouts/foreman_rh_cloud/application.html.erb} +2 -2
  15. data/config/routes.rb +12 -1
  16. data/db/migrate/20191215104806_create_insights_hits.foreman_inventory_upload.rb +14 -0
  17. data/db/migrate/20191216062008_create_insights_facets.foreman_inventory_upload.rb +7 -0
  18. data/lib/foreman_inventory_upload.rb +12 -0
  19. data/lib/foreman_inventory_upload/async/async_helpers.rb +13 -0
  20. data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +8 -0
  21. data/lib/foreman_inventory_upload/async/shell_process.rb +9 -1
  22. data/lib/foreman_inventory_upload/async/upload_report_job.rb +1 -1
  23. data/lib/foreman_inventory_upload/generators/archived_report.rb +6 -3
  24. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +56 -0
  25. data/lib/foreman_inventory_upload/generators/json_stream.rb +10 -0
  26. data/lib/foreman_inventory_upload/generators/queries.rb +7 -0
  27. data/lib/foreman_inventory_upload/generators/slice.rb +48 -22
  28. data/lib/foreman_inventory_upload/notifications/manifest_import_success_notification_override.rb +19 -0
  29. data/lib/foreman_inventory_upload/scripts/uploader.sh.erb +1 -1
  30. data/lib/foreman_rh_cloud/engine.rb +33 -5
  31. data/lib/foreman_rh_cloud/version.rb +1 -1
  32. data/lib/insights_cloud.rb +15 -0
  33. data/lib/insights_cloud/async/insights_full_sync.rb +96 -0
  34. data/test/controllers/accounts_controller_test.rb +8 -3
  35. data/test/controllers/uploads_controller_test.rb +13 -0
  36. data/test/factories/inventory_upload_factories.rb +13 -13
  37. data/test/jobs/insights_full_sync_test.rb +92 -0
  38. data/test/unit/archived_report_generator_test.rb +1 -0
  39. data/test/unit/fact_helpers_test.rb +29 -0
  40. data/test/unit/slice_generator_test.rb +277 -15
  41. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +14 -2
  42. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.js +13 -10
  43. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +6 -3
  44. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListHelper.js +10 -0
  45. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +16 -0
  46. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +10 -1
  47. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/EmptyResults.js +15 -0
  48. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/EmptyResults.test.js +13 -0
  49. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/__snapshots__/EmptyResults.test.js.snap +18 -0
  50. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/emptyResults.scss +7 -0
  51. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/index.js +1 -0
  52. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItem.js +1 -4
  53. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountList.test.js +1 -0
  54. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +8 -1
  55. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListHelper.test.js +12 -0
  56. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListIntegration.test.js +1 -1
  57. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +22 -0
  58. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +20 -8
  59. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountList.test.js.snap +2 -3
  60. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +20 -2
  61. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +20 -0
  62. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +8 -2
  63. data/webpack/ForemanInventoryUpload/Components/AccountList/index.js +2 -0
  64. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.fixtures.js +1 -0
  65. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.js +32 -0
  66. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherActions.js +30 -0
  67. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherConstants.js +2 -0
  68. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcher.test.js +14 -0
  69. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcherActions.test.js +14 -0
  70. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcher.test.js.snap +38 -0
  71. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcherActions.test.js.snap +14 -0
  72. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/autoUploadSwitcher.scss +3 -0
  73. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/index.js +17 -0
  74. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardActions.js +4 -3
  75. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardSelectors.js +1 -1
  76. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardActions.test.js +2 -3
  77. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardIntegration.test.js +2 -1
  78. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardSelectors.test.js +3 -2
  79. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.fixtures.js +1 -0
  80. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.js +29 -0
  81. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherActions.js +30 -0
  82. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherConstants.js +3 -0
  83. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcher.test.js +14 -0
  84. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcherActions.test.js +14 -0
  85. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcher.test.js.snap +38 -0
  86. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcherActions.test.js.snap +14 -0
  87. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/hostObfuscationSwitcher.scss +0 -0
  88. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/index.js +20 -0
  89. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/Components/ClearButton/ClearButton.js +26 -0
  90. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/Components/ClearButton/index.js +1 -0
  91. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.fixtures.js +2 -0
  92. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.js +39 -0
  93. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterActions.js +16 -0
  94. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterConstants.js +3 -0
  95. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js +36 -0
  96. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterSelectors.js +7 -0
  97. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilter.test.js +14 -0
  98. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterActions.test.js +14 -0
  99. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterReducer.test.js +35 -0
  100. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterSelectors.test.js +21 -0
  101. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilter.test.js.snap +25 -0
  102. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterActions.test.js.snap +17 -0
  103. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterReducer.test.js.snap +25 -0
  104. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterSelectors.test.js.snap +9 -0
  105. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +31 -0
  106. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/integration.test.js +18 -0
  107. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/index.js +17 -0
  108. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/inventoryFilter.scss +28 -0
  109. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.js +15 -0
  110. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/InventorySettings.test.js +13 -0
  111. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettings.test.js.snap +13 -0
  112. data/webpack/ForemanInventoryUpload/Components/InventorySettings/index.js +1 -0
  113. data/webpack/ForemanInventoryUpload/Components/InventorySettings/inventorySettings.scss +15 -0
  114. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js +40 -0
  115. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/PageHeader.test.js +13 -0
  116. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap +61 -0
  117. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/DocsButton.js +17 -0
  118. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/__tests__/DocsButton.test.js +12 -0
  119. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/__tests__/__snapshots__/DocsButton.test.js.snap +20 -0
  120. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/index.js +1 -0
  121. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/HistoryButton.js +18 -0
  122. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/__tests__/HistoryButton.test.js +12 -0
  123. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/__tests__/__snapshots__/HistoryButton.test.js.snap +21 -0
  124. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/index.js +1 -0
  125. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +24 -0
  126. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/PageDescription.test.js +11 -0
  127. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +17 -0
  128. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/index.js +1 -0
  129. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js +13 -0
  130. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/ToolbarButtons.test.js +12 -0
  131. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/__snapshots__/ToolbarButtons.test.js.snap +10 -0
  132. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/index.js +1 -0
  133. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/toolbarButtons.scss +7 -0
  134. data/webpack/ForemanInventoryUpload/Components/PageHeader/index.js +1 -0
  135. data/webpack/ForemanInventoryUpload/Components/PageHeader/pageHeader.scss +3 -0
  136. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRun.fixtures.js +1 -0
  137. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRun.js +4 -2
  138. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/ScheduledRun.test.js +0 -1
  139. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/__snapshots__/ScheduledRun.test.js.snap +0 -2
  140. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/index.js +12 -1
  141. data/webpack/ForemanInventoryUpload/Components/TabBody/__tests__/__snapshots__/TabBody.test.js.snap +1 -1
  142. data/webpack/ForemanInventoryUpload/ForemanInventoryConstants.js +7 -0
  143. data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +17 -0
  144. data/webpack/ForemanInventoryUpload/ForemanInventoryUpload.js +18 -9
  145. data/webpack/ForemanInventoryUpload/ForemanInventoryUploadReducers.js +4 -4
  146. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/SubscriptionsPageExtensionActions.js +34 -0
  147. data/webpack/ForemanInventoryUpload/__tests__/ForemanInventoryHelpers.test.js +10 -0
  148. data/webpack/ForemanInventoryUpload/{ForemanInventoryUpload.test.js → __tests__/ForemanInventoryUpload.test.js} +1 -1
  149. data/webpack/ForemanInventoryUpload/__tests__/__snapshots__/ForemanInventoryHelpers.test.js.snap +5 -0
  150. data/webpack/ForemanInventoryUpload/{__snapshots__ → __tests__/__snapshots__}/ForemanInventoryUpload.test.js.snap +6 -5
  151. data/webpack/ForemanRhCloudHelpers.js +6 -0
  152. data/webpack/ForemanRhCloudReducers.js +10 -0
  153. data/webpack/ForemanRhCloudSelectors.js +5 -0
  154. data/webpack/ForemanRhCloudTestHelpers.js +6 -0
  155. data/webpack/InsightsCloudSync/InsightsCloudSync.js +55 -0
  156. data/webpack/InsightsCloudSync/InsightsCloudSync.test.js +16 -0
  157. data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +23 -0
  158. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +6 -0
  159. data/webpack/InsightsCloudSync/InsightsCloudSyncHelpers.js +3 -0
  160. data/webpack/InsightsCloudSync/InsightsCloudSyncReducers.js +3 -0
  161. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +62 -0
  162. data/webpack/InsightsCloudSync/__tests__/InsightsCloudSyncHelpers.test.js +9 -0
  163. data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncHelpers.test.js.snap +3 -0
  164. data/webpack/InsightsCloudSync/index.js +17 -0
  165. data/webpack/__mocks__/foremanReact/components/Layout/LayoutConstants.js +1 -0
  166. data/webpack/__tests__/ForemanRhCloudHelpers.test.js +11 -0
  167. data/webpack/__tests__/ForemanRhCloudSelectors.test.js +19 -0
  168. data/webpack/__tests__/ForemanRhCloudTestHelpers.test.js +10 -0
  169. data/webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap +3 -0
  170. data/webpack/__tests__/__snapshots__/ForemanRhCloudSelectors.test.js.snap +24 -0
  171. data/webpack/__tests__/__snapshots__/ForemanRhCloudTestHelpers.test.js.snap +14 -0
  172. data/webpack/index.js +8 -1
  173. data/webpack/subscriptions_extension_index.js +8 -0
  174. metadata +124 -7
  175. data/app/controllers/foreman_inventory_upload/react_controller.rb +0 -7
  176. data/webpack/ForemanInventoryUpload/ForemanInventoryUploadSelectors.js +0 -4
@@ -0,0 +1,92 @@
1
+ require 'test_helper'
2
+
3
+ class InsightsFullSyncTest < ActiveJob::TestCase
4
+ setup do
5
+ @host1 = FactoryBot.create(:host, :managed, name: 'host1')
6
+ @host2 = FactoryBot.create(:host, :managed, name: 'host2')
7
+
8
+ hits_json = <<-HITS_JSON
9
+ [
10
+ {
11
+ "hostname": "#{@host1.name}",
12
+ "rhel_version": "7.5",
13
+ "uuid": "accdf444-5628-451d-bf3e-cf909ad72756",
14
+ "last_seen": "2019-11-22T08:41:42.447244Z",
15
+ "title": "New Ansible Engine packages are inaccessible when dedicated Ansible repo is not enabled",
16
+ "solution_url": "",
17
+ "total_risk": 2,
18
+ "likelihood": 2,
19
+ "publish_date": "2018-04-16T10:03:16Z",
20
+ "results_url": "https://cloud.redhat.com/insights/overview/stability/ansible_deprecated_repo%7CANSIBLE_DEPRECATED_REPO/accdf444-5628-451d-bf3e-cf909ad72756/"
21
+ },
22
+ {
23
+ "hostname": "#{@host1.name}",
24
+ "rhel_version": "7.5",
25
+ "uuid": "accdf444-5628-451d-bf3e-cf909ad72756",
26
+ "last_seen": "2019-11-22T08:41:42.447244Z",
27
+ "title": "CPU vulnerable to side-channel attacks using Microarchitectural Data Sampling (CVE-2018-12130, CVE-2018-12126, CVE-2018-12127, CVE-2019-11091)",
28
+ "solution_url": "https://access.redhat.com/node/4134081",
29
+ "total_risk": 2,
30
+ "likelihood": 2,
31
+ "publish_date": "2019-05-14T17:00:00Z",
32
+ "results_url": "https://cloud.redhat.com/insights/overview/security/CVE_2018_12130_cpu_kernel%7CCVE_2018_12130_CPU_KERNEL_NEED_UPDATE/accdf444-5628-451d-bf3e-cf909ad72756/"
33
+ },
34
+ {
35
+ "hostname": "#{@host2.name}",
36
+ "rhel_version": "7.5",
37
+ "uuid": "accdf444-5628-451d-bf3e-cf909ad72757",
38
+ "last_seen": "2019-11-22T08:41:42.447244Z",
39
+ "title": "CPU vulnerable to side-channel attacks using L1 Terminal Fault (CVE-2018-3620)",
40
+ "solution_url": "https://access.redhat.com/node/3560291",
41
+ "total_risk": 2,
42
+ "likelihood": 2,
43
+ "publish_date": "2018-08-14T17:00:00Z",
44
+ "results_url": "https://cloud.redhat.com/insights/overview/security/CVE_2018_3620_cpu_kernel%7CCVE_2018_3620_CPU_KERNEL_NEED_UPDATE/accdf444-5628-451d-bf3e-cf909ad72756/"
45
+ }
46
+ ]
47
+ HITS_JSON
48
+ @hits = JSON.parse(hits_json)
49
+ end
50
+
51
+ test 'Hits data is replaced with data from cloud' do
52
+ InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).returns(@hits)
53
+
54
+ InsightsCloud::Async::InsightsFullSync.perform_now(@host1.organization)
55
+
56
+ @host1.reload
57
+ @host2.reload
58
+
59
+ assert_equal 2, @host1.insights.hits.count
60
+ assert_equal 1, @host2.insights.hits.count
61
+ end
62
+
63
+ test 'Hits ignoring non-existent hosts' do
64
+ hits_json = <<-HITS_JSON
65
+ [
66
+ {
67
+ "hostname": "#{@host1.name}_non_existent",
68
+ "rhel_version": "7.5",
69
+ "uuid": "accdf444-5628-451d-bf3e-cf909ad72756",
70
+ "last_seen": "2019-11-22T08:41:42.447244Z",
71
+ "title": "New Ansible Engine packages are inaccessible when dedicated Ansible repo is not enabled",
72
+ "solution_url": "",
73
+ "total_risk": 2,
74
+ "likelihood": 2,
75
+ "publish_date": "2018-04-16T10:03:16Z",
76
+ "results_url": "https://cloud.redhat.com/insights/overview/stability/ansible_deprecated_repo%7CANSIBLE_DEPRECATED_REPO/accdf444-5628-451d-bf3e-cf909ad72756/"
77
+ }
78
+ ]
79
+ HITS_JSON
80
+ hits = JSON.parse(hits_json)
81
+
82
+ InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).returns(hits)
83
+
84
+ InsightsCloud::Async::InsightsFullSync.perform_now(@host1.organization)
85
+
86
+ @host1.reload
87
+ @host2.reload
88
+
89
+ assert_nil @host1.insights
90
+ assert_nil @host2.insights
91
+ end
92
+ end
@@ -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,9 @@ 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
+
21
+ ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
20
22
  end
21
23
 
22
24
  def interesting_facts
@@ -30,9 +32,17 @@ class ReportGeneratorTest < ActiveSupport::TestCase
30
32
  'dmi::bios::vendor',
31
33
  'dmi::bios::version',
32
34
  'dmi::bios::relase_date',
33
- 'distribution::name',
34
35
  'uname::release',
35
36
  'lscpu::flags',
37
+ 'distribution::name',
38
+ 'distribution::version',
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',
36
46
  ]
37
47
  end
38
48
 
@@ -46,22 +56,99 @@ class ReportGeneratorTest < ActiveSupport::TestCase
46
56
 
47
57
  test 'generates a report for a single host' do
48
58
  batch = Host.where(id: @host.id).in_batches.first
49
- 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_nil actual_host['ip_addresses']
67
+ assert_nil actual_host['mac_addresses']
68
+ assert_equal @host.fqdn, actual_host['fqdn']
69
+ assert_equal '1234', actual_host['account']
70
+ assert_equal 1, generator.hosts_count
71
+ end
72
+
73
+ test 'generates ip_address and mac_address fields' do
74
+ @host.interfaces << FactoryBot.build(:nic_managed)
75
+ batch = Host.where(id: @host.id).in_batches.first
76
+ generator = create_generator(batch)
50
77
 
51
78
  json_str = generator.render
52
79
  actual = JSON.parse(json_str.join("\n"))
53
80
 
54
81
  assert_equal 'slice_123', actual['report_slice_id']
55
82
  assert_not_nil(actual_host = actual['hosts'].first)
56
- assert_equal @host.name, actual_host['display_name']
83
+ assert_equal @host.interfaces.where.not(ip: nil).first.ip, actual_host['ip_addresses'].first
84
+ assert_equal @host.interfaces.where.not(mac: nil).first.mac, actual_host['mac_addresses'].first
57
85
  assert_equal @host.fqdn, actual_host['fqdn']
58
86
  assert_equal '1234', actual_host['account']
87
+ assert_equal 1, generator.hosts_count
88
+ end
89
+
90
+ test 'obfuscates fqdn when instructed by insights-client' do
91
+ FactoryBot.create(:fact_value, fact_name: fact_names['insights_client::obfuscate_hostname_enabled'], value: 'true', host: @host)
92
+ FactoryBot.create(:fact_value, fact_name: fact_names['insights_client::hostname'], value: 'obfuscated_name', host: @host)
93
+
94
+ batch = Host.where(id: @host.id).in_batches.first
95
+ generator = create_generator(batch)
96
+
97
+ json_str = generator.render
98
+ actual = JSON.parse(json_str.join("\n"))
99
+
100
+ assert_equal 'slice_123', actual['report_slice_id']
101
+ assert_not_nil(actual_host = actual['hosts'].first)
102
+ assert_equal 'obfuscated_name', actual_host['fqdn']
103
+ assert_equal '1234', actual_host['account']
104
+ assert_not_nil(actual_facts = actual_host['facts'].first['facts'])
105
+ assert_equal true, actual_facts['is_hostname_obfuscated']
106
+ assert_equal 1, generator.hosts_count
107
+ end
108
+
109
+ test 'obfuscates fqdn when setting set' do
110
+ FactoryBot.create(:setting, :name => 'obfuscate_inventory_hostnames', :value => true)
111
+
112
+ batch = Host.where(id: @host.id).in_batches.first
113
+ generator = create_generator(batch)
114
+
115
+ json_str = generator.render
116
+ actual = JSON.parse(json_str.join("\n"))
117
+
118
+ obfuscated_fqdn = Digest::SHA1.hexdigest(@host.fqdn)
119
+
120
+ assert_equal 'slice_123', actual['report_slice_id']
121
+ assert_not_nil(actual_host = actual['hosts'].first)
122
+ assert_equal obfuscated_fqdn, actual_host['fqdn']
123
+ assert_equal '1234', actual_host['account']
124
+ assert_not_nil(actual_facts = actual_host['facts'].first['facts'])
125
+ assert_equal true, actual_facts['is_hostname_obfuscated']
126
+ assert_equal 1, generator.hosts_count
127
+ end
128
+
129
+ test 'does not obfuscate fqdn when insights-client sets to false' do
130
+ FactoryBot.create(:fact_value, fact_name: fact_names['insights_client::obfuscate_hostname_enabled'], value: 'false', host: @host)
131
+ FactoryBot.create(:fact_value, fact_name: fact_names['insights_client::hostname'], value: 'obfuscated_name', host: @host)
132
+
133
+ batch = Host.where(id: @host.id).in_batches.first
134
+ generator = create_generator(batch)
135
+
136
+ json_str = generator.render
137
+ actual = JSON.parse(json_str.join("\n"))
138
+
139
+ assert_equal 'slice_123', actual['report_slice_id']
140
+ assert_not_nil(actual_host = actual['hosts'].first)
141
+ assert_equal @host.fqdn, actual_host['fqdn']
142
+ assert_equal '1234', actual_host['account']
143
+ assert_not_nil(actual_facts = actual_host['facts'].first['facts'])
144
+ assert_equal false, actual_facts['is_hostname_obfuscated']
145
+ assert_equal 1, generator.hosts_count
59
146
  end
60
147
 
61
148
  test 'generates a report with satellite facts' do
62
149
  Foreman.expects(:instance_id).twice.returns('satellite-id')
63
150
  batch = Host.where(id: @host.id).in_batches.first
64
- generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice-123')
151
+ generator = create_generator(batch)
65
152
 
66
153
  json_str = generator.render
67
154
  actual = JSON.parse(json_str.join("\n"))
@@ -72,13 +159,14 @@ class ReportGeneratorTest < ActiveSupport::TestCase
72
159
  assert_equal 'satellite-id', satellite_facts['satellite_instance_id']
73
160
  assert_equal @host.organization_id, satellite_facts['organization_id']
74
161
 
75
- instance_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'satellite_instance_id'}
162
+ instance_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'satellite_instance_id' }
76
163
  assert_not_nil instance_id_tag
77
164
  assert_equal 'satellite-id', instance_id_tag['value']
78
165
 
79
- org_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'organization_id'}
166
+ org_id_tag = actual['hosts'].first['tags'].find { |tag| tag['namespace'] == 'satellite' && tag['key'] == 'organization_id' }
80
167
  assert_not_nil org_id_tag
81
- assert_equal @host.organization_id, org_id_tag['value']
168
+ assert_equal @host.organization_id.to_s, org_id_tag['value']
169
+ assert_equal false, satellite_facts['is_hostname_obfuscated']
82
170
 
83
171
  version = satellite_facts['satellite_version']
84
172
  if defined?(ForemanThemeSatellite)
@@ -102,14 +190,13 @@ class ReportGeneratorTest < ActiveSupport::TestCase
102
190
  @host.save!
103
191
 
104
192
  batch = Host.where(id: @host.id).in_batches.first
105
- generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
193
+ generator = create_generator(batch)
106
194
 
107
195
  json_str = generator.render
108
196
  actual = JSON.parse(json_str.join("\n"))
109
197
 
110
198
  assert_equal 'slice_123', actual['report_slice_id']
111
199
  assert_not_nil(actual_host = actual['hosts'].first)
112
- assert_equal @host.name, actual_host['display_name']
113
200
  assert_equal @host.fqdn, actual_host['fqdn']
114
201
  assert_not_nil(host_facts = actual_host['facts']&.first)
115
202
  assert_equal 'satellite', host_facts['namespace']
@@ -124,14 +211,13 @@ class ReportGeneratorTest < ActiveSupport::TestCase
124
211
  @host.subscription_facet.save!
125
212
 
126
213
  batch = Host.where(id: @host.id).in_batches.first
127
- generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
214
+ generator = create_generator(batch)
128
215
 
129
216
  json_str = generator.render
130
217
  actual = JSON.parse(json_str.join("\n"))
131
218
 
132
219
  assert_equal 'slice_123', actual['report_slice_id']
133
220
  assert_not_nil(actual_host = actual['hosts'].first)
134
- assert_equal @host.name, actual_host['display_name']
135
221
  assert_equal @host.fqdn, actual_host['fqdn']
136
222
  assert_not_nil(host_facts = actual_host['facts']&.first)
137
223
  assert_equal 'satellite', host_facts['namespace']
@@ -140,6 +226,22 @@ class ReportGeneratorTest < ActiveSupport::TestCase
140
226
  assert_equal 'test_role', fact_values['system_purpose_role']
141
227
  end
142
228
 
229
+ test 'generates a report for a golden ticket' do
230
+ batch = Host.where(id: @host.id).in_batches.first
231
+ generator = create_generator(batch) do |generator|
232
+ generator.stubs(:golden_ticket?).returns(true)
233
+ end
234
+
235
+ json_str = generator.render
236
+ actual = JSON.parse(json_str.join("\n"))
237
+
238
+ assert_equal 'slice_123', actual['report_slice_id']
239
+ assert_not_nil(actual_host = actual['hosts'].first)
240
+ assert_equal @host.fqdn, actual_host['fqdn']
241
+ assert_equal '1234', actual_host['account']
242
+ assert_equal 1, generator.hosts_count
243
+ end
244
+
143
245
  test 'skips hosts without subscription' do
144
246
  a_host = FactoryBot.create(
145
247
  :host,
@@ -148,23 +250,23 @@ class ReportGeneratorTest < ActiveSupport::TestCase
148
250
 
149
251
  # make a_host last
150
252
  batch = Host.where(id: [@host.id, a_host.id]).order(:name).in_batches.first
151
- generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
253
+ generator = create_generator(batch)
152
254
 
153
255
  json_str = generator.render
154
256
  actual = JSON.parse(json_str.join("\n"))
155
257
 
156
258
  assert_equal 'slice_123', actual['report_slice_id']
157
259
  assert_not_nil(actual_host = actual['hosts'].first)
158
- assert_equal @host.name, actual_host['display_name']
159
260
  assert_equal @host.fqdn, actual_host['fqdn']
160
261
  assert_equal '1234', actual_host['account']
262
+ assert_equal 1, generator.hosts_count
161
263
  end
162
264
 
163
265
  test 'shows system_memory_bytes in bytes' do
164
266
  FactoryBot.create(:fact_value, fact_name: fact_names['memory::memtotal'], value: '1', host: @host)
165
267
 
166
268
  batch = Host.where(id: @host.id).in_batches.first
167
- generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], 'slice_123')
269
+ generator = create_generator(batch)
168
270
 
169
271
  json_str = generator.render
170
272
  actual = JSON.parse(json_str.join("\n"))
@@ -174,4 +276,164 @@ class ReportGeneratorTest < ActiveSupport::TestCase
174
276
  assert_not_nil(actual_profile = actual_host['system_profile'])
175
277
  assert_equal 1024, actual_profile['system_memory_bytes']
176
278
  end
279
+
280
+ test 'reports an account for hosts with multiple pools' do
281
+ first_pool = @host.organization.pools.first
282
+ second_pool = FactoryBot.create(:katello_pool, account_number: nil, cp_id: 2)
283
+ new_org = FactoryBot.create(:organization, pools: [first_pool, second_pool])
284
+
285
+ another_host = FactoryBot.create(
286
+ :host,
287
+ :with_subscription,
288
+ :with_content,
289
+ content_view: @host.content_view,
290
+ lifecycle_environment: @host.lifecycle_environment,
291
+ organization: new_org
292
+ )
293
+
294
+ batch = Host.where(id: another_host.id).in_batches.first
295
+ generator = create_generator(batch)
296
+
297
+ json_str = generator.render
298
+ actual = JSON.parse(json_str.join("\n"))
299
+
300
+ assert_equal 'slice_123', actual['report_slice_id']
301
+ assert_not_nil(actual_host = actual['hosts'].first)
302
+ assert_not_nil(actual_host['account'])
303
+ assert_not_empty(actual_host['account'])
304
+ end
305
+
306
+ test 'Generates os_release with version and id' do
307
+ FactoryBot.create(:fact_value, fact_name: fact_names['distribution::name'], value: 'Red Hat Test Linux', host: @host)
308
+ FactoryBot.create(:fact_value, fact_name: fact_names['distribution::version'], value: '7.1', host: @host)
309
+ FactoryBot.create(:fact_value, fact_name: fact_names['distribution::id'], value: 'TestId', host: @host)
310
+
311
+ batch = Host.where(id: @host.id).in_batches.first
312
+ generator = create_generator(batch)
313
+
314
+ json_str = generator.render
315
+ actual = JSON.parse(json_str.join("\n"))
316
+
317
+ assert_equal 'slice_123', actual['report_slice_id']
318
+ assert_not_nil(actual_host = actual['hosts'].first)
319
+ assert_not_nil(actual_profile = actual_host['system_profile'])
320
+ assert_equal 'Red Hat Test Linux 7.1 (TestId)', actual_profile['os_release']
321
+ end
322
+
323
+ test 'sets infrastructure_type to "virtual" based on virt.is_guest fact' do
324
+ FactoryBot.create(:fact_value, fact_name: fact_names['virt::is_guest'], value: true, host: @host)
325
+
326
+ batch = Host.where(id: @host.id).in_batches.first
327
+ generator = create_generator(batch)
328
+
329
+ json_str = generator.render
330
+ actual = JSON.parse(json_str.join("\n"))
331
+
332
+ assert_equal 'slice_123', actual['report_slice_id']
333
+ assert_not_nil(actual_host = actual['hosts'].first)
334
+ assert_not_nil(actual_profile = actual_host['system_profile'])
335
+ assert_equal 'virtual', actual_profile['infrastructure_type']
336
+ end
337
+
338
+ test 'sets infrastructure_type to "physical" based on virt.is_guest fact' do
339
+ FactoryBot.create(:fact_value, fact_name: fact_names['virt::is_guest'], value: false, host: @host)
340
+
341
+ batch = Host.where(id: @host.id).in_batches.first
342
+ generator = create_generator(batch)
343
+
344
+ json_str = generator.render
345
+ actual = JSON.parse(json_str.join("\n"))
346
+
347
+ assert_equal 'slice_123', actual['report_slice_id']
348
+ assert_not_nil(actual_host = actual['hosts'].first)
349
+ assert_not_nil(actual_profile = actual_host['system_profile'])
350
+ assert_equal 'physical', actual_profile['infrastructure_type']
351
+ end
352
+
353
+ test 'Identifies Amazon cloud provider' do
354
+ FactoryBot.create(:fact_value, fact_name: fact_names['dmi::bios::version'], value: 'Test Amazon version', host: @host)
355
+
356
+ batch = Host.where(id: @host.id).in_batches.first
357
+ generator = create_generator(batch)
358
+
359
+ json_str = generator.render
360
+ actual = JSON.parse(json_str.join("\n"))
361
+
362
+ assert_equal 'slice_123', actual['report_slice_id']
363
+ assert_not_nil(actual_host = actual['hosts'].first)
364
+ assert_not_nil(actual_profile = actual_host['system_profile'])
365
+ assert_equal 'aws', actual_profile['cloud_provider']
366
+ end
367
+
368
+ test 'Identifies Google cloud provider' do
369
+ FactoryBot.create(:fact_value, fact_name: fact_names['dmi::bios::version'], value: 'Test Google version', host: @host)
370
+
371
+ batch = Host.where(id: @host.id).in_batches.first
372
+ generator = create_generator(batch)
373
+
374
+ json_str = generator.render
375
+ actual = JSON.parse(json_str.join("\n"))
376
+
377
+ assert_equal 'slice_123', actual['report_slice_id']
378
+ assert_not_nil(actual_host = actual['hosts'].first)
379
+ assert_not_nil(actual_profile = actual_host['system_profile'])
380
+ assert_equal 'google', actual_profile['cloud_provider']
381
+ end
382
+
383
+ test 'Identifies Azure cloud provider' do
384
+ FactoryBot.create(:fact_value, fact_name: fact_names['dmi::chassis::asset_tag'], value: '7783-7084-3265-9085-8269-3286-77', host: @host)
385
+
386
+ batch = Host.where(id: @host.id).in_batches.first
387
+ generator = create_generator(batch)
388
+
389
+ json_str = generator.render
390
+ actual = JSON.parse(json_str.join("\n"))
391
+
392
+ assert_equal 'slice_123', actual['report_slice_id']
393
+ assert_not_nil(actual_host = actual['hosts'].first)
394
+ assert_not_nil(actual_profile = actual_host['system_profile'])
395
+ assert_equal 'azure', actual_profile['cloud_provider']
396
+ end
397
+
398
+ test 'Identifies Alibaba cloud provider via manufacturer' do
399
+ FactoryBot.create(:fact_value, fact_name: fact_names['dmi::system::manufacturer'], value: 'Test Alibaba Cloud version', host: @host)
400
+
401
+ batch = Host.where(id: @host.id).in_batches.first
402
+ generator = create_generator(batch)
403
+
404
+ json_str = generator.render
405
+ actual = JSON.parse(json_str.join("\n"))
406
+
407
+ assert_equal 'slice_123', actual['report_slice_id']
408
+ assert_not_nil(actual_host = actual['hosts'].first)
409
+ assert_not_nil(actual_profile = actual_host['system_profile'])
410
+ assert_equal 'alibaba', actual_profile['cloud_provider']
411
+ end
412
+
413
+ test 'Identifies Alibaba cloud provider via product name' do
414
+ FactoryBot.create(:fact_value, fact_name: fact_names['dmi::system::product_name'], value: 'Test Alibaba Cloud ECS product', host: @host)
415
+
416
+ batch = Host.where(id: @host.id).in_batches.first
417
+ generator = create_generator(batch)
418
+
419
+ json_str = generator.render
420
+ actual = JSON.parse(json_str.join("\n"))
421
+
422
+ assert_equal 'slice_123', actual['report_slice_id']
423
+ assert_not_nil(actual_host = actual['hosts'].first)
424
+ assert_not_nil(actual_profile = actual_host['system_profile'])
425
+ assert_equal 'alibaba', actual_profile['cloud_provider']
426
+ end
427
+
428
+ private
429
+
430
+ def create_generator(batch, name = 'slice_123')
431
+ generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], name)
432
+ if block_given?
433
+ yield(generator)
434
+ else
435
+ generator.stubs(:golden_ticket?).returns(false)
436
+ end
437
+ generator
438
+ end
177
439
  end