Skip to content

Commit 51480ee

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Separate OSError with ValueError" into stable/2023.1
2 parents 8a87f34 + fc54bc9 commit 51480ee

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
@@ -3188,12 +3188,15 @@ def refresh(self, instance_uuid=None, volume_id=None, connector_path=None):
31883188
) as e:
31893189
print(str(e))
31903190
return 4
3191-
except (ValueError, OSError):
3191+
except ValueError as e:
31923192
print(
31933193
f'Failed to open {connector_path}. Does it contain valid '
3194-
f'connector_info data?'
3194+
f'connector_info data?\nError: {str(e)}'
31953195
)
31963196
return 3
3197+
except OSError as e:
3198+
print(str(e))
3199+
return 3
31973200
except exception.InvalidInput as e:
31983201
print(str(e))
31993202
return 2

nova/tests/unit/cmd/test_manage.py

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

3471+
@mock.patch('os.path.exists')
3472+
def test_refresh_connector_file_oserr(self, mock_exists):
3473+
"""Test refresh with connector file having no read permission.
3474+
"""
3475+
mock_exists.return_value = True
3476+
with self.patch_open('fake_path', b'invalid json') as mock_file:
3477+
mock_file.side_effect = OSError("Permission denied")
3478+
ret = self.commands.refresh(
3479+
uuidsentinel.volume, uuidsentinel.instance, 'fake_path'
3480+
)
3481+
self.assertEqual(3, ret)
3482+
34713483
@mock.patch('os.path.exists')
34723484
def _test_refresh(self, mock_exists):
34733485
ctxt = context.get_admin_context()

0 commit comments

Comments
 (0)