From ffbd22476a85848208d488ee0f3d16f63260b108 Mon Sep 17 00:00:00 2001 From: Emmanuel Jannetti <4819607+ejannett@users.noreply.github.com> Date: Tue, 10 Nov 2020 16:46:07 +0100 Subject: [PATCH 1/4] fix for LINUX-9592 - mapping between vNIC and NIC broken if some vNIC are removed --- lib/oci_utils/kvm/virt.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/oci_utils/kvm/virt.py b/lib/oci_utils/kvm/virt.py index c71a7ef2..c932adcd 100644 --- a/lib/oci_utils/kvm/virt.py +++ b/lib/oci_utils/kvm/virt.py @@ -213,37 +213,38 @@ def find_unassigned_vf_by_phys(phys, domain_interfaces, desired_mac, vfs_blackli return list(vfs.values())[0] -def get_phys_by_index(vnic, vnics, nics): +def get_phys_by_index(vnic, nics): """ Uses information stored in the OCI VNIC metadata to find the physical interface that a VNIC is associated with. - Parameters ---------- vnic : dict - The virtual interface card name. - vnics : dict - The list of virtual interface cards. + The OCI vNIC we are looking for the assocaited phys nics : dict The list of available network interface cards. - + as the one returned by network_helpers.get_interfaces() Returns ------- str The interface name if found, None otherwise. - """ - candidates = {} - for v in vnics: - if vnic['nicIndex'] == v['nicIndex']: - candidates[v['macAddr'].lower()] = True - for n, d in nics.items(): - if d['physical'] and d['mac'] in candidates and not d.get('physfn'): - return n + # 1. we get the NIC index from the OCI vNIC + # 2. we find for physical interfaces and sort them + # 3. we find the associated physical nic + + # the one we look for are the onw without physical function information (because they are one) + # and have a PCI id. PCI is like 0000:3b:00.0. We keep the last digit as it is our index + _phys_ones = [(int(intf['pci'].split('.')[-1]),name ) for (name,intf) in nics.items() if 'physfn' not in intf and 'pci' in intf] + # _phys_ones is like [(idx,'name'),...] + for idx, name in _phys_ones: + if idx == vnic['nicIndex']: + return name return None + def _get_intf_used_by_guest(): """ Get dict of intf used by guests @@ -344,7 +345,7 @@ def test_vnic_and_assign_vf(ip_addr, free_vnics_ips, backlisted_vfs=()): _print_available_vnics(free_vnics_ips) return False, False, False - phys_nic = get_phys_by_index(vnic, vnics, get_interfaces()) + phys_nic = get_phys_by_index(vnic, get_interfaces()) _logger.debug('physical intf found by index : %s' % phys_nic) vf_pci_id, vf_num = find_unassigned_vf_by_phys(phys_nic, domain_interfaces, @@ -603,6 +604,7 @@ def create(**kargs): _logger.debug('checking vnic [%s] and find VF' % free_vnic_ip_addr) vnic, vf, vf_num = test_vnic_and_assign_vf(free_vnic_ip_addr, free_vnics, _blacklisted_vfs) if not vnic: + _logger.debug('vnic check failed, fnd find VF') return 1 # be sure thi won't be used at next iteration _blacklisted_vfs.append((vf, vf_num)) From 6389f7973e3703ab326dc6835f245318d0beb929 Mon Sep 17 00:00:00 2001 From: Emmanuel Jannetti <4819607+ejannett@users.noreply.github.com> Date: Tue, 10 Nov 2020 16:56:35 +0100 Subject: [PATCH 2/4] update spec file --- buildrpm/oci-utils.spec | 3 +++ 1 file changed, 3 insertions(+) diff --git a/buildrpm/oci-utils.spec b/buildrpm/oci-utils.spec index ee879eb8..7f8a7652 100644 --- a/buildrpm/oci-utils.spec +++ b/buildrpm/oci-utils.spec @@ -176,6 +176,9 @@ rm -rf %{buildroot} /opt/oci-utils/tests/__init__* %changelog +* Tue Nov 10 2020 Emmanuel Jannetti --0.11.7 +- LINUX-9592 - mapping between vNIC and NIC broken if some vNIC are removed + * Thu Sep 24 2020 Emmanuel Jannetti --0.11.6 - LINUX-7035 - oci-utils: move base functionality from al-config to oci-utils - LINUX-8976 - multi-vnic on bare metal shapes suffer from connection issues From 82a5d276ab170220a0a321bfb44dbff2b39f987f Mon Sep 17 00:00:00 2001 From: Emmanuel Jannetti <4819607+ejannett@users.noreply.github.com> Date: Tue, 10 Nov 2020 16:46:07 +0100 Subject: [PATCH 3/4] fix for LINUX-9592 - mapping between vNIC and NIC broken if some vNIC are removed --- buildrpm/oci-utils.spec | 3 +++ lib/oci_utils/kvm/virt.py | 32 +++++++++++++++++--------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/buildrpm/oci-utils.spec b/buildrpm/oci-utils.spec index ee879eb8..7f8a7652 100644 --- a/buildrpm/oci-utils.spec +++ b/buildrpm/oci-utils.spec @@ -176,6 +176,9 @@ rm -rf %{buildroot} /opt/oci-utils/tests/__init__* %changelog +* Tue Nov 10 2020 Emmanuel Jannetti --0.11.7 +- LINUX-9592 - mapping between vNIC and NIC broken if some vNIC are removed + * Thu Sep 24 2020 Emmanuel Jannetti --0.11.6 - LINUX-7035 - oci-utils: move base functionality from al-config to oci-utils - LINUX-8976 - multi-vnic on bare metal shapes suffer from connection issues diff --git a/lib/oci_utils/kvm/virt.py b/lib/oci_utils/kvm/virt.py index c71a7ef2..c932adcd 100644 --- a/lib/oci_utils/kvm/virt.py +++ b/lib/oci_utils/kvm/virt.py @@ -213,37 +213,38 @@ def find_unassigned_vf_by_phys(phys, domain_interfaces, desired_mac, vfs_blackli return list(vfs.values())[0] -def get_phys_by_index(vnic, vnics, nics): +def get_phys_by_index(vnic, nics): """ Uses information stored in the OCI VNIC metadata to find the physical interface that a VNIC is associated with. - Parameters ---------- vnic : dict - The virtual interface card name. - vnics : dict - The list of virtual interface cards. + The OCI vNIC we are looking for the assocaited phys nics : dict The list of available network interface cards. - + as the one returned by network_helpers.get_interfaces() Returns ------- str The interface name if found, None otherwise. - """ - candidates = {} - for v in vnics: - if vnic['nicIndex'] == v['nicIndex']: - candidates[v['macAddr'].lower()] = True - for n, d in nics.items(): - if d['physical'] and d['mac'] in candidates and not d.get('physfn'): - return n + # 1. we get the NIC index from the OCI vNIC + # 2. we find for physical interfaces and sort them + # 3. we find the associated physical nic + + # the one we look for are the onw without physical function information (because they are one) + # and have a PCI id. PCI is like 0000:3b:00.0. We keep the last digit as it is our index + _phys_ones = [(int(intf['pci'].split('.')[-1]),name ) for (name,intf) in nics.items() if 'physfn' not in intf and 'pci' in intf] + # _phys_ones is like [(idx,'name'),...] + for idx, name in _phys_ones: + if idx == vnic['nicIndex']: + return name return None + def _get_intf_used_by_guest(): """ Get dict of intf used by guests @@ -344,7 +345,7 @@ def test_vnic_and_assign_vf(ip_addr, free_vnics_ips, backlisted_vfs=()): _print_available_vnics(free_vnics_ips) return False, False, False - phys_nic = get_phys_by_index(vnic, vnics, get_interfaces()) + phys_nic = get_phys_by_index(vnic, get_interfaces()) _logger.debug('physical intf found by index : %s' % phys_nic) vf_pci_id, vf_num = find_unassigned_vf_by_phys(phys_nic, domain_interfaces, @@ -603,6 +604,7 @@ def create(**kargs): _logger.debug('checking vnic [%s] and find VF' % free_vnic_ip_addr) vnic, vf, vf_num = test_vnic_and_assign_vf(free_vnic_ip_addr, free_vnics, _blacklisted_vfs) if not vnic: + _logger.debug('vnic check failed, fnd find VF') return 1 # be sure thi won't be used at next iteration _blacklisted_vfs.append((vf, vf_num)) From 0f4dc42e5937b38a56f3a8fbdb2dad1006cd3be2 Mon Sep 17 00:00:00 2001 From: Emmanuel Jannetti <4819607+ejannett@users.noreply.github.com> Date: Tue, 10 Nov 2020 17:06:16 +0100 Subject: [PATCH 4/4] update spec file --- buildrpm/oci-utils.spec | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/buildrpm/oci-utils.spec b/buildrpm/oci-utils.spec index 7f8a7652..3647b0ee 100644 --- a/buildrpm/oci-utils.spec +++ b/buildrpm/oci-utils.spec @@ -176,10 +176,8 @@ rm -rf %{buildroot} /opt/oci-utils/tests/__init__* %changelog -* Tue Nov 10 2020 Emmanuel Jannetti --0.11.7 -- LINUX-9592 - mapping between vNIC and NIC broken if some vNIC are removed - * Thu Sep 24 2020 Emmanuel Jannetti --0.11.6 +- LINUX-9592 - mapping between vNIC and NIC broken if some vNIC are removed - LINUX-7035 - oci-utils: move base functionality from al-config to oci-utils - LINUX-8976 - multi-vnic on bare metal shapes suffer from connection issues - LINUX-8952 - oci-growfs does not prompt for y/n and hangs.