diff --git a/config/api.yml b/config/api.yml index aa5dc9bb70a..dc0dcfd8f85 100644 --- a/config/api.yml +++ b/config/api.yml @@ -1612,6 +1612,8 @@ :post: - :name: create :identifier: vm_snapshot_add + - :name: delete + :identifier: vm_snapshot_delete :subresource_actions: :get: - :name: read diff --git a/spec/requests/api/snapshots_spec.rb b/spec/requests/api/snapshots_spec.rb index e80c0d9c64f..6c3a2efd352 100644 --- a/spec/requests/api/snapshots_spec.rb +++ b/spec/requests/api/snapshots_spec.rb @@ -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) @@ -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))