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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/models/transformation_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class TransformationMapping < ApplicationRecord
VM_MIGRATED = "migrated".freeze
VM_NOT_EXIST = "not_exist".freeze
VM_VALID = "ok".freeze
VM_INACTIVE = "inactive".freeze

has_many :transformation_mapping_items, :dependent => :destroy
has_many :service_resources, :as => :resource, :dependent => :nullify
Expand Down Expand Up @@ -82,15 +83,18 @@ 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) || '',
"path" => vm.ext_management_system ? "#{vm.ext_management_system.name}/#{vm.parent_blue_folder_path(:exclude_non_display_folders => true)}" : '',
"allocated_size" => vm.allocated_disk_storage,
"id" => vm.id,
"reason" => reason
}
end

def validate_vm(vm, quick = true)
validate_result = vm.validate_v2v_migration
return validate_result unless validate_result == VM_VALID

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

Expand All @@ -111,8 +115,7 @@ def validate_vm(vm, quick = true)
return no_mapping_msg(invalid_list) if quick
end

return no_mapping_msg(invalid_list) if invalid_list.present?
vm.validate_v2v_migration
invalid_list.present? ? no_mapping_msg(invalid_list) : VM_VALID
end

def no_mapping_msg(list)
Expand Down
2 changes: 2 additions & 0 deletions app/models/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ def supported_consoles
end

def validate_v2v_migration
return TransformationMapping::VM_INACTIVE unless active?

vm_as_resources = ServiceResource.where(:resource => self).includes(:service_template).where(:service_templates => {:type => "ServiceTemplateTransformationPlan"})

# VM has not been migrated before
Expand Down
7 changes: 7 additions & 0 deletions spec/models/transformation_mapping_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

describe '#validate_vms' do
let(:vm) { FactoryGirl.create(:vm_vmware, :name => 'test_vm', :ems_cluster => src, :ext_management_system => FactoryGirl.create(:ext_management_system)) }
let(:inactive_vm) { FactoryGirl.create(:vm_vmware, :name => 'test_vm_inactive', :ems_cluster => src, :ext_management_system => nil) }
let(:storage) { FactoryGirl.create(:storage) }
let(:lan) { FactoryGirl.create(:lan) }
let(:nic) { FactoryGirl.create(:guest_device_nic, :lan => lan) }
Expand All @@ -49,6 +50,12 @@
expect(result['invalid_vms'].first).to match(hash_including('reason' => TransformationMapping::VM_NOT_EXIST))
end

it 'if VM is inactive' do
inactive_vm.storages << FactoryGirl.create(:storage, :name => 'storage_for_inactive_vm')
result = mapping.validate_vms(['name' => 'test_vm_inactive'])
expect(result['invalid_vms'].first).to match(hash_including('reason' => TransformationMapping::VM_INACTIVE))
end

it "if VM's cluster is not in the mapping" do
FactoryGirl.create(
:vm_vmware,
Expand Down