foreman_rh_cloud 4.0.25.1 → 4.0.30
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/insights_cloud/api/machine_telemetries_controller.rb +8 -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 +41822 -0
- data/config/routes.rb +1 -1
- data/lib/foreman_inventory_upload/generators/queries.rb +1 -0
- data/lib/foreman_inventory_upload/generators/tags.rb +9 -3
- data/lib/foreman_rh_cloud/engine.rb +2 -0
- 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/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/package.json +2 -2
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +16 -39
- data/test/factories/inventory_upload_factories.rb +14 -0
- data/test/jobs/insights_resolutions_sync_test.rb +10 -1
- data/test/jobs/inventory_full_sync_test.rb +28 -2
- data/test/jobs/inventory_hosts_sync_test.rb +15 -0
- data/test/unit/foreman_rh_cloud_self_host_test.rb +28 -0
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +26 -0
- data/test/unit/slice_generator_test.rb +36 -4
- data/test/unit/tags_generator_test.rb +31 -16
- data/webpack/InsightsCloudSync/Components/InsightsHeader/index.js +0 -2
- data/webpack/InsightsCloudSync/Components/InsightsSettings/insightsSettings.scss +1 -0
- data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/InsightsHeader.test.js.snap +0 -1
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +2 -0
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +1 -0
- data/webpack/common/Switcher/HelpLabel.js +1 -1
- data/webpack/common/Switcher/__tests__/__snapshots__/HelpLabel.test.js.snap +1 -1
- metadata +6 -3
data/config/routes.rb
CHANGED
@@ -39,7 +39,7 @@ Rails.application.routes.draw do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
scope '/r/insights' do
|
42
|
-
match '/*path', :constraints => lambda { |req| !req.path.include?('view/api') }, to: 'machine_telemetries#forward_request', via: [:get, :post, :delete,:put, :patch]
|
42
|
+
match '(/*path)(/)', :constraints => lambda { |req| !req.path.include?('view/api') }, to: 'machine_telemetries#forward_request', via: [:get, :post, :delete,:put, :patch]
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -13,15 +13,15 @@ module ForemanInventoryUpload
|
|
13
13
|
organizations +
|
14
14
|
content_data +
|
15
15
|
satellite_server_data
|
16
|
-
).reject { |key, value| value.empty? }
|
16
|
+
).reject { |key, value| value.empty? }.map { |key, value| [key, truncated_value(value)] }
|
17
17
|
end
|
18
18
|
|
19
19
|
def generate_parameters
|
20
20
|
return [] unless Setting[:include_parameter_tags]
|
21
21
|
|
22
|
-
(@host.
|
23
|
-
.map { |item| [item.name, item.value] }
|
22
|
+
(@host.host_params || {})
|
24
23
|
.select { |_name, value| value.present? || value.is_a?(FalseClass) }
|
24
|
+
.map { |key, value| [key, truncated_value(value)] }
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
@@ -58,6 +58,12 @@ module ForemanInventoryUpload
|
|
58
58
|
['organization_id', @host.organization_id.to_s],
|
59
59
|
]
|
60
60
|
end
|
61
|
+
|
62
|
+
def truncated_value(value)
|
63
|
+
return 'Original value exceeds 250 characters' if value.to_s.length > 250
|
64
|
+
|
65
|
+
value
|
66
|
+
end
|
61
67
|
end
|
62
68
|
end
|
63
69
|
end
|
@@ -42,6 +42,8 @@ module ForemanRhCloud
|
|
42
42
|
Foreman::Plugin.register :foreman_rh_cloud do
|
43
43
|
requires_foreman '>= 2.3'
|
44
44
|
|
45
|
+
apipie_documented_controllers ["#{ForemanRhCloud::Engine.root}/app/controllers/api/v2/**/*.rb"]
|
46
|
+
|
45
47
|
# Add permissions
|
46
48
|
security_block :foreman_rh_cloud do
|
47
49
|
permission(
|
data/lib/foreman_rh_cloud.rb
CHANGED
@@ -98,7 +98,18 @@ module ForemanRhCloud
|
|
98
98
|
|
99
99
|
# For testing purposes we can override the default hostname with an environment variable SATELLITE_RH_CLOUD_FOREMAN_HOST
|
100
100
|
def self.foreman_host
|
101
|
-
@foreman_host ||=
|
101
|
+
@foreman_host ||= begin
|
102
|
+
fullname = foreman_host_name
|
103
|
+
::Host.unscoped.friendly.find(fullname)
|
104
|
+
rescue ActiveRecord::RecordNotFound
|
105
|
+
# fullname didn't work. Let's try shortname
|
106
|
+
shortname = /(?<shortname>[^\.]*)\.?.*/.match(fullname)[:shortname]
|
107
|
+
::Host.unscoped.friendly.find(shortname)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.foreman_host_name
|
112
|
+
ENV['SATELLITE_RH_CLOUD_FOREMAN_HOST'] || ::SmartProxy.default_capsule.name
|
102
113
|
end
|
103
114
|
|
104
115
|
def self.legacy_insights_ca
|
@@ -19,8 +19,9 @@ module InsightsCloud
|
|
19
19
|
def run
|
20
20
|
InsightsResolution.transaction do
|
21
21
|
InsightsResolution.delete_all
|
22
|
-
|
23
|
-
|
22
|
+
rule_ids = relevant_rules
|
23
|
+
api_response = query_insights_resolutions(rule_ids) unless rule_ids.empty?
|
24
|
+
write_resolutions(api_response) if api_response
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
@@ -70,6 +71,10 @@ module InsightsCloud
|
|
70
71
|
def to_rule_id(resolution_rule_id)
|
71
72
|
RULE_ID_REGEX.match(resolution_rule_id).named_captures.fetch('id', resolution_rule_id)
|
72
73
|
end
|
74
|
+
|
75
|
+
def rescue_strategy_for_self
|
76
|
+
Dynflow::Action::Rescue::Fail
|
77
|
+
end
|
73
78
|
end
|
74
79
|
end
|
75
80
|
end
|
@@ -11,8 +11,12 @@ module InsightsCloud
|
|
11
11
|
return
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
# since the tasks are not connected, we need to force sequence execution here
|
15
|
+
# to make sure we don't run resolutions until we synced all our rules
|
16
|
+
sequence do
|
17
|
+
plan_self
|
18
|
+
plan_resolutions
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
def plan_resolutions
|
@@ -71,6 +75,10 @@ module InsightsCloud
|
|
71
75
|
rating: rule_hash['rating'],
|
72
76
|
}
|
73
77
|
end
|
78
|
+
|
79
|
+
def rescue_strategy_for_self
|
80
|
+
Dynflow::Action::Rescue::Fail
|
81
|
+
end
|
74
82
|
end
|
75
83
|
end
|
76
84
|
end
|
@@ -17,7 +17,6 @@ module InventorySync
|
|
17
17
|
@sub_ids.map do |sub_id|
|
18
18
|
host_id = host_id(sub_id)
|
19
19
|
if host_id
|
20
|
-
touched << host_id
|
21
20
|
{
|
22
21
|
host_id: host_id,
|
23
22
|
status: InventorySync::InventoryStatus::SYNC,
|
@@ -28,10 +27,6 @@ module InventorySync
|
|
28
27
|
end.compact
|
29
28
|
end
|
30
29
|
|
31
|
-
def touched
|
32
|
-
@touched ||= []
|
33
|
-
end
|
34
|
-
|
35
30
|
def host_id(sub_id)
|
36
31
|
hosts[sub_id]
|
37
32
|
end
|
@@ -14,11 +14,7 @@ module InventorySync
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def setup_statuses
|
17
|
-
@subscribed_hosts_ids = Set.new(
|
18
|
-
ForemanInventoryUpload::Generators::Queries.for_slice(
|
19
|
-
Host.unscoped.where(organization: input[:organization_id])
|
20
|
-
).pluck(:id)
|
21
|
-
)
|
17
|
+
@subscribed_hosts_ids = Set.new(affected_host_ids)
|
22
18
|
|
23
19
|
InventorySync::InventoryStatus.transaction do
|
24
20
|
InventorySync::InventoryStatus.where(host_id: @subscribed_hosts_ids).delete_all
|
@@ -35,15 +31,22 @@ module InventorySync
|
|
35
31
|
def update_statuses_batch
|
36
32
|
results = yield
|
37
33
|
|
38
|
-
|
39
|
-
|
34
|
+
existing_hosts = results.status_hashes.select { |hash| @subscribed_hosts_ids.include?(hash[:host_id]) }
|
35
|
+
|
36
|
+
update_hosts_status(existing_hosts)
|
37
|
+
host_statuses[:sync] += existing_hosts.size
|
38
|
+
end
|
39
|
+
|
40
|
+
def rescue_strategy_for_self
|
41
|
+
Dynflow::Action::Rescue::Fail
|
40
42
|
end
|
41
43
|
|
42
44
|
private
|
43
45
|
|
44
|
-
def update_hosts_status(status_hashes
|
46
|
+
def update_hosts_status(status_hashes)
|
45
47
|
InventorySync::InventoryStatus.create(status_hashes)
|
46
|
-
|
48
|
+
updated_ids = status_hashes.map { |hash| hash[:host_id] }
|
49
|
+
@subscribed_hosts_ids.subtract(updated_ids)
|
47
50
|
end
|
48
51
|
|
49
52
|
def add_missing_hosts_statuses(hosts_ids)
|
@@ -64,6 +67,12 @@ module InventorySync
|
|
64
67
|
disconnect: 0,
|
65
68
|
}
|
66
69
|
end
|
70
|
+
|
71
|
+
def affected_host_ids
|
72
|
+
ForemanInventoryUpload::Generators::Queries.for_slice(
|
73
|
+
Host.unscoped.where(organization: input[:organization_id])
|
74
|
+
).pluck(:id)
|
75
|
+
end
|
67
76
|
end
|
68
77
|
end
|
69
78
|
end
|
@@ -28,21 +28,21 @@ module InventorySync
|
|
28
28
|
results
|
29
29
|
end
|
30
30
|
|
31
|
+
def rescue_strategy_for_self
|
32
|
+
Dynflow::Action::Rescue::Fail
|
33
|
+
end
|
34
|
+
|
31
35
|
private
|
32
36
|
|
33
37
|
def add_missing_insights_facets(uuids_hash)
|
34
|
-
|
35
|
-
missing_facets = uuids_hash.except(*existing_facets.map(&:first)).map do |host_id, uuid|
|
38
|
+
all_facets = uuids_hash.map do |host_id, uuid|
|
36
39
|
{
|
37
40
|
host_id: host_id,
|
38
41
|
uuid: uuid,
|
39
42
|
}
|
40
43
|
end
|
41
|
-
InsightsFacet.create(missing_facets)
|
42
44
|
|
43
|
-
|
44
|
-
InsightsFacet.where(host_id: host_id).update_all(uuid: uuids_hash[host_id])
|
45
|
-
end
|
45
|
+
InsightsFacet.upsert_all(all_facets, unique_by: :host_id) unless all_facets.empty?
|
46
46
|
end
|
47
47
|
|
48
48
|
def plan_self_host_sync
|
data/package.json
CHANGED
@@ -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
|
-
"FzAVBgNVBAMMDnRoZWZvcmVtYW4ub3JnMB4XDTE4MDMyNDEyMzYyOFoXDTI4MDMy\r\n" +
|
23
|
-
"MTEyMzYyOFowTzELMAkGA1UEBhMCSUwxETAPBgNVBAgMCFRlbCBBdml2MRQwEgYD\r\n" +
|
24
|
-
"VQQKDAtUaGUgRm9yZW1hbjEXMBUGA1UEAwwOdGhlZm9yZW1hbi5vcmcwggIiMA0G\r\n" +
|
25
|
-
"CSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDF04/s4h+BgHPG1HDZ/sDlYq925pkc\r\n" +
|
26
|
-
"RTVAfnE2EXDAmZ6W4Q9ueDY65MHe3ZWO5Dg72kNSP2sK9kRI7Dk5CAFOgyw1rH8t\r\n" +
|
27
|
-
"Hd1+0xp/lv6e4SvSYghxIL68vFe0ftKkm1usqejBM5ZTgKr7JCI+XSIN36F65Kde\r\n" +
|
28
|
-
"c+vxwBnayuhP04r9/aaE/709SXML4eRVYW8I3qFy9FPtUOm+bY8U2PIv5fHayqbG\r\n" +
|
29
|
-
"cL/4t3+MCtMhHJsLzdBXya+1P5t+HcKjUNlmwoUF961YAktVuEFloGd0RMRlqF3/\r\n" +
|
30
|
-
"itU3QNlXgA5QBIciE5VPr/PiqgMC3zgd5avjF4OribZ+N9AATLiQMW78il5wSfcc\r\n" +
|
31
|
-
"kQjU9ChOLrzku455vQ8KE4bc0qvpCWGfUah6MvL9JB+TQkRl/8kxl0b9ZinIvJDH\r\n" +
|
32
|
-
"ynVMb4cB/TDEjrjOfzn9mWLH0ZJqjmc2bER/G12WQxOaYLxdVwRStD3Yh6PtiFWu\r\n" +
|
33
|
-
"sXOk19UOTVkeuvGFVtvzLfEwQ1lDEo7+VBQz8FG/HBu2Hpq3IwCFrHuicikwjQJk\r\n" +
|
34
|
-
"nfturgD0rBOKEc1qWNZRCvovYOLL6ihvv5Orujsx5ZCHOAtnVNxkvIlFt2RS45LF\r\n" +
|
35
|
-
"MtPJyhAc6SjitllfUEirxprsbmeSZqrIfzcGaEhgOSnyik1WMv6bYiqPfBg8Fzjh\r\n" +
|
36
|
-
"vOCbtiDNPmvgOwIDAQABo1MwUTAdBgNVHQ4EFgQUtkAgQopsTtG9zSG3MgW2IxHD\r\n" +
|
37
|
-
"MDwwHwYDVR0jBBgwFoAUtkAgQopsTtG9zSG3MgW2IxHDMDwwDwYDVR0TAQH/BAUw\r\n" +
|
38
|
-
"AwEB/zANBgkqhkiG9w0BAQsFAAOCAgEAJq7iN+ZroRBweNhvUobxs75bLIV6tNn1\r\n" +
|
39
|
-
"MdNHDRA+hezwf+gxHZhFyaAHfTpst2/9leK5Qe5Zd6gZLr3E5/8ppQuRod72H39B\r\n" +
|
40
|
-
"vxMlG5zxDss0WMo3vZeKZbTY6QhXi/lY2IZ6OGV4feSvCsYxn27GTjjrRUSLFeHH\r\n" +
|
41
|
-
"JVemCwCDMavaE3+OIY4v2P4FcG+MjUvfOB9ahI24TWL7YgrsNVmJjCILq+EeUj0t\r\n" +
|
42
|
-
"Gde1SXVyLkqt7PoxHRJAE0BCEMJSnjxaVB329acJgeehBUxjj4CCPqtDxtbz9HEH\r\n" +
|
43
|
-
"mOKfNdaKpFor+DUeEKUWVGnr9U9xOaC+Ws+oX7MIEUCDM7p2ob4JwcjnFs1jZgHh\r\n" +
|
44
|
-
"Hwig+i7doTlc701PvKWO96fuNHK3B3/jTb1fVvSZ49O/RvY1VWODdUdxWmXGHNh3\r\n" +
|
45
|
-
"LoR8tSPEb46lC2DXGaIQumqQt8PnBG+vL1qkQa1SGTV7dJ8TTbxbv0S+sS+igkk9\r\n" +
|
46
|
-
"zsIEK8Ea3Ep935cXximz0faAAKHSA+It+xHLAyDtqy2KaAEBgGsBuuWlUfK6TaP3\r\n" +
|
47
|
-
"Gwdjct3y4yYUO45lUsUfHqX8vk/4ttW5zYeDiW+HArJz+9VUXNbEdury4kGuHgBj\r\n" +
|
48
|
-
"xHD4Bsul65+hHZ9QywKU26F1A6TLkYpQ2rk/Dx9LGICM4m4IlHjWJPFsQdtkyOor\r\n" +
|
49
|
-
"osxMtcaZZ1E=\r\n" +
|
50
|
-
"-----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
|
@@ -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 InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
@@ -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
|
@@ -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"
|
@@ -271,4 +283,18 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
|
|
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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -22,7 +22,13 @@ class SliceGeneratorTest < ActiveSupport::TestCase
|
|
22
22
|
location: location
|
23
23
|
)
|
24
24
|
|
25
|
-
@host.organization.pools << FactoryBot.create(
|
25
|
+
@host.organization.pools << FactoryBot.create(
|
26
|
+
:katello_pool,
|
27
|
+
account_number: '1234',
|
28
|
+
cp_id: 1,
|
29
|
+
organization: env.organization,
|
30
|
+
subscription: FactoryBot.create(:katello_subscription, organization_id: env.organization.id)
|
31
|
+
)
|
26
32
|
@host.interfaces.first.identifier = 'test_nic1'
|
27
33
|
@host.save!
|
28
34
|
|
@@ -441,6 +447,18 @@ class SliceGeneratorTest < ActiveSupport::TestCase
|
|
441
447
|
assert_equal 1, generator.hosts_count
|
442
448
|
end
|
443
449
|
|
450
|
+
test 'excludes hosts with host_registration_insights set to false' do
|
451
|
+
@host.host_parameters << HostParameter.create(
|
452
|
+
name: 'host_registration_insights',
|
453
|
+
value: "false",
|
454
|
+
parameter_type: 'boolean'
|
455
|
+
)
|
456
|
+
|
457
|
+
count = ForemanInventoryUpload::Generators::Queries.for_org(@host.organization_id).count
|
458
|
+
|
459
|
+
assert_equal 0, count
|
460
|
+
end
|
461
|
+
|
444
462
|
test 'shows system_memory_bytes in bytes' do
|
445
463
|
FactoryBot.create(:fact_value, fact_name: fact_names['memory::memtotal'], value: '1', host: @host)
|
446
464
|
|
@@ -457,9 +475,23 @@ class SliceGeneratorTest < ActiveSupport::TestCase
|
|
457
475
|
end
|
458
476
|
|
459
477
|
test 'reports an account for hosts with multiple pools' do
|
460
|
-
|
461
|
-
|
462
|
-
|
478
|
+
new_org = FactoryBot.create(:organization)
|
479
|
+
first_pool = FactoryBot.create(
|
480
|
+
:katello_pool,
|
481
|
+
account_number: '5678',
|
482
|
+
cp_id: 2,
|
483
|
+
organization: new_org,
|
484
|
+
subscription: FactoryBot.create(:katello_subscription, organization_id: new_org.id)
|
485
|
+
)
|
486
|
+
second_pool = FactoryBot.create(
|
487
|
+
:katello_pool,
|
488
|
+
account_number: '9012',
|
489
|
+
cp_id: 3,
|
490
|
+
organization: new_org,
|
491
|
+
subscription: FactoryBot.create(:katello_subscription, organization_id: new_org.id)
|
492
|
+
)
|
493
|
+
new_org.pools << first_pool
|
494
|
+
new_org.pools << second_pool
|
463
495
|
|
464
496
|
another_host = FactoryBot.create(
|
465
497
|
:host,
|