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

Support create snapshot for VM #189

Merged
merged 1 commit into from
Feb 26, 2018

Conversation

sasoc
Copy link
Contributor

@sasoc sasoc commented Feb 23, 2018

Add vm_create_snapshot method that calls vCloud API
to create snapshot for VM.

BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1550906

@sasoc
Copy link
Contributor Author

sasoc commented Feb 23, 2018

create_snapshot

@sasoc
Copy link
Contributor Author

sasoc commented Feb 23, 2018

screen shot 2018-02-23 at 14 50 35

@sasoc
Copy link
Contributor Author

sasoc commented Feb 23, 2018

cc @miha-plesko

Copy link
Contributor

@miha-plesko miha-plesko left a 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)
Copy link
Contributor

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.

Copy link
Contributor

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'
Copy link
Contributor

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?

Copy link
Contributor

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)
Copy link
Contributor

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} }
Copy link
Contributor

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"

@miha-plesko
Copy link
Contributor

@miq-bot assign @agrare
@miq-bot add_label enhancement,gaprindashvili/yes

@@ -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'
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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.

@sasoc sasoc force-pushed the support-create-snapshot-for-vm branch from 8c9df02 to 1482014 Compare February 26, 2018 08:36
Add `vm_create_snapshot` method that calls vCloud API
to create snapshot for VM.
@sasoc sasoc force-pushed the support-create-snapshot-for-vm branch from 1482014 to 54eb5b0 Compare February 26, 2018 10:39
@miq-bot
Copy link
Member

miq-bot commented Feb 26, 2018

Checked commit sasoc@54eb5b0 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 0 offenses detected
Everything looks fine. 🍰

Copy link
Member

@agrare agrare left a 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

@agrare agrare merged commit 04ff0cd into ManageIQ:master Feb 26, 2018
@agrare agrare added this to the Sprint 80 Ending Feb 26, 2018 milestone Feb 26, 2018
@miha-plesko
Copy link
Contributor

simaishi pushed a commit that referenced this pull request Mar 7, 2018
@simaishi
Copy link
Contributor

simaishi commented Mar 7, 2018

Gaprindashvili backport details:

$ git log -1
commit 1153155d392bec7ff863e4951e1d1b93944c6e5b
Author: Adam Grare <[email protected]>
Date:   Mon Feb 26 08:48:04 2018 -0500

    Merge pull request #189 from sasoc/support-create-snapshot-for-vm
    
    Support create snapshot for VM
    (cherry picked from commit 04ff0cd0553d028a92716a902939ec01531e7689)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1552686

agrare pushed a commit to agrare/manageiq-providers-vmware that referenced this pull request Apr 15, 2019
…ement_typo

Fixed typo in Service Retirement method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants