Skip to content

Commit

Permalink
Merge pull request #13711 from imtayadeway/api/snapshots-bulk-delete
Browse files Browse the repository at this point in the history
Add bulk delete for snapshots API
  • Loading branch information
abellotti committed Jan 31, 2017
2 parents 0ebc2e9 + 9782e4e commit 77af12e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,8 @@
:post:
- :name: create
:identifier: vm_snapshot_add
- :name: delete
:identifier: vm_snapshot_delete
:subresource_actions:
:get:
- :name: read
Expand Down
41 changes: 40 additions & 1 deletion spec/requests/api/snapshots_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
end
end

describe "POST /api/vms/:c_id/snapshots with delete action" do
describe "POST /api/vms/:c_id/snapshots/:s_id with delete action" do
it "can queue a snapshot for deletion" do
api_basic_authorize(action_identifier(:snapshots, :delete, :subresource_actions, :delete))
ems = FactoryGirl.create(:ext_management_system)
Expand Down Expand Up @@ -179,6 +179,45 @@
end
end

describe "POST /api/vms/:c_id/snapshots with delete action" do
it "can queue multiple snapshots for deletion" do
api_basic_authorize(action_identifier(:snapshots, :delete, :subresource_actions, :delete))
ems = FactoryGirl.create(:ext_management_system)
host = FactoryGirl.create(:host, :ext_management_system => ems)
vm = FactoryGirl.create(:vm_vmware, :name => "Alice and Bob's VM", :host => host, :ext_management_system => ems)
snapshot1 = FactoryGirl.create(:snapshot, :name => "Alice's snapshot", :vm_or_template => vm)
snapshot2 = FactoryGirl.create(:snapshot, :name => "Bob's snapshot", :vm_or_template => vm)

run_post(
"#{vms_url(vm.id)}/snapshots",
:action => "delete",
:resources => [
{:href => "#{vms_url(vm.id)}/snapshots/#{snapshot1.id}"},
{:href => "#{vms_url(vm.id)}/snapshots/#{snapshot2.id}"}
]
)

expected = {
"results" => a_collection_containing_exactly(
a_hash_including(
"message" => "Deleting snapshot Alice's snapshot for Vm id:#{vm.id} name:'Alice and Bob's VM'",
"success" => true,
"task_href" => a_string_matching(tasks_url),
"task_id" => anything
),
a_hash_including(
"message" => "Deleting snapshot Bob's snapshot for Vm id:#{vm.id} name:'Alice and Bob's VM'",
"success" => true,
"task_href" => a_string_matching(tasks_url),
"task_id" => anything
)
)
}
expect(response.parsed_body).to include(expected)
expect(response).to have_http_status(:ok)
end
end

describe "DELETE /api/vms/:c_id/snapshots/:s_id" do
it "can delete a snapshot" do
api_basic_authorize(action_identifier(:snapshots, :delete, :subresource_actions, :delete))
Expand Down

0 comments on commit 77af12e

Please sign in to comment.