diff --git a/tests/unit/storage/test_pool_catalog.py b/tests/unit/storage/test_pool_catalog.py index 55e313b25..be23c52db 100644 --- a/tests/unit/storage/test_pool_catalog.py +++ b/tests/unit/storage/test_pool_catalog.py @@ -51,7 +51,7 @@ class PoolCatalogTest(testing.TestBase): self.pools_ctrl.create(self.pool, 100, 'mongodb://localhost:27017') self.pools_ctrl.create(self.pool2, 100, - 'mongodb://localhost:27017', + 'mongodb://127.0.0.1:27017', group=self.pool_group) self.catalogue_ctrl.insert(self.project, self.queue, self.pool) self.catalog = pooling.Catalog(self.conf, cache, control) diff --git a/zaqar/storage/mongodb/pools.py b/zaqar/storage/mongodb/pools.py index 8dbe06148..38c39084a 100644 --- a/zaqar/storage/mongodb/pools.py +++ b/zaqar/storage/mongodb/pools.py @@ -33,6 +33,10 @@ POOLS_INDEX = [ ('n', 1) ] +URI_INDEX = [ + ('u', 1) +] + # NOTE(cpp-cabrera): used for get/list operations. There's no need to # show the marker or the _id - they're implementation details. OMIT_FIELDS = (('_id', False),) @@ -53,6 +57,11 @@ class PoolsController(base.PoolsBase): name='pools_name', unique=True) + self._col.ensure_index(URI_INDEX, + background=True, + name='pools_uri', + unique=True) + @utils.raises_conn_error def _list(self, marker=None, limit=10, detailed=False): query = {} diff --git a/zaqar/tests/unit/storage/base.py b/zaqar/tests/unit/storage/base.py index ee4bee102..16aeb65b3 100644 --- a/zaqar/tests/unit/storage/base.py +++ b/zaqar/tests/unit/storage/base.py @@ -68,7 +68,11 @@ class ControllerBaseTest(testing.TestBase): else: uri = "mongodb://localhost:27017" for i in range(4): - options = {'database': "zaqar_test_pools_" + str(i)} + db_name = "zaqar_test_pools_" + str(i) + + # NOTE(dynarro): we need to create a unique uri. + uri = "%s/%s" % (uri, db_name) + options = {'database': db_name} self.control.pools_controller.create(six.text_type(i), 100, uri, options=options) self.driver = self.driver_class(self.conf, cache, self.control) @@ -1099,20 +1103,20 @@ class PoolsControllerTest(ControllerBaseTest): def test_create_succeeds(self): self.pools_controller.create(str(uuid.uuid1()), - 100, 'localhost', + 100, 'localhost:13124', options={}) def test_create_replaces_on_duplicate_insert(self): name = str(uuid.uuid1()) self.pools_controller.create(name, - 100, 'localhost', + 100, 'localhost:76553', options={}) self.pools_controller.create(name, - 111, 'localhost2', + 111, 'localhost:758353', options={}) entry = self.pools_controller.get(name) self._pool_expects(entry, xname=name, xweight=111, - xlocation='localhost2') + xlocation='localhost:758353') def _pool_expects(self, pool, xname, xweight, xlocation): self.assertIn('name', pool) @@ -1398,7 +1402,7 @@ class FlavorsControllerTest(ControllerBaseTest): capabilities={}) pool2 = 'another_pool' - self.pools_controller.create(pool2, 100, 'localhost', + self.pools_controller.create(pool2, 100, 'localhost:27017', group=pool2, options={}) self.addCleanup(self.pools_controller.delete, pool2) @@ -1487,7 +1491,8 @@ class FlavorsControllerTest(ControllerBaseTest): name_gen = lambda i: chr(ord('A') + i) for i in range(15): pool = str(i) - self.pools_controller.create(pool, 100, 'localhost', + uri = 'localhost:2701' + pool + self.pools_controller.create(pool, 100, uri, group=pool, options={}) self.addCleanup(self.pools_controller.delete, pool) diff --git a/zaqar/tests/unit/transport/wsgi/v1/test_default_limits.py b/zaqar/tests/unit/transport/wsgi/v1/test_default_limits.py index 5a959483f..4d62f52b2 100644 --- a/zaqar/tests/unit/transport/wsgi/v1/test_default_limits.py +++ b/zaqar/tests/unit/transport/wsgi/v1/test_default_limits.py @@ -43,6 +43,7 @@ class TestDefaultLimits(base.V1Base): def test_queue_listing(self): # 2 queues to list + self.addCleanup(self.simulate_delete, self.queue_path + '/q2') self.simulate_put(self.queue_path + '/q2') self.assertEqual(self.srmock.status, falcon.HTTP_201) diff --git a/zaqar/tests/unit/transport/wsgi/v1/test_messages.py b/zaqar/tests/unit/transport/wsgi/v1/test_messages.py index 367de98b9..760ec1fa3 100644 --- a/zaqar/tests/unit/transport/wsgi/v1/test_messages.py +++ b/zaqar/tests/unit/transport/wsgi/v1/test_messages.py @@ -34,10 +34,9 @@ class MessagesBaseTest(base.V1Base): def setUp(self): super(MessagesBaseTest, self).setUp() - if self.conf.pooling: for i in range(4): - uri = self.conf['drivers:management_store:mongodb'].uri + uri = "%s/%s" % ('mongodb://localhost:27017', str(i)) doc = {'weight': 100, 'uri': uri} self.simulate_put(self.url_prefix + '/pools/' + str(i), body=jsonutils.dumps(doc)) diff --git a/zaqar/tests/unit/transport/wsgi/v1/test_pools.py b/zaqar/tests/unit/transport/wsgi/v1/test_pools.py index 939c7d893..ae8839119 100644 --- a/zaqar/tests/unit/transport/wsgi/v1/test_pools.py +++ b/zaqar/tests/unit/transport/wsgi/v1/test_pools.py @@ -38,6 +38,7 @@ def pool(test, name, weight, uri, options={}): :returns: (name, weight, uri, options) :rtype: see above """ + uri = "%s/%s" % (uri, str(uuid.uuid4())) doc = {'weight': weight, 'uri': uri, 'options': options} path = test.url_prefix + '/pools/' + name @@ -67,6 +68,7 @@ def pools(test, count, uri): {str(i): i}) for i in range(count)] for path, weight, option in args: + uri = "%s/%s" % (uri, str(uuid.uuid4())) doc = {'weight': weight, 'uri': uri, 'options': option} test.simulate_put(path, body=jsonutils.dumps(doc)) @@ -160,7 +162,10 @@ class PoolsBaseTest(base.V1Base): self.assertIn('weight', pool) self.assertEqual(pool['weight'], xweight) self.assertIn('uri', pool) - self.assertEqual(pool['uri'], xuri) + + # NOTE(dynarro): we are using startwith because we are adding to + # pools UUIDs, to avoid dupplications + self.assertTrue(pool['uri'].startswith(xuri)) def test_get_works(self): result = self.simulate_get(self.pool) diff --git a/zaqar/tests/unit/transport/wsgi/v1_1/test_messages.py b/zaqar/tests/unit/transport/wsgi/v1_1/test_messages.py index 600ed533d..43aa12ef5 100644 --- a/zaqar/tests/unit/transport/wsgi/v1_1/test_messages.py +++ b/zaqar/tests/unit/transport/wsgi/v1_1/test_messages.py @@ -39,7 +39,7 @@ class MessagesBaseTest(base.V1_1Base): if self.conf.pooling: for i in range(4): - uri = self.conf['drivers:management_store:mongodb'].uri + uri = "%s/%s" % ('mongodb://localhost:27017', str(i)) doc = {'weight': 100, 'uri': uri} self.simulate_put(self.url_prefix + '/pools/' + str(i), body=jsonutils.dumps(doc)) diff --git a/zaqar/tests/unit/transport/wsgi/v1_1/test_pools.py b/zaqar/tests/unit/transport/wsgi/v1_1/test_pools.py index 4eb8bff1b..0203cd9e0 100644 --- a/zaqar/tests/unit/transport/wsgi/v1_1/test_pools.py +++ b/zaqar/tests/unit/transport/wsgi/v1_1/test_pools.py @@ -38,11 +38,13 @@ def pool(test, name, weight, uri, group=None, options={}): :returns: (name, weight, uri, options) :rtype: see above """ + uri = "%s/%s" % (uri, str(uuid.uuid4())) doc = {'weight': weight, 'uri': uri, 'group': group, 'options': options} path = test.url_prefix + '/pools/' + name test.simulate_put(path, body=jsonutils.dumps(doc)) + test.addCleanup(test.simulate_delete, path) try: yield name, weight, uri, group, options @@ -68,6 +70,7 @@ def pools(test, count, uri, group): {str(i): i}) for i in range(count)] for path, weight, option in args: + uri = "%s/%s" % (uri, str(uuid.uuid4())) doc = {'weight': weight, 'uri': uri, 'group': group, 'options': option} test.simulate_put(path, body=jsonutils.dumps(doc)) @@ -164,7 +167,10 @@ class PoolsBaseTest(base.V1_1Base): self.assertIn('weight', pool) self.assertEqual(pool['weight'], xweight) self.assertIn('uri', pool) - self.assertEqual(pool['uri'], xuri) + + # NOTE(dynarro): we are using startwith because we are adding to + # pools UUIDs, to avoid dupplications + self.assertTrue(pool['uri'].startswith(xuri)) def test_get_works(self): result = self.simulate_get(self.pool) diff --git a/zaqar/tests/unit/transport/wsgi/v2_0/test_flavors.py b/zaqar/tests/unit/transport/wsgi/v2_0/test_flavors.py index 2f3f5b84c..b956adb9c 100644 --- a/zaqar/tests/unit/transport/wsgi/v2_0/test_flavors.py +++ b/zaqar/tests/unit/transport/wsgi/v2_0/test_flavors.py @@ -91,7 +91,7 @@ class FlavorsBaseTest(base.V2Base): self.pool_path = self.url_prefix + '/pools/' + self.pool self.pool_doc = {'weight': 100, 'group': self.pool_group, - 'uri': 'mongodb://localhost:27017'} + 'uri': 'mongodb://localhost:27017/test'} self.simulate_put(self.pool_path, body=jsonutils.dumps(self.pool_doc)) self.flavor = 'test-flavor' diff --git a/zaqar/tests/unit/transport/wsgi/v2_0/test_messages.py b/zaqar/tests/unit/transport/wsgi/v2_0/test_messages.py index 046c6c46d..fd46ce602 100644 --- a/zaqar/tests/unit/transport/wsgi/v2_0/test_messages.py +++ b/zaqar/tests/unit/transport/wsgi/v2_0/test_messages.py @@ -38,9 +38,13 @@ class MessagesBaseTest(base.V2Base): self.default_message_ttl = self.boot.transport._defaults.message_ttl if self.conf.pooling: + uri = "mongodb://localhost:27017" for i in range(4): - uri = self.conf['drivers:management_store:mongodb'].uri - doc = {'weight': 100, 'uri': uri} + db_name = "zaqar_test_pools_" + str(i) + # NOTE(dynarro): we need to create a unique uri. + uri = "%s/%s" % (uri, db_name) + options = {'database': db_name} + doc = {'weight': 100, 'uri': uri, 'options': options} self.simulate_put(self.url_prefix + '/pools/' + str(i), body=jsonutils.dumps(doc)) self.assertEqual(self.srmock.status, falcon.HTTP_201) diff --git a/zaqar/tests/unit/transport/wsgi/v2_0/test_pools.py b/zaqar/tests/unit/transport/wsgi/v2_0/test_pools.py index e67e9bf21..d49403620 100644 --- a/zaqar/tests/unit/transport/wsgi/v2_0/test_pools.py +++ b/zaqar/tests/unit/transport/wsgi/v2_0/test_pools.py @@ -38,6 +38,7 @@ def pool(test, name, weight, uri, group=None, options={}): :returns: (name, weight, uri, options) :rtype: see above """ + uri = "%s/%s" % (uri, str(uuid.uuid4())) doc = {'weight': weight, 'uri': uri, 'group': group, 'options': options} path = test.url_prefix + '/pools/' + name @@ -68,6 +69,7 @@ def pools(test, count, uri, group): {str(i): i}) for i in range(count)] for path, weight, option in args: + uri = "%s/%s" % (uri, str(uuid.uuid4())) doc = {'weight': weight, 'uri': uri, 'group': group, 'options': option} test.simulate_put(path, body=jsonutils.dumps(doc)) @@ -164,7 +166,10 @@ class PoolsBaseTest(base.V2Base): self.assertIn('weight', pool) self.assertEqual(pool['weight'], xweight) self.assertIn('uri', pool) - self.assertEqual(pool['uri'], xuri) + + # NOTE(dynarro): we are using startwith because we are adding to + # pools UUIDs, to avoid dupplications + self.assertTrue(pool['uri'].startswith(xuri)) def test_get_works(self): result = self.simulate_get(self.pool)