-
Notifications
You must be signed in to change notification settings - Fork 69
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
Support create snapshot for VM #189
Conversation
cc @miha-plesko |
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.
Thanks @sasoc , I have some comments, please take a look.
def vm_create_snapshot(vm, options = {}) | ||
options[:quiesce] = 'false' | ||
with_provider_connection do |service| | ||
service.post_create_snapshot(vm.uid_ems, options) |
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.
You can simply use ems_ref
instead of vm.uid_ems
, because we're on Cloud Provider anyway.
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.
Also, this seems to be asynchronous task but we usually wait for tasks to complete. So could you please go with:
response = service.post_create_snapshot(ems_ref, options)
service.process_task(response.body)
(see here)
@@ -84,4 +84,11 @@ def vm_restart(vm, _options = {}) | |||
def self.display_name(number = 1) | |||
n_('Cloud Provider (VMware vCloud)', 'Cloud Providers (VMware vCloud)', number) | |||
end | |||
|
|||
def vm_create_snapshot(vm, options = {}) | |||
options[:quiesce] = 'false' |
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 would be safer if you do it like it's done on the infra manager: https://github.com/ManageIQ/manageiq-providers-vmware/blob/master/app/models/manageiq/providers/vmware/infra_manager.rb#L334-L340
So basically you set all default options and then only override those that were specifically passed. Also, I'm not sure why would you pass 'false'
(string) and not false
(boolean), is there a reason?
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 agree with @miha-plesko. Set defaults for memory and quiesce (both false) and then merge with given options to allow users to override them.
let(:connection) { double("connection", :post_create_snapshot => "post_create_snapshot") } | ||
|
||
it 'creates a snapshot' do | ||
expect(@ems).to receive(:with_provider_connection).and_yield(connection) |
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.
Please move this into before do
let(:vm) { FactoryGirl.create(:vm_vmware, :ext_management_system => @ems) } | ||
|
||
context ".vm_create_snapshot" do | ||
let(:snapshot_options) { {:name => 'name', :memory => false, :quiesce => false} } |
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 are you passing :quiesce
here? I think it's never used then, because it's hard-coded to "false"
@@ -84,4 +84,11 @@ def vm_restart(vm, _options = {}) | |||
def self.display_name(number = 1) | |||
n_('Cloud Provider (VMware vCloud)', 'Cloud Providers (VMware vCloud)', number) | |||
end | |||
|
|||
def vm_create_snapshot(vm, options = {}) | |||
options[:quiesce] = 'false' |
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 agree with @miha-plesko. Set defaults for memory and quiesce (both false) and then merge with given options to allow users to override them.
it 'creates a snapshot' do | ||
expect(@ems).to receive(:with_provider_connection).and_yield(connection) | ||
|
||
expect(connection).to receive(:post_create_snapshot) |
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.
When you add the process_task
as suggested by @miha-plesko check the example here on how to mock the response.
@@ -22,4 +22,6 @@ def self.calculate_power_state(raw_power_state) | |||
def self.display_name(number = 1) | |||
n_('Instance (VMware vCloud)', 'Instances (VMware vCloud)', number) | |||
end | |||
|
|||
supports :snapshots |
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.
Move this to line 3 (add empty lines) as otherwise it is really hard to spot that the VM supports this.
8c9df02
to
1482014
Compare
Add `vm_create_snapshot` method that calls vCloud API to create snapshot for VM.
1482014
to
54eb5b0
Compare
Checked commit sasoc@54eb5b0 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0 |
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.
👍 looks great thanks @sasoc
Support create snapshot for VM (cherry picked from commit 04ff0cd) https://bugzilla.redhat.com/show_bug.cgi?id=1552686
Gaprindashvili backport details:
|
…ement_typo Fixed typo in Service Retirement method.
Add
vm_create_snapshot
method that calls vCloud APIto create snapshot for VM.
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1550906