Merge "Fix migration_success before completing" into stable/ocata
This commit is contained in:
commit
eb2e91d937
@ -1241,20 +1241,17 @@ class ShareManager(manager.SchedulerDependentManager):
|
||||
context, dest_share_instance['id'],
|
||||
{'status': constants.STATUS_AVAILABLE})
|
||||
|
||||
self._migration_delete_instance(context, src_share_instance['id'])
|
||||
self.db.share_instance_update(context, src_share_instance['id'],
|
||||
{'status': constants.STATUS_INACTIVE})
|
||||
|
||||
self.db.share_update(
|
||||
context, dest_share_instance['share_id'],
|
||||
{'task_state': constants.TASK_STATE_MIGRATION_SUCCESS})
|
||||
self._migration_delete_instance(context, src_share_instance['id'])
|
||||
|
||||
def _migration_delete_instance(self, context, instance_id):
|
||||
|
||||
# refresh the share instance model
|
||||
share_instance = self.db.share_instance_get(
|
||||
context, instance_id, with_share_data=True)
|
||||
|
||||
self.db.share_instance_update(
|
||||
context, instance_id, {'status': constants.STATUS_INACTIVE})
|
||||
|
||||
rules = self.access_helper.get_and_update_share_instance_access_rules(
|
||||
context, share_instance_id=instance_id)
|
||||
|
||||
@ -1336,8 +1333,13 @@ class ShareManager(manager.SchedulerDependentManager):
|
||||
{'status': constants.STATUS_AVAILABLE})
|
||||
raise exception.ShareMigrationFailed(reason=msg)
|
||||
|
||||
self._update_migrated_share_model(
|
||||
context, share_ref['id'], dest_share_instance)
|
||||
model_update = self._get_extra_specs_from_share_type(
|
||||
context, dest_share_instance['share_type_id'])
|
||||
|
||||
model_update['task_state'] = constants.TASK_STATE_MIGRATION_SUCCESS
|
||||
|
||||
self.db.share_update(
|
||||
context, dest_share_instance['share_id'], model_update)
|
||||
|
||||
LOG.info(_LI("Share Migration for share %s"
|
||||
" completed successfully."), share_ref['id'])
|
||||
@ -1350,14 +1352,6 @@ class ShareManager(manager.SchedulerDependentManager):
|
||||
|
||||
return share_api.get_share_attributes_from_share_type(share_type)
|
||||
|
||||
def _update_migrated_share_model(
|
||||
self, context, share_id, dest_share_instance):
|
||||
|
||||
update = self._get_extra_specs_from_share_type(
|
||||
context, dest_share_instance['share_type_id'])
|
||||
|
||||
self.db.share_update(context, share_id, update)
|
||||
|
||||
def _migration_complete_host_assisted(self, context, share_ref,
|
||||
src_instance_id, dest_instance_id):
|
||||
|
||||
@ -1404,6 +1398,10 @@ class ShareManager(manager.SchedulerDependentManager):
|
||||
LOG.error(msg)
|
||||
raise exception.ShareMigrationFailed(reason=msg)
|
||||
|
||||
self.db.share_update(
|
||||
context, share_ref['id'],
|
||||
{'task_state': constants.TASK_STATE_MIGRATION_COMPLETING})
|
||||
|
||||
try:
|
||||
helper.apply_new_access_rules(dest_share_instance)
|
||||
except Exception:
|
||||
@ -1420,24 +1418,15 @@ class ShareManager(manager.SchedulerDependentManager):
|
||||
|
||||
raise exception.ShareMigrationFailed(reason=msg)
|
||||
|
||||
self.db.share_update(
|
||||
context, share_ref['id'],
|
||||
{'task_state': constants.TASK_STATE_MIGRATION_COMPLETING})
|
||||
|
||||
self.db.share_instance_update(context, dest_instance_id,
|
||||
{'status': constants.STATUS_AVAILABLE})
|
||||
self.db.share_instance_update(
|
||||
context, dest_share_instance['id'],
|
||||
{'status': constants.STATUS_AVAILABLE})
|
||||
|
||||
self.db.share_instance_update(context, src_instance_id,
|
||||
{'status': constants.STATUS_INACTIVE})
|
||||
|
||||
helper.delete_instance_and_wait(src_share_instance)
|
||||
|
||||
self._check_delete_share_server(context, src_share_instance)
|
||||
|
||||
self.db.share_update(
|
||||
context, share_ref['id'],
|
||||
{'task_state': constants.TASK_STATE_MIGRATION_SUCCESS})
|
||||
|
||||
@utils.require_driver_initialized
|
||||
def migration_cancel(self, context, src_instance_id, dest_instance_id):
|
||||
|
||||
|
@ -4423,6 +4423,8 @@ class ShareManagerTestCase(test.TestCase):
|
||||
instances=[instance_1, instance_2],
|
||||
task_state=task_state)
|
||||
model_type_update = {'create_share_from_snapshot_support': False}
|
||||
share_update = model_type_update
|
||||
share_update['task_state'] = constants.TASK_STATE_MIGRATION_SUCCESS
|
||||
|
||||
# mocks
|
||||
self.mock_object(self.share_manager.db, 'share_get',
|
||||
@ -4463,6 +4465,7 @@ class ShareManagerTestCase(test.TestCase):
|
||||
'share_snapshot_instance_get_all_with_filters',
|
||||
mock.Mock(
|
||||
return_value=[snapshot_ins1, snapshot_ins2]))
|
||||
|
||||
self.assertRaises(
|
||||
exception.ShareMigrationFailed,
|
||||
self.share_manager.migration_complete,
|
||||
@ -4528,7 +4531,7 @@ class ShareManagerTestCase(test.TestCase):
|
||||
share_types.get_share_type.assert_called_once_with(
|
||||
self.context, 'fake_type_id')
|
||||
self.share_manager.db.share_update.assert_called_once_with(
|
||||
self.context, share['id'], model_type_update)
|
||||
self.context, share['id'], share_update)
|
||||
|
||||
@ddt.data(constants.TASK_STATE_DATA_COPYING_ERROR,
|
||||
constants.TASK_STATE_DATA_COPYING_CANCELLED,
|
||||
@ -4680,16 +4683,15 @@ class ShareManagerTestCase(test.TestCase):
|
||||
assert_called_once_with(dest_instance))
|
||||
self.share_manager._migration_delete_instance.assert_called_once_with(
|
||||
self.context, src_instance['id'])
|
||||
self.share_manager.db.share_instance_update.assert_called_once_with(
|
||||
self.context, dest_instance['id'],
|
||||
{'status': constants.STATUS_AVAILABLE})
|
||||
self.share_manager.db.share_update.assert_has_calls([
|
||||
mock.call(
|
||||
self.context, dest_instance['share_id'],
|
||||
{'task_state': constants.TASK_STATE_MIGRATION_COMPLETING}),
|
||||
mock.call(
|
||||
self.context, dest_instance['share_id'],
|
||||
{'task_state': constants.TASK_STATE_MIGRATION_SUCCESS})])
|
||||
self.share_manager.db.share_instance_update.assert_has_calls([
|
||||
mock.call(self.context, dest_instance['id'],
|
||||
{'status': constants.STATUS_AVAILABLE}),
|
||||
mock.call(self.context, src_instance['id'],
|
||||
{'status': constants.STATUS_INACTIVE})])
|
||||
self.share_manager.db.share_update.assert_called_once_with(
|
||||
self.context, dest_instance['share_id'],
|
||||
{'task_state': constants.TASK_STATE_MIGRATION_COMPLETING})
|
||||
|
||||
(self.share_manager.db.share_snapshot_instance_get_all_with_filters.
|
||||
assert_has_calls([
|
||||
mock.call(self.context,
|
||||
@ -4728,8 +4730,8 @@ class ShareManagerTestCase(test.TestCase):
|
||||
mock.Mock(side_effect=[instance, new_instance]))
|
||||
self.mock_object(self.share_manager.db, 'share_instance_update')
|
||||
self.mock_object(self.share_manager.db, 'share_update')
|
||||
self.mock_object(migration_api.ShareMigrationHelper,
|
||||
'delete_instance_and_wait')
|
||||
delete_mock = self.mock_object(migration_api.ShareMigrationHelper,
|
||||
'delete_instance_and_wait')
|
||||
self.mock_object(migration_api.ShareMigrationHelper,
|
||||
'apply_new_access_rules')
|
||||
|
||||
@ -4749,18 +4751,13 @@ class ShareManagerTestCase(test.TestCase):
|
||||
mock.call(self.context, instance['id'],
|
||||
{'status': constants.STATUS_INACTIVE})
|
||||
])
|
||||
self.share_manager.db.share_update.assert_has_calls([
|
||||
mock.call(
|
||||
self.context, share['id'],
|
||||
{'task_state': constants.TASK_STATE_MIGRATION_COMPLETING}),
|
||||
mock.call(
|
||||
self.context, share['id'],
|
||||
{'task_state': constants.TASK_STATE_MIGRATION_SUCCESS}),
|
||||
])
|
||||
|
||||
self.share_manager.db.share_update.assert_called_once_with(
|
||||
self.context, share['id'],
|
||||
{'task_state': constants.TASK_STATE_MIGRATION_COMPLETING})
|
||||
migration_api.ShareMigrationHelper.apply_new_access_rules.\
|
||||
assert_called_once_with(new_instance)
|
||||
migration_api.ShareMigrationHelper.delete_instance_and_wait.\
|
||||
assert_called_once_with(instance)
|
||||
delete_mock.assert_called_once_with(instance)
|
||||
|
||||
@ddt.data(constants.TASK_STATE_MIGRATION_DRIVER_IN_PROGRESS,
|
||||
constants.TASK_STATE_MIGRATION_DRIVER_PHASE1_DONE,
|
||||
@ -4890,7 +4887,6 @@ class ShareManagerTestCase(test.TestCase):
|
||||
# mocks
|
||||
self.mock_object(self.share_manager.db, 'share_instance_get',
|
||||
mock.Mock(return_value=instance))
|
||||
self.mock_object(self.share_manager.db, 'share_instance_update')
|
||||
mock_get_access_rules_call = self.mock_object(
|
||||
self.share_manager.access_helper,
|
||||
'get_and_update_share_instance_access_rules',
|
||||
@ -4914,9 +4910,6 @@ class ShareManagerTestCase(test.TestCase):
|
||||
# asserts
|
||||
self.share_manager.db.share_instance_get.assert_called_once_with(
|
||||
self.context, instance['id'], with_share_data=True)
|
||||
self.share_manager.db.share_instance_update.assert_called_once_with(
|
||||
self.context, instance['id'],
|
||||
{'status': constants.STATUS_INACTIVE})
|
||||
mock_get_access_rules_call.assert_called_once_with(
|
||||
self.context, share_instance_id=instance['id'])
|
||||
mock_delete_access_rules_call.assert_called_once_with(
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
fixes:
|
||||
- Fixed ``task_state`` field in the share model
|
||||
being set to ``migration_success`` before actually
|
||||
completing a share migration.
|
||||
|
Loading…
Reference in New Issue
Block a user