foreman_rh_cloud 1.0.10 → 1.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -0
  3. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +2 -0
  4. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +18 -0
  5. data/app/controllers/insights_cloud/hits_controller.rb +17 -0
  6. data/app/helpers/foreman_inventory_upload_host_helper.rb +2 -3
  7. data/app/models/concerns/rh_cloud_host.rb +15 -0
  8. data/app/models/insights_hit.rb +1 -1
  9. data/app/models/setting/rh_cloud.rb +2 -0
  10. data/app/overrides/hosts_list.rb +1 -1
  11. data/app/services/foreman_rh_cloud/cloud_auth.rb +28 -0
  12. data/app/views/hosts/_insights_tab.html.erb +15 -0
  13. data/config/routes.rb +3 -0
  14. data/db/migrate/20201007115752_add_hits_count_to_insights_facets_table.foreman_rh_cloud.rb +5 -0
  15. data/db/migrate/20201007121540_setup_hits_count_cache.foreman_rh_cloud.rb +10 -0
  16. data/lib/foreman_inventory_upload/async/generate_report_job.rb +1 -1
  17. data/lib/foreman_inventory_upload/async/shell_process.rb +15 -9
  18. data/lib/foreman_inventory_upload/async/upload_report_job.rb +21 -9
  19. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +35 -0
  20. data/lib/foreman_inventory_upload/generators/json_stream.rb +7 -2
  21. data/lib/foreman_inventory_upload/generators/metadata.rb +3 -0
  22. data/lib/foreman_inventory_upload/generators/queries.rb +4 -4
  23. data/lib/foreman_inventory_upload/generators/slice.rb +27 -25
  24. data/lib/foreman_rh_cloud.rb +55 -0
  25. data/lib/foreman_rh_cloud/engine.rb +13 -2
  26. data/lib/foreman_rh_cloud/version.rb +1 -1
  27. data/lib/insights_cloud/async/insights_full_sync.rb +5 -24
  28. data/lib/inventory_sync/async/inventory_full_sync.rb +3 -22
  29. data/lib/tasks/insights.rake +15 -0
  30. data/lib/tasks/rh_cloud_inventory.rake +37 -0
  31. data/package.json +3 -1
  32. data/test/jobs/upload_report_job_test.rb +34 -0
  33. data/test/unit/fact_helpers_test.rb +22 -0
  34. data/test/unit/insights_facet_test.rb +7 -0
  35. data/test/unit/metadata_generator_test.rb +2 -0
  36. data/test/unit/rh_cloud_http_proxy_test.rb +65 -0
  37. data/test/unit/slice_generator_test.rb +167 -2
  38. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +14 -1
  39. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +22 -18
  40. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +16 -0
  41. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +6 -0
  42. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +7 -0
  43. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +12 -8
  44. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +9 -0
  45. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +19 -0
  46. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +11 -0
  47. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +6 -0
  48. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.fixtures.js +2 -0
  49. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherActions.js +10 -11
  50. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherConstants.js +0 -1
  51. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcherActions.test.js +12 -2
  52. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcherActions.test.js.snap +17 -0
  53. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcher.fixtures.js +1 -0
  54. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcher.js +30 -0
  55. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcherActions.js +29 -0
  56. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcherConstants.js +1 -0
  57. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/ExcludePackagesSwitcher.test.js +13 -0
  58. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/ExcludePackagesSwitcherActions.test.js +21 -0
  59. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/ExcludePackagesSwitcher.test.js.snap +38 -0
  60. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/ExcludePackagesSwitcherActions.test.js.snap +31 -0
  61. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/integration.test.js.snap +41 -0
  62. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/integration.test.js +38 -0
  63. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/excludePackagesSwitcher.scss +3 -0
  64. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/index.js +20 -0
  65. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.fixtures.js +2 -1
  66. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.js +1 -0
  67. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.scss +3 -0
  68. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherActions.js +10 -11
  69. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherConstants.js +0 -2
  70. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcherActions.test.js +12 -2
  71. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcherActions.test.js.snap +18 -1
  72. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +3 -0
  73. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.js +4 -0
  74. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettings.test.js.snap +2 -0
  75. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcher.fixtures.js +1 -0
  76. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcher.js +29 -0
  77. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcherActions.js +29 -0
  78. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcherConstants.js +1 -0
  79. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/IpsObfuscationSwitcher.test.js +13 -0
  80. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/IpsObfuscationSwitcherActions.test.js +21 -0
  81. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/__snapshots__/IpsObfuscationSwitcher.test.js.snap +38 -0
  82. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/__snapshots__/IpsObfuscationSwitcherActions.test.js.snap +31 -0
  83. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/index.js +20 -0
  84. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButton.js +8 -2
  85. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +9 -11
  86. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonConstants.js +1 -1
  87. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonReducer.js +2 -2
  88. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonActions.test.js +18 -0
  89. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonReducer.test.js +1 -8
  90. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonActions.test.js.snap +62 -0
  91. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonReducer.test.js.snap +0 -7
  92. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Modal.js +2 -2
  93. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Toast.js +1 -1
  94. data/webpack/ForemanInventoryUpload/Components/StatusChart/StatusChart.js +1 -1
  95. data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/__snapshots__/StatusChart.test.js.snap +1 -1
  96. data/webpack/ForemanInventoryUpload/Components/TabContainer/tabContainer.scss +1 -1
  97. data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeader.js +6 -1
  98. data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +2 -4
  99. data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +8 -0
  100. data/webpack/ForemanRhCloudPages.js +2 -0
  101. data/webpack/ForemanRhCloudReducers.js +2 -0
  102. data/webpack/ForemanRhCloudSelectors.js +5 -0
  103. data/webpack/ForemanRhCloudTestHelpers.js +6 -1
  104. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsActions.js +17 -20
  105. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsConstants.js +0 -6
  106. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsReducer.js +0 -4
  107. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js +16 -0
  108. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsReducer.test.js +1 -24
  109. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsActions.test.js.snap +38 -4
  110. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsReducer.test.js.snap +0 -14
  111. data/webpack/InsightsCloudSync/InsightsCloudSync.js +1 -1
  112. data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +10 -11
  113. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +0 -2
  114. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +1 -1
  115. data/webpack/InsightsHostDetailsTab/InsightsTab.js +64 -0
  116. data/webpack/InsightsHostDetailsTab/InsightsTab.scss +86 -0
  117. data/webpack/InsightsHostDetailsTab/InsightsTabActions.js +31 -0
  118. data/webpack/InsightsHostDetailsTab/InsightsTabConstants.js +2 -0
  119. data/webpack/InsightsHostDetailsTab/InsightsTabReducer.js +19 -0
  120. data/webpack/InsightsHostDetailsTab/InsightsTabSelectors.js +3 -0
  121. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTab.fixtures.js +25 -0
  122. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTab.test.js +13 -0
  123. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabActions.test.js +19 -0
  124. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabIntegration.test.js +17 -0
  125. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabReducer.test.js +26 -0
  126. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabSelectors.test.js +13 -0
  127. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTab.test.js.snap +30 -0
  128. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabActions.test.js.snap +58 -0
  129. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabReducer.test.js.snap +34 -0
  130. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabSelectors.test.js.snap +20 -0
  131. data/webpack/InsightsHostDetailsTab/components/ListItem/ListItem.js +69 -0
  132. data/webpack/InsightsHostDetailsTab/components/ListItem/index.js +1 -0
  133. data/webpack/InsightsHostDetailsTab/index.js +20 -0
  134. data/webpack/__tests__/__snapshots__/ForemanRhCloudSelectors.test.js.snap +1 -0
  135. data/webpack/__tests__/__snapshots__/ForemanRhCloudTestHelpers.test.js.snap +3 -0
  136. data/webpack/stories/decorators/withCardsDecorator.js +1 -1
  137. metadata +67 -16
  138. data/lib/tasks/generator.rake +0 -29
  139. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/hostObfuscationSwitcher.scss +0 -0
@@ -26,4 +26,26 @@ class FactHelpersTest < ActiveSupport::TestCase
26
26
 
27
27
  assert actual
28
28
  end
29
+
30
+ test 'obfuscates ips with insights-client data' do
31
+ host = mock('host')
32
+ @instance.expects(:fact_value).with(host, 'insights_client::ips').returns(
33
+ '[{"obfuscated": "10.230.230.1", "original": "224.0.0.1"}, {"obfuscated": "10.230.230.2", "original": "224.0.0.251"}]'
34
+ )
35
+
36
+ actual = @instance.obfuscated_ips(host)
37
+
38
+ assert_equal '10.230.230.1', actual['224.0.0.1']
39
+ assert_equal '10.230.230.3', actual['224.0.0.2']
40
+ end
41
+
42
+ test 'obfuscates ips without insights-client data' do
43
+ host = mock('host')
44
+ @instance.expects(:fact_value).with(host, 'insights_client::ips').returns(nil)
45
+
46
+ actual = @instance.obfuscated_ips(host)
47
+
48
+ assert_equal '10.230.230.1', actual['224.0.0.1']
49
+ assert_equal '10.230.230.2', actual['224.0.0.2']
50
+ end
29
51
  end
@@ -3,6 +3,7 @@ require 'test_plugin_helper'
3
3
  class InsightsFacetTest < ActiveSupport::TestCase
4
4
  setup do
5
5
  @host = FactoryBot.create(:host, :with_insights_hits)
6
+ InsightsFacet.reset_counters(@host.insights.id, :hits_count)
6
7
  end
7
8
 
8
9
  test 'host with hits can be deleted' do
@@ -13,4 +14,10 @@ class InsightsFacetTest < ActiveSupport::TestCase
13
14
  actual_host = Host.find_by_id(host_id)
14
15
  assert_nil actual_host
15
16
  end
17
+
18
+ test 'search host by recommendations_count' do
19
+ FactoryBot.create(:host) # create another host with no recommendations
20
+
21
+ assert_equal 1, Host.search_for('insights_recommendations_count = 1').count
22
+ end
16
23
  end
@@ -13,6 +13,8 @@ class MetadataGeneratorTest < ActiveSupport::TestCase
13
13
 
14
14
  assert_not_nil actual['report_id']
15
15
  assert_equal 'Satellite', actual['source']
16
+ assert_not_nil (actual_metadata = actual['source_metadata'])
17
+ assert_equal ForemanRhCloud::VERSION, actual_metadata['foreman_rh_cloud_version']
16
18
  assert_equal({}, actual['report_slices'])
17
19
  end
18
20
 
@@ -0,0 +1,65 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class RhCloudHttpProxyTest < ActiveSupport::TestCase
4
+ setup do
5
+ @global_content_proxy_mock = 'http://global:content@localhost:8888'
6
+ @global_foreman_proxy_mock = 'http://global:foreman@localhost:8888'
7
+ @katello_cdn_proxy_mock = {
8
+ host: 'localhost',
9
+ port: '8888',
10
+ user: 'katello',
11
+ password: 'cdn',
12
+ scheme: 'http',
13
+ }
14
+ @katello_cdn_proxy_string_mock = 'http://katello:cdn@localhost:8888'
15
+ end
16
+
17
+ test 'selects global content proxy' do
18
+ setup_global_content_proxy
19
+ setup_global_foreman_proxy
20
+ setup_cdn_proxy do
21
+ assert_equal @global_content_proxy_mock, ForemanRhCloud.proxy_setting
22
+ end
23
+ end
24
+
25
+ test 'selects cdn proxy' do
26
+ setup_global_foreman_proxy
27
+ setup_cdn_proxy do
28
+ assert_equal @katello_cdn_proxy_string_mock, ForemanRhCloud.proxy_setting
29
+ end
30
+ end
31
+
32
+ test 'selects global foreman proxy' do
33
+ setup_global_foreman_proxy
34
+
35
+ assert_equal @global_foreman_proxy_mock, ForemanRhCloud.proxy_setting
36
+ end
37
+
38
+ def setup_global_content_proxy
39
+ http_proxy = FactoryBot.create(:http_proxy, url: @global_content_proxy_mock)
40
+ HttpProxy.stubs(:default_global_content_proxy).returns(http_proxy)
41
+ end
42
+
43
+ def setup_global_foreman_proxy
44
+ FactoryBot.create(:setting, :name => 'http_proxy', :value => @global_foreman_proxy_mock)
45
+ end
46
+
47
+ def setup_cdn_proxy
48
+ old_cdn_setting = SETTINGS[:katello][:cdn_proxy]
49
+ SETTINGS[:katello][:cdn_proxy] = @katello_cdn_proxy_mock
50
+ yield
51
+ ensure
52
+ SETTINGS[:katello][:cdn_proxy] = old_cdn_setting
53
+ end
54
+
55
+ test 'transform proxy scheme test' do
56
+ mock_http_proxy = 'http://user:password@localhost:8888'
57
+ mock_https_proxy = 'https://user:password@localhost:8888'
58
+
59
+ transformed_http_uri = URI.parse(ForemanRhCloud.transform_scheme(mock_http_proxy))
60
+ transformed_https_uri = URI.parse(ForemanRhCloud.transform_scheme(mock_https_proxy))
61
+
62
+ assert_equal 'proxy', transformed_http_uri.scheme
63
+ assert_equal 'proxys', transformed_https_uri.scheme
64
+ end
65
+ end
@@ -1,6 +1,6 @@
1
1
  require 'test_plugin_helper'
2
2
 
3
- class ReportGeneratorTest < ActiveSupport::TestCase
3
+ class SliceGeneratorTest < ActiveSupport::TestCase
4
4
  setup do
5
5
  User.current = User.find_by(login: 'secret_admin')
6
6
 
@@ -9,6 +9,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
9
9
 
10
10
  @host = FactoryBot.create(
11
11
  :host,
12
+ :redhat,
12
13
  :with_subscription,
13
14
  :with_content,
14
15
  content_view: cv.first,
@@ -43,6 +44,8 @@ class ReportGeneratorTest < ActiveSupport::TestCase
43
44
  'dmi::chassis::asset_tag',
44
45
  'insights_client::obfuscate_hostname_enabled',
45
46
  'insights_client::hostname',
47
+ 'insights_client::obfuscate_ip_enabled',
48
+ 'insights_client::ips',
46
49
  ]
47
50
  end
48
51
 
@@ -68,10 +71,42 @@ class ReportGeneratorTest < ActiveSupport::TestCase
68
71
  assert_equal @host.fqdn, actual_host['fqdn']
69
72
  assert_equal '1234', actual_host['account']
70
73
  assert_equal 1, generator.hosts_count
74
+ assert_not_nil(actual_system_profile = actual_host['system_profile'])
75
+ assert_nil actual_system_profile['number_of_cpus']
76
+ assert_nil actual_system_profile['number_of_sockets']
77
+ assert_nil actual_system_profile['cores_per_socket']
78
+ assert_nil actual_system_profile['system_memory_bytes']
79
+ assert_nil actual_system_profile['os_release']
80
+ assert_not_nil(actual_network_interfaces = actual_system_profile['network_interfaces'])
81
+ assert_not_nil(actual_nic = actual_network_interfaces.first)
82
+ refute actual_nic.key?('mtu')
83
+ refute actual_nic.key?('mac_address')
84
+ refute actual_nic.key?('name')
85
+ end
86
+
87
+ test 'hosts report fields should be present if fact exist' do
88
+ FactoryBot.create(:fact_value, fact_name: fact_names['cpu::cpu(s)'], value: '4', host: @host)
89
+ FactoryBot.create(:fact_value, fact_name: fact_names['cpu::cpu_socket(s)'], value: '2', host: @host)
90
+ FactoryBot.create(:fact_value, fact_name: fact_names['cpu::core(s)_per_socket'], value: '1', host: @host)
91
+
92
+ batch = Host.where(id: @host.id).in_batches.first
93
+ generator = create_generator(batch)
94
+
95
+ json_str = generator.render
96
+ actual = JSON.parse(json_str.join("\n"))
97
+
98
+ assert_equal 'slice_123', actual['report_slice_id']
99
+ assert_not_nil(actual_host = actual['hosts'].first)
100
+ assert_not_nil(actual_system_profile = actual_host['system_profile'])
101
+ assert_equal 4, actual_system_profile['number_of_cpus']
102
+ assert_equal 2, actual_system_profile['number_of_sockets']
103
+ assert_equal 1, actual_system_profile['cores_per_socket']
71
104
  end
72
105
 
73
106
  test 'generates ip_address and mac_address fields' do
74
- @host.interfaces << FactoryBot.build(:nic_managed)
107
+ nic = FactoryBot.build(:nic_managed)
108
+ nic.attrs['mtu'] = '1500'
109
+ @host.interfaces << nic
75
110
  batch = Host.where(id: @host.id).in_batches.first
76
111
  generator = create_generator(batch)
77
112
 
@@ -87,6 +122,89 @@ class ReportGeneratorTest < ActiveSupport::TestCase
87
122
  assert_equal 1, generator.hosts_count
88
123
  end
89
124
 
125
+ test 'generates nic fields' do
126
+ ip6 = Array.new(4) { '%x' % rand(16**4) }.join(':') + '::' + '5'
127
+ nic = FactoryBot.build(:nic_managed, ip6: ip6)
128
+ nic.attrs['mtu'] = '1500'
129
+ @host.interfaces << nic
130
+ batch = Host.where(id: @host.id).in_batches.first
131
+ generator = create_generator(batch)
132
+
133
+ json_str = generator.render
134
+ actual = JSON.parse(json_str.join("\n"))
135
+
136
+ assert_equal 'slice_123', actual['report_slice_id']
137
+ assert_not_nil(actual_host = actual['hosts'].first)
138
+ expected_ip = @host.interfaces.where.not(ip: nil).first.ip
139
+ assert_not_nil actual_host['ip_addresses'].find { |addr| addr == expected_ip }
140
+ expected_mac = @host.interfaces.where.not(mac: nil).first.mac
141
+ assert_not_nil actual_host['mac_addresses'].find { |mac| mac == expected_mac }
142
+ assert_not_nil(actual_system_profile = actual_host['system_profile'])
143
+ assert_not_nil(actual_network_interfaces = actual_system_profile['network_interfaces'])
144
+ assert_not_nil(actual_nic = actual_network_interfaces.find { |nic_node| nic_node['ipv4_addresses'].first == nic.ip })
145
+ assert_equal nic.ip, actual_nic['ipv4_addresses'].first
146
+ assert_equal nic.ip6, actual_nic['ipv6_addresses'].first
147
+ assert_equal 1500, actual_nic['mtu']
148
+ assert_equal nic.mac, actual_nic['mac_address']
149
+ assert_equal nic.identifier, actual_nic['name']
150
+ assert_equal @host.fqdn, actual_host['fqdn']
151
+ assert_equal '1234', actual_host['account']
152
+ assert_equal 1, generator.hosts_count
153
+ end
154
+
155
+ test 'generates obfuscated ip_address fields without inisghts-client' do
156
+ FactoryBot.create(:setting, :name => 'obfuscate_inventory_ips', :value => true)
157
+
158
+ @host.interfaces << FactoryBot.build(:nic_managed)
159
+ batch = Host.where(id: @host.id).in_batches.first
160
+ generator = create_generator(batch)
161
+
162
+ json_str = generator.render
163
+ actual = JSON.parse(json_str.join("\n"))
164
+
165
+ assert_equal 'slice_123', actual['report_slice_id']
166
+ assert_not_nil(actual_host = actual['hosts'].first)
167
+ assert_equal '10.230.230.1', actual_host['ip_addresses'].first
168
+ assert_not_nil(actual_system_profile = actual_host['system_profile'])
169
+ assert_not_nil(actual_network_interfaces = actual_system_profile['network_interfaces'])
170
+ assert_not_nil(actual_nic = actual_network_interfaces.first)
171
+ assert_equal '10.230.230.1', actual_nic['ipv4_addresses'].first
172
+ assert_equal @host.fqdn, actual_host['fqdn']
173
+ assert_equal '1234', actual_host['account']
174
+ assert_equal 1, generator.hosts_count
175
+ end
176
+
177
+ test 'generates obfuscated ip_address fields with inisghts-client' do
178
+ nic = FactoryBot.build(:nic_primary_and_provision)
179
+ @host.interfaces = [nic]
180
+ @host.save!
181
+
182
+ FactoryBot.create(:fact_value, fact_name: fact_names['insights_client::obfuscate_ip_enabled'], value: 'true', host: @host)
183
+ FactoryBot.create(
184
+ :fact_value,
185
+ fact_name: fact_names['insights_client::ips'],
186
+ value: "[{\"obfuscated\": \"10.230.230.100\", \"original\": \"#{nic.ip}\"}]",
187
+ host: @host
188
+ )
189
+
190
+ batch = Host.where(id: @host.id).in_batches.first
191
+ generator = create_generator(batch)
192
+
193
+ json_str = generator.render
194
+ actual = JSON.parse(json_str.join("\n"))
195
+
196
+ assert_equal 'slice_123', actual['report_slice_id']
197
+ assert_not_nil(actual_host = actual['hosts'].first)
198
+ assert_equal '10.230.230.100', actual_host['ip_addresses'].first
199
+ assert_not_nil(actual_system_profile = actual_host['system_profile'])
200
+ assert_not_nil(actual_network_interfaces = actual_system_profile['network_interfaces'])
201
+ assert_not_nil(actual_nic = actual_network_interfaces.first)
202
+ assert_equal '10.230.230.100', actual_nic['ipv4_addresses'].first
203
+ assert_equal @host.fqdn, actual_host['fqdn']
204
+ assert_equal '1234', actual_host['account']
205
+ assert_equal 1, generator.hosts_count
206
+ end
207
+
90
208
  test 'obfuscates fqdn when instructed by insights-client' do
91
209
  FactoryBot.create(:fact_value, fact_name: fact_names['insights_client::obfuscate_hostname_enabled'], value: 'true', host: @host)
92
210
  FactoryBot.create(:fact_value, fact_name: fact_names['insights_client::hostname'], value: 'obfuscated_name', host: @host)
@@ -146,6 +264,10 @@ class ReportGeneratorTest < ActiveSupport::TestCase
146
264
  end
147
265
 
148
266
  test 'generates a report with satellite facts' do
267
+ hostgroup = FactoryBot.create(:hostgroup)
268
+ @host.hostgroup = hostgroup
269
+ @host.save!
270
+
149
271
  Foreman.expects(:instance_id).twice.returns('satellite-id')
150
272
  batch = Host.where(id: @host.id).in_batches.first
151
273
  generator = create_generator(batch)
@@ -165,6 +287,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
165
287
  assert_tag(@host.content_view.name, actual_host, 'content_view')
166
288
  assert_tag(@host.location.name, actual_host, 'location')
167
289
  assert_tag(@host.organization.name, actual_host, 'organization')
290
+ assert_tag(@host.hostgroup.name, actual_host, 'hostgroup')
168
291
 
169
292
  assert_equal false, satellite_facts['is_hostname_obfuscated']
170
293
 
@@ -264,6 +387,22 @@ class ReportGeneratorTest < ActiveSupport::TestCase
264
387
  assert_equal 1, generator.hosts_count
265
388
  end
266
389
 
390
+ test 'include also hosts with non-redhat OS' do
391
+ os = @host.operatingsystem
392
+ os.name = 'Centos'
393
+ os.save!
394
+
395
+ # make a_host last
396
+ batch = ForemanInventoryUpload::Generators::Queries.for_org(@host.organization_id).first
397
+ generator = create_generator(batch)
398
+
399
+ json_str = generator.render
400
+ actual = JSON.parse(json_str.join("\n"))
401
+
402
+ assert_equal 'slice_123', actual['report_slice_id']
403
+ assert_equal 1, generator.hosts_count
404
+ end
405
+
267
406
  test 'shows system_memory_bytes in bytes' do
268
407
  FactoryBot.create(:fact_value, fact_name: fact_names['memory::memtotal'], value: '1', host: @host)
269
408
 
@@ -427,6 +566,32 @@ class ReportGeneratorTest < ActiveSupport::TestCase
427
566
  assert_equal 'alibaba', actual_profile['cloud_provider']
428
567
  end
429
568
 
569
+ test 'include packages installed in the report' do
570
+ FactoryBot.create(:setting, :name => 'exclude_installed_packages', :value => false)
571
+ installed_package = ::Katello::InstalledPackage.create(name: 'test-package', nvra: 'test-package-1.0.x86_64')
572
+
573
+ another_host = FactoryBot.create(
574
+ :host,
575
+ :with_subscription,
576
+ :with_content,
577
+ content_view: @host.content_view,
578
+ lifecycle_environment: @host.lifecycle_environment,
579
+ organization: @host.organization,
580
+ installed_packages: [installed_package]
581
+ )
582
+
583
+ batch = Host.where(id: another_host.id).in_batches.first
584
+ generator = create_generator(batch)
585
+
586
+ json_str = generator.render
587
+ actual = JSON.parse(json_str.join("\n"))
588
+
589
+ assert_equal 'slice_123', actual['report_slice_id']
590
+ assert_not_nil(actual_host = actual['hosts'].first)
591
+ assert_not_nil(actual_profile = actual_host['system_profile'])
592
+ assert_not_nil(actual_profile['installed_packages'])
593
+ end
594
+
430
595
  private
431
596
 
432
597
  def create_generator(batch, name = 'slice_123')
@@ -34,10 +34,14 @@ export const autoUploadEnabled = true;
34
34
 
35
35
  export const hostObfuscationEnabled = true;
36
36
 
37
+ export const ipsObfuscationEnabled = true;
38
+
37
39
  export const filterTerm = 'some_filter';
38
40
 
39
41
  export const cloudToken = 'some-cloud-token';
40
42
 
43
+ export const excludePackages = false;
44
+
41
45
  export const props = {
42
46
  accounts,
43
47
  fetchAccountsStatus: noop,
@@ -46,6 +50,15 @@ export const props = {
46
50
  pollingProcessID,
47
51
  };
48
52
 
53
+ export const pollingResponse = {
54
+ accounts,
55
+ autoUploadEnabled,
56
+ hostObfuscationEnabled,
57
+ ipsObfuscationEnabled,
58
+ cloudToken,
59
+ excludePackages,
60
+ };
61
+
49
62
  export const fetchAccountsStatusResponse = {
50
- data: { accounts, autoUploadEnabled, hostObfuscationEnabled, cloudToken },
63
+ data: pollingResponse,
51
64
  };
@@ -1,4 +1,5 @@
1
1
  import API from 'foremanReact/API';
2
+ import { addToast } from 'foremanReact/redux/actions/toasts';
2
3
  import { inventoryUrl } from '../../ForemanInventoryHelpers';
3
4
  import {
4
5
  INVENTORY_ACCOUNT_STATUS_POLLING,
@@ -10,17 +11,10 @@ import {
10
11
 
11
12
  export const fetchAccountsStatus = () => async dispatch => {
12
13
  try {
13
- const {
14
- data: { accounts, autoUploadEnabled, hostObfuscationEnabled, cloudToken },
15
- } = await API.get(inventoryUrl('accounts'));
14
+ const { data } = await API.get(inventoryUrl('accounts'));
16
15
  dispatch({
17
16
  type: INVENTORY_ACCOUNT_STATUS_POLLING,
18
- payload: {
19
- accounts,
20
- autoUploadEnabled,
21
- hostObfuscationEnabled,
22
- cloudToken,
23
- },
17
+ payload: data,
24
18
  });
25
19
  } catch (error) {
26
20
  dispatch({
@@ -46,7 +40,7 @@ export const stopAccountStatusPolling = pollingProcessID => dispatch => {
46
40
  });
47
41
  };
48
42
 
49
- export const restartProcess = (accountID, activeTab) => dispatch => {
43
+ export const restartProcess = (accountID, activeTab) => async dispatch => {
50
44
  let processController = null;
51
45
  let processStatusName = null;
52
46
 
@@ -58,12 +52,22 @@ export const restartProcess = (accountID, activeTab) => dispatch => {
58
52
  processStatusName = 'generate_report_status';
59
53
  }
60
54
 
61
- API.post(inventoryUrl(`${accountID}/${processController}`));
62
- dispatch({
63
- type: INVENTORY_PROCESS_RESTART,
64
- payload: {
65
- accountID,
66
- processStatusName,
67
- },
68
- });
55
+ try {
56
+ await API.post(inventoryUrl(`${accountID}/${processController}`));
57
+ dispatch({
58
+ type: INVENTORY_PROCESS_RESTART,
59
+ payload: {
60
+ accountID,
61
+ processStatusName,
62
+ },
63
+ });
64
+ } catch (error) {
65
+ dispatch(
66
+ addToast({
67
+ sticky: true,
68
+ type: 'error',
69
+ message: error.message,
70
+ })
71
+ );
72
+ }
69
73
  };