Adds macvtap support
The current logic handles only VFs with direct vnic-type. This fix will add support for VFs with macvtap vnic-type, By checking the relevant upper_macvtap directory. Change-Id: Id69b7e64858020682fd0f68b0e162e5e8022eea3 Closes-Bug: 1383098
This commit is contained in:
parent
6fc4dc7bba
commit
5a376fa84a
@ -13,6 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import glob
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@ -30,6 +31,7 @@ class PciOsWrapper(object):
|
|||||||
PCI_PATH = "/sys/class/net/%s/device/virtfn%s/net"
|
PCI_PATH = "/sys/class/net/%s/device/virtfn%s/net"
|
||||||
VIRTFN_FORMAT = "^virtfn(?P<vf_index>\d+)"
|
VIRTFN_FORMAT = "^virtfn(?P<vf_index>\d+)"
|
||||||
VIRTFN_REG_EX = re.compile(VIRTFN_FORMAT)
|
VIRTFN_REG_EX = re.compile(VIRTFN_FORMAT)
|
||||||
|
MAC_VTAP_PREFIX = "upper_macvtap*"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def scan_vf_devices(cls, dev_name):
|
def scan_vf_devices(cls, dev_name):
|
||||||
@ -65,12 +67,18 @@ class PciOsWrapper(object):
|
|||||||
"""Check if VF is assigned.
|
"""Check if VF is assigned.
|
||||||
|
|
||||||
Checks if a given vf index of a given device name is assigned
|
Checks if a given vf index of a given device name is assigned
|
||||||
by checking the relevant path in the system
|
by checking the relevant path in the system:
|
||||||
|
VF is assigned if:
|
||||||
|
Direct VF: PCI_PATH does not exist.
|
||||||
|
Macvtap VF: upper_macvtap path exists.
|
||||||
@param dev_name: pf network device name
|
@param dev_name: pf network device name
|
||||||
@param vf_index: vf index
|
@param vf_index: vf index
|
||||||
"""
|
"""
|
||||||
path = cls.PCI_PATH % (dev_name, vf_index)
|
path = cls.PCI_PATH % (dev_name, vf_index)
|
||||||
return not (os.path.isdir(path))
|
if not os.path.isdir(path):
|
||||||
|
return True
|
||||||
|
upper_macvtap_path = os.path.join(path, "*", cls.MAC_VTAP_PREFIX)
|
||||||
|
return bool(glob.glob(upper_macvtap_path))
|
||||||
|
|
||||||
|
|
||||||
class EmbSwitch(object):
|
class EmbSwitch(object):
|
||||||
|
@ -363,3 +363,22 @@ class TestPciOsWrapper(base.BaseTestCase):
|
|||||||
|
|
||||||
def test_is_assigned_vf_false(self):
|
def test_is_assigned_vf_false(self):
|
||||||
self._mock_assign_vf(False)
|
self._mock_assign_vf(False)
|
||||||
|
|
||||||
|
def _mock_assign_vf_macvtap(self, macvtap_exists):
|
||||||
|
def _glob(file_path):
|
||||||
|
return ["upper_macvtap0"] if macvtap_exists else []
|
||||||
|
|
||||||
|
with contextlib.nested(
|
||||||
|
mock.patch("os.path.isdir",
|
||||||
|
return_value=True),
|
||||||
|
mock.patch("glob.glob",
|
||||||
|
side_effect=_glob)):
|
||||||
|
result = esm.PciOsWrapper.is_assigned_vf(self.DEV_NAME,
|
||||||
|
self.VF_INDEX)
|
||||||
|
self.assertEqual(macvtap_exists, result)
|
||||||
|
|
||||||
|
def test_is_assigned_vf_macvtap_true(self):
|
||||||
|
self._mock_assign_vf_macvtap(True)
|
||||||
|
|
||||||
|
def test_is_assigned_vf_macvtap_false(self):
|
||||||
|
self._mock_assign_vf_macvtap(False)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user