foreman_rh_cloud 4.0.25.1 → 5.0.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +4 -1
- data/app/controllers/concerns/inventory_upload/report_actions.rb +1 -1
- data/app/controllers/foreman_inventory_upload/reports_controller.rb +1 -1
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +8 -0
- data/app/controllers/insights_cloud/hits_controller.rb +1 -1
- data/app/models/insights_hit.rb +4 -0
- data/app/models/setting/rh_cloud.rb +0 -1
- data/app/models/task_output_line.rb +2 -0
- data/app/models/task_output_status.rb +2 -0
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +14 -2
- data/config/Gemfile.lock.gh_test +169 -152
- data/config/database.yml.example +2 -2
- data/config/package-lock.json.plugin +10551 -7500
- data/config/routes.rb +1 -1
- data/db/migrate/20211027000001_create_task_output.foreman_rh_cloud.rb +18 -0
- data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +11 -7
- data/lib/foreman_inventory_upload/async/generate_report_job.rb +24 -12
- data/lib/foreman_inventory_upload/async/progress_output.rb +5 -28
- data/lib/foreman_inventory_upload/async/queue_for_upload_job.rb +20 -5
- data/lib/foreman_inventory_upload/async/shell_process.rb +17 -4
- data/lib/foreman_inventory_upload/async/upload_report_job.rb +22 -13
- data/lib/foreman_inventory_upload/generators/queries.rb +1 -0
- data/lib/foreman_inventory_upload/generators/tags.rb +1 -2
- data/lib/foreman_rh_cloud/engine.rb +4 -10
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/foreman_rh_cloud.rb +12 -1
- data/lib/insights_cloud/async/insights_client_status_aging.rb +4 -0
- data/lib/insights_cloud/async/insights_full_sync.rb +4 -0
- data/lib/insights_cloud/async/insights_generate_notifications.rb +4 -0
- data/lib/insights_cloud/async/insights_resolutions_sync.rb +7 -2
- data/lib/insights_cloud/async/insights_rules_sync.rb +10 -2
- data/lib/insights_cloud/async/insights_scheduled_sync.rb +11 -7
- data/lib/inventory_sync/async/host_result.rb +0 -5
- data/lib/inventory_sync/async/inventory_full_sync.rb +18 -9
- data/lib/inventory_sync/async/inventory_hosts_sync.rb +6 -6
- data/lib/inventory_sync/async/inventory_scheduled_sync.rb +4 -0
- data/lib/inventory_sync/async/inventory_self_host_sync.rb +4 -0
- data/lib/inventory_sync/async/query_inventory_job.rb +4 -0
- data/lib/tasks/rh_cloud_inventory.rake +2 -2
- data/package.json +8 -13
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +16 -39
- data/test/controllers/insights_sync/settings_controller_test.rb +2 -2
- data/test/controllers/uploads_settings_controller_test.rb +2 -2
- data/test/factories/inventory_upload_factories.rb +14 -0
- data/test/jobs/insights_full_sync_test.rb +2 -2
- data/test/jobs/insights_resolutions_sync_test.rb +11 -2
- data/test/jobs/insights_rules_sync_test.rb +2 -2
- data/test/jobs/inventory_full_sync_test.rb +31 -5
- data/test/jobs/inventory_hosts_sync_test.rb +16 -1
- data/test/jobs/inventory_scheduled_sync_test.rb +2 -2
- data/test/jobs/inventory_self_host_sync_test.rb +1 -1
- data/test/jobs/upload_report_job_test.rb +6 -4
- data/test/test_plugin_helper.rb +0 -2
- data/test/unit/foreman_rh_cloud_self_host_test.rb +28 -0
- data/test/unit/rh_cloud_http_proxy_test.rb +1 -1
- data/test/unit/services/foreman_rh_cloud/branch_info_test.rb +1 -1
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +26 -0
- data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +1 -1
- data/test/unit/shell_process_job_test.rb +3 -1
- data/test/unit/slice_generator_test.rb +39 -7
- data/test/unit/tags_generator_test.rb +20 -20
- data/webpack/ForemanInventoryUpload/Components/AccountList/accountList.scss +8 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.scss +17 -4
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageTitle.js +29 -17
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageTitle.test.js.snap +58 -47
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +12 -10
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +10 -10
- data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/__snapshots__/InventoryAutoUpload.test.js.snap +1 -1
- data/webpack/ForemanRhCloudFills.js +7 -0
- data/webpack/InsightsCloudSync/Components/InsightsHeader/index.js +0 -2
- data/webpack/InsightsCloudSync/Components/InsightsSettings/insightsSettings.scss +1 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +22 -6
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +23 -16
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableConstants.js +49 -2
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js +31 -14
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +19 -2
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +0 -1
- data/webpack/InsightsCloudSync/Components/InsightsTable/table.scss +11 -13
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +0 -14
- data/webpack/InsightsCloudSync/Components/ToolbarDropdown.js +13 -0
- data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/InsightsHeader.test.js.snap +0 -1
- data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +24 -13
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +2 -0
- data/webpack/InsightsCloudSync/InsightsCloudSyncHelpers.js +8 -0
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +2 -1
- data/webpack/InsightsHostDetailsTab/InsightsTab.scss +4 -0
- data/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js +104 -0
- data/webpack/__mocks__/foremanReact/components/Head.js +11 -0
- data/webpack/common/DropdownToggle.js +24 -0
- data/webpack/common/Switcher/HelpLabel.js +1 -1
- data/webpack/common/Switcher/__tests__/__snapshots__/HelpLabel.test.js.snap +1 -1
- data/webpack/common/Switcher/__tests__/__snapshots__/SwitcherPF4.test.js.snap +1 -0
- metadata +11 -3
@@ -12,7 +12,7 @@ namespace :rh_cloud_inventory do
|
|
12
12
|
|
13
13
|
User.as_anonymous_admin do
|
14
14
|
organizations.each do |organization|
|
15
|
-
ForemanInventoryUpload::Async::GenerateReportJob
|
15
|
+
ForemanTasks.async_task(ForemanInventoryUpload::Async::GenerateReportJob, ForemanInventoryUpload.generated_reports_folder, organization.id)
|
16
16
|
puts "Generated and uploaded inventory report for organization '#{organization.name}'"
|
17
17
|
end
|
18
18
|
end
|
@@ -47,7 +47,7 @@ namespace :rh_cloud_inventory do
|
|
47
47
|
base_folder = ENV['target'] || ForemanInventoryUpload.generated_reports_folder
|
48
48
|
organization_id = ENV['organization_id']
|
49
49
|
report_file = ForemanInventoryUpload.facts_archive_name(organization_id)
|
50
|
-
ForemanInventoryUpload::Async::QueueForUploadJob
|
50
|
+
ForemanTasks.sync_task(ForemanInventoryUpload::Async::QueueForUploadJob, base_folder, report_file, organization_id)
|
51
51
|
puts "Uploaded #{report_file}"
|
52
52
|
end
|
53
53
|
end
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "foreman_rh_cloud",
|
3
|
-
"version": "
|
3
|
+
"version": "5.0.29",
|
4
4
|
"description": "Inventory Upload =============",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
@@ -22,27 +22,22 @@
|
|
22
22
|
"url": "http://projects.theforeman.org/projects/foreman_rh_cloud/issues"
|
23
23
|
},
|
24
24
|
"peerDependencies": {
|
25
|
-
"@theforeman/vendor": "~
|
25
|
+
"@theforeman/vendor": "~8.16.0"
|
26
26
|
},
|
27
27
|
"devDependencies": {
|
28
28
|
"@babel/core": "~7.7.0",
|
29
|
-
"@
|
30
|
-
"@theforeman/
|
31
|
-
"@theforeman/
|
32
|
-
"@theforeman/
|
33
|
-
"@theforeman/vendor-dev": "~4.14.0",
|
34
|
-
"@theforeman/eslint-plugin-foreman": "~4.14.0",
|
29
|
+
"@theforeman/builder": "~8.16.0",
|
30
|
+
"@theforeman/stories": "~8.16.0",
|
31
|
+
"@theforeman/test": "~8.16.0",
|
32
|
+
"@theforeman/eslint-plugin-foreman": "~8.16.0",
|
35
33
|
"babel-eslint": "~10.0.0",
|
36
34
|
"eslint": "~6.7.2",
|
37
35
|
"eslint-plugin-spellcheck": "~0.0.17",
|
36
|
+
"jed": "~1.1.1",
|
38
37
|
"prettier": "~1.19.1",
|
39
38
|
"stylelint": "~9.3.0",
|
40
39
|
"stylelint-config-standard": "~18.0.0",
|
41
40
|
"surge": "~0.20.3",
|
42
41
|
"redux-mock-store": "~1.2.2"
|
43
|
-
},
|
44
|
-
"dependencies": {
|
45
|
-
"jed": "~1.1.1",
|
46
|
-
"react-intl": "~2.8.0"
|
47
42
|
}
|
48
|
-
}
|
43
|
+
}
|
@@ -7,6 +7,8 @@ module InsightsCloud::Api
|
|
7
7
|
end
|
8
8
|
|
9
9
|
context '#forward_request' do
|
10
|
+
include MockCerts
|
11
|
+
|
10
12
|
setup do
|
11
13
|
@body = 'Cloud response body'
|
12
14
|
@http_req = RestClient::Request.new(:method => 'GET', :url => 'http://test.theforeman.org')
|
@@ -16,38 +18,9 @@ module InsightsCloud::Api
|
|
16
18
|
User.current = ::Katello::CpConsumerUser.new(:uuid => host.subscription_facet.uuid, :login => host.subscription_facet.uuid)
|
17
19
|
InsightsCloud::Api::MachineTelemetriesController.any_instance.stubs(:upstream_owner).returns({ 'uuid' => 'abcdefg' })
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
"FzAVBgNVBAMMDnRoZWZvcmVtYW4ub3JnMB4XDTE4MDMyNDEyMzYyOFoXDT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
-
"-----END CERTIFICATE-----"
|
21
|
+
setup_certs_expectation do
|
22
|
+
InsightsCloud::Api::MachineTelemetriesController.any_instance.stubs(:candlepin_id_cert)
|
23
|
+
end
|
51
24
|
end
|
52
25
|
|
53
26
|
test "should respond with response from cloud" do
|
@@ -67,13 +40,6 @@ module InsightsCloud::Api
|
|
67
40
|
::ForemanRhCloud::CloudRequestForwarder.any_instance.expects(:execute_cloud_request).with do |opts|
|
68
41
|
opts[:headers][:content_type] == 'application/json'
|
69
42
|
end.returns(res)
|
70
|
-
InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:candlepin_id_cert)
|
71
|
-
.returns(
|
72
|
-
{
|
73
|
-
cert: @cert1,
|
74
|
-
key: OpenSSL::PKey::RSA.new(1024).to_pem,
|
75
|
-
}
|
76
|
-
)
|
77
43
|
InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:cp_owner_id).returns('123')
|
78
44
|
|
79
45
|
post :forward_request, as: :json, params: { "path" => "static/v1/test", "machine_telemetry" => {"foo" => "bar"} }
|
@@ -103,6 +69,17 @@ module InsightsCloud::Api
|
|
103
69
|
assert_equal 502, @response.status
|
104
70
|
assert_equal 'Authentication to the Insights Service failed.', JSON.parse(@response.body)['message']
|
105
71
|
end
|
72
|
+
|
73
|
+
test "should forward errors to the client" do
|
74
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 500, "TEST_RESPONSE")
|
75
|
+
res = RestClient::Response.create(@body, net_http_resp, @http_req)
|
76
|
+
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:execute_cloud_request).raises(RestClient::InternalServerError.new(res))
|
77
|
+
|
78
|
+
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
79
|
+
assert_equal 500, @response.status
|
80
|
+
assert_equal 'Cloud request failed', JSON.parse(@response.body)['message']
|
81
|
+
assert_match /#{@body}/, JSON.parse(@response.body)['response']
|
82
|
+
end
|
106
83
|
end
|
107
84
|
|
108
85
|
context '#branch_info' do
|
@@ -4,7 +4,7 @@ class SettingsControllerTest < ActionController::TestCase
|
|
4
4
|
tests InsightsCloud::SettingsController
|
5
5
|
|
6
6
|
test 'should return allow_auto_insights_sync setting' do
|
7
|
-
|
7
|
+
Setting[:allow_auto_insights_sync] = false
|
8
8
|
|
9
9
|
assert_equal false, Setting[:allow_auto_insights_sync]
|
10
10
|
|
@@ -16,7 +16,7 @@ class SettingsControllerTest < ActionController::TestCase
|
|
16
16
|
end
|
17
17
|
|
18
18
|
test 'should update allow_auto_insights_sync setting' do
|
19
|
-
|
19
|
+
Setting[:allow_auto_insights_sync] = false
|
20
20
|
|
21
21
|
assert_equal false, Setting[:allow_auto_insights_sync]
|
22
22
|
|
@@ -4,7 +4,7 @@ class UploadsSettingsControllerTest < ActionController::TestCase
|
|
4
4
|
tests ForemanInventoryUpload::UploadsSettingsController
|
5
5
|
|
6
6
|
test 'should get upload inventory settings' do
|
7
|
-
|
7
|
+
Setting[:allow_auto_inventory_upload] = true
|
8
8
|
|
9
9
|
assert_equal true, Setting[:allow_auto_inventory_upload]
|
10
10
|
|
@@ -17,7 +17,7 @@ class UploadsSettingsControllerTest < ActionController::TestCase
|
|
17
17
|
end
|
18
18
|
|
19
19
|
test 'should update allow_auto_inventory_upload setting' do
|
20
|
-
|
20
|
+
Setting[:allow_auto_inventory_upload] = false
|
21
21
|
|
22
22
|
assert_equal false, Setting[:allow_auto_inventory_upload]
|
23
23
|
|
@@ -54,10 +54,24 @@ FactoryBot.define do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
FactoryBot.define do
|
58
|
+
factory :katello_subscription, :class => Katello::Subscription do
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
57
62
|
FactoryBot.define do
|
58
63
|
factory :katello_pool, :class => Katello::Pool do
|
59
64
|
active { true }
|
60
65
|
end_date { Date.today + 1.year }
|
66
|
+
cp_id { 1 }
|
67
|
+
|
68
|
+
association :organization, :factory => :katello_organization
|
69
|
+
|
70
|
+
after(:build) do |pool, _evaluator|
|
71
|
+
pool.subscription.organization = pool.organization
|
72
|
+
end
|
73
|
+
|
74
|
+
association :subscription, :factory => :katello_subscription
|
61
75
|
end
|
62
76
|
end
|
63
77
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_plugin_helper'
|
2
2
|
require 'foreman_tasks/test_helpers'
|
3
3
|
|
4
4
|
class InsightsFullSyncTest < ActiveSupport::TestCase
|
@@ -7,7 +7,7 @@ class InsightsFullSyncTest < ActiveSupport::TestCase
|
|
7
7
|
setup do
|
8
8
|
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_rules_sync)
|
9
9
|
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_notifications)
|
10
|
-
|
10
|
+
Setting[:rh_cloud_token] = 'MOCK_TOKEN'
|
11
11
|
|
12
12
|
uuid1 = 'accdf444-5628-451d-bf3e-cf909ad72756'
|
13
13
|
@host1 = FactoryBot.create(:host, :managed, name: 'host1')
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_plugin_helper'
|
2
2
|
require 'foreman_tasks/test_helpers'
|
3
3
|
|
4
4
|
class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
@@ -63,7 +63,7 @@ class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
|
63
63
|
}
|
64
64
|
|
65
65
|
@rule = FactoryBot.create(:insights_rule, rule_id: 'network_tcp_connection_hang|NETWORK_TCP_CONNECTION_HANG_WARN')
|
66
|
-
|
66
|
+
Setting[:rh_cloud_token] = 'MOCK_TOKEN'
|
67
67
|
end
|
68
68
|
|
69
69
|
test 'Resolutions data is replaced with data from cloud' do
|
@@ -75,4 +75,13 @@ class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
|
75
75
|
assert_equal 5, InsightsResolution.all.count
|
76
76
|
assert_equal 2, @rule.resolutions.count
|
77
77
|
end
|
78
|
+
|
79
|
+
test 'Skips pinging the cloud if no rule ids were found' do
|
80
|
+
InsightsCloud::Async::InsightsResolutionsSync.any_instance.expects(:query_insights_resolutions).never
|
81
|
+
InsightsRule.all.delete_all
|
82
|
+
|
83
|
+
ForemanTasks.sync_task(InsightsCloud::Async::InsightsResolutionsSync)
|
84
|
+
|
85
|
+
assert_equal 0, InsightsResolution.all.count
|
86
|
+
end
|
78
87
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_plugin_helper'
|
2
2
|
require 'foreman_tasks/test_helpers'
|
3
3
|
|
4
4
|
class InsightsRulesSyncTest < ActiveSupport::TestCase
|
@@ -112,7 +112,7 @@ class InsightsRulesSyncTest < ActiveSupport::TestCase
|
|
112
112
|
@hit = FactoryBot.create(:insights_hit, host_id: @host.id)
|
113
113
|
|
114
114
|
InsightsCloud::Async::InsightsRulesSync.any_instance.stubs(:plan_resolutions)
|
115
|
-
|
115
|
+
Setting[:rh_cloud_token] = 'MOCK_TOKEN'
|
116
116
|
end
|
117
117
|
|
118
118
|
test 'Hits data is replaced with data from cloud' do
|
@@ -37,6 +37,18 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
37
37
|
@host2.subscription_facet.pools << pool
|
38
38
|
@host2_inventory_id = '4536bf5c-ff03-4154-a8c9-32ff4b40e40c'
|
39
39
|
|
40
|
+
# this host would pass our plugin queries, so it could be uploaded to the cloud.
|
41
|
+
@host3 = FactoryBot.create(
|
42
|
+
:host,
|
43
|
+
:with_subscription,
|
44
|
+
:with_content,
|
45
|
+
content_view: cv.first,
|
46
|
+
lifecycle_environment: env,
|
47
|
+
organization: env.organization
|
48
|
+
)
|
49
|
+
|
50
|
+
@host3.subscription_facet.pools << pool
|
51
|
+
|
40
52
|
ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
|
41
53
|
|
42
54
|
inventory_json = <<-INVENTORY_JSON
|
@@ -151,7 +163,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
151
163
|
{
|
152
164
|
"insights_id": "b533848e-465f-4f1a-9b2b-b71cb2d5239d",
|
153
165
|
"rhel_machine_id": null,
|
154
|
-
"subscription_manager_id": "
|
166
|
+
"subscription_manager_id": "#{@host3.subscription_facet.uuid}",
|
155
167
|
"satellite_id": "d29bde40-348e-437c-8acf-8fa98320fc1b",
|
156
168
|
"bios_uuid": "3cd5d972-cfb5-451a-8314-fd2f56629d7c",
|
157
169
|
"ip_addresses": [
|
@@ -159,7 +171,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
159
171
|
"fd6e:2298:736e::857",
|
160
172
|
"fd6e:2298:736e:0:2c66:6101:9cc6:2b23"
|
161
173
|
],
|
162
|
-
"fqdn": "
|
174
|
+
"fqdn": "#{@host3.fqdn}",
|
163
175
|
"mac_addresses": [
|
164
176
|
"6e:66:a6:fe:fc:07",
|
165
177
|
"00:00:00:00:00:00"
|
@@ -242,7 +254,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
242
254
|
end
|
243
255
|
|
244
256
|
test 'Host status should be SYNC for inventory hosts' do
|
245
|
-
|
257
|
+
Setting[:rh_cloud_token] = 'TEST TOKEN'
|
246
258
|
InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
|
247
259
|
|
248
260
|
ForemanTasks.sync_task(InventorySync::Async::InventoryFullSync, @host2.organization)
|
@@ -254,7 +266,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
254
266
|
end
|
255
267
|
|
256
268
|
test 'Host status should be DISCONNECT for hosts that are not returned from cloud' do
|
257
|
-
|
269
|
+
Setting[:rh_cloud_token] = 'TEST TOKEN'
|
258
270
|
InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
|
259
271
|
FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
|
260
272
|
|
@@ -265,10 +277,24 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
265
277
|
end
|
266
278
|
|
267
279
|
test 'Task should be aborted if token is not present' do
|
268
|
-
|
280
|
+
Setting[:rh_cloud_token] = ''
|
269
281
|
|
270
282
|
InventorySync::Async::InventoryFullSync.any_instance.expects(:plan_self).never
|
271
283
|
|
272
284
|
ForemanTasks.sync_task(InventorySync::Async::InventoryFullSync, @host1.organization)
|
273
285
|
end
|
286
|
+
|
287
|
+
test 'Should skip hosts that are not returned in query' do
|
288
|
+
assert_nil InventorySync::InventoryStatus.where(host_id: @host3.id).first
|
289
|
+
|
290
|
+
Setting[:rh_cloud_token] = 'TEST TOKEN'
|
291
|
+
InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
|
292
|
+
InventorySync::Async::InventoryFullSync.any_instance.expects(:affected_host_ids).returns([@host1.id, @host2.id])
|
293
|
+
FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
|
294
|
+
|
295
|
+
ForemanTasks.sync_task(InventorySync::Async::InventoryFullSync, @host1.organization)
|
296
|
+
@host2.reload
|
297
|
+
|
298
|
+
assert_nil InventorySync::InventoryStatus.where(host_id: @host3.id).first
|
299
|
+
end
|
274
300
|
end
|
@@ -6,7 +6,7 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
|
|
6
6
|
|
7
7
|
setup do
|
8
8
|
User.current = User.find_by(login: 'secret_admin')
|
9
|
-
|
9
|
+
Setting[:rh_cloud_token] = 'MOCK_TOKEN'
|
10
10
|
|
11
11
|
env = FactoryBot.create(:katello_k_t_environment)
|
12
12
|
cv = env.content_views << FactoryBot.create(:katello_content_view, organization: env.organization)
|
@@ -265,4 +265,19 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
|
|
265
265
|
|
266
266
|
assert_equal @host2_inventory_id, @host2.insights.uuid
|
267
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
|
268
283
|
end
|
@@ -5,7 +5,7 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase
|
|
5
5
|
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
6
6
|
|
7
7
|
test 'Schedules an execution if auto upload is enabled' do
|
8
|
-
|
8
|
+
Setting[:allow_auto_inventory_upload] = true
|
9
9
|
|
10
10
|
InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).times(Organization.unscoped.count)
|
11
11
|
|
@@ -13,7 +13,7 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
test 'Skips execution if auto upload is disabled' do
|
16
|
-
|
16
|
+
Setting[:allow_auto_inventory_upload] = false
|
17
17
|
|
18
18
|
InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).never
|
19
19
|
|
@@ -6,7 +6,7 @@ class InventorySelfHostSyncTest < ActiveSupport::TestCase
|
|
6
6
|
|
7
7
|
setup do
|
8
8
|
User.current = User.find_by(login: 'secret_admin')
|
9
|
-
|
9
|
+
Setting[:rh_cloud_token] = 'MOCK_TOKEN'
|
10
10
|
|
11
11
|
# this host would pass our plugin queries, so it could be uploaded to the cloud.
|
12
12
|
@host1 = FactoryBot.create(:host)
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'test_plugin_helper'
|
2
|
+
require 'foreman_tasks/test_helpers'
|
2
3
|
|
3
|
-
class UploadReportJobTest <
|
4
|
+
class UploadReportJobTest < ActiveSupport::TestCase
|
5
|
+
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
4
6
|
include FolderIsolation
|
5
7
|
|
6
8
|
test 'returns aborted state when disconnected' do
|
@@ -10,9 +12,9 @@ class UploadReportJobTest < ActiveJob::TestCase
|
|
10
12
|
'idCert' => 'TEST_CERT',
|
11
13
|
}
|
12
14
|
)
|
13
|
-
|
15
|
+
Setting[:content_disconnected] = true
|
14
16
|
|
15
|
-
ForemanInventoryUpload::Async::UploadReportJob
|
17
|
+
ForemanTasks.sync_task(ForemanInventoryUpload::Async::UploadReportJob, '', organization.id)
|
16
18
|
|
17
19
|
label = ForemanInventoryUpload::Async::UploadReportJob.output_label(organization.id)
|
18
20
|
progress_output = ForemanInventoryUpload::Async::ProgressOutput.get(label)
|
@@ -24,7 +26,7 @@ class UploadReportJobTest < ActiveJob::TestCase
|
|
24
26
|
organization = FactoryBot.create(:organization)
|
25
27
|
Organization.any_instance.expects(:owner_details).returns(nil)
|
26
28
|
|
27
|
-
ForemanInventoryUpload::Async::UploadReportJob
|
29
|
+
ForemanTasks.sync_task(ForemanInventoryUpload::Async::UploadReportJob, '', organization.id)
|
28
30
|
|
29
31
|
label = ForemanInventoryUpload::Async::UploadReportJob.output_label(organization.id)
|
30
32
|
progress_output = ForemanInventoryUpload::Async::ProgressOutput.get(label)
|
data/test/test_plugin_helper.rb
CHANGED
@@ -32,8 +32,6 @@ module KatelloLocationFix
|
|
32
32
|
|
33
33
|
included do
|
34
34
|
setup do
|
35
|
-
FactoryBot.create(:setting, name: 'default_location_subscribed_hosts')
|
36
|
-
FactoryBot.create(:setting, name: 'default_location_puppet_content')
|
37
35
|
Setting[:default_location_subscribed_hosts] = Location.first.title
|
38
36
|
end
|
39
37
|
end
|
@@ -0,0 +1,28 @@
|
|
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
|
@@ -41,7 +41,7 @@ class RhCloudHttpProxyTest < ActiveSupport::TestCase
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def setup_global_foreman_proxy
|
44
|
-
|
44
|
+
Setting[:http_proxy] = @global_foreman_proxy_mock
|
45
45
|
end
|
46
46
|
|
47
47
|
def setup_cdn_proxy
|
@@ -38,7 +38,7 @@ class BranchInfoTest < ActiveSupport::TestCase
|
|
38
38
|
test 'should generate appropriate labels' do
|
39
39
|
2.times { FactoryBot.create(:katello_host_collection, :organization_id => @host.organization.id) }
|
40
40
|
|
41
|
-
|
41
|
+
Setting[:include_parameter_tags] = true
|
42
42
|
|
43
43
|
Katello::HostCollection.all.map do |collection|
|
44
44
|
FactoryBot.create(:katello_host_collection_host, :host_id => @host.id, :host_collection_id => collection.id)
|
@@ -17,6 +17,7 @@ class CloudRequestForwarderTest < ActiveSupport::TestCase
|
|
17
17
|
"/redhat_access/r/insights/platform/inventory/v1/hosts" => "https://cert.cloud.redhat.com/api/inventory/v1/hosts",
|
18
18
|
"/redhat_access/r/insights/platform/ingress/v1/upload" => "https://cert.cloud.redhat.com/api/ingress/v1/upload",
|
19
19
|
"/redhat_access/r/insights/uploads/67200803-132b-474b-a6f9-37be74185df4" => "https://cert-api.access.redhat.com/r/insights/uploads/67200803-132b-474b-a6f9-37be74185df4",
|
20
|
+
"/redhat_access/r/insights/" => "https://cert.cloud.redhat.com/api/apicast-tests/ping",
|
20
21
|
}
|
21
22
|
|
22
23
|
paths.each do |key, value|
|
@@ -107,4 +108,29 @@ class CloudRequestForwarderTest < ActiveSupport::TestCase
|
|
107
108
|
)
|
108
109
|
assert_equal params.merge(:branch_id => 74), @forwarder.prepare_forward_params(req, 74)
|
109
110
|
end
|
111
|
+
|
112
|
+
test 'should reuse BranchInfo identifiers for user_agent' do
|
113
|
+
user_agent = { :foo => :bar }
|
114
|
+
params = { :page => 5, :per_page => 42 }
|
115
|
+
ForemanRhCloud::BranchInfo.any_instance.expects(:core_app_name).returns('test_app')
|
116
|
+
ForemanRhCloud::BranchInfo.any_instance.expects(:core_app_version).returns('test_ver')
|
117
|
+
|
118
|
+
req = ActionDispatch::Request.new(
|
119
|
+
'REQUEST_URI' => '/foo/bar',
|
120
|
+
'REQUEST_METHOD' => 'GET',
|
121
|
+
'HTTP_USER_AGENT' => user_agent,
|
122
|
+
'rack.input' => ::Puma::NullIO.new,
|
123
|
+
'action_dispatch.request.query_parameters' => params
|
124
|
+
)
|
125
|
+
|
126
|
+
actual = @forwarder.prepare_request_opts(req, 'TEST PAYLOAD', params, generate_certs_hash)
|
127
|
+
|
128
|
+
assert_match /foo/, actual[:headers][:user_agent]
|
129
|
+
assert_match /bar/, actual[:headers][:user_agent]
|
130
|
+
assert_match /test_app/, actual[:headers][:user_agent]
|
131
|
+
assert_match /test_ver/, actual[:headers][:user_agent]
|
132
|
+
assert_equal 'TEST PAYLOAD', actual[:payload]
|
133
|
+
assert_equal 'GET', actual[:method]
|
134
|
+
assert_equal params, actual[:headers][:params]
|
135
|
+
end
|
110
136
|
end
|
@@ -8,7 +8,7 @@ class TemplateRendererHelperTest < ActiveSupport::TestCase
|
|
8
8
|
response.stubs(:body).returns('TEST PLAYBOOK')
|
9
9
|
ForemanRhCloud::RemediationsRetriever.any_instance.stubs(:query_playbook).returns(response)
|
10
10
|
@host1 = FactoryBot.create(:host)
|
11
|
-
|
11
|
+
Setting[:rh_cloud_token] = 'MOCK_TOKEN'
|
12
12
|
end
|
13
13
|
|
14
14
|
test 'Generates a playbook for hit and remediation' do
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'test_plugin_helper'
|
2
|
+
require 'foreman_tasks/test_helpers'
|
2
3
|
|
3
4
|
class ShellProcessJobTest < ActiveSupport::TestCase
|
4
5
|
class TestProcessJob < ForemanInventoryUpload::Async::ShellProcess
|
@@ -13,11 +14,12 @@ class ShellProcessJobTest < ActiveSupport::TestCase
|
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
17
|
+
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
16
18
|
include FolderIsolation
|
17
19
|
|
18
20
|
test 'Runs a process with environment vars' do
|
19
21
|
label = Foreman.uuid
|
20
|
-
|
22
|
+
ForemanTasks.sync_task(TestProcessJob, label)
|
21
23
|
|
22
24
|
progress_output = ForemanInventoryUpload::Async::ProgressOutput.get(label)
|
23
25
|
|