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

Get mac addr if the selected profile is '<Empty>' or '<Template>' #227

Merged
merged 1 commit into from
Mar 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,24 @@ def get_mac_address_of_nic_on_requested_vlan(args)
end

def find_mac_address_on_network(nics, vnic_profile_id)
nic = nics.detect do |n|
n.vnic_profile.id == vnic_profile_id
nic = if vnic_profile_id == '<Empty>'
nics.detect do |n|
n.vnic_profile.nil?
end
elsif vnic_profile_id == '<Template>'
nics.first
else
nics.detect do |n|
n.vnic_profile.id == vnic_profile_id
end
end

if nics.empty?
_log.warn("Cannot find a MAC address, there are no NICs")
elsif nic.nil?
_log.warn("Cannot find a MAC address based on vnic_profile=#{vnic_profile_id}, there is no NIC with this profile")
end
_log.warn "Cannot find NIC with vnic_profile=#{vnic_profile_id}" if nic.nil?

nic && nic.mac && nic.mac.address
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@
let(:vnic_profile_1) { double("vnic_prof1", :id => vnic_profile_id) }
let(:vnic_profile_2) { double("vnic_prof2", :id => "vnic_profile_id_2") }
let(:vnic_profile_name) { "vnic_profile_name" }
let(:set_vnic_profile) { @task.options[:vlan] = [vnic_profile_id, vnic_profile_name + " (" + network_name + ")"] }
let(:network_profile) { double(:id => vnic_profile_id, :name => vnic_profile_name, :network => double(:id => network_id)) }
let(:ovirtSDK4_mac) { OvirtSDK4::Mac.new(:address => mac_address) }

Expand Down Expand Up @@ -185,7 +184,7 @@
end

it "first NIC from dialog" do
set_vnic_profile
assign_vnic_profile(vnic_profile_id)

expect(nic1_service).to receive(:update)
expect(nic2_service).to receive(:update)
Expand All @@ -207,7 +206,7 @@
end

it "dialog NIC only" do
set_vnic_profile
assign_vnic_profile(vnic_profile_id)

expect(nic1_service).to receive(:update)
expect(nic2_service).to receive(:remove)
Expand Down Expand Up @@ -268,18 +267,69 @@

context "#get_mac_address_of_nic_on_requested_vlan" do
before do
set_vnic_profile
allow(ems.ovirt_services).to receive(:nics_for_vm).with(target_vm).and_return([rhevm_nic1, rhevm_nic2])
end
it "NIC found" do
expect(@task.get_mac_address_of_nic_on_requested_vlan).to eq(mac_address)

context "profile_id is <Template>" do
before do
assign_vnic_profile('<Template>')
end

it 'nics list is empty' do
test_empty_nic_list
end

it 'nics list is not empty' do
expect(@task.get_mac_address_of_nic_on_requested_vlan).to eq(mac_address)
end
end

it "NIC not found" do
allow(rhevm_nic1).to receive(:vnic_profile).and_return(vnic_profile_2)
context "profile_id is <Empty>" do
before do
assign_vnic_profile('<Empty>')
end

expect(@task.get_mac_address_of_nic_on_requested_vlan).to eq(nil)
it 'nics list is empty' do
test_empty_nic_list
end

it 'nics list contains a nic with no profile' do
allow(rhevm_nic1).to receive(:vnic_profile).and_return(nil)
expect(@task.get_mac_address_of_nic_on_requested_vlan).to eq(mac_address)
end

it 'nics list does not contain a nic with no profile' do
expect(@task.get_mac_address_of_nic_on_requested_vlan).to eq(nil)
end
end

context "profile_id is specified" do
before do
assign_vnic_profile(vnic_profile_id)
end

it 'nics list is empty' do
test_empty_nic_list
end

it 'nics list contains a nic with the specified profile_id' do
expect(@task.get_mac_address_of_nic_on_requested_vlan).to eq(mac_address)
end

it 'nics list does not contain a nic with the specified profile_id' do
allow(rhevm_nic1).to receive(:vnic_profile).and_return(vnic_profile_2)
expect(@task.get_mac_address_of_nic_on_requested_vlan).to eq(nil)
end
end
end

def assign_vnic_profile(vnic_profile_id)
@task.options[:vlan] = [vnic_profile_id, vnic_profile_name + " (" + network_name + ")"]
end

def test_empty_nic_list
allow(ems.ovirt_services).to receive(:nics_for_vm).with(target_vm).and_return([])
expect(@task.get_mac_address_of_nic_on_requested_vlan).to eq(nil)
end
end
end
Expand Down