Skip to content

Commit

Permalink
Adding Chassis and Racks as PhysicalStorages subcollections
Browse files Browse the repository at this point in the history
  • Loading branch information
EsdrasVP committed Jul 25, 2018
1 parent 39e81ec commit 156d65e
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/controllers/api/physical_storages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module Api
class PhysicalStoragesController < BaseController
include Subcollections::PhysicalRacks
include Subcollections::PhysicalChassis

def refresh_resource(type, id, _data = nil)
raise BadRequestError, "Must specify an id for refreshing a #{type} resource" if id.blank?

Expand Down
9 changes: 9 additions & 0 deletions app/controllers/api/subcollections/physical_chassis.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Api
module Subcollections
module PhysicalChassis
def physical_chassis_query_resource(object)
object.respond_to?(:physical_chassis) ? ManageIQ::Providers::PhysicalInfraManager::PhysicalChassis.where(:id => object.physical_chassis_id) : []
end
end
end
end
9 changes: 9 additions & 0 deletions app/controllers/api/subcollections/physical_racks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Api
module Subcollections
module PhysicalRacks
def physical_racks_query_resource(object)
object.respond_to?(:physical_racks) ? PhysicalRack.where(:id => object.physical_rack_id) : []
end
end
end
end
20 changes: 20 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,7 @@
:identifier: physical_chassis
:options:
- :collection
- :subcollection
:verbs: *gp
:klass: PhysicalChassis
:subcollections:
Expand All @@ -1755,18 +1756,27 @@
:post:
- :name: refresh
:identifier: physical_chassis_refresh
:subcollection_actions:
:get:
- :name: read
:identifier: physical_chassis_show_list
:resource_actions:
:get:
- :name: read
:identifier: physical_chassis_show
:post:
- :name: refresh
:identifier: physical_chassis_refresh
:subresource_actions:
:get:
- :name: read
:identifier: physical_chassis_show
:physical_racks:
:description: Physical Racks
:identifier: physical_rack
:options:
- :collection
- :subcollection
:verbs: *gp
:klass: PhysicalRack
:subcollections:
Expand All @@ -1779,13 +1789,21 @@
:identifier: physical_rack_show_list
- :name: refresh
:identifier: physical_rack_refresh
:subcollection_actions:
:get:
- :name: read
:identifier: physical_rack_show_list
:resource_actions:
:get:
- :name: read
:identifier: physical_rack_show
:post:
- :name: refresh
:identifier: physical_rack_refresh
:subresource_actions:
:get:
- :name: read
:identifier: physical_rack_show
:physical_servers:
:description: Physical Servers
:identifier: physical_server
Expand Down Expand Up @@ -1862,6 +1880,8 @@
:verbs: *gp
:klass: PhysicalStorage
:subcollections:
- :physical_racks
- :physical_chassis
:collection_actions:
:get:
- :name: read
Expand Down
98 changes: 98 additions & 0 deletions spec/requests/physical_storages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,102 @@
end
end
end

context 'Physical Racks subcollection' do
let(:physical_rack) { FactoryGirl.create(:physical_rack) }
let(:physical_storage) { FactoryGirl.create(:physical_storage, :physical_rack_id => physical_rack.id) }

context 'GET /api/physical_storages/:id/physical_racks' do
it 'returns the physical racks with an appropriate role' do
api_basic_authorize(collection_action_identifier(:physical_racks, :read, :get))

url_get = api_physical_storage_physical_racks_url(nil, physical_storage)
url_resource = api_physical_storage_physical_rack_url(nil, physical_storage, physical_rack)

expected = {
'resources' => [{'href' => url_resource}]
}
get(url_get)

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'does not return the physical racks without an appropriate role' do
api_basic_authorize

get(api_physical_storage_physical_rack_url(nil, physical_storage, physical_rack))

expect(response).to have_http_status(:forbidden)
end
end

context 'GET /api/physical_storages/:id/physical_racks/:s_id' do
it 'returns the physical rack with an appropriate role' do
api_basic_authorize action_identifier(:physical_racks, :read, :resource_actions, :get)

get(api_physical_storage_physical_rack_url(nil, physical_storage, physical_rack))

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include('id' => physical_rack.id.to_s)
end

it 'does not return the physical rack without an appropriate role' do
api_basic_authorize

get(api_physical_storage_physical_rack_url(nil, physical_storage, physical_rack))

expect(response).to have_http_status(:forbidden)
end
end
end

context 'Physical Chassis subcollection' do
let(:physical_chassis) { FactoryGirl.create(:physical_chassis) }
let(:physical_storage) { FactoryGirl.create(:physical_storage, :physical_chassis_id => physical_chassis.id) }

context 'GET /api/physical_storages/:id/physical_chassis' do
it 'returns the physical chassis with an appropriate role' do
api_basic_authorize(collection_action_identifier(:physical_chassis, :read, :get))

url_get = api_physical_storage_physical_chassis_url(nil, physical_storage)
url_resource = api_physical_storage_one_physical_chassis_url(nil, physical_storage, physical_chassis)

expected = {
'resources' => [{'href' => url_resource}]
}
get(url_get)

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'does not return the physical chassis without an appropriate role' do
api_basic_authorize

get(api_physical_storage_one_physical_chassis_url(nil, physical_storage, physical_chassis))

expect(response).to have_http_status(:forbidden)
end
end

context 'GET /api/physical_storages/:id/physical_chassis/:s_id' do
it 'returns the physical chassis with an appropriate role' do
api_basic_authorize action_identifier(:physical_chassis, :read, :resource_actions, :get)

get(api_physical_storage_one_physical_chassis_url(nil, physical_storage, physical_chassis))

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include('id' => physical_chassis.id.to_s)
end

it 'does not return the physical chassis without an appropriate role' do
api_basic_authorize

get(api_physical_storage_one_physical_chassis_url(nil, physical_storage, physical_chassis))

expect(response).to have_http_status(:forbidden)
end
end
end
end

0 comments on commit 156d65e

Please sign in to comment.