Skip to content

Commit

Permalink
Merge pull request #14731 from tzumainn/cloud-tenant-api
Browse files Browse the repository at this point in the history
Add cloud tenants to API
(cherry picked from commit 27e1ab0)

https://bugzilla.redhat.com/show_bug.cgi?id=1458377
  • Loading branch information
abellotti authored and simaishi committed Jun 2, 2017
1 parent 9dc5189 commit a2b8ebe
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/api/cloud_tenants_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Api
class CloudTenantsController < 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::CloudTenants
include Subcollections::CustomAttributes
include Subcollections::LoadBalancers

Expand Down
9 changes: 9 additions & 0 deletions app/controllers/api/subcollections/cloud_tenants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Api
module Subcollections
module CloudTenants
def cloud_tenants_query_resource(object)
object.cloud_tenants
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 @@ -484,6 +484,33 @@
:get:
- :name: read
:identifier: miq_cloud_networks_view
:cloud_tenants:
:description: Cloud Tenants
:identifier: cloud_tenant
:options:
- :collection
- :subcollection
:verbs: *gp
:klass: CloudTenant
:collection_actions:
:get:
- :name: read
:identifier: cloud_tenant_show_list
:post:
- :name: query
:identifier: cloud_tenant_show_list
:resource_actions:
:get:
- :name: read
:identifier: cloud_tenant_show
:subcollection_actions:
:get:
- :name: read
:identifier: cloud_tenant_show_list
:subresource_actions:
:get:
- :name: read
:identifier: cloud_tenant_show
:cloud_volumes:
:description: Cloud Volumes
:identifier: cloud_volume
Expand Down Expand Up @@ -1194,6 +1221,7 @@
- :policies
- :policy_profiles
- :cloud_networks
- :cloud_tenants
- :custom_attributes
- :load_balancers
:collection_actions:
Expand Down
49 changes: 49 additions & 0 deletions spec/requests/api/cloud_tenants_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
RSpec.describe 'CloudTenants API' do
describe 'GET /api/cloud_tenants' do
it 'lists all cloud tenants with an appropriate role' do
cloud_tenant = FactoryGirl.create(:cloud_tenant)
api_basic_authorize collection_action_identifier(:cloud_tenants, :read, :get)
run_get(cloud_tenants_url)

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

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

run_get(cloud_tenants_url)

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

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

run_get(cloud_tenants_url(cloud_tenant.id))

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

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

run_get(cloud_tenants_url(cloud_tenant.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 @@ -295,6 +295,11 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
test_collection_query(:cloud_networks, cloud_networks_url, CloudNetwork)
end

it 'queries CloudTenants' do
FactoryGirl.create(:cloud_tenant)
test_collection_query(:cloud_tenants, cloud_tenants_url, CloudTenant)
end

it 'queries ArbitrationSettings' do
FactoryGirl.create(:arbitration_setting)
test_collection_query(:arbitration_settings, arbitration_settings_url, ArbitrationSetting)
Expand Down Expand Up @@ -576,6 +581,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 CloudTenants' do
FactoryGirl.create(:cloud_tenant)
test_collection_bulk_query(:cloud_tenants, cloud_tenants_url, CloudTenant)
end

it 'bulk query CloudVolumes' do
FactoryGirl.create(:cloud_volume)
test_collection_bulk_query(:cloud_volumes, cloud_volumes_url, CloudVolume)
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 @@ -929,6 +929,53 @@ def gen_import_request
end
end

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

it 'queries all cloud tenants' do
api_basic_authorize subcollection_action_identifier(:providers, :cloud_tenants, :read, :get)

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

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

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

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

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

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

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

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

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

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

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

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

describe 'edit custom_attributes on providers' do
context 'provider_class=provider' do
let(:generic_provider) { FactoryGirl.create(:provider) }
Expand Down

0 comments on commit a2b8ebe

Please sign in to comment.