Merge "Fix status update for replicas"

This commit is contained in:
Jenkins 2016-03-11 14:35:19 +00:00 committed by Gerrit Code Review
commit e763d43c47
2 changed files with 21 additions and 14 deletions

View File

@ -1392,19 +1392,18 @@ class ShareManager(manager.SchedulerDependentManager):
share_replica = self._get_share_replica_dict(context, share_replica)
try:
replica_state = self.driver.update_replica_state(
context, replica_list, share_replica, access_rules,
share_server=share_server)
except Exception:
# If the replica_state was previously in 'error', it is
# possible that the driver throws an exception during its
# update. This exception can be ignored.
with excutils.save_and_reraise_exception() as exc_context:
if (share_replica.get('replica_state') ==
constants.STATUS_ERROR):
exc_context.reraise = False
msg = _LE("Driver error when updating replica "
"state for replica %s.")
LOG.exception(msg, share_replica['id'])
self.db.share_replica_update(
context, share_replica['id'],
{'replica_state': constants.STATUS_ERROR,
'status': constants.STATUS_ERROR})
return
if replica_state in (constants.REPLICA_STATE_IN_SYNC,
constants.REPLICA_STATE_OUT_OF_SYNC,

View File

@ -1114,10 +1114,14 @@ class ShareManagerTestCase(test.TestCase):
mock_db_update_call = self.mock_object(
self.share_manager.db, 'share_replica_update')
self.assertRaises(exception.ManilaException,
self.share_manager._share_replica_update,
self.context, replica, share_id=replica['share_id'])
self.assertFalse(mock_db_update_call.called)
self.share_manager._share_replica_update(
self.context, replica, share_id=replica['share_id'])
mock_db_update_call.assert_called_once_with(
self.context, replica['id'],
{'replica_state': constants.STATUS_ERROR,
'status': constants.STATUS_ERROR}
)
self.assertEqual(1, mock_debug_log.call_count)
def test__share_replica_update_driver_exception_ignored(self):
@ -1138,7 +1142,11 @@ class ShareManagerTestCase(test.TestCase):
self.share_manager._share_replica_update(
self.context, replica, share_id=replica['share_id'])
self.assertFalse(mock_db_update_call.called)
mock_db_update_call.assert_called_once_with(
self.context, replica['id'],
{'replica_state': constants.STATUS_ERROR,
'status': constants.STATUS_ERROR}
)
self.assertEqual(1, mock_debug_log.call_count)
@ddt.data({'status': constants.STATUS_AVAILABLE,