diff --git a/tests/functional/queues/v1/test_shard.py b/tests/functional/queues/v1/test_pool.py similarity index 86% rename from tests/functional/queues/v1/test_shard.py rename to tests/functional/queues/v1/test_pool.py index 4622200a..0b9de3ca 100644 --- a/tests/functional/queues/v1/test_shard.py +++ b/tests/functional/queues/v1/test_pool.py @@ -14,11 +14,11 @@ # limitations under the License. -from zaqarclient.tests.queues import shard +from zaqarclient.tests.queues import pool from zaqarclient.transport import http -class QueuesV1ShardHttpFunctionalTest(shard.QueuesV1ShardFunctionalTest): +class QueuesV1PoolHttpFunctionalTest(pool.QueuesV1PoolFunctionalTest): is_functional = True transport_cls = http.HttpTransport diff --git a/tests/unit/queues/v1/test_core.py b/tests/unit/queues/v1/test_core.py index 7bb0401f..7919fa54 100644 --- a/tests/unit/queues/v1/test_core.py +++ b/tests/unit/queues/v1/test_core.py @@ -193,25 +193,25 @@ class TestV1Core(base.TestBase): self.assertEqual(ids, req.params['ids']) # ADMIN API - def test_shard_create(self): + def test_pool_create(self): with mock.patch.object(self.transport, 'send', autospec=True) as send_method: resp = response.Response(None, None) send_method.return_value = resp req = request.Request() - core.shard_create(self.transport, req, - 'test_shard', {'uri': 'sqlite://', - 'weight': 0}) + core.pool_create(self.transport, req, + 'test_pool', {'uri': 'sqlite://', + 'weight': 0}) - def test_shard_delete(self): + def test_pool_delete(self): with mock.patch.object(self.transport, 'send', autospec=True) as send_method: resp = response.Response(None, None) send_method.return_value = resp req = request.Request() - core.shard_delete(self.transport, req, 'test_shard') + core.pool_delete(self.transport, req, 'test_pool') def test_health(self): with mock.patch.object(self.transport, 'send', diff --git a/tests/unit/queues/v1/test_shard.py b/tests/unit/queues/v1/test_pool.py similarity index 87% rename from tests/unit/queues/v1/test_shard.py rename to tests/unit/queues/v1/test_pool.py index badc9f23..25c09164 100644 --- a/tests/unit/queues/v1/test_shard.py +++ b/tests/unit/queues/v1/test_pool.py @@ -14,11 +14,11 @@ # limitations under the License. -from zaqarclient.tests.queues import shard +from zaqarclient.tests.queues import pool from zaqarclient.transport import http -class QueuesV1ShardHttpUnitTest(shard.QueuesV1ShardUnitTest): +class QueuesV1PoolHttpUnitTest(pool.QueuesV1PoolUnitTest): transport_cls = http.HttpTransport url = 'http://127.0.0.1:8888/v1' diff --git a/zaqarclient/queues/v1/api.py b/zaqarclient/queues/v1/api.py index 7d993d05..fa30f40c 100644 --- a/zaqarclient/queues/v1/api.py +++ b/zaqarclient/queues/v1/api.py @@ -154,21 +154,21 @@ class V1(api.Api): } }, - 'shard_create': { - 'ref': 'shards/{shard_name}', + 'pool_create': { + 'ref': 'pools/{pool_name}', 'method': 'PUT', - 'required': ['shard_name'], + 'required': ['pool_name'], 'properties': { - 'shard_name': {'type': 'string'}, + 'pool_name': {'type': 'string'}, } }, - 'shard_delete': { - 'ref': 'shards/{shard_name}', + 'pool_delete': { + 'ref': 'pools/{pool_name}', 'method': 'DELETE', - 'required': ['shard_name'], + 'required': ['pool_name'], 'properties': { - 'shard_name': {'type': 'string'}, + 'pool_name': {'type': 'string'}, } }, diff --git a/zaqarclient/queues/v1/client.py b/zaqarclient/queues/v1/client.py index 87572d4a..a5c86c3c 100644 --- a/zaqarclient/queues/v1/client.py +++ b/zaqarclient/queues/v1/client.py @@ -14,11 +14,12 @@ # limitations under the License. import uuid +import warnings from zaqarclient.queues.v1 import core from zaqarclient.queues.v1 import iterator +from zaqarclient.queues.v1 import pool from zaqarclient.queues.v1 import queues -from zaqarclient.queues.v1 import shard from zaqarclient import transport from zaqarclient.transport import request @@ -120,15 +121,20 @@ class Client(object): # ADMIN API def shard(self, ref, **kwargs): - """Returns a shard instance + warnings.warn(_('`shard_create`\'s been renamed to `pool_create` '), + DeprecationWarning, stacklevel=2) + return self.pool(ref, **kwargs) - :param ref: Shard's reference name. + def pool(self, ref, **kwargs): + """Returns a pool instance + + :param ref: Pool's reference name. :type ref: `six.text_type` - :returns: A shard instance - :rtype: `shard.Shard` + :returns: A pool instance + :rtype: `pool.Pool` """ - return shard.Shard(self, ref, **kwargs) + return pool.Pool(self, ref, **kwargs) def health(self): """Gets the health status of Zaqar server.""" diff --git a/zaqarclient/queues/v1/core.py b/zaqarclient/queues/v1/core.py index 61b4036f..7061233b 100644 --- a/zaqarclient/queues/v1/core.py +++ b/zaqarclient/queues/v1/core.py @@ -28,6 +28,7 @@ Functions present in this module assume that: """ import json +import warnings import zaqarclient.transport.errors as errors @@ -385,38 +386,50 @@ def claim_delete(transport, request, queue_name, claim_id): transport.send(request) -def shard_create(transport, request, shard_name, shard_data): - """Creates a shard called `shard_name` +def shard_create(transport, request, pool_name, pool_data): + warnings.warn(_('`shard_create`\'s been renamed to `pool_create` '), + DeprecationWarning, stacklevel=2) + return pool_create(transport, request, pool_name, pool_data) + + +def shard_delete(transport, request, pool_name): + warnings.warn(_('`shard_delete`\'s been renamed to `pool_delete` '), + DeprecationWarning, stacklevel=2) + return pool_delete(transport, request, pool_name) + + +def pool_create(transport, request, pool_name, pool_data): + """Creates a pool called `pool_name` :param transport: Transport instance to use :type transport: `transport.base.Transport` :param request: Request instance ready to be sent. :type request: `transport.request.Request` - :param shard_name: Shard reference name. - :type shard_name: `six.text_type` - :param shard_data: Shard's properties, i.e: weight, uri, options. - :type shard_data: `dict` + :param pool_name: Pool reference name. + :type pool_name: `six.text_type` + :param pool_data: Pool's properties, i.e: weight, uri, options. + :type pool_data: `dict` """ - request.operation = 'shard_create' - request.params['shard_name'] = shard_name - request.content = json.dumps(shard_data) + request.operation = 'pool_create' + request.params['pool_name'] = pool_name + request.content = json.dumps(pool_data) transport.send(request) -def shard_delete(transport, request, shard_name): - """Deletes the shard `shard_name` +def pool_delete(transport, request, pool_name): + """Deletes the pool `pool_name` :param transport: Transport instance to use :type transport: `transport.base.Transport` :param request: Request instance ready to be sent. :type request: `transport.request.Request` - :param shard_name: Shard reference name. - :type shard_name: `six.text_type` + :param pool_name: Pool reference name. + :type pool_name: `six.text_type` """ - request.operation = 'shard_delete' - request.params['shard_name'] = shard_name + request.operation = 'pool_delete' + request.params['pool_name'] = pool_name transport.send(request) diff --git a/zaqarclient/queues/v1/pool.py b/zaqarclient/queues/v1/pool.py new file mode 100644 index 00000000..9230fbdb --- /dev/null +++ b/zaqarclient/queues/v1/pool.py @@ -0,0 +1,51 @@ +# Copyright (c) 2014 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from zaqarclient.queues.v1 import core + + +class Pool(object): + + def __init__(self, client, name, + weight=None, uri=None, + auto_create=True, **options): + self.client = client + + self.uri = uri + self.name = name + self.weight = weight + self.options = options + + if auto_create: + self.ensure_exists() + + def ensure_exists(self): + """Ensures pool exists + + This method is not race safe, + the pool could've been deleted + right after it was called. + """ + req, trans = self.client._request_and_transport() + + data = {'uri': self.uri, + 'weight': self.weight, + 'options': self.options} + + core.pool_create(trans, req, self.name, data) + + def delete(self): + req, trans = self.client._request_and_transport() + core.pool_delete(trans, req, self.name) diff --git a/zaqarclient/queues/v1/shard.py b/zaqarclient/queues/v1/shard.py index 25e2401f..9bfb02d7 100644 --- a/zaqarclient/queues/v1/shard.py +++ b/zaqarclient/queues/v1/shard.py @@ -13,39 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -from zaqarclient.queues.v1 import core +import warnings + +from zaqarclient.queues.v1 import pool -class Shard(object): +class Shard(pool.Pool): - def __init__(self, client, name, - weight=None, uri=None, - auto_create=True, **options): - self.client = client - - self.uri = uri - self.name = name - self.weight = weight - self.options = options - - if auto_create: - self.ensure_exists() - - def ensure_exists(self): - """Ensures shard exists - - This method is not race safe, - the shard could've been deleted - right after it was called. - """ - req, trans = self.client._request_and_transport() - - data = {'uri': self.uri, - 'weight': self.weight, - 'options': self.options} - - core.shard_create(trans, req, self.name, data) - - def delete(self): - req, trans = self.client._request_and_transport() - core.shard_delete(trans, req, self.name) + def __init__(self, *args, **kwargs): + warnings.warn(_('Shard\'s been renamed to `Pool` ' + 'please use `zaqarclient.queues.v1.pool.Pool` ' + ' instead'), DeprecationWarning, stacklevel=2) + super(Shard, self).__init__(*args, **kwargs) diff --git a/zaqarclient/tests/queues/shard.py b/zaqarclient/tests/queues/pool.py similarity index 60% rename from zaqarclient/tests/queues/shard.py rename to zaqarclient/tests/queues/pool.py index 32eb3e5a..4e51baf0 100644 --- a/zaqarclient/tests/queues/shard.py +++ b/zaqarclient/tests/queues/pool.py @@ -19,11 +19,11 @@ from zaqarclient.tests.queues import base from zaqarclient.transport import response -class QueuesV1ShardUnitTest(base.QueuesTestBase): +class QueuesV1PoolUnitTest(base.QueuesTestBase): - def test_shard_create(self): - shard_data = {'weight': 10, - 'uri': 'sqlite://'} + def test_pool_create(self): + pool_data = {'weight': 10, + 'uri': 'sqlite://'} with mock.patch.object(self.transport, 'send', autospec=True) as send_method: @@ -34,13 +34,13 @@ class QueuesV1ShardUnitTest(base.QueuesTestBase): # NOTE(flaper87): This will call # ensure exists in the client instance # since auto_create's default is True - shard = self.client.shard('test', **shard_data) - self.assertEqual(shard.name, 'test') - self.assertEqual(shard.weight, 10) + pool = self.client.pool('test', **pool_data) + self.assertEqual(pool.name, 'test') + self.assertEqual(pool.weight, 10) - def test_shard_delete(self): - shard_data = {'weight': 10, - 'uri': 'sqlite://'} + def test_pool_delete(self): + pool_data = {'weight': 10, + 'uri': 'sqlite://'} with mock.patch.object(self.transport, 'send', autospec=True) as send_method: @@ -51,27 +51,27 @@ class QueuesV1ShardUnitTest(base.QueuesTestBase): # NOTE(flaper87): This will call # ensure exists in the client instance # since auto_create's default is True - shard = self.client.shard('test', **shard_data) - shard.delete() + pool = self.client.pool('test', **pool_data) + pool.delete() # NOTE(flaper87): Nothing to assert here, # just checking our way down to the transport # doesn't crash. -class QueuesV1ShardFunctionalTest(base.QueuesTestBase): +class QueuesV1PoolFunctionalTest(base.QueuesTestBase): - def test_shard_create(self): - shard_data = {'weight': 10, - 'uri': 'sqlite://'} + def test_pool_create(self): + pool_data = {'weight': 10, + 'uri': 'sqlite://'} - shard = self.client.shard('test', **shard_data) - self.assertEqual(shard.name, 'test') - self.assertEqual(shard.weight, 10) + pool = self.client.pool('test', **pool_data) + self.assertEqual(pool.name, 'test') + self.assertEqual(pool.weight, 10) - def test_shard_delete(self): - shard_data = {'weight': 10, - 'uri': 'sqlite://'} + def test_pool_delete(self): + pool_data = {'weight': 10, + 'uri': 'sqlite://'} - shard = self.client.shard('test', **shard_data) - shard.delete() + pool = self.client.pool('test', **pool_data) + pool.delete()