Merge "Fix DBDeadLock error resulting into 500" into stable/queens

This commit is contained in:
Zuul 2019-06-17 20:16:00 +00:00 committed by Gerrit Code Review
commit c7987ef4b7
2 changed files with 27 additions and 1 deletions

View File

@ -2313,8 +2313,8 @@ class Service(service.RPCService, service.Service):
"""
# TODO(kiall): If the status is SUCCESS and the zone is already ACTIVE,
# we likely don't need to do anything.
self._update_record_status(context, zone_id, status, serial)
zone = self._update_zone_status(context, zone_id, status, serial)
self._update_record_status(context, zone_id, status, serial)
return zone
def _update_zone_status(self, context, zone_id, status, serial):

View File

@ -433,6 +433,32 @@ class CentralServiceTestCase(CentralBasic):
assert self.service._enforce_record_quota.called
assert self.service._update_zone_in_storage.called
def test_create_recordset_checking_DBDeadLock(self):
self.service._enforce_recordset_quota = mock.Mock()
self.service._enforce_record_quota = mock.Mock()
self.service._is_valid_recordset_name = mock.Mock()
self.service._is_valid_recordset_placement = mock.Mock()
self.service._is_valid_recordset_placement_subzone = mock.Mock()
self.service._is_valid_ttl = mock.Mock()
self.service.storage.create_recordset = mock.Mock(return_value='rs')
self.service._update_zone_in_storage = mock.Mock()
# NOTE(thirose): Since this is a race condition we assume that
# we will hit it if we try to do the operations in a loop 100 times.
for num in range(100):
recordset = Mock()
recordset.name = "b%s".format(num)
recordset.obj_attr_is_set.return_value = True
recordset.records = [MockRecord()]
rs, zone = self.service._create_recordset_in_storage(
self.context, Mockzone(), recordset
)
assert not self.service.storage._retry_on_deadlock.called
assert self.service._update_zone_in_storage.called
assert self.service.storage.create_recordset.called
def test__create_soa(self):
self.service._create_recordset_in_storage = Mock(
return_value=(None, None)