Skip to content

Commit ec0c207

Browse files
committed
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 (cherry picked from commit 77851bb)
1 parent 9eebaf3 commit ec0c207

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

nova/cmd/manage.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3208,12 +3208,15 @@ def refresh(self, instance_uuid=None, volume_id=None, connector_path=None):
32083208
) as e:
32093209
print(str(e))
32103210
return 4
3211-
except (ValueError, OSError):
3211+
except ValueError as e:
32123212
print(
32133213
f'Failed to open {connector_path}. Does it contain valid '
3214-
f'connector_info data?'
3214+
f'connector_info data?\nError: {str(e)}'
32153215
)
32163216
return 3
3217+
except OSError as e:
3218+
print(str(e))
3219+
return 3
32173220
except exception.InvalidInput as e:
32183221
print(str(e))
32193222
return 2

nova/tests/unit/cmd/test_manage.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,6 +3488,18 @@ def test_refresh_invalid_connector_path_file(self, mock_exists):
34883488
output = self.output.getvalue().strip()
34893489
self.assertIn('Failed to open fake_path', output)
34903490

3491+
@mock.patch('os.path.exists')
3492+
def test_refresh_connector_file_oserr(self, mock_exists):
3493+
"""Test refresh with connector file having no read permission.
3494+
"""
3495+
mock_exists.return_value = True
3496+
with self.patch_open('fake_path', b'invalid json') as mock_file:
3497+
mock_file.side_effect = OSError("Permission denied")
3498+
ret = self.commands.refresh(
3499+
uuidsentinel.volume, uuidsentinel.instance, 'fake_path'
3500+
)
3501+
self.assertEqual(3, ret)
3502+
34913503
@mock.patch('os.path.exists')
34923504
def _test_refresh(self, mock_exists):
34933505
ctxt = context.get_admin_context()

0 commit comments

Comments
 (0)