-
Notifications
You must be signed in to change notification settings - Fork 896
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
Snapshots revert API #13829
Snapshots revert API #13829
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,52 @@ | |
end | ||
end | ||
|
||
describe "POST /api/vms/:c_id/snapshots/:s_id with revert action" do | ||
it "can queue a VM for reverting to a snapshot" do | ||
api_basic_authorize(action_identifier(:vms, :revert, :snapshots_subresource_actions)) | ||
ems = FactoryGirl.create(:ext_management_system) | ||
host = FactoryGirl.create(:host, :ext_management_system => ems) | ||
vm = FactoryGirl.create(:vm_vmware, :name => "Alice's VM", :host => host, :ext_management_system => ems) | ||
snapshot = FactoryGirl.create(:snapshot, :name => "Alice's snapshot", :vm_or_template => vm) | ||
|
||
run_post("#{vms_url(vm.id)}/snapshots/#{snapshot.id}", :action => "revert") | ||
|
||
expected = { | ||
"message" => "Reverting to snapshot Alice's snapshot for Virtual Machine id:#{vm.id} name:'Alice'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 | ||
|
||
it "renders a failed action response if reverting is not supported" do | ||
api_basic_authorize(action_identifier(:vms, :revert, :snapshots_subresource_actions)) | ||
vm = FactoryGirl.create(:vm_vmware) | ||
snapshot = FactoryGirl.create(:snapshot, :vm_or_template => vm) | ||
|
||
run_post("#{vms_url(vm.id)}/snapshots/#{snapshot.id}", :action => "revert") | ||
|
||
expected = { | ||
"success" => false, | ||
"message" => "The VM is not connected to a Host" | ||
} | ||
expect(response.parsed_body).to include(expected) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it "will not revert to a snapshot unless authorized" do | ||
api_basic_authorize | ||
vm = FactoryGirl.create(:vm_vmware) | ||
snapshot = FactoryGirl.create(:snapshot, :vm_or_template => vm) | ||
|
||
run_post("#{vms_url(vm.id)}/snapshots/#{snapshot.id}", :action => "revert") | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
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(:vms, :delete, :snapshots_subresource_actions, :delete)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing delete post action test ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I understand - is this not it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, misread the diffs. yes you have it. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change here ? do you need to rebase maybe ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Up to this point we haven't needed to have a subresource POST action, so this wasn't needed in the previous PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused, we had the delete post action before. we may be missing a test for that, so it was never exercised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abellotti in the case of snapshots, the delete action would have used the collection identifier erroneously, which happens to be the same. So there was no way to test this in an integration test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it now, problem is that it worked for delete because it used the delete action's identifier on the subcollection, but we don't implement a bulk revert action on the snapshots subcollection (does not make sense to do so), thus this problem emerged. So I'm good with this fix, Thanks.