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

Adjust VM validity correctly while editing a ServiceTemplate record #18065

Merged
merged 3 commits into from
Oct 24, 2018

Conversation

AparnaKarve
Copy link
Contributor

Currently VM belonging to a migration plan is being categorized as an invalid VM (in_other_plan) when the plan is being edited.
This is incorrect since the VM is already part of the plan and should be evaluated to a valid VM.

Fixes ManageIQ/manageiq-v2v#677

VMs belonging to a Plan are valid VMs and should not be categorized as `in_other_plan`
@AparnaKarve
Copy link
Contributor Author

@miq-bot add_label hammer/yes

@miq-bot assign @lfu

@@ -31,6 +31,7 @@

describe '#search_vms_and_validate' do
let(:vm) { FactoryGirl.create(:vm_vmware, :name => 'test_vm', :ems_cluster => src, :ext_management_system => FactoryGirl.create(:ext_management_system)) }
let(:vm2) { FactoryGirl.create(:vm_vmware, :name => 'test_vm2', :ems_cluster => src, :ext_management_system => FactoryGirl.create(:ext_management_system)) }
Copy link
Member

Choose a reason for hiding this comment

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

Please remove :name attribute since the factory sequences this for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, addressed that.

@@ -98,7 +99,7 @@ def vm_migration_status(vm)
return VM_MIGRATED unless vm_as_resources.where(:status => ServiceResource::STATUS_COMPLETED).empty?

# VM failed in previous migration
vm_as_resources.all? { |rsc| rsc.status == ServiceResource::STATUS_FAILED } ? VM_VALID : VM_IN_OTHER_PLAN
vm_as_resources.all? { |rsc| rsc.status == ServiceResource::STATUS_FAILED || rsc.service_template_id.to_s == @service_template_id } ? VM_VALID : VM_IN_OTHER_PLAN
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 @service_template_id a string?

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 UI has service_template_id info available to it as a string (extracted from a JSON), so it sends that as is to the backend.

Usually the interaction between the UI and the backend when it comes to id's is always in the string format.

Copy link
Member

Choose a reason for hiding this comment

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

I know about the JSON limitation with bigint, but once we're in a model, I would expect anything_id to be a bigint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, in that case I would have to apply .to_i to service_template_id in

@service_template_id = service_template_id

Does that work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bdunne I have made the above change in the last commit c7dc8ae
Does that look OK?

@lfu
Copy link
Member

lfu commented Oct 8, 2018

LGTM 👍
cc @roliveri

@mapping = mapping
@vm_list = vm_list
@service_template_id = service_template_id.to_i
Copy link
Member

Choose a reason for hiding this comment

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

This can hit a null pointer if the param is nil. Probably just need to protect against this, or decide that the service_template_id param can't be nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I addressed that with -

@service_template_id = service_template_id.try(:to_i)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interestingly enough, nil.to_i returns 0 :)

@miq-bot
Copy link
Member

miq-bot commented Oct 12, 2018

Checked commits AparnaKarve/manageiq@36de171~...d41949d with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 1 offense detected

app/models/transformation_mapping/vm_migration_validator.rb

@AparnaKarve
Copy link
Contributor Author

@miq-bot assign @roliveri

@roliveri Would you be able to review and merge this?
Thanks!

@miq-bot miq-bot assigned roliveri and unassigned lfu Oct 16, 2018
@roliveri roliveri merged commit 9caf12f into ManageIQ:master Oct 24, 2018
@roliveri roliveri added this to the Sprint 98 Ending Nov 5, 2018 milestone Oct 24, 2018
@AparnaKarve AparnaKarve deleted the adjust_vm_validity_edit_plan branch October 24, 2018 15:49
simaishi pushed a commit that referenced this pull request Oct 25, 2018
Adjust VM validity correctly while editing a ServiceTemplate record

(cherry picked from commit 9caf12f)
@simaishi
Copy link
Contributor

Hammer backport details:

$ git log -1
commit 9ae1f0df46ed6b7712e71bd0c4c9294c14e773a0
Author: Richard Oliveri <oliveri.richard.github@gmail.com>
Date:   Wed Oct 24 11:44:27 2018 -0400

    Merge pull request #18065 from AparnaKarve/adjust_vm_validity_edit_plan
    
    Adjust VM validity correctly while editing a ServiceTemplate record
    
    (cherry picked from commit 9caf12f16ed45819bcf82510d6e73619096bf5f2)

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.

7 participants