Skip to content

Commit

Permalink
Merge "Separate OSError with ValueError" into stable/2023.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed Aug 31, 2024
2 parents 8a87f34 + fc54bc9 commit 51480ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions nova/cmd/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3188,12 +3188,15 @@ def refresh(self, instance_uuid=None, volume_id=None, connector_path=None):
) 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
Expand Down
12 changes: 12 additions & 0 deletions nova/tests/unit/cmd/test_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3468,6 +3468,18 @@ def test_refresh_invalid_connector_path_file(self, mock_exists):
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()
Expand Down

0 comments on commit 51480ee

Please sign in to comment.