foreman_rh_cloud 3.0.33 → 4.0.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_inventory_upload/reports_controller.rb +1 -3
  3. data/app/controllers/foreman_inventory_upload/tasks_controller.rb +13 -5
  4. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +4 -4
  5. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +7 -29
  6. data/app/controllers/insights_cloud/hits_controller.rb +3 -7
  7. data/app/models/insights_client_report_status.rb +22 -11
  8. data/app/services/foreman_rh_cloud/cloud_auth.rb +0 -16
  9. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +17 -27
  10. data/app/services/foreman_rh_cloud/remediations_retriever.rb +4 -6
  11. data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +9 -0
  12. data/config/Gemfile.lock.gh_test +95 -93
  13. data/config/database.yml.example +2 -2
  14. data/config/routes.rb +1 -20
  15. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +1 -22
  16. data/lib/foreman_inventory_upload/generators/queries.rb +0 -1
  17. data/lib/foreman_inventory_upload/generators/slice.rb +5 -6
  18. data/lib/foreman_inventory_upload/generators/tags.rb +2 -11
  19. data/lib/foreman_inventory_upload.rb +1 -9
  20. data/lib/foreman_rh_cloud/engine.rb +10 -17
  21. data/lib/foreman_rh_cloud/version.rb +1 -1
  22. data/lib/foreman_rh_cloud.rb +1 -12
  23. data/lib/insights_cloud/async/insights_full_sync.rb +14 -9
  24. data/lib/insights_cloud/async/insights_resolutions_sync.rb +6 -13
  25. data/lib/insights_cloud/async/insights_rules_sync.rb +9 -13
  26. data/lib/inventory_sync/async/host_result.rb +5 -4
  27. data/lib/inventory_sync/async/inventory_full_sync.rb +10 -21
  28. data/lib/inventory_sync/async/inventory_hosts_sync.rb +3 -18
  29. data/lib/inventory_sync/async/inventory_scheduled_sync.rb +0 -12
  30. data/lib/inventory_sync/async/query_inventory_job.rb +5 -6
  31. data/lib/tasks/insights.rake +0 -15
  32. data/lib/tasks/rh_cloud_inventory.rake +1 -8
  33. data/package.json +3 -3
  34. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +0 -41
  35. data/test/factories/inventory_upload_factories.rb +1 -1
  36. data/test/jobs/insights_full_sync_test.rb +0 -1
  37. data/test/jobs/insights_resolutions_sync_test.rb +1 -11
  38. data/test/jobs/insights_rules_sync_test.rb +0 -1
  39. data/test/jobs/inventory_full_sync_test.rb +2 -38
  40. data/test/models/insights_client_report_status_test.rb +72 -70
  41. data/test/test_plugin_helper.rb +0 -55
  42. data/test/unit/fact_helpers_test.rb +2 -2
  43. data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +3 -21
  44. data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +0 -1
  45. data/test/unit/slice_generator_test.rb +27 -70
  46. data/test/unit/tags_generator_test.rb +0 -56
  47. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +0 -11
  48. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +0 -11
  49. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +63 -28
  50. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +3 -2
  51. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +19 -19
  52. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +14 -14
  53. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +0 -1
  54. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +0 -14
  55. data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +13 -20
  56. data/webpack/InsightsCloudSync/InsightsCloudSync.js +1 -4
  57. data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +20 -44
  58. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +0 -2
  59. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +2 -2
  60. data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +7 -11
  61. metadata +4 -32
  62. data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +0 -50
  63. data/app/controllers/concerns/inventory_upload/report_actions.rb +0 -26
  64. data/app/controllers/concerns/inventory_upload/task_actions.rb +0 -25
  65. data/app/helpers/foreman_insights_deprecations_helper.rb +0 -9
  66. data/app/helpers/foreman_insights_host_helper.rb +0 -19
  67. data/app/overrides/old_plugin_deprecation.rb +0 -20
  68. data/app/services/foreman_rh_cloud/cloud_request.rb +0 -14
  69. data/app/services/foreman_rh_cloud/insights_status_cleaner.rb +0 -17
  70. data/config/package-lock.json.plugin +0 -32774
  71. data/db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb +0 -6
  72. data/lib/insights_cloud/async/insights_client_status_aging.rb +0 -23
  73. data/lib/inventory_sync/async/inventory_self_host_sync.rb +0 -39
  74. data/test/controllers/inventory_upload/api/inventory_controller_test.rb +0 -53
  75. data/test/jobs/insights_client_status_aging_test.rb +0 -33
  76. data/test/jobs/inventory_hosts_sync_test.rb +0 -283
  77. data/test/jobs/inventory_scheduled_sync_test.rb +0 -22
  78. data/test/jobs/inventory_self_host_sync_test.rb +0 -104
  79. data/test/unit/foreman_rh_cloud_self_host_test.rb +0 -28
  80. data/test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb +0 -31
  81. data/webpack/common/ForemanTasks/ForemanTasksActions.js +0 -64
  82. data/webpack/common/ForemanTasks/ForemanTasksHelpers.js +0 -7
  83. data/webpack/common/ForemanTasks/index.js +0 -1
@@ -1,6 +0,0 @@
1
- class RemoveOldInsightsStatuses < ActiveRecord::Migration[5.2]
2
- def up
3
- InsightsClientReportStatus.where(status: 2).update_all(status: InsightsClientReportStatus::NO_REPORT)
4
- InsightsClientReportStatus.where(status: 3).update_all(status: InsightsClientReportStatus::REPORTING)
5
- end
6
- end
@@ -1,23 +0,0 @@
1
- module InsightsCloud
2
- module Async
3
- class InsightsClientStatusAging < ::Actions::EntryAction
4
- include ::Actions::RecurringAction
5
-
6
- def run
7
- host_ids = InsightsClientReportStatus.stale.reporting.pluck(:host_id)
8
-
9
- # update all stale records
10
- InsightsClientReportStatus.where(host_id: host_ids).update_all(status: InsightsClientReportStatus::NO_REPORT)
11
-
12
- # refresh global status
13
- Host.where(id: host_ids).preload(:host_statuses).find_in_batches do |hosts|
14
- hosts.each { |host| host.refresh_global_status! }
15
- end
16
- end
17
-
18
- def logger
19
- action_logger
20
- end
21
- end
22
- end
23
- end
@@ -1,39 +0,0 @@
1
- module InventorySync
2
- module Async
3
- class InventorySelfHostSync < QueryInventoryJob
4
- set_callback :step, :around, :create_facets
5
-
6
- def plan
7
- unless cloud_auth_available?
8
- logger.debug('Cloud authentication is not available, skipping self host sync')
9
- return
10
- end
11
-
12
- plan_self
13
- end
14
-
15
- def create_facets
16
- # get the results from the event
17
- results = yield
18
-
19
- add_missing_insights_facet(results.uuid_by_fqdn) unless results.uuid_by_fqdn.empty?
20
- results
21
- end
22
-
23
- private
24
-
25
- def add_missing_insights_facet(uuids_hash)
26
- facet = InsightsFacet.find_or_create_by(host_id: ForemanRhCloud.foreman_host.id) do |facet|
27
- facet.uuid = uuids_hash.values.first
28
- end
29
-
30
- # fix empty uuid in case the facet already exists
31
- facet.update(uuid: uuids_hash.values.first) unless facet.uuid
32
- end
33
-
34
- def request_url
35
- ForemanInventoryUpload.inventory_self_url
36
- end
37
- end
38
- end
39
- end
@@ -1,53 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- module InventoryUpload::Api
4
- class InventoryControllerTest < ActionController::TestCase
5
- tests Api::V2::RhCloud::InventoryController
6
-
7
- setup do
8
- @test_org = FactoryBot.create(:organization)
9
- end
10
-
11
- test 'Starts report generation' do
12
- Api::V2::RhCloud::InventoryController.any_instance
13
- .expects(:start_report_generation)
14
- .with(@test_org.id.to_s)
15
-
16
- post :generate_report, params: { organization_id: @test_org.id }
17
-
18
- assert_response :success
19
- end
20
-
21
- test 'Starts inventory sync action' do
22
- test_task = FactoryBot.create(:some_task)
23
-
24
- Api::V2::RhCloud::InventoryController.any_instance
25
- .expects(:start_inventory_sync)
26
- .with() { |actual_org| @test_org.id == actual_org.id }
27
- .returns(test_task)
28
-
29
- post :sync_inventory_status, params: { organization_id: @test_org.id }
30
-
31
- assert_response :success
32
-
33
- assert_not_nil(actual_task = @response.parsed_body['task'])
34
- assert_equal test_task.id.to_s, actual_task['id']
35
- end
36
-
37
- test 'Starts cloud connector configuration job' do
38
- test_job = FactoryBot.create(:job_invocation)
39
-
40
- ForemanRhCloud::CloudConnector.any_instance
41
- .expects(:install)
42
- .returns(test_job)
43
-
44
- post :enable_cloud_connector
45
-
46
- assert_response :success
47
-
48
- actual_job = @response.parsed_body
49
-
50
- assert_equal test_job.id, actual_job['id']
51
- end
52
- end
53
- end
@@ -1,33 +0,0 @@
1
- require 'test_plugin_helper'
2
- require 'foreman_tasks/test_helpers'
3
-
4
- class InsightsClientStatusAgingTest < ActiveSupport::TestCase
5
- include ForemanTasks::TestHelpers::WithInThreadExecutor
6
-
7
- setup do
8
- User.current = User.find_by(login: 'secret_admin')
9
-
10
- @host1 = FactoryBot.create(:host)
11
- @host2 = FactoryBot.create(:host)
12
- @host3 = FactoryBot.create(:host)
13
- @host4 = FactoryBot.create(:host)
14
-
15
- @hosts = [@host1, @host2, @host3, @host4]
16
- end
17
-
18
- test 'stale statuses should change' do
19
- InsightsClientReportStatus.find_or_initialize_by(host_id: @host1.id).update(status: InsightsClientReportStatus::REPORTING, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL + 1.day)
20
- InsightsClientReportStatus.find_or_initialize_by(host_id: @host2.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL + 1.day)
21
- InsightsClientReportStatus.find_or_initialize_by(host_id: @host3.id).update(status: InsightsClientReportStatus::REPORTING, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)
22
- InsightsClientReportStatus.find_or_initialize_by(host_id: @host4.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)
23
-
24
- ForemanTasks.sync_task(InsightsCloud::Async::InsightsClientStatusAging)
25
-
26
- @hosts.each(&:reload)
27
-
28
- assert_equal InsightsClientReportStatus::REPORTING, @host1.get_status(InsightsClientReportStatus).status
29
- assert_equal InsightsClientReportStatus::NO_REPORT, @host2.get_status(InsightsClientReportStatus).status
30
- assert_equal InsightsClientReportStatus::NO_REPORT, @host3.get_status(InsightsClientReportStatus).status
31
- assert_equal InsightsClientReportStatus::NO_REPORT, @host4.get_status(InsightsClientReportStatus).status
32
- end
33
- end
@@ -1,283 +0,0 @@
1
- require 'test_plugin_helper'
2
- require 'foreman_tasks/test_helpers'
3
-
4
- class InventoryHostsSyncTest < ActiveSupport::TestCase
5
- include ForemanTasks::TestHelpers::WithInThreadExecutor
6
-
7
- setup do
8
- User.current = User.find_by(login: 'secret_admin')
9
- FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
10
-
11
- env = FactoryBot.create(:katello_k_t_environment)
12
- cv = env.content_views << FactoryBot.create(:katello_content_view, organization: env.organization)
13
-
14
- # this host would pass our plugin queries, so it could be uploaded to the cloud.
15
- @host1 = FactoryBot.create(
16
- :host,
17
- :with_subscription,
18
- :with_content,
19
- content_view: cv.first,
20
- lifecycle_environment: env,
21
- organization: env.organization
22
- )
23
-
24
- pool = FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
25
-
26
- @host1.subscription_facet.pools << pool
27
-
28
- # this host would pass our plugin queries, so it could be uploaded to the cloud.
29
- @host2 = FactoryBot.create(
30
- :host,
31
- :with_subscription,
32
- :with_content,
33
- content_view: cv.first,
34
- lifecycle_environment: env,
35
- organization: env.organization
36
- )
37
-
38
- @host2.subscription_facet.pools << pool
39
- @host2_inventory_id = '4536bf5c-ff03-4154-a8c9-32ff4b40e40c'
40
-
41
- ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
42
-
43
- inventory_json = <<-INVENTORY_JSON
44
- {
45
- "total": 3,
46
- "count": 3,
47
- "page": 1,
48
- "per_page": 3,
49
- "results": [
50
- {
51
- "insights_id": "72d29d75-dbbf-4121-9566-2f581ab77f36",
52
- "rhel_machine_id": null,
53
- "subscription_manager_id": "#{@host2.subscription_facet.uuid}",
54
- "satellite_id": "bb72bf95-0a19-4090-8009-f0d8c68aca61",
55
- "bios_uuid": "b48a7e5f-cb50-4029-a75e-366bf43db641",
56
- "ip_addresses": [
57
- "192.168.122.56"
58
- ],
59
- "fqdn": "#{@host2.fqdn}",
60
- "mac_addresses": [
61
- "52:54:00:aa:12:12",
62
- "00:00:00:00:00:00"
63
- ],
64
- "external_id": null,
65
- "id": "#{@host2_inventory_id}",
66
- "account": "1460290",
67
- "display_name": "insights-rh7.example.com",
68
- "ansible_host": null,
69
- "facts": [
70
- {
71
- "namespace": "satellite",
72
- "facts": {
73
- "virtual_host_name": "virt-who-nobody.home-1",
74
- "satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
75
- "is_simple_content_access": false,
76
- "distribution_version": "7.3",
77
- "satellite_version": "6.8.4",
78
- "organization_id": 1,
79
- "is_hostname_obfuscated": false,
80
- "virtual_host_uuid": "a90e6294-4766-420a-8dc0-3ec5b96d60ec"
81
- }
82
- },
83
- {
84
- "namespace": "yupana",
85
- "facts": {
86
- "report_platform_id": "d37afa50-08ce-4efb-a0e5-759c2a016661",
87
- "report_slice_id": "5bf791d7-5e30-4a3c-929a-11dd9fa6eb72",
88
- "source": "Satellite",
89
- "yupana_host_id": "e85958b6-58db-4cfd-aeb6-01ee81bc0f43",
90
- "account": "1460290"
91
- }
92
- }
93
- ],
94
- "reporter": "puptoo",
95
- "stale_timestamp": "2021-03-19T07:57:42.466399+00:00",
96
- "stale_warning_timestamp": "2021-03-26T07:57:42.466399+00:00",
97
- "culled_timestamp": "2021-04-02T07:57:42.466399+00:00",
98
- "created": "2021-02-08T14:36:03.613880+00:00",
99
- "updated": "2021-03-18T02:57:42.535250+00:00"
100
- },
101
- {
102
- "insights_id": "e0dc5144-d78e-43ed-97be-a7a21d1b6946",
103
- "rhel_machine_id": null,
104
- "subscription_manager_id": "0f97ee19-6862-4900-aea4-f121c8754776",
105
- "satellite_id": "0f97ee19-6862-4900-aea4-f121c8754776",
106
- "bios_uuid": "6a0b199a-8225-4ade-ae44-3b18cfc84a01",
107
- "ip_addresses": [
108
- "192.168.122.136"
109
- ],
110
- "fqdn": "#{@host1.fqdn}",
111
- "mac_addresses": [
112
- "52:54:00:02:d1:2a",
113
- "00:00:00:00:00:00"
114
- ],
115
- "external_id": null,
116
- "id": "3255d080-e6c1-44e2-8d72-b044b9a38d8f",
117
- "account": "1460290",
118
- "display_name": "insights-rh8.example.com",
119
- "ansible_host": null,
120
- "facts": [
121
- {
122
- "namespace": "satellite",
123
- "facts": {
124
- "virtual_host_name": "virt-who-nobody.home-1",
125
- "satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
126
- "is_simple_content_access": false,
127
- "distribution_version": "8.3",
128
- "satellite_version": "6.8.4",
129
- "organization_id": 1,
130
- "is_hostname_obfuscated": false,
131
- "virtual_host_uuid": "a90e6294-4766-420a-8dc0-3ec5b96d60ec"
132
- }
133
- },
134
- {
135
- "namespace": "yupana",
136
- "facts": {
137
- "report_platform_id": "d37afa50-08ce-4efb-a0e5-759c2a016661",
138
- "report_slice_id": "5bf791d7-5e30-4a3c-929a-11dd9fa6eb72",
139
- "source": "Satellite",
140
- "yupana_host_id": "78c62486-0ac4-406c-a4c0-3a1f81112a2d",
141
- "account": "1460290"
142
- }
143
- }
144
- ],
145
- "reporter": "puptoo",
146
- "stale_timestamp": "2021-03-19T06:05:12.092136+00:00",
147
- "stale_warning_timestamp": "2021-03-26T06:05:12.092136+00:00",
148
- "culled_timestamp": "2021-04-02T06:05:12.092136+00:00",
149
- "created": "2021-02-08T13:22:50.555671+00:00",
150
- "updated": "2021-03-18T01:05:12.131847+00:00"
151
- },
152
- {
153
- "insights_id": "b533848e-465f-4f1a-9b2b-b71cb2d5239d",
154
- "rhel_machine_id": null,
155
- "subscription_manager_id": "d29bde40-348e-437c-8acf-8fa98320fc1b",
156
- "satellite_id": "d29bde40-348e-437c-8acf-8fa98320fc1b",
157
- "bios_uuid": "3cd5d972-cfb5-451a-8314-fd2f56629d7c",
158
- "ip_addresses": [
159
- "172.16.5.39",
160
- "fd6e:2298:736e::857",
161
- "fd6e:2298:736e:0:2c66:6101:9cc6:2b23"
162
- ],
163
- "fqdn": "rhel8-demo.oss-lab.net",
164
- "mac_addresses": [
165
- "6e:66:a6:fe:fc:07",
166
- "00:00:00:00:00:00"
167
- ],
168
- "external_id": null,
169
- "id": "59ab38db-c25b-4fc7-bfb2-c8eb01d865a9",
170
- "account": "1460290",
171
- "display_name": "rhel8-demo.oss-lab.net",
172
- "ansible_host": null,
173
- "facts": [
174
- {
175
- "namespace": "satellite",
176
- "facts": {
177
- "satellite_instance_id": "fb3643d8-9030-487b-b95c-684783806ffd",
178
- "system_purpose_sla": "",
179
- "is_simple_content_access": false,
180
- "distribution_version": "8.3",
181
- "satellite_version": "6.8.1",
182
- "organization_id": 1,
183
- "system_purpose_role": "",
184
- "system_purpose_usage": "",
185
- "is_hostname_obfuscated": false
186
- }
187
- },
188
- {
189
- "namespace": "yupana",
190
- "facts": {
191
- "report_platform_id": "fa8b924c-51ee-479d-97d2-b4623cf1d4aa",
192
- "report_slice_id": "0b49103f-6471-4ade-ad74-a51537bc5691",
193
- "source": "Satellite",
194
- "yupana_host_id": "30e43340-12fb-445d-b23f-faaf5cbc2092",
195
- "account": "1460290"
196
- }
197
- }
198
- ],
199
- "reporter": "puptoo",
200
- "stale_timestamp": "2021-03-19T05:55:23.700781+00:00",
201
- "stale_warning_timestamp": "2021-03-26T05:55:23.700781+00:00",
202
- "culled_timestamp": "2021-04-02T05:55:23.700781+00:00",
203
- "created": "2021-01-13T20:05:51.059012+00:00",
204
- "updated": "2021-03-18T00:55:23.739162+00:00"
205
- }
206
- ]
207
- }
208
- INVENTORY_JSON
209
- @inventory = JSON.parse(inventory_json)
210
- end
211
-
212
- def interesting_facts
213
- [
214
- 'dmi::system::uuid',
215
- 'virt::uuid',
216
- 'cpu::cpu(s)',
217
- 'cpu::cpu_socket(s)',
218
- 'cpu::core(s)_per_socket',
219
- 'memory::memtotal',
220
- 'dmi::bios::vendor',
221
- 'dmi::bios::version',
222
- 'dmi::bios::relase_date',
223
- 'uname::release',
224
- 'lscpu::flags',
225
- 'distribution::name',
226
- 'distribution::version',
227
- 'distribution::id',
228
- 'virt::is_guest',
229
- 'dmi::system::manufacturer',
230
- 'dmi::system::product_name',
231
- 'dmi::chassis::asset_tag',
232
- 'insights_client::obfuscate_hostname_enabled',
233
- 'insights_client::hostname',
234
- ]
235
- end
236
-
237
- def fact_names
238
- @fact_names ||= Hash[
239
- interesting_facts.map do |fact|
240
- [fact, FactoryBot.create(:fact_name, name: fact, type: 'Katello::RhsmFactName')]
241
- end
242
- ]
243
- end
244
-
245
- test 'Inventory should sync UUID for existing Insights Facets' do
246
- InventorySync::Async::InventoryHostsSync.any_instance.expects(:query_inventory).returns(@inventory)
247
- InventorySync::Async::InventoryHostsSync.any_instance.expects(:plan_self_host_sync)
248
-
249
- @host2.build_insights.save
250
-
251
- ForemanTasks.sync_task(InventorySync::Async::InventoryHostsSync)
252
-
253
- @host2.reload
254
-
255
- assert_equal @host2_inventory_id, @host2.insights.uuid
256
- end
257
-
258
- test 'Inventory should sync UUID for new Insights Facets' do
259
- InventorySync::Async::InventoryHostsSync.any_instance.expects(:query_inventory).returns(@inventory)
260
- InventorySync::Async::InventoryHostsSync.any_instance.expects(:plan_self_host_sync)
261
-
262
- ForemanTasks.sync_task(InventorySync::Async::InventoryHostsSync)
263
-
264
- @host2.reload
265
-
266
- assert_equal @host2_inventory_id, @host2.insights.uuid
267
- end
268
-
269
- test 'Inventory should sync empty facets list' do
270
- empty_inventory = @inventory.deep_clone
271
- empty_inventory['results'] = []
272
- InventorySync::Async::InventoryHostsSync.any_instance.expects(:query_inventory).returns(empty_inventory)
273
- InventorySync::Async::InventoryHostsSync.any_instance.expects(:plan_self_host_sync)
274
-
275
- assert_nil @host2.insights
276
-
277
- ForemanTasks.sync_task(InventorySync::Async::InventoryHostsSync)
278
-
279
- @host2.reload
280
-
281
- assert_nil @host2.insights
282
- end
283
- end
@@ -1,22 +0,0 @@
1
- require 'test_plugin_helper'
2
- require 'foreman_tasks/test_helpers'
3
-
4
- class InventoryScheduledSyncTest < ActiveSupport::TestCase
5
- include ForemanTasks::TestHelpers::WithInThreadExecutor
6
-
7
- test 'Schedules an execution if auto upload is enabled' do
8
- FactoryBot.create(:setting, :name => 'allow_auto_inventory_upload', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => true)
9
-
10
- InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).times(Organization.unscoped.count)
11
-
12
- ForemanTasks.sync_task(InventorySync::Async::InventoryScheduledSync)
13
- end
14
-
15
- test 'Skips execution if auto upload is disabled' do
16
- FactoryBot.create(:setting, :name => 'allow_auto_inventory_upload', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => false)
17
-
18
- InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).never
19
-
20
- ForemanTasks.sync_task(InventorySync::Async::InventoryScheduledSync)
21
- end
22
- end
@@ -1,104 +0,0 @@
1
- require 'test_plugin_helper'
2
- require 'foreman_tasks/test_helpers'
3
-
4
- class InventorySelfHostSyncTest < ActiveSupport::TestCase
5
- include ForemanTasks::TestHelpers::WithInThreadExecutor
6
-
7
- setup do
8
- User.current = User.find_by(login: 'secret_admin')
9
- FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
10
-
11
- # this host would pass our plugin queries, so it could be uploaded to the cloud.
12
- @host1 = FactoryBot.create(:host)
13
- @host1_inventory_id = '3255d080-e6c1-44e2-8d72-b044b9a38d8f'
14
-
15
- ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
16
-
17
- ForemanRhCloud.stubs(:foreman_host).returns(@host1)
18
-
19
- inventory_json = <<-INVENTORY_JSON
20
- {
21
- "total": 1,
22
- "count": 1,
23
- "page": 1,
24
- "per_page": 1,
25
- "results": [
26
- {
27
- "insights_id": "e0dc5144-d78e-43ed-97be-a7a21d1b6946",
28
- "rhel_machine_id": null,
29
- "subscription_manager_id": "0f97ee19-6862-4900-aea4-f121c8754776",
30
- "satellite_id": "0f97ee19-6862-4900-aea4-f121c8754776",
31
- "bios_uuid": "6a0b199a-8225-4ade-ae44-3b18cfc84a01",
32
- "ip_addresses": [
33
- "192.168.122.136"
34
- ],
35
- "fqdn": "#{@host1.fqdn}",
36
- "mac_addresses": [
37
- "52:54:00:02:d1:2a",
38
- "00:00:00:00:00:00"
39
- ],
40
- "external_id": null,
41
- "id": "#{@host1_inventory_id}",
42
- "account": "1460290",
43
- "display_name": "insights-rh8.example.com",
44
- "ansible_host": null,
45
- "facts": [
46
- {
47
- "namespace": "satellite",
48
- "facts": {
49
- "virtual_host_name": "virt-who-nobody.home-1",
50
- "satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
51
- "is_simple_content_access": false,
52
- "distribution_version": "8.3",
53
- "satellite_version": "6.8.4",
54
- "organization_id": 1,
55
- "is_hostname_obfuscated": false,
56
- "virtual_host_uuid": "a90e6294-4766-420a-8dc0-3ec5b96d60ec"
57
- }
58
- },
59
- {
60
- "namespace": "yupana",
61
- "facts": {
62
- "report_platform_id": "d37afa50-08ce-4efb-a0e5-759c2a016661",
63
- "report_slice_id": "5bf791d7-5e30-4a3c-929a-11dd9fa6eb72",
64
- "source": "Satellite",
65
- "yupana_host_id": "78c62486-0ac4-406c-a4c0-3a1f81112a2d",
66
- "account": "1460290"
67
- }
68
- }
69
- ],
70
- "reporter": "puptoo",
71
- "stale_timestamp": "2021-03-19T06:05:12.092136+00:00",
72
- "stale_warning_timestamp": "2021-03-26T06:05:12.092136+00:00",
73
- "culled_timestamp": "2021-04-02T06:05:12.092136+00:00",
74
- "created": "2021-02-08T13:22:50.555671+00:00",
75
- "updated": "2021-03-18T01:05:12.131847+00:00"
76
- }
77
- ]
78
- }
79
- INVENTORY_JSON
80
- @inventory = JSON.parse(inventory_json)
81
- end
82
-
83
- test 'Inventory should sync UUID for existing Insights Facets' do
84
- InventorySync::Async::InventorySelfHostSync.any_instance.expects(:query_inventory).returns(@inventory)
85
-
86
- @host1.build_insights.save
87
-
88
- ForemanTasks.sync_task(InventorySync::Async::InventorySelfHostSync)
89
-
90
- @host1.reload
91
-
92
- assert_equal @host1_inventory_id, @host1.insights.uuid
93
- end
94
-
95
- test 'Inventory should sync UUID for new Insights Facets' do
96
- InventorySync::Async::InventorySelfHostSync.any_instance.expects(:query_inventory).returns(@inventory)
97
-
98
- ForemanTasks.sync_task(InventorySync::Async::InventorySelfHostSync)
99
-
100
- @host1.reload
101
-
102
- assert_equal @host1_inventory_id, @host1.insights.uuid
103
- end
104
- end
@@ -1,28 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- class ForemanRhCloudSelfHostTest < ActiveSupport::TestCase
4
- setup do
5
- # reset cached value
6
- ForemanRhCloud.instance_variable_set(:@foreman_host, nil)
7
- end
8
-
9
- test 'finds host by fullname' do
10
- @domain
11
- @host = FactoryBot.create(:host, :managed)
12
- ForemanRhCloud.expects(:foreman_host_name).returns(@host.name)
13
-
14
- actual = ForemanRhCloud.foreman_host
15
-
16
- assert_not_nil actual
17
- end
18
-
19
- test 'finds host by shortname' do
20
- @host = FactoryBot.create(:host, :managed)
21
- Host.where(name: @host.name).update_all(name: @host.shortname)
22
- ForemanRhCloud.expects(:foreman_host_name).returns(@host.name)
23
-
24
- actual = ForemanRhCloud.foreman_host
25
-
26
- assert_not_nil actual
27
- end
28
- end
@@ -1,31 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- class InsightsStatusCleanerTest < ActiveSupport::TestCase
4
- setup do
5
- @host1 = FactoryBot.create(:host)
6
- @host2 = FactoryBot.create(:host)
7
-
8
- InsightsClientReportStatus.find_or_initialize_by(host_id: @host1.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL + 1.day)
9
- InsightsClientReportStatus.find_or_initialize_by(host_id: @host2.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL + 1.day)
10
-
11
- @host1.refresh_global_status!
12
- @host2.refresh_global_status!
13
- end
14
-
15
- test 'Cleans hosts by search condition' do
16
- assert_equal HostStatus::Global::ERROR, @host1.global_status
17
- assert_equal HostStatus::Global::ERROR, @host2.global_status
18
-
19
- instance = ForemanRhCloud::InsightsStatusCleaner.new
20
- actual_count = instance.clean("name = #{@host1.name}")
21
-
22
- @host1.reload
23
- @host2.refresh_global_status!
24
-
25
- assert_equal 1, actual_count
26
- assert_equal HostStatus::Global::OK, @host1.global_status
27
- assert_equal HostStatus::Global::ERROR, @host2.global_status
28
- assert InsightsClientReportStatus.where(host_id: @host1.id).empty?
29
- refute InsightsClientReportStatus.where(host_id: @host2.id).empty?
30
- end
31
- end