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

Fixes undefined method name error during CSV validation required for v2v migration #17650

Merged
merged 4 commits into from
Jun 29, 2018

Conversation

AparnaKarve
Copy link
Contributor

@AparnaKarve AparnaKarve commented Jun 28, 2018

Account for a case when there is no cluster or ext_management_system info available from the csv file.

https://bugzilla.redhat.com/show_bug.cgi?id=1596318

Also requires v2v UI PR to show the new inactive VM state in the UI -
ManageIQ/manageiq-v2v#450

@AparnaKarve
Copy link
Contributor Author

@bzwei Can you review this?

@miq-bot add_label bug

@miq-bot miq-bot added the bug label Jun 28, 2018
@@ -82,8 +82,8 @@ def describe_non_vm(vm_name)
def describe_vm(vm, reason)
{
"name" => vm.name,
"cluster" => vm.ems_cluster.name,
"path" => "#{vm.ext_management_system.name}/#{vm.parent_blue_folder_path(:exclude_non_display_folders => true)}",
"cluster" => vm.ems_cluster.try(:name),
Copy link
Contributor

Choose a reason for hiding this comment

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

vm.ems_cluster.try(:name) || ''

"cluster" => vm.ems_cluster.name,
"path" => "#{vm.ext_management_system.name}/#{vm.parent_blue_folder_path(:exclude_non_display_folders => true)}",
"cluster" => vm.ems_cluster.try(:name),
"path" => vm.try(:ext_management_system) ? "#{vm.ext_management_system.name}/#{vm.parent_blue_folder_path(:exclude_non_display_folders => true)}" : "",
Copy link
Contributor

Choose a reason for hiding this comment

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

vm.ext_management_system ? "#{vm.ext_management_system.name}/#{vm.parent_blue_folder_path(:exclude_non_display_folders => true)}" : ''

@bzwei
Copy link
Contributor

bzwei commented Jun 28, 2018

@miq-bot add_label transformation

@miq-bot miq-bot added the v2v label Jun 28, 2018
@AparnaKarve AparnaKarve force-pushed the fix_csv_describe_vm branch from eb044f4 to a1d9804 Compare June 28, 2018 15:02
@AparnaKarve
Copy link
Contributor Author

Thanks @bzwei

@chrispy1
Copy link

@miq-bot add_label blocker

@AparnaKarve
Copy link
Contributor Author

@miq-bot add_label gaprindashvili/yes

@AparnaKarve
Copy link
Contributor Author

@gmcculloug Can you please merge this? Thanks.

@gmcculloug
Copy link
Member

@AparnaKarve I think this is the wrong fix. It looks like the vm is no longer valid (either orphaned or archived) so we should not be returning it in the list of available VMs.

Discuss with @bzwei about moving the VM into the invalid return set.

@bzwei
Copy link
Contributor

bzwei commented Jun 28, 2018

@AparnaKarve in #validate_vm method we should check whether vm.ext_management_system exists. Return an error message if not.

@AparnaKarve
Copy link
Contributor Author

@gmcculloug, I came across this issue after looking into a use case that @bthurber mentioned.

His csv file had the following entry (only the Name field)

Name
dev-windows-server-2012

@bthurber Can you confirm if the VM in your environment dev-windows-server-2012 is valid or orphaned or archived?

@AparnaKarve
Copy link
Contributor Author

#validate_vm method we should check whether vm.ext_management_system exists. Return an error message if not.

@bzwei @gmcculloug That does make sense.

The other change is vm.ems_cluster.try(:name) || ''
For a VM, is is possible to have a cluster with no name?

@gmcculloug
Copy link
Member

For the cluster issue, name is a column on the ems_clusters table so if you have a cluster the name properly will be available. My guess here is that the VM had no Provider and therefore was also disconnected from the cluster in the database.

@AparnaKarve
Copy link
Contributor Author

The change in this PR was added in the describe_vm method

The VM in question may belong in the invalid list, but it still needs to be described to show the Cluster/Path details in the UI as shown below -

screen shot 2018-06-28 at 12 45 10 pm

So to be able to describe, we do need all the try/nil checks that have been added in the PR regardless of the validity of the VM.
Hence I think the changes in the PR are valid.

@Loicavenel
Copy link

@bzwei can we review and merge ASAP?

@bzwei
Copy link
Contributor

bzwei commented Jun 28, 2018

@AparnaKarve You're right. The changes are still needed to describe the VM. But we need to enhance #validate_vm method to raise an error message either when ext_management_system or ems_cluster is nil. It is good to have all the changes in one PR to make the fix complete.

I think you will need a BZ to back port the fix .

@AparnaKarve
Copy link
Contributor Author

@bzwei Can you review 74c7efa?

@@ -5,6 +5,7 @@ class TransformationMapping < ApplicationRecord
VM_MIGRATED = "migrated".freeze
VM_NOT_EXIST = "not_exist".freeze
VM_VALID = "ok".freeze
VM_ORPHANED_OR_ARCHIVED = "orphaned".freeze
Copy link
Contributor

Choose a reason for hiding this comment

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

change to VM_INACTIVE = "inactive".freeze

@@ -94,6 +95,11 @@ def validate_vm(vm, quick = true)
# a valid vm must find all resources in the mapping and has never been migrated
invalid_list = []

if vm.ext_management_system.nil?
Copy link
Contributor

Choose a reason for hiding this comment

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

remove Ln 98 - 102.
Add following to https://github.com/ManageIQ/manageiq/blob/master/app/models/vm.rb#L125

return TransformationMapping::VM_INACTIVE unless active?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With this change, the return reason I get is undefined and not VM_INACTIVE because the return happens from here - https://github.com/ManageIQ/manageiq/blob/master/app/models/transformation_mapping.rb#L99

and not from validate_v2v_migration

Copy link
Contributor Author

@AparnaKarve AparnaKarve Jun 28, 2018

Choose a reason for hiding this comment

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

I think the active? check needs to happen before we call this block

unless valid_cluster?(vm)
  invalid_list << "cluster: %{name}" % {:name => vm.ems_cluster.name}
  return no_mapping_msg(invalid_list) if quick
end

since the return is intercepted by the above block, because of which our return reason is undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bzwei I had to go with the implementation in c2b8ec7, for the reason mentioned above.

@bzwei
Copy link
Contributor

bzwei commented Jun 28, 2018

@AparnaKarve Please add a spec case for an inactive VM in the context of https://github.com/ManageIQ/manageiq/blob/master/spec/models/transformation_mapping_spec.rb#L46

@AparnaKarve AparnaKarve force-pushed the fix_csv_describe_vm branch from 74c7efa to 9206cc0 Compare June 28, 2018 22:41
@@ -94,6 +95,8 @@ def validate_vm(vm, quick = true)
# a valid vm must find all resources in the mapping and has never been migrated
invalid_list = []

return VM_INACTIVE unless vm.active?
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this line into #validate_v2v_migration and move vm.validate_v2v_migration to the beginning of this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if I move vm.validate_v2v_migration to the beginning of this method, it would have to be a return call as shown below in order to avoid executing the unless valid_cluster?(vm) block

return vm.validate_v2v_migration

which won't work for other cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand that you are trying not to use the VM_INACTIVE constant in the TransformationMapping methods, but that does not seem to be easily doable.

Copy link
Member

Choose a reason for hiding this comment

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

@bzwei any suggestions for Aparna. We need this PR merged asap.

Copy link
Contributor

Choose a reason for hiding this comment

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

def validate_vm(vm, quick = true)
  validate_error = vm.validate_v2v_migration
  return validate_error if validate_error

  invalid_list = []
  ...

  # remove vm.validate_v2v_migration

Copy link
Member

Choose a reason for hiding this comment

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

@AparnaKarve VM_VALID is a contant in TransformationMapping.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

VM_INACTIVE is also a new constant in TransformationMapping added in this PR

@lfu just trying to understand why this approach is preferable compared to the approach taken in the PR

Copy link
Contributor

Choose a reason for hiding this comment

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

We are not trying to avoid using constants in this class. Logically active? check belongs to method #validate_v2v_transformation.
You will still need to add

  return TransformationMapping::VM_INACTIVE unless active?

in Vm#validate_v2v_migration.
Lucy has a refactoring PR to restructure the constants and methods. For now this is the solution.

Copy link
Contributor Author

@AparnaKarve AparnaKarve Jun 29, 2018

Choose a reason for hiding this comment

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

In the interest of time, I can just go ahead and make the above changes now
(although I am not sure how this approach is better than the PR approach)

@bzwei Does the above code look OK? If yes, I can push an update shortly.
Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

New update pushed. deacfdc

# a valid vm must find all resources in the mapping and has never been migrated
invalid_list = []

return VM_INACTIVE unless vm.active?
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this line return VM_INACTIVE unless vm.active?. Looks good else.

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, agree that should have been removed. Thanks

@AparnaKarve AparnaKarve force-pushed the fix_csv_describe_vm branch from deacfdc to 04d8b3e Compare June 29, 2018 17:41
@miq-bot
Copy link
Member

miq-bot commented Jun 29, 2018

Checked commits AparnaKarve/manageiq@a1d9804~...04d8b3e with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 0 offenses detected
Everything looks fine. 🍪

@JPrause
Copy link
Member

JPrause commented Jun 29, 2018

@AparnaKarve @bzwei are reviews/edits complete? If yes, who can merge.

@bzwei
Copy link
Contributor

bzwei commented Jun 29, 2018

LGTM. But I can't merge. @mkanoor please help.

@mkanoor mkanoor merged commit 5ff11a6 into ManageIQ:master Jun 29, 2018
@mkanoor mkanoor added this to the Sprint 89 Ending Jul 2, 2018 milestone Jun 29, 2018
@JPrause
Copy link
Member

JPrause commented Jun 29, 2018

Thanks all! Team effort 👍

simaishi pushed a commit that referenced this pull request Jun 29, 2018
Fixes undefined method `name` error during CSV validation required for v2v migration
(cherry picked from commit 5ff11a6)

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

Gaprindashvili backport details:

$ git log -1
commit 27c37f1f3e9ca64db05dfbe348bb06b31e19c6d8
Author: Madhu Kanoor <[email protected]>
Date:   Fri Jun 29 15:12:11 2018 -0400

    Merge pull request #17650 from AparnaKarve/fix_csv_describe_vm
    
    Fixes undefined method `name` error during CSV validation required for v2v migration
    (cherry picked from commit 5ff11a6f899bd9fac9f4146fbbb23b9869995fb9)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1596850

@AparnaKarve AparnaKarve deleted the fix_csv_describe_vm branch June 29, 2018 20:07
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.

10 participants