Skip to content

Commit

Permalink
Accept 'profile_name (network_name)' as a valid vlan for vm provision
Browse files Browse the repository at this point in the history
'profile_id' or 'profile_name (network_name)' are both acceptable.

Fixes https://bugzilla.redhat.com/1574351
  • Loading branch information
AlonaKaplan committed May 30, 2018
1 parent fc84f4b commit 05354c6
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 13 deletions.
Expand Up @@ -110,14 +110,7 @@ def configure_vnics(requested_vnics, destination_vnics, destination_cluster, des
end

def load_allowed_networks(_hosts, vlans, workflow)
uid_ems_cluster = VmOrTemplate.find(workflow.get_source_vm.id).ems_cluster.uid_ems
profiles = get_vnic_profiles_in_cluster(uid_ems_cluster)
profiles.each do |profile, profile_network|
vlans[profile.id] = "#{profile.name} (#{profile_network.name})"
end

vlans['<Empty>'] = _('<No Profile>')
vlans['<Template>'] = _('<Use template nics>')
private_load_allowed_networks(vlans, VmOrTemplate.find(workflow.get_source_vm.id).ems_cluster.uid_ems)
end

def filter_allowed_hosts(_workflow, all_hosts)
Expand Down Expand Up @@ -550,11 +543,13 @@ def uuid_from_href(ems_ref)
end

def get_mac_address_of_nic_on_requested_vlan(args)
nics = nics_for_vm(args[:destination])
find_mac_address_on_network(nics, args[:value_of_vlan_option])
vm = args[:destination]
nics = nics_for_vm(vm)
find_mac_address_on_network(nics, args[:value_of_vlan_option], vm.uid_ems)
end

def find_mac_address_on_network(nics, vnic_profile_id)
def find_mac_address_on_network(nics, vnic_profile_id, uid_ems)
vnic_profile_id = parse_vnic_profile_id(vnic_profile_id, uid_ems)
nic = if vnic_profile_id == '<Empty>'
nics.detect do |n|
n.vnic_profile.nil?
Expand Down Expand Up @@ -792,7 +787,7 @@ def remove_vm_disks(vm_service, disk_specs)
end

def configure_vnic_with_requested_data(name, requested_vnic, destination_vnic, nics_service, destination_cluster)
requested_profile_id = requested_vnic[:network]
requested_profile_id = parse_vnic_profile_id(requested_vnic[:network], destination_cluster.uid_ems)
if requested_profile_id == '<Empty>'
profile_id = nil
else
Expand All @@ -815,6 +810,27 @@ def configure_vnic_with_requested_data(name, requested_vnic, destination_vnic, n
)
end

def private_load_allowed_networks(vlans, uid_ems_cluster)
profiles = get_vnic_profiles_in_cluster(uid_ems_cluster)
profiles.each do |profile, profile_network|
vlans[profile.id] = "#{profile.name} (#{profile_network.name})"
end

vlans['<Empty>'] = _('<No Profile>')
vlans['<Template>'] = _('<Use template nics>')
end

def parse_vnic_profile_id(requested_profile, uid_ems_cluster)
if requested_profile.include?('(')
vlans = {}
private_load_allowed_networks(vlans, uid_ems_cluster)
matches = vlans.select { |_profile_id, profile_description| profile_description == requested_profile }
return matches.keys[0] unless matches.empty?
end

requested_profile
end

def configure_vnic(args)
mac_addr = args[:mac_addr]
vnic = args[:vnic]
Expand Down
Expand Up @@ -118,6 +118,17 @@ def load_allowed_vlans(hosts, vlans)
ems.ovirt_services.load_allowed_networks(hosts, vlans, self) if ems
end

def ws_network_fields(values, fields, data)
requested_vlan = data[:vlan]
super(values, fields, data)
return if (dlg_fields = get_ws_dialog_fields(:network)).nil?
if values[:vlan].nil?
dlg_fields_vlan = dlg_fields[:vlan]
field_values = dlg_fields_vlan && dlg_fields_vlan[:values]
values[:vlan] = field_values&.values&.detect { |value| value == requested_vlan }
end
end

def filter_allowed_hosts(all_hosts)
ems = source_ems
return all_hosts unless ems
Expand Down
Expand Up @@ -228,6 +228,15 @@
@task.configure_network_adapters
end

it "should update an existing adapter's network using 'profile_id (network_name)'" do
@task.options[:networks] = [{:network => get_profile_description(vnic_profile_name, network.name)}]

expect(rhevm_vm).to receive(:nics).and_return([rhevm_nic1])
expect(nic1_service).to receive(:update).with(:name => "nic1", :vnic_profile => {:id => vnic_profile_id})

@task.configure_network_adapters
end

it "should update an existing adapter's network with 'Empty' profile" do
@task.options[:networks] = [{:network => '<Empty>'}]

Expand Down Expand Up @@ -321,10 +330,29 @@
expect(@task.get_mac_address_of_nic_on_requested_vlan).to eq(nil)
end
end

context "'profile_id (network_name)' is specified" do
before do
assign_vnic_profile(get_profile_description(vnic_profile_name, network.name))
end

it 'returns mac address since nics list contains a nic with the specified profile description' do
expect(@task.get_mac_address_of_nic_on_requested_vlan).to eq(mac_address)
end

it 'returns nil since nics list does not contain a nic with the specified profile description' 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 + ")"]
@task.options[:vlan] = [vnic_profile_id, get_profile_description(vnic_profile_name, network_name)]
end

def get_profile_description(vnic_profile_name, network_name)
"#{vnic_profile_name} (#{network_name})"
end

def test_empty_nic_list
Expand Down

0 comments on commit 05354c6

Please sign in to comment.