Fix BadRequest from share-server-migration-get-progress

The share-server-migration-get-progress command was returning error
when executed immediataly after starting migration.

This patch fix all the errors related to this change.

Closes-bug: #2025075

Change-Id: Iaaf15906aa3a29543860d878cde305cfddc7f70e
This commit is contained in:
MelloCaique 2023-07-26 18:14:39 +00:00 committed by Caique Mello
parent 504d0a10c6
commit 8229f3e5c1
3 changed files with 63 additions and 5 deletions

View File

@ -2750,6 +2750,8 @@ class API(base.Base):
def share_server_migration_get_destination(self, context, source_server_id,
status=None):
"""Returns destination share server for a share server migration."""
filters = {'source_share_server_id': source_server_id}
if status:
filters.update({'status': status})
@ -3153,10 +3155,25 @@ class API(base.Base):
LOG.error(msg)
raise exception.InvalidShareServer(reason=msg)
dest_share_server = self.share_server_migration_get_destination(
context, share_server['id'],
status=constants.STATUS_SERVER_MIGRATING_TO
)
try:
dest_share_server = self.share_server_migration_get_destination(
context, share_server['id'],
status=constants.STATUS_SERVER_MIGRATING_TO
)
except Exception:
msg = ("Migration progress of share server %s cannot be "
"determined yet. Please retry the migration get "
"progress operation.") % share_server['id']
LOG.info(msg)
result = {
'destination_share_server_id': '',
'task_state': ''
}
result.update(self._migration_get_progress_state(share_server))
return result
if (share_server['task_state'] ==
constants.TASK_STATE_MIGRATION_DRIVER_IN_PROGRESS):

View File

@ -4961,7 +4961,9 @@ class ShareAPITestCase(test.TestCase):
self.assertEqual(filtered_server['id'], server['id'])
mock_get_all.assert_called_once_with(self.context, filters=filters)
def test_share_server_migration_get_destination_no_share_server(self):
def test_share_server_migration_get_destination_no_share_server(
self):
fake_source_server_id = 'fake_source_id'
server_data = {
'id': 'fake',
@ -6039,6 +6041,39 @@ class ShareAPITestCase(test.TestCase):
mock_get_destination.assert_called_once_with(
self.context, 'fake_src_server_id', status=constants.STATUS_ACTIVE)
def test_share_server_migration_get_progress_not_determinated(self):
fake_service_host = 'host@backend'
fake_share_server = db_utils.create_share_server(
status=constants.STATUS_SERVER_MIGRATING,
task_state=None,
host=fake_service_host)
mock_server_get = self.mock_object(
db_api, 'share_server_get',
mock.Mock(return_value=fake_share_server))
mock_get_destination = self.mock_object(
self.api, 'share_server_migration_get_destination',
mock.Mock(side_effect=exception.InvalidShareServer(reason='')))
mock_get_progress_state = self.mock_object(
self.api, '_migration_get_progress_state',
mock.Mock(return_value={'total_progress': 0}))
result = self.api.share_server_migration_get_progress(
self.context, 'fake_source_server_id')
expected = {
'total_progress': 0,
'destination_share_server_id': '',
'task_state': '',
}
self.assertEqual(expected, result)
mock_server_get.assert_called_once_with(self.context,
'fake_source_server_id')
mock_get_destination.assert_called_once_with(
self.context, fake_share_server['id'],
status=constants.STATUS_SERVER_MIGRATING_TO)
mock_get_progress_state.assert_called_once_with(fake_share_server)
def test_migration_get_progress_race(self):
instance1 = db_utils.create_share_instance(

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fix BadRequest error from share-server-migration-get-progress.
For more details please refer to
`launchpad bug #2025075 <https://bugs.launchpad.net/manila/+bug/2025075>`