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
This commit is contained in:
Edan David 2016-09-19 10:48:55 -04:00
parent 983cc7c75e
commit 859de9c997
2 changed files with 6 additions and 2 deletions

View File

@ -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)

View File

@ -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):