Separate OSError with ValueError
OSError will only be raised, if file path is not readable because of permission issue. With this change we will get correct error msg. Change-Id: Iad3b0f2ab3e6eafd9f6c98477edfa35c4cd46ee8
This commit is contained in:
+5
-2
@@ -3208,12 +3208,15 @@ class VolumeAttachmentCommands(object):
|
||||
) as e:
|
||||
print(str(e))
|
||||
return 4
|
||||
except (ValueError, OSError):
|
||||
except ValueError as e:
|
||||
print(
|
||||
f'Failed to open {connector_path}. Does it contain valid '
|
||||
f'connector_info data?'
|
||||
f'connector_info data?\nError: {str(e)}'
|
||||
)
|
||||
return 3
|
||||
except OSError as e:
|
||||
print(str(e))
|
||||
return 3
|
||||
except exception.InvalidInput as e:
|
||||
print(str(e))
|
||||
return 2
|
||||
|
||||
@@ -3488,6 +3488,18 @@ class VolumeAttachmentCommandsTestCase(test.NoDBTestCase):
|
||||
output = self.output.getvalue().strip()
|
||||
self.assertIn('Failed to open fake_path', output)
|
||||
|
||||
@mock.patch('os.path.exists')
|
||||
def test_refresh_connector_file_oserr(self, mock_exists):
|
||||
"""Test refresh with connector file having no read permission.
|
||||
"""
|
||||
mock_exists.return_value = True
|
||||
with self.patch_open('fake_path', b'invalid json') as mock_file:
|
||||
mock_file.side_effect = OSError("Permission denied")
|
||||
ret = self.commands.refresh(
|
||||
uuidsentinel.volume, uuidsentinel.instance, 'fake_path'
|
||||
)
|
||||
self.assertEqual(3, ret)
|
||||
|
||||
@mock.patch('os.path.exists')
|
||||
def _test_refresh(self, mock_exists):
|
||||
ctxt = context.get_admin_context()
|
||||
|
||||
Reference in New Issue
Block a user