diff --git a/nova/pci/utils.py b/nova/pci/utils.py index 1993561852..3030b54bf8 100644 --- a/nova/pci/utils.py +++ b/nova/pci/utils.py @@ -83,7 +83,7 @@ def get_function_by_ifname(ifname): if os.path.isdir(dev_path): try: # sriov_totalvfs contains the maximum possible VFs for this PF - with open(dev_path + _SRIOV_TOTALVFS) as fd: + with open(os.path.join(dev_path, _SRIOV_TOTALVFS)) as fd: sriov_totalvfs = int(fd.read()) return (os.readlink(dev_path).strip("./"), sriov_totalvfs > 0) diff --git a/nova/tests/unit/pci/test_utils.py b/nova/tests/unit/pci/test_utils.py index 2bded05933..1fad561fbc 100644 --- a/nova/tests/unit/pci/test_utils.py +++ b/nova/tests/unit/pci/test_utils.py @@ -83,12 +83,16 @@ class GetFunctionByIfnameTestCase(test.NoDBTestCase): @mock.patch('os.path.isdir', return_value=True) @mock.patch.object(os, 'readlink') def test_physical_function(self, mock_readlink, *args): + ifname = 'eth0' + totalvf_path = "/sys/class/net/%s/device/%s" % (ifname, + utils._SRIOV_TOTALVFS) mock_readlink.return_value = '../../../0000:00:00.1' with mock.patch.object( - builtins, 'open', mock.mock_open(read_data='4')): + builtins, 'open', mock.mock_open(read_data='4')) as mock_open: address, physical_function = utils.get_function_by_ifname('eth0') self.assertEqual(address, '0000:00:00.1') self.assertTrue(physical_function) + mock_open.assert_called_once_with(totalvf_path) @mock.patch('os.path.isdir', return_value=False) def test_exception(self, *args):