From 859de9c9971a3dd13f245d2245686fb3d19a832d Mon Sep 17 00:00:00 2001 From: Edan David Date: Mon, 19 Sep 2016 10:48:55 -0400 Subject: [PATCH] Add missing slash to dir path When validating a PF in the method 'get_function_by_ifname' the number of VFs are read from a file, the path to that file was missing a slash ('/'). Change-Id: I7bf4bb96f1f769bff247f5af2c81dd96b08e2f04 Closes-Bug: #1625220 --- nova/pci/utils.py | 2 +- nova/tests/unit/pci/test_utils.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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):