diff --git a/marconi/storage/mongodb/utils.py b/marconi/storage/mongodb/utils.py index 3137aef7d..4f19b7f5a 100644 --- a/marconi/storage/mongodb/utils.py +++ b/marconi/storage/mongodb/utils.py @@ -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): diff --git a/marconi/tests/storage/test_impl_mongodb.py b/marconi/tests/storage/test_impl_mongodb.py index 639b2dab8..384dece03 100644 --- a/marconi/tests/storage/test_impl_mongodb.py +++ b/marconi/tests/storage/test_impl_mongodb.py @@ -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)