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

Add empty IP address check to preflight check #18425

Merged
merged 2 commits into from
Feb 15, 2019
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
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) { FactoryBot.create(:vm_vmware, :ext_management_system => src_ems, :ems_cluster => src_cluster, :host => src_host, :hardware => src_hardware) }
let(:src_vm_2) { FactoryBot.create(:vm_vmware, :ext_management_system => src_ems, :ems_cluster => src_cluster, :host => src_host) }

let(:src_network) { FactoryBot.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) { 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 @@ -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