-
Notifications
You must be signed in to change notification settings - Fork 897
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
Transformation Plan, Request, and Task for V2V #16960
Conversation
@miq-bot add_label v2v |
cc @fdupont-redhat @lfu |
34cb4fd
to
f6c0a0a
Compare
cc @jntullo |
96f24fd
to
90f64b9
Compare
3fe7629
to
d3f93fc
Compare
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.
@bzwei Can we find a point to un-wip this and iterate over multiple PRs before this PR gets to large.
@@ -138,7 +138,7 @@ def deliver_to_automate(req_type = request_type, _zone = nil) | |||
args[:attrs].merge!(ra.ae_attributes) | |||
end | |||
|
|||
args[:attrs].merge!(MiqAeEngine.create_automation_attributes(destination.class.base_model.name => destination)) | |||
args[:attrs].merge!(MiqAeEngine.create_automation_attributes(destination.class.base_model.name => destination)) unless destination.nil? |
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.
Prefer if destination.present?
over unless logic.
|
||
def add_vms(vm_ids) | ||
vm_ids.each { |vm_id| add_vm(vm_id) } | ||
save! |
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.
Can we load the VM objects and use the existing add_resource
logic of ServiceTemplate instead of creating our own add_vm
method? You may not require the save!
if you make this change.
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.
This is purposely to by-pass the constraint that a VM can belong to only one service/service_template.
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.
Does it make more sense to override the enforce_single_service_parent
method for this service type?
https://github.com/ManageIQ/manageiq/blob/master/app/models/mixins/service_mixin.rb#L113
For now it could just skip it and in the future be used to control if a VM can be in multiple migration plans.
c3df843
to
cba456c
Compare
@miq-bot remove_label wip |
wip label removed. Please review. |
@@ -158,6 +158,10 @@ def deliver_to_automate(req_type = request_type, _zone = nil) | |||
end | |||
end | |||
|
|||
def resource_action | |||
source.resource_actions.detect { |ra| ra.action == 'Provision' } if source.respond_to?(:resource_actions) |
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.
@bzwei This method name should be more descriptive. My guess is you might be trying to abstract the "Provision" part away from the Transformation models. If that is not correct this could be provision_resource_action
.
Otherwise we could use a more generic term like initialize_resource_action
or create_resource_action
.
If we abstract this method name it would allow the subclass to define a different ra.action
value (currently "Provision") by moving the "Provision"
value into a constant that the subclass could override.
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.
My understanding ruby's naming convention - resource_action
means get_resource_action
. I want to abstract the resource action, no matter where it come from. Can be from source
or miq_request
, or other place, can be type Provision
or other type.
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 see that you are already overriding this method for the ServiceTemplateTransformationPlanTask
class.
At the base class I feel it is misleading to have resource_action
return the "Provision" action. It would not be clear to me that resource_action
== "Provision" but there are also "Reconfigure" and "Retirement" actions. This is my main objection to the proposed method name.
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.
The base class is ServiceTemplateProvisionTask
, so the action has to be Provision
. A task can only have one action, for this task Provision
is implied.
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.
Right, the piece I was overlooking was "A task can only have one action". Thanks.
config_info = options[:config_info] | ||
|
||
mapping = if config_info[:transformation_mapping_id] | ||
TransformationMapping.find(config_info[:transformation_mapping_id]) |
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.
Do you mean to raise the RecordNotFound
error here or should this return nil
and raise on line 73 on the check if mapping.blank?
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.
Yes. I mean to have the RecordNotFound
if the caller provides transformation_mapping_id
but invalid. The next exception occurs if no transformation_mapping is given at all.
end | ||
|
||
if mapping.blank? | ||
raise _('Must provide an existing transformation mapping') |
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.
Convert to a single line
end | ||
|
||
if vms.blank? | ||
raise _('Must select a list of valid vms') |
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.
Same
true | ||
end | ||
|
||
def approve_vm(vm_id) |
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.
Who is the caller of this? Is it the UI (through API?)
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.
automate calls it.
|
||
describe 'customize_request_task_attributes' do | ||
it 'overrides #customize_request_task_attributes' do | ||
expect(described_class.instance_methods(false)).to include(:customize_request_task_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.
We should be testing the result of the method and not just the existence of the override.
describe '.create_catalog_item' do | ||
it 'creates and returns a transformation plan' do | ||
service_template = described_class.create_catalog_item(catalog_item_options) | ||
service_template.reload |
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 is this reloaded needed if the call is returning the object for the first time?
If it is needed move the reload
to the end of the first line.
|
||
describe '#after_request_task_create' do | ||
it 'overrides #after_request_task_create' do | ||
expect(described_class.instance_methods(false)).to include(:after_request_task_create) |
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.
Same here. We should be testing the result of the method and not just the existence of the override.
This pull request is not mergeable. Please rebase and repush. |
cba456c
to
b497025
Compare
Changes made to prepare for introducing new models for V2V service template
This is the model to store a migration plan
b497025
to
074edae
Compare
074edae
to
ee4b78b
Compare
Checked commits bzwei/manageiq@ebc0505~...ee4b78b with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0 |
@miq-bot add_label enhancement |
@miq-bot add_label gaprindashvili/yes (ManageIQ/manageiq-ui-classic#3963: because (looks like the factory merge conflict comes from #16939) |
Transformation Plan, Request, and Task for V2V (cherry picked from commit 02af759)
Gaprindashvili backport details:
|
Depends on #16787