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

[V2V] Remove fatal nil IP check in preflight check #18496

Merged
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
5 changes: 2 additions & 3 deletions app/models/service_template_transformation_plan_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,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.ipaddress
}
:ip_address => nic.network.try(:ipaddress)
}.compact
end
end

Expand Down
22 changes: 4 additions & 18 deletions spec/models/service_template_transformation_plan_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,7 @@
let(:src_vm_2) { FactoryBot.create(:vm_openstack, :ext_management_system => src_ems, :ems_cluster => src_cluster, :host => src_host) }

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) }
let(:src_network_2) { FactoryBot.create(:network, :ipaddress => nil) }

# Disks have to be stubbed because there's no factory for Disk class
before do
Expand All @@ -353,6 +352,7 @@
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_1)
allow(src_nic_2).to receive(:network).and_return(src_network_2)
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 @@ -479,7 +479,6 @@

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) }
Expand All @@ -491,15 +490,10 @@
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' }
{ :source => src_lan_2.name, :destination => dst_lan_2.name, :mac_address => src_nic_2.address }
]
)
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

it "passes preflight check regardless of power_state" do
Expand Down Expand Up @@ -562,8 +556,6 @@
let(:dst_cloud_volume_type) { FactoryBot.create(:cloud_volume_type) }
let(:dst_cloud_network_1) { FactoryBot.create(:cloud_network) }
let(:dst_cloud_network_2) { FactoryBot.create(:cloud_network) }
let(:dst_net_1) { dst_cloud_network_1 }
let(:dst_net_2) { dst_cloud_network_2 }
let(:dst_flavor) { FactoryBot.create(:flavor) }
let(:dst_security_group) { FactoryBot.create(:security_group) }
let(:conversion_host_vm) { FactoryBot.create(:vm_openstack, :ext_management_system => dst_ems, :cloud_tenant => dst_cloud_tenant) }
Expand All @@ -583,7 +575,6 @@

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) }
Expand All @@ -595,15 +586,10 @@
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' }
{ :source => src_lan_2.name, :destination => dst_cloud_network_2.ems_ref, :mac_address => src_nic_2.address }
]
)
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

it "fails preflight check if src is power off" do
Expand Down