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 bulk delete for snapshots API #13711

Merged
merged 2 commits into from
Jan 31, 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
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