Skip to content

Commit

Permalink
Merge pull request #15097 from AparnaKarve/api_cloud_volume_delete
Browse files Browse the repository at this point in the history
[api] Add support for Cloud Volume Delete action
  • Loading branch information
abellotti authored May 22, 2017
2 parents 8ca456c + 6ca849f commit d4e12c9
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/controllers/api/cloud_volumes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
module Api
class CloudVolumesController < BaseController
def delete_resource(type, id, _data = {})
cloud_volume = resource_search(id, type, collection_class(:cloud_volumes))
task_id = cloud_volume.delete_volume_queue(User.current_user)
action_result(true, "Deleting Cloud Volume #{cloud_volume.name}", :task_id => task_id)
rescue => err
action_result(false, err.to_s)
end
end
end
10 changes: 9 additions & 1 deletion config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@
:identifier: cloud_volume
:options:
- :collection
:verbs: *gp
:verbs: *gpd
:klass: CloudVolume
:collection_actions:
:get:
Expand All @@ -477,10 +477,18 @@
:post:
- :name: query
:identifier: cloud_volume_show_list
- :name: delete
:identifier: cloud_volume_delete
:resource_actions:
:get:
- :name: read
:identifier: cloud_volume
:post:
- :name: delete
:identifier: cloud_volume_delete
:delete:
- :name: delete
:identifier: cloud_volume_delete
:clusters:
:description: Clusters
:identifier: ems_cluster
Expand Down
80 changes: 80 additions & 0 deletions spec/requests/api/cloud_volumes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,84 @@
"id" => cloud_volume.id
)
end

it "rejects delete request without appropriate role" do
api_basic_authorize

run_post(cloud_volumes_url, :action => 'delete')

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

it "can delete a single cloud volume" do
zone = FactoryGirl.create(:zone, :name => "api_zone")
aws = FactoryGirl.create(:ems_amazon, :zone => zone)

cloud_volume1 = FactoryGirl.create(:cloud_volume, :ext_management_system => aws, :name => "CloudVolume1")

api_basic_authorize action_identifier(:cloud_volumes, :delete, :resource_actions, :post)

run_post(cloud_volumes_url(cloud_volume1.id), :action => "delete")

expected = {
'message' => 'Deleting Cloud Volume CloudVolume1',
'success' => true,
'task_id' => a_kind_of(Numeric)
}

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

it "can delete a cloud volume with DELETE as a resource action" do
zone = FactoryGirl.create(:zone, :name => "api_zone")
aws = FactoryGirl.create(:ems_amazon, :zone => zone)

cloud_volume1 = FactoryGirl.create(:cloud_volume, :ext_management_system => aws, :name => "CloudVolume1")

api_basic_authorize action_identifier(:cloud_volumes, :delete, :resource_actions, :delete)

run_delete cloud_volumes_url(cloud_volume1.id)

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

it "rejects delete request with DELETE as a resource action without appropriate role" do
cloud_volume = FactoryGirl.create(:cloud_volume)

api_basic_authorize

run_delete cloud_volumes_url(cloud_volume.id)

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

it 'can delete cloud volumes through POST' do
zone = FactoryGirl.create(:zone, :name => "api_zone")
aws = FactoryGirl.create(:ems_amazon, :zone => zone)

cloud_volume1 = FactoryGirl.create(:cloud_volume, :ext_management_system => aws, :name => "CloudVolume1")
cloud_volume2 = FactoryGirl.create(:cloud_volume, :ext_management_system => aws, :name => "CloudVolume2")

api_basic_authorize collection_action_identifier(:cloud_volumes, :delete, :post)

expected = {
'results' => a_collection_containing_exactly(
a_hash_including(
'success' => true,
'message' => a_string_including('Deleting Cloud Volume CloudVolume1'),
'task_id' => a_kind_of(Numeric)
),
a_hash_including(
'success' => true,
'message' => a_string_including('Deleting Cloud Volume CloudVolume2'),
'task_id' => a_kind_of(Numeric)
)
)
}
run_post(cloud_volumes_url, :action => 'delete', :resources => [{ 'id' => cloud_volume1.id }, { 'id' => cloud_volume2.id }])

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

0 comments on commit d4e12c9

Please sign in to comment.