Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cloud subnet REST API #15248

Merged
merged 1 commit into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/controllers/api/cloud_subnets_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Api
class CloudSubnetsController < BaseController
end
end
1 change: 1 addition & 0 deletions app/controllers/api/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ProvidersController < BaseController
include Subcollections::PolicyProfiles
include Subcollections::Tags
include Subcollections::CloudNetworks
include Subcollections::CloudSubnets
include Subcollections::CloudTenants
include Subcollections::CustomAttributes
include Subcollections::LoadBalancers
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/api/subcollections/cloud_subnets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Api
module Subcollections
module CloudSubnets
def cloud_subnets_query_resource(object)
object.cloud_subnets
end
end
end
end
28 changes: 28 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,33 @@
:get:
- :name: read
:identifier: miq_cloud_networks_view
:cloud_subnets:
:description: Cloud Subnets
:identifier: cloud_subnet
:options:
- :collection
- :subcollection
:verbs: *gp
:klass: CloudSubnet
:collection_actions:
:get:
- :name: read
:identifier: cloud_subnet_show_list
:post:
- :name: query
:identifier: cloud_subnet_show_list
:resource_actions:
:get:
- :name: read
:identifier: cloud_subnet_show
:subcollection_actions:
:get:
- :name: read
:identifier: cloud_tenant_show_list
:subresource_actions:
:get:
- :name: read
:identifier: cloud_tenant_show
:cloud_tenants:
:description: Cloud Tenants
:identifier: cloud_tenant
Expand Down Expand Up @@ -1263,6 +1290,7 @@
- :policies
- :policy_profiles
- :cloud_networks
- :cloud_subnets
- :cloud_tenants
- :custom_attributes
- :load_balancers
Expand Down
49 changes: 49 additions & 0 deletions spec/requests/api/cloud_subnets_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
RSpec.describe 'CloudSubnets API' do
describe 'GET /api/cloud_subnets' do
it 'lists all cloud subnets with an appropriate role' do
cloud_subnet = FactoryGirl.create(:cloud_subnet)
api_basic_authorize collection_action_identifier(:cloud_subnets, :read, :get)
run_get(cloud_subnets_url)

expected = {
'count' => 1,
'subcount' => 1,
'name' => 'cloud_subnets',
'resources' => [
hash_including('href' => a_string_matching(cloud_subnets_url(cloud_subnet.id)))
]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'forbids access to cloud subnets without an appropriate role' do
api_basic_authorize

run_get(cloud_subnets_url)

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

describe 'GET /api/cloud_subnets/:id' do
it 'will show a cloud subnet with an appropriate role' do
cloud_subnet = FactoryGirl.create(:cloud_subnet)
api_basic_authorize action_identifier(:cloud_subnets, :read, :resource_actions, :get)

run_get(cloud_subnets_url(cloud_subnet.id))

expect(response.parsed_body).to include('href' => a_string_matching(cloud_subnets_url(cloud_subnet.id)))
expect(response).to have_http_status(:ok)
end

it 'forbids access to a cloud tenant without an appropriate role' do
cloud_subnet = FactoryGirl.create(:cloud_subnet)
api_basic_authorize

run_get(cloud_subnets_url(cloud_subnet.id))

expect(response).to have_http_status(:forbidden)
end
end
end
10 changes: 10 additions & 0 deletions spec/requests/api/collections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
test_collection_query(:cloud_networks, cloud_networks_url, CloudNetwork)
end

it 'queries CloudSubnets' do
FactoryGirl.create(:cloud_subnet)
test_collection_query(:cloud_subnets, cloud_subnets_url, CloudSubnet)
end

it 'queries CloudTenants' do
FactoryGirl.create(:cloud_tenant)
test_collection_query(:cloud_tenants, cloud_tenants_url, CloudTenant)
Expand Down Expand Up @@ -558,6 +563,11 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
test_collection_bulk_query(:load_balancers, load_balancers_url, LoadBalancer)
end

it "bulk query CloudSubnets" do
FactoryGirl.create(:cloud_subnet)
test_collection_bulk_query(:cloud_subnets, cloud_subnets_url, CloudSubnet)
end

it 'bulk query CloudTenants' do
FactoryGirl.create(:cloud_tenant)
test_collection_bulk_query(:cloud_tenants, cloud_tenants_url, CloudTenant)
Expand Down
47 changes: 47 additions & 0 deletions spec/requests/api/providers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,53 @@ def gen_import_request
end
end

context 'cloud subnets subcollection' do
before do
@provider = FactoryGirl.create(:ems_openstack).network_manager
@cloud_subnet = FactoryGirl.create(:cloud_subnet, :ext_management_system => @provider)
end

it 'queries all cloud subnets' do
api_basic_authorize subcollection_action_identifier(:providers, :cloud_subnets, :read, :get)

run_get("#{providers_url(@provider.id)}/cloud_subnets")

expected = {
'resources' => [
{ 'href' => a_string_matching("#{providers_url(@provider.id)}/cloud_subnets/#{@cloud_subnet.id}") }
]

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

it "will not show a provider's cloud subnets without the appropriate role" do
api_basic_authorize

run_get("#{providers_url(@provider.id)}/cloud_subnets")

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

it 'queries a single cloud subnet' do
api_basic_authorize action_identifier(:cloud_subnets, :read, :subresource_actions, :get)

run_get("#{providers_url(@provider.id)}/cloud_subnets/#{@cloud_subnet.id}")

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

it "will not show a provider's cloud subnet without the appropriate role" do
api_basic_authorize

run_get("#{providers_url(@provider.id)}/cloud_subnets/#{@cloud_subnet.id}")

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

context 'cloud tenants subcollection' do
before do
@provider = FactoryGirl.create(:ems_openstack)
Expand Down