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

Refactor VM naming method in provisioning task to support call from automate #16897

Merged
merged 2 commits into from
Jan 26, 2018

Conversation

gmcculloug
Copy link
Member

@gmcculloug gmcculloug commented Jan 26, 2018

VM naming during provisioning runs when the provision task is initially created. This is generally not an issue with Lifecycle provisioning. For Service provisioning this can be an issue because the dialog field data gets pushed down to the tasks after they are created (seems obvious) and therefore after the naming method has run.

Therefore it is difficult for the dialog field data to be used as part of the VM naming.

Furthermore, the naming logic at task creation supports an auto-incrementing feature, with synchronization to ensure uniqueness, which is not available from other calls.

This PR does not change the location of when the naming code runs, it make the vm_naming method available to an external caller so they can generate the name at a later time in the provisioning process and take advantage of the auto-incrementing name feature.

Note: The first commit is refactoring. The main changes are in the second commit.

Links [Optional]

Steps for Testing/QA [Optional]

In automate override one of the VM provisioning state-machine methods, like the Provision method and to call the newly exposed update_vm_name method and pass any name. It can contain the enumeration sequence ($n{#}) used to auto-increment the name. For example, "clone_test_$n{4}" should generate a VM with a name like "clone_test_0001".

options[:vm_target_name] = new_name
options[:vm_target_hostname] = get_hostname(new_name)

update(:description => self.class.get_description(self, new_name), :options => options)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to use update rather than update_attributes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I think either works here so I'll change it if you prefer.

Copy link
Member

@tinaafitz tinaafitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmcculloug Looks good.

@gmcculloug
Copy link
Member Author

@bdunne Wanted to mention the smaller refactoring in the test as well to not use MiqRegion.seed and just create a MiqRegion instance.

end

it "Updates the request description with only name parameter passed" do
expect(@pr).to receive(:update_description_from_tasks)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be more to this than just checking that the method was called?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, working on it.

end

def update_vm_name(new_name, update_request: true)
new_name = get_vm_full_name(new_name, true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call the class method directly? (even though it seems strange that it is a class method)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can remove the instance method. It is a class method because the logic used from both MiqRequest and MiqRequestTask.

@gmcculloug gmcculloug force-pushed the provision_vm_name branch 2 times, most recently from 109131d to 3eacbb8 Compare January 26, 2018 21:43
@gmcculloug
Copy link
Member Author

@bdunne Changes pushed.

@miq-bot
Copy link
Member

miq-bot commented Jan 26, 2018

Checked commits gmcculloug/manageiq@1b85d4a~...0818e15 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0
5 files checked, 0 offenses detected
Everything looks fine. ⭐

@bdunne bdunne merged commit ee6cb2d into ManageIQ:master Jan 26, 2018
@bdunne bdunne added this to the Sprint 78 Ending Jan 29, 2018 milestone Jan 26, 2018
simaishi pushed a commit that referenced this pull request Jan 29, 2018
Refactor VM naming method in provisioning task to support call from automate
(cherry picked from commit ee6cb2d)

https://bugzilla.redhat.com/show_bug.cgi?id=1539750
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit e72d1155b356a77c1256dcdd34e4cf37884413f9
Author: Brandon Dunne <brandondunne@hotmail.com>
Date:   Fri Jan 26 17:23:11 2018 -0500

    Merge pull request #16897 from gmcculloug/provision_vm_name
    
    Refactor VM naming method in provisioning task to support call from automate
    (cherry picked from commit ee6cb2d7ffab0853db0376aa5b4d31e20410c5b8)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1539750

simaishi pushed a commit that referenced this pull request Jan 29, 2018
Refactor VM naming method in provisioning task to support call from automate
(cherry picked from commit ee6cb2d)

https://bugzilla.redhat.com/show_bug.cgi?id=1539752
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit 97a67036c90689c9cbde3813dce16eb09a6502f7
Author: Brandon Dunne <brandondunne@hotmail.com>
Date:   Fri Jan 26 17:23:11 2018 -0500

    Merge pull request #16897 from gmcculloug/provision_vm_name
    
    Refactor VM naming method in provisioning task to support call from automate
    (cherry picked from commit ee6cb2d7ffab0853db0376aa5b4d31e20410c5b8)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1539752

d-m-u pushed a commit to d-m-u/manageiq that referenced this pull request Jun 6, 2018
Refactor VM naming method in provisioning task to support call from automate
(cherry picked from commit ee6cb2d)

https://bugzilla.redhat.com/show_bug.cgi?id=1539752
@gmcculloug gmcculloug deleted the provision_vm_name branch September 7, 2018 00:27
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.

5 participants