summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdan David <edand@mellanox.com>2016-09-19 10:48:55 -0400
committerMoshe Levi <moshele@mellanox.com>2016-09-24 15:11:35 +0000
commit3cd8d23a3a16b55dca3f8e8c552ea936f684d100 (patch)
tree9136b4f52b440eb110429feb71d7526302b9f17a
parentdd30603f91e6fd3d1a4db452f20a51ba8820e1f4 (diff)
downloadnova-3cd8d23a3a16b55dca3f8e8c552ea936f684d100.tar.gz
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 (cherry picked from commit 859de9c9971a3dd13f245d2245686fb3d19a832d)
-rw-r--r--nova/pci/utils.py2
-rw-r--r--nova/tests/unit/pci/test_utils.py6
2 files changed, 6 insertions, 2 deletions
diff --git a/nova/pci/utils.py b/nova/pci/utils.py
index e10a303156..b28568fcc1 100644
--- a/nova/pci/utils.py
+++ b/nova/pci/utils.py
@@ -82,7 +82,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 109f47eb4c..bd1acba3df 100644
--- a/nova/tests/unit/pci/test_utils.py
+++ b/nova/tests/unit/pci/test_utils.py
@@ -82,12 +82,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):