Skip to content

Commit fc54bc9

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) (cherry picked from commit ec0c207)
1 parent a1fa92f commit fc54bc9

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)