Browse Source

Merge "Fix sensitivity to the initial device driver"

tags/1.1.0
Zuul 1 week ago
parent
commit
3e5e4950db

+ 9
- 4
kuryr_kubernetes/cni/binding/sriov.py View File

@@ -128,7 +128,7 @@ class VIFSriovDriver(object):
128 128
 
129 129
     def _compute_pci(self, pci, driver, pod_link, vif, ifname, netns):
130 130
         port_id = vif.id
131
-        vf_name, vf_index, pf, pci_info = self._get_vf_info(pci)
131
+        vf_name, vf_index, pf, pci_info = self._get_vf_info(pci, driver)
132 132
         if driver in constants.USERSPACE_DRIVERS:
133 133
             LOG.info("PCI device %s will be rebinded to userspace network "
134 134
                      "driver %s", pci, driver)
@@ -165,10 +165,15 @@ class VIFSriovDriver(object):
165 165
 
166 166
         return pci_info
167 167
 
168
-    def _get_vf_info(self, pci):
168
+    def _get_vf_info(self, pci, driver):
169 169
         vf_sys_path = '/sys/bus/pci/devices/{}/net/'.format(pci)
170
-        vf_names = os.listdir(vf_sys_path)
171
-        vf_name = vf_names[0]
170
+        if not os.path.exists(vf_sys_path):
171
+            if driver not in constants.USERSPACE_DRIVERS:
172
+                raise OSError(_("No vf name for device {}").format(pci))
173
+            vf_name = None
174
+        else:
175
+            vf_names = os.listdir(vf_sys_path)
176
+            vf_name = vf_names[0]
172 177
 
173 178
         pfysfn_path = '/sys/bus/pci/devices/{}/physfn/net/'.format(pci)
174 179
         pf_names = os.listdir(pfysfn_path)

+ 2
- 2
kuryr_kubernetes/tests/unit/cni/test_binding.py View File

@@ -330,7 +330,7 @@ class TestSriovDriver(TestDriverMixin, test_base.TestCase):
330 330
                                                          self.vif,
331 331
                                                          self.ifname,
332 332
                                                          self.netns))
333
-        m_driver._get_vf_info.assert_called_once_with(self.pci)
333
+        m_driver._get_vf_info.assert_called_once_with(self.pci, new_driver)
334 334
         m_driver._set_vf_mac.assert_called_once_with(pf, vf_index,
335 335
                                                      self.vif.address)
336 336
         m_driver._bind_device.assert_called_once_with(self.pci, new_driver)
@@ -359,7 +359,7 @@ class TestSriovDriver(TestDriverMixin, test_base.TestCase):
359 359
                                                          self.ifname,
360 360
                                                          self.netns))
361 361
 
362
-        m_driver._get_vf_info.assert_called_once_with(self.pci)
362
+        m_driver._get_vf_info.assert_called_once_with(self.pci, new_driver)
363 363
         m_driver._move_to_netns.assert_called_once_with(self.pci, self.ifname,
364 364
                                                         self.netns, self.vif,
365 365
                                                         vf_name, vf_index, pf,

Loading…
Cancel
Save