-
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
Fixes undefined method name
error during CSV validation required for v2v migration
#17650
Conversation
app/models/transformation_mapping.rb
Outdated
@@ -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), |
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.
vm.ems_cluster.try(:name) || ''
app/models/transformation_mapping.rb
Outdated
"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)}" : "", |
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.
vm.ext_management_system ? "#{vm.ext_management_system.name}/#{vm.parent_blue_folder_path(:exclude_non_display_folders => true)}" : ''
@miq-bot add_label transformation |
eb044f4
to
a1d9804
Compare
Thanks @bzwei |
@miq-bot add_label blocker |
@miq-bot add_label gaprindashvili/yes |
@gmcculloug Can you please merge this? Thanks. |
@AparnaKarve I think this is the wrong fix. It looks like the Discuss with @bzwei about moving the VM into the invalid return set. |
@AparnaKarve in |
@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)
@bthurber Can you confirm if the VM in your environment |
@bzwei @gmcculloug That does make sense. The other change is |
For the cluster issue, |
The change in this PR was added in the 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 - So to be able to describe, we do need all the |
@bzwei can we review and merge ASAP? |
@AparnaKarve You're right. The changes are still needed to describe the VM. But we need to enhance I think you will need a BZ to back port the fix . |
app/models/transformation_mapping.rb
Outdated
@@ -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 |
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.
change to VM_INACTIVE = "inactive".freeze
app/models/transformation_mapping.rb
Outdated
@@ -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? |
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.
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?
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.
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
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 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
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.
@AparnaKarve Please add a spec case for an inactive VM in the context of |
74c7efa
to
9206cc0
Compare
app/models/transformation_mapping.rb
Outdated
@@ -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? |
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.
Move this line into #validate_v2v_migration
and move vm.validate_v2v_migration
to the beginning of this 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.
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.
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 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.
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 any suggestions for Aparna. We need this PR merged asap.
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.
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
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.
@AparnaKarve VM_VALID
is a contant in TransformationMapping.
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.
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
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 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.
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.
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.
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.
New update pushed. deacfdc
app/models/transformation_mapping.rb
Outdated
# a valid vm must find all resources in the mapping and has never been migrated | ||
invalid_list = [] | ||
|
||
return VM_INACTIVE unless vm.active? |
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.
remove this line return VM_INACTIVE unless vm.active?
. Looks good else.
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, agree that should have been removed. Thanks
deacfdc
to
04d8b3e
Compare
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 |
@AparnaKarve @bzwei are reviews/edits complete? If yes, who can merge. |
LGTM. But I can't merge. @mkanoor please help. |
Thanks all! Team effort 👍 |
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
Gaprindashvili backport details:
|
Account for a case when there is no
cluster
orext_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