Merge "Avoid OSError in get_blkdev_major_minor with network filesystems"
This commit is contained in:
commit
b28ee394f2
|
@ -577,18 +577,17 @@ class GenericUtilsTestCase(test.TestCase):
|
||||||
mock_stat.return_value = stat_result
|
mock_stat.return_value = stat_result
|
||||||
dev = utils.get_blkdev_major_minor(test_device)
|
dev = utils.get_blkdev_major_minor(test_device)
|
||||||
self.assertEqual('253:7', dev)
|
self.assertEqual('253:7', dev)
|
||||||
mock_stat.aseert_called_once_with(test_device)
|
mock_stat.assert_called_once_with(test_device)
|
||||||
|
|
||||||
@mock.patch('os.stat')
|
@mock.patch('os.stat')
|
||||||
@mock.patch.object(utils, 'execute')
|
@mock.patch.object(utils, 'execute')
|
||||||
def test_get_blkdev_major_minor_file(self, mock_exec, mock_stat):
|
def _test_get_blkdev_major_minor_file(self, test_partition,
|
||||||
|
mock_exec, mock_stat):
|
||||||
mock_exec.return_value = (
|
mock_exec.return_value = (
|
||||||
'Filesystem Size Used Avail Use% Mounted on\n'
|
'Filesystem Size Used Avail Use%% Mounted on\n'
|
||||||
'/dev/made_up_disk1 4096 2048 2048 50% /tmp\n', None)
|
'%s 4096 2048 2048 50%% /tmp\n' % test_partition, None)
|
||||||
|
|
||||||
test_file = '/tmp/file'
|
test_file = '/tmp/file'
|
||||||
test_partition = '/dev/made_up_disk1'
|
|
||||||
test_disk = '/dev/made_up_disk'
|
test_disk = '/dev/made_up_disk'
|
||||||
|
|
||||||
class stat_result_file:
|
class stat_result_file:
|
||||||
|
@ -613,11 +612,20 @@ class GenericUtilsTestCase(test.TestCase):
|
||||||
mock_stat.side_effect = fake_stat
|
mock_stat.side_effect = fake_stat
|
||||||
|
|
||||||
dev = utils.get_blkdev_major_minor(test_file)
|
dev = utils.get_blkdev_major_minor(test_file)
|
||||||
|
mock_stat.assert_any_call(test_file)
|
||||||
|
mock_exec.assert_called_once_with('df', test_file)
|
||||||
|
if test_partition.startswith('/'):
|
||||||
|
mock_stat.assert_any_call(test_partition)
|
||||||
|
mock_stat.assert_any_call(test_disk)
|
||||||
|
return dev
|
||||||
|
|
||||||
|
def test_get_blkdev_major_minor_file(self):
|
||||||
|
dev = self._test_get_blkdev_major_minor_file('/dev/made_up_disk1')
|
||||||
self.assertEqual('8:64', dev)
|
self.assertEqual('8:64', dev)
|
||||||
mock_exec.aseert_called_once_with(test_file)
|
|
||||||
mock_stat.aseert_called_once_with(test_file)
|
def test_get_blkdev_major_minor_file_nfs(self):
|
||||||
mock_stat.aseert_called_once_with(test_partition)
|
dev = self._test_get_blkdev_major_minor_file('nfs-server:/export/path')
|
||||||
mock_stat.aseert_called_once_with(test_disk)
|
self.assertIsNone(dev)
|
||||||
|
|
||||||
|
|
||||||
class MonkeyPatchTestCase(test.TestCase):
|
class MonkeyPatchTestCase(test.TestCase):
|
||||||
|
|
|
@ -679,6 +679,9 @@ def get_blkdev_major_minor(path, lookup_for_file=True):
|
||||||
# lookup the mounted disk which the file lies on
|
# lookup the mounted disk which the file lies on
|
||||||
out, _err = execute('df', path)
|
out, _err = execute('df', path)
|
||||||
devpath = out.split("\n")[1].split()[0]
|
devpath = out.split("\n")[1].split()[0]
|
||||||
|
if devpath[0] is not '/':
|
||||||
|
# the file is on a network file system
|
||||||
|
return None
|
||||||
return get_blkdev_major_minor(devpath, False)
|
return get_blkdev_major_minor(devpath, False)
|
||||||
else:
|
else:
|
||||||
msg = _("Unable to get a block device for file \'%s\'") % path
|
msg = _("Unable to get a block device for file \'%s\'") % path
|
||||||
|
|
Loading…
Reference in New Issue