-
Notifications
You must be signed in to change notification settings - Fork 898
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
Conversation
app/models/miq_provision.rb
Outdated
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) |
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.
Any reason to use update
rather than update_attributes
?
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.
Nope, I think either works here so I'll change it if you prefer.
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.
@gmcculloug Looks good.
@bdunne Wanted to mention the smaller refactoring in the test as well to not use |
spec/models/miq_provision_spec.rb
Outdated
end | ||
|
||
it "Updates the request description with only name parameter passed" do | ||
expect(@pr).to receive(:update_description_from_tasks) |
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.
Should there be more to this than just checking that the method was called?
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.
Yup, working on it.
app/models/miq_provision.rb
Outdated
end | ||
|
||
def update_vm_name(new_name, update_request: true) | ||
new_name = get_vm_full_name(new_name, true) |
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.
Should we call the class method directly? (even though it seems strange that it is a class method)
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.
Sure, I can remove the instance method. It is a class method because the logic used from both MiqRequest
and MiqRequestTask
.
109131d
to
3eacbb8
Compare
3eacbb8
to
0818e15
Compare
@bdunne Changes pushed. |
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 |
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
Gaprindashvili backport details:
|
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
Fine backport details:
|
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
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 exposedupdate_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".