Skip to content

Commit

Permalink
Merge pull request #18425 from fdupont-redhat/v2v_preflight_nic_ip_ad…
Browse files Browse the repository at this point in the history
…dress

Add empty IP address check to preflight check

(cherry picked from commit 3d26260)

https://bugzilla.redhat.com/show_bug.cgi?id=1678376
  • Loading branch information
agrare authored and simaishi committed Feb 18, 2019
1 parent 4568a21 commit d0ee841
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
3 changes: 2 additions & 1 deletion app/models/service_template_transformation_plan_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,12 @@ def calculate_network_mappings
source_network = nic.lan
destination_network = transformation_destination(source_network)
raise "[#{source.name}] NIC #{nic.device_name} [#{source_network.name}] has no mapping." if destination_network.nil?
raise "[#{source.name}] NIC #{nic.device_name} [#{source_network.name}] has an empty IP address." if nic.network.try(:ipaddress).nil?
{
:source => source_network.name,
:destination => destination_network_ref(destination_network),
:mac_address => nic.address,
:ip_address => nic.network.try(:ipaddress)
:ip_address => nic.network.ipaddress
}
end
end
Expand Down
52 changes: 36 additions & 16 deletions spec/models/service_template_transformation_plan_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,17 @@
let(:src_vm_1) { FactoryGirl.create(:vm_vmware, :ext_management_system => src_ems, :ems_cluster => src_cluster, :host => src_host, :hardware => src_hardware) }
let(:src_vm_2) { FactoryGirl.create(:vm_vmware, :ext_management_system => src_ems, :ems_cluster => src_cluster, :host => src_host) }

let(:src_network) { FactoryGirl.create(:network, :ipaddress => '10.0.0.1') }
let(:src_network_1) { FactoryBot.create(:network, :ipaddress => '10.0.1.1') }
let(:src_network_2a) { FactoryBot.create(:network, :ipaddress => '10.0.1.2') }
let(:src_network_2b) { FactoryBot.create(:network, :ipaddress => nil) }

# Disks have to be stubbed because there's no factory for Disk class
before do
allow(src_hardware).to receive(:disks).and_return([src_disk_1, src_disk_2])
allow(src_disk_1).to receive(:storage).and_return(src_storage)
allow(src_disk_2).to receive(:storage).and_return(src_storage)
allow(src_vm_1).to receive(:allocated_disk_storage).and_return(34_359_738_368)
allow(src_nic_1).to receive(:network).and_return(src_network)
allow(src_nic_1).to receive(:network).and_return(src_network_1)
allow(src_host).to receive(:thumbprint_sha1).and_return('01:23:45:67:89:ab:cd:ef:01:23:45:67:89:ab:cd:ef:01:23:45:67')
allow(src_host).to receive(:authentication_userid).and_return('esx_user')
allow(src_host).to receive(:authentication_password).and_return('esx_passwd')
Expand Down Expand Up @@ -438,19 +440,27 @@

before do
task_1.conversion_host = conversion_host
allow(src_nic_2).to receive(:network).and_return(src_network_2a)
end

it { expect(task_1.destination_cluster).to eq(dst_cluster) }

it_behaves_like "#virtv2v_disks"

it "checks network mappings and generates network_mappings hash" do
expect(task_1.network_mappings).to eq(
[
{ :source => src_lan_1.name, :destination => dst_lan_1.name, :mac_address => src_nic_1.address, :ip_address => '10.0.0.1' },
{ :source => src_lan_2.name, :destination => dst_lan_2.name, :mac_address => src_nic_2.address, :ip_address => nil }
]
)
context "#network_mappings" do
it "generates network_mappings hash" do
expect(task_1.network_mappings).to eq(
[
{ :source => src_lan_1.name, :destination => dst_lan_1.name, :mac_address => src_nic_1.address, :ip_address => '10.0.1.1' },
{ :source => src_lan_2.name, :destination => dst_lan_2.name, :mac_address => src_nic_2.address, :ip_address => '10.0.1.2' }
]
)
end

it "fails if network IP address is nil" do
allow(src_nic_2).to receive(:network).and_return(src_network_2b)
expect { task_1.network_mappings }.to raise_error("[#{src_vm_1.name}] NIC #{src_nic_2.device_name} [#{src_lan_2.name}] has an empty IP address.")
end
end

context "transport method is vddk" do
Expand Down Expand Up @@ -508,6 +518,8 @@
let(:dst_cloud_volume_type) { FactoryGirl.create(:cloud_volume_type) }
let(:dst_cloud_network_1) { FactoryGirl.create(:cloud_network) }
let(:dst_cloud_network_2) { FactoryGirl.create(:cloud_network) }
let(:dst_net_1) { dst_cloud_network_1 }
let(:dst_net_2) { dst_cloud_network_2 }
let(:dst_flavor) { FactoryGirl.create(:flavor) }
let(:dst_security_group) { FactoryGirl.create(:security_group) }
let(:conversion_host_vm) { FactoryGirl.create(:vm_openstack, :ext_management_system => dst_ems, :cloud_tenant => dst_cloud_tenant) }
Expand All @@ -527,19 +539,27 @@

before do
task_1.conversion_host = conversion_host
allow(src_nic_2).to receive(:network).and_return(src_network_2a)
end

it { expect(task_1.destination_cluster).to eq(dst_cloud_tenant) }

it_behaves_like "#virtv2v_disks"

it "checks network mappings and generates network_mappings hash" do
expect(task_1.network_mappings).to eq(
[
{ :source => src_lan_1.name, :destination => dst_cloud_network_1.ems_ref, :mac_address => src_nic_1.address, :ip_address => '10.0.0.1' },
{ :source => src_lan_2.name, :destination => dst_cloud_network_2.ems_ref, :mac_address => src_nic_2.address, :ip_address => nil }
]
)
context "#network_mappings" do
it "generates network_mappings hash" do
expect(task_1.network_mappings).to eq(
[
{ :source => src_lan_1.name, :destination => dst_cloud_network_1.ems_ref, :mac_address => src_nic_1.address, :ip_address => '10.0.1.1' },
{ :source => src_lan_2.name, :destination => dst_cloud_network_2.ems_ref, :mac_address => src_nic_2.address, :ip_address => '10.0.1.2' }
]
)
end

it "fails if network IP address is nil" do
allow(src_nic_2).to receive(:network).and_return(src_network_2b)
expect { task_1.network_mappings }.to raise_error("[#{src_vm_1.name}] NIC #{src_nic_2.device_name} [#{src_lan_2.name}] has an empty IP address.")
end
end

context "transport method is vddk" do
Expand Down

0 comments on commit d0ee841

Please sign in to comment.