Skip to content

Commit 6016c34

Browse files
committedApr 12, 2024··
add /api/providers/#/metric_rollups
1 parent 12687ca commit 6016c34

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed
 

‎app/controllers/api/providers_controller.rb

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class ProvidersController < BaseController
2525
include Subcollections::Folders
2626
include Subcollections::Lans
2727
include Subcollections::LoadBalancers
28+
include Subcollections::MetricRollups
2829
include Subcollections::Networks
2930
include Subcollections::NetworkServices
3031
include Subcollections::Policies

‎app/controllers/api/subcollections/metric_rollups.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module Api
22
module Subcollections
33
module MetricRollups
44
RESOURCE_TYPES = {
5-
'vms' => 'VmOrTemplate'
5+
'vms' => 'VmOrTemplate',
6+
'providers' => 'ExtManagementSystem'
67
}.freeze
78

89
def metric_rollups_query_resource(object)

‎config/api.yml

+7
Original file line numberDiff line numberDiff line change
@@ -2782,6 +2782,7 @@
27822782
- :cloud_volume_types
27832783
- :custom_attributes
27842784
- :load_balancers
2785+
- :metric_rollups
27852786
- :network_services
27862787
- :security_groups
27872788
- :security_policies
@@ -2904,6 +2905,12 @@
29042905
:identifier:
29052906
- ems_infra_show
29062907
- ems_storage_show
2908+
:metric_rollups_subcollection_actions:
2909+
:get:
2910+
- :name: read
2911+
:identifier:
2912+
- ems_infra_show
2913+
- ems_storage_show_list
29072914
:networks_subcollection_actions:
29082915
:get:
29092916
- :name: read

‎spec/requests/providers_spec.rb

+36
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,42 @@ def gen_import_request
14531453
end
14541454
end
14551455

1456+
describe "metric rollups subcollection" do
1457+
let(:provider) { FactoryBot.create(:ems_redhat) }
1458+
let(:provider1) { FactoryBot.create(:ems_redhat) }
1459+
let(:url) { api_provider_metric_rollups_url(nil, provider) }
1460+
1461+
before do
1462+
FactoryBot.create_list(:metric_rollup_cm_hr, 3, :resource => provider, :timestamp => 1.hour.ago)
1463+
FactoryBot.create_list(:metric_rollup_cm_daily, 1, :resource => provider)
1464+
FactoryBot.create_list(:metric_rollup_cm_hr, 1, :resource => provider1)
1465+
end
1466+
1467+
it 'returns the metric rollups for the provider' do
1468+
api_basic_authorize subcollection_action_identifier(:providers, :metric_rollups, :read, :get)
1469+
1470+
provider.metric_rollups.where(:capture_interval_name => 'hourly').name
1471+
get(url, :params => { :capture_interval => 'hourly', :start_date => Time.zone.today.to_s })
1472+
1473+
expected = {
1474+
'count' => 5,
1475+
'subcount' => 3,
1476+
'pages' => 1
1477+
}
1478+
expect(response).to have_http_status(:ok)
1479+
expect(response.parsed_body).to include(expected)
1480+
expect(response.parsed_body['links'].keys).to match_array(%w[self first last])
1481+
end
1482+
1483+
it 'will not return metric rollups without an appropriate role' do
1484+
api_basic_authorize
1485+
1486+
get(url, :params => { :capture_interval => 'hourly', :start_date => Time.zone.today.to_s })
1487+
1488+
expect(response).to have_http_status(:forbidden)
1489+
end
1490+
end
1491+
14561492
context 'cloud volume types subcollection' do
14571493
before do
14581494
@provider = FactoryBot.create(:ems_storage)

0 commit comments

Comments
 (0)
Please sign in to comment.