Fix check+set race condition in APIv1/Sink

Change-Id: I02d22212511246f0c1b8138fa3413770cd5810a1
Closes-Bug: 1454262
This commit is contained in:
Kiall Mac Innes 2015-05-12 14:59:15 +01:00
parent b674cbf6ac
commit ef769bf960
2 changed files with 14 additions and 9 deletions

View File

@ -46,9 +46,7 @@ def _find_or_create_recordset(context, domain_id, name, type, ttl):
central_api.find_domain(context, criterion=criterion)
try:
recordset = _find_recordset(context, domain_id, name, type)
except exceptions.RecordSetNotFound:
# Create an empty recordset
# Attempt to create an empty recordset
values = {
'name': name,
'type': type,
@ -58,6 +56,10 @@ def _find_or_create_recordset(context, domain_id, name, type, ttl):
recordset = central_api.create_recordset(
context, domain_id, objects.RecordSet(**values))
except exceptions.DuplicateRecordSet:
# Fetch the existing recordset
recordset = _find_recordset(context, domain_id, name, type)
return recordset

View File

@ -69,12 +69,7 @@ class NotificationHandler(ExtensionPlugin):
name = name.encode('idna')
try:
recordset = self.central_api.find_recordset(context, {
'domain_id': domain_id,
'name': name,
'type': type,
})
except exceptions.RecordSetNotFound:
# Attempt to create an empty recordset
values = {
'name': name,
'type': type,
@ -83,6 +78,14 @@ class NotificationHandler(ExtensionPlugin):
recordset = self.central_api.create_recordset(
context, domain_id, RecordSet(**values))
except exceptions.DuplicateRecordSet:
# Fetch the existing recordset
recordset = self.central_api.find_recordset(context, {
'domain_id': domain_id,
'name': name,
'type': type,
})
return recordset