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

Transformation Plan, Request, and Task for V2V #16960

Merged
merged 4 commits into from
Feb 19, 2018

Conversation

bzwei
Copy link
Contributor

@bzwei bzwei commented Feb 6, 2018

  1. Introduce new class for migration plan
  2. Introduce new request and task types for execution

Depends on #16787

@bzwei
Copy link
Contributor Author

bzwei commented Feb 6, 2018

@miq-bot add_label v2v

@bzwei
Copy link
Contributor Author

bzwei commented Feb 6, 2018

cc @fdupont-redhat @lfu
@miq-bot assign @gmcculloug

@bzwei
Copy link
Contributor Author

bzwei commented Feb 7, 2018

cc @jntullo

@bzwei bzwei force-pushed the v2v_service_template branch 2 times, most recently from 96f24fd to 90f64b9 Compare February 7, 2018 22:12
@bzwei bzwei force-pushed the v2v_service_template branch 3 times, most recently from 3fe7629 to d3f93fc Compare February 13, 2018 14:10
Copy link
Member

@gmcculloug gmcculloug left a 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?
Copy link
Member

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!
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@bzwei bzwei force-pushed the v2v_service_template branch 4 times, most recently from c3df843 to cba456c Compare February 14, 2018 22:22
@bzwei bzwei changed the title [WIP] initial support for migration plan and request Transformation Plan, Request, and Task for V2V Feb 14, 2018
@bzwei
Copy link
Contributor Author

bzwei commented Feb 14, 2018

@miq-bot remove_label wip

@miq-bot miq-bot removed the wip label Feb 14, 2018
@bzwei
Copy link
Contributor Author

bzwei commented Feb 14, 2018

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

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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])
Copy link
Member

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?

Copy link
Contributor Author

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')
Copy link
Member

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')
Copy link
Member

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

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?)

Copy link
Contributor Author

@bzwei bzwei Feb 19, 2018

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

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

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

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.

@miq-bot
Copy link
Member

miq-bot commented Feb 19, 2018

This pull request is not mergeable. Please rebase and repush.

Changes made to prepare for introducing new models for V2V service template
@bzwei bzwei force-pushed the v2v_service_template branch from b497025 to 074edae Compare February 19, 2018 16:37
@bzwei bzwei force-pushed the v2v_service_template branch from 074edae to ee4b78b Compare February 19, 2018 17:10
@miq-bot
Copy link
Member

miq-bot commented Feb 19, 2018

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
14 files checked, 0 offenses detected
Everything looks fine. ⭐

@gmcculloug gmcculloug merged commit 02af759 into ManageIQ:master Feb 19, 2018
@gmcculloug gmcculloug added this to the Sprint 80 Ending Feb 26, 2018 milestone Feb 19, 2018
@bzwei
Copy link
Contributor Author

bzwei commented Feb 27, 2018

@miq-bot add_label enhancement

@himdel
Copy link
Contributor

himdel commented May 29, 2018

@miq-bot add_label gaprindashvili/yes

(ManageIQ/manageiq-ui-classic#3963: because Could not create Service Template - uninitialized constant ServiceTemplateTransformationPlan when attempting to create a Migration Plan in v2v.)

(looks like the factory merge conflict comes from #16939)

simaishi pushed a commit that referenced this pull request May 29, 2018
Transformation Plan, Request, and Task for V2V
(cherry picked from commit 02af759)
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit b272ec13bf625da36d3df9eb817d34a0593722d2
Author: Greg McCullough <[email protected]>
Date:   Mon Feb 19 13:41:15 2018 -0500

    Merge pull request #16960 from bzwei/v2v_service_template
    
    Transformation Plan, Request, and Task for V2V
    (cherry picked from commit 02af759aa7525ea840177178589619fc892853c7)

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