Merge "Fixes unique constraint regex"
This commit is contained in:
commit
9272cf4742
@ -28,7 +28,7 @@ from marconi.openstack.common import timeutils
|
||||
from marconi.storage import exceptions as storage_exceptions
|
||||
|
||||
|
||||
DUP_MARKER_REGEX = re.compile(r'\$queue_marker\s+dup key: { : [^:]+: (\d)+')
|
||||
DUP_MARKER_REGEX = re.compile(r'\$queue_marker.*?:\s(\d+)')
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -42,13 +42,13 @@ def dup_marker_from_error(error_message):
|
||||
:raises: marconi.common.exceptions.PatternNotFound
|
||||
:returns: extracted marker as an integer
|
||||
"""
|
||||
match = DUP_MARKER_REGEX.search(error_message)
|
||||
if match is None:
|
||||
match = DUP_MARKER_REGEX.findall(error_message)
|
||||
if not match:
|
||||
description = ('Error message could not be parsed: %s' %
|
||||
error_message)
|
||||
raise exceptions.PatternNotFound(description)
|
||||
|
||||
return int(match.groups()[0])
|
||||
return int(match[-1])
|
||||
|
||||
|
||||
def cached_gen(iterable):
|
||||
|
@ -37,14 +37,14 @@ class MongodbUtilsTest(testing.TestBase):
|
||||
def test_dup_marker_from_error(self):
|
||||
error_message = ('E11000 duplicate key error index: '
|
||||
'marconi.messages.$queue_marker dup key: '
|
||||
'{ : ObjectId("51adff46b100eb85d8a93a2d"), : 3 }')
|
||||
'{ : "queue", : "project", : 3 }')
|
||||
|
||||
marker = utils.dup_marker_from_error(error_message)
|
||||
self.assertEquals(marker, 3)
|
||||
|
||||
error_message = ('E11000 duplicate key error index: '
|
||||
'marconi.messages.$x_y dup key: '
|
||||
'{ : ObjectId("51adff46b100eb85d8a93a2d"), : 3 }')
|
||||
'{ : "queue", : "project", : 3 }')
|
||||
|
||||
self.assertRaises(exceptions.PatternNotFound,
|
||||
utils.dup_marker_from_error, error_message)
|
||||
|
Loading…
Reference in New Issue
Block a user