Merge "Handling Invalid argument iflag=direct in dd"

This commit is contained in:
Jenkins 2016-01-13 22:11:51 +00:00 committed by Gerrit Code Review
commit 073f6bbb6b
2 changed files with 30 additions and 3 deletions

View File

@ -445,6 +445,20 @@ class OdirectSupportTestCase(test.TestCase):
mock_exec.assert_called_once_with('dd', 'count=0', 'if=/dev/abc',
'of=/dev/def', 'iflag=direct',
run_as_root=True)
mock_exec.reset_mock()
output = volume_utils.check_for_odirect_support('/dev/zero',
'/dev/def',
'iflag=direct')
self.assertFalse(output)
mock_exec.reset_mock()
output = volume_utils.check_for_odirect_support('/dev/zero',
'/dev/def')
self.assertTrue(output)
mock_exec.assert_called_once_with('dd', 'count=0', 'if=/dev/zero',
'of=/dev/def', 'oflag=direct',
run_as_root=True)
@mock.patch('cinder.utils.execute',
side_effect=processutils.ProcessExecutionError)
@ -454,6 +468,13 @@ class OdirectSupportTestCase(test.TestCase):
mock_exec.assert_called_once_with('dd', 'count=0', 'if=/dev/abc',
'of=/dev/def', 'oflag=direct',
run_as_root=True)
mock_exec.reset_mock()
output = volume_utils.check_for_odirect_support('/dev/zero',
'/dev/def')
self.assertFalse(output)
mock_exec.assert_called_once_with('dd', 'count=0', 'if=/dev/zero',
'of=/dev/def', 'oflag=direct',
run_as_root=True)
class ClearVolumeTestCase(test.TestCase):

View File

@ -299,7 +299,13 @@ def check_for_odirect_support(src, dest, flag='oflag=direct'):
# Check whether O_DIRECT is supported
try:
utils.execute('dd', 'count=0', 'if=%s' % src, 'of=%s' % dest,
# iflag=direct and if=/dev/zero combination does not work
# error: dd: failed to open '/dev/zero': Invalid argument
if (src == '/dev/zero' and flag == 'iflag=direct'):
return False
else:
utils.execute('dd', 'count=0', 'if=%s' % src,
'of=%s' % dest,
flag, run_as_root=True)
return True
except processutils.ProcessExecutionError: