Auto PCI picking issue fix 76/69776/2
authormklyus <mklyus@cisco.com>
Fri, 13 Mar 2020 12:12:49 +0000 (15:12 +0300)
committerAlec Hothan <ahothan@cisco.com>
Tue, 7 Apr 2020 16:10:20 +0000 (16:10 +0000)
Change-Id: I2492baf4deffff2d11cf04ab9b79711ea5dd2f16
Signed-off-by: Max Klyus <mklyus@cisco.com>
nfvbench/utils.py

index 94cc11d..d4482fd 100644 (file)
@@ -149,19 +149,21 @@ def get_intel_pci(nic_slot=None, nic_ports=None):
             continue
 
         matches.sort()
+        device_list = list(x[0].split('.')[0] for x in matches)
+        device_ports_list = {i: {'ports': device_list.count(i)} for i in device_list}
         for port in matches:
             intf_name = glob.glob("/sys/bus/pci/devices/%s/net/*" % port[0])
-            if not intf_name:
-                # Interface is not bind to kernel driver, so take it
-                pcis.append(port[1])
-            else:
+            if intf_name:
                 intf_name = intf_name[0][intf_name[0].rfind('/') + 1:]
                 process = subprocess.Popen(['ip', '-o', '-d', 'link', 'show', intf_name],
                                            stdout=subprocess.PIPE,
                                            stderr=subprocess.PIPE)
                 intf_info, _ = process.communicate()
-                if not re.search('team_slave|bond_slave', intf_info.decode("utf-8")):
-                    pcis.append(port[1])
+                if re.search('team_slave|bond_slave', intf_info.decode("utf-8")):
+                    device_ports_list[port[0].split('.')[0]]['busy'] = True
+        for port in matches:
+            if not device_ports_list[port[0].split('.')[0]].get('busy'):
+                pcis.append(port[1])
             if len(pcis) == 2:
                 break