Update pool on pool create if it exists
As of now on PUT, zaqar server updates pool if it is already exists else it will create a new one. However zaqar client return previous pool info if it is already exists. This result to a confusion for operator. The zaqar client should maitain symmetry with zaqar server. Change-Id: I0e7311321630c3f931cf27b0828394589eaf7320 Partial-Bug: #1532776
This commit is contained in:
parent
6cff72fd23
commit
f985063ff1
@ -14,7 +14,6 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from zaqarclient.queues.v1 import core
|
from zaqarclient.queues.v1 import core
|
||||||
from zaqarclient.transport import errors
|
|
||||||
|
|
||||||
|
|
||||||
class Pool(object):
|
class Pool(object):
|
||||||
@ -41,24 +40,21 @@ class Pool(object):
|
|||||||
right after it was called.
|
right after it was called.
|
||||||
"""
|
"""
|
||||||
req, trans = self.client._request_and_transport()
|
req, trans = self.client._request_and_transport()
|
||||||
|
# As of now on PUT, zaqar server updates pool if it is already
|
||||||
|
# exists else it will create a new one. The zaqar client should
|
||||||
|
# maitain symmetry with zaqar server.
|
||||||
|
# TBD(mdnadeem): Have to change this code when zaqar server
|
||||||
|
# behaviour change for PUT operation.
|
||||||
|
|
||||||
try:
|
data = {'uri': self.uri,
|
||||||
pool = core.pool_get(trans, req, self.name)
|
'weight': self.weight,
|
||||||
self.uri = pool["uri"]
|
'options': self.options}
|
||||||
self.weight = pool["weight"]
|
|
||||||
self.group = pool.get("group", None)
|
|
||||||
self.options = pool.get("options", {})
|
|
||||||
|
|
||||||
except errors.ResourceNotFound:
|
if self.client.api_version >= 1.1 and self.group:
|
||||||
data = {'uri': self.uri,
|
data['group'] = self.group
|
||||||
'weight': self.weight,
|
|
||||||
'options': self.options}
|
|
||||||
|
|
||||||
if self.client.api_version >= 1.1 and self.group:
|
req, trans = self.client._request_and_transport()
|
||||||
data['group'] = self.group
|
core.pool_create(trans, req, self.name, data)
|
||||||
|
|
||||||
req, trans = self.client._request_and_transport()
|
|
||||||
core.pool_create(trans, req, self.name, data)
|
|
||||||
|
|
||||||
def update(self, pool_data):
|
def update(self, pool_data):
|
||||||
req, trans = self.client._request_and_transport()
|
req, trans = self.client._request_and_transport()
|
||||||
|
@ -18,7 +18,6 @@ import mock
|
|||||||
|
|
||||||
from zaqarclient.queues.v1 import iterator
|
from zaqarclient.queues.v1 import iterator
|
||||||
from zaqarclient.tests.queues import base
|
from zaqarclient.tests.queues import base
|
||||||
from zaqarclient.transport import errors
|
|
||||||
from zaqarclient.transport import response
|
from zaqarclient.transport import response
|
||||||
|
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ class QueuesV1PoolUnitTest(base.QueuesTestBase):
|
|||||||
autospec=True) as send_method:
|
autospec=True) as send_method:
|
||||||
|
|
||||||
resp = response.Response(None, None)
|
resp = response.Response(None, None)
|
||||||
send_method.side_effect = iter([errors.ResourceNotFound, resp])
|
send_method.return_value = resp
|
||||||
|
|
||||||
# NOTE(flaper87): This will call
|
# NOTE(flaper87): This will call
|
||||||
# ensure exists in the client instance
|
# ensure exists in the client instance
|
||||||
@ -43,6 +42,7 @@ class QueuesV1PoolUnitTest(base.QueuesTestBase):
|
|||||||
|
|
||||||
def test_pool_get(self):
|
def test_pool_get(self):
|
||||||
pool_data = {'weight': 10,
|
pool_data = {'weight': 10,
|
||||||
|
'name': 'test',
|
||||||
'uri': 'sqlite://',
|
'uri': 'sqlite://',
|
||||||
'options': {}}
|
'options': {}}
|
||||||
|
|
||||||
@ -55,9 +55,11 @@ class QueuesV1PoolUnitTest(base.QueuesTestBase):
|
|||||||
# NOTE(flaper87): This will call
|
# NOTE(flaper87): This will call
|
||||||
# ensure exists in the client instance
|
# ensure exists in the client instance
|
||||||
# since auto_create's default is True
|
# since auto_create's default is True
|
||||||
|
|
||||||
pool = self.client.pool('test')
|
pool = self.client.pool('test')
|
||||||
self.assertEqual('test', pool.name)
|
pool1 = pool.get()
|
||||||
self.assertEqual(10, pool.weight)
|
self.assertEqual('test', pool1['name'])
|
||||||
|
self.assertEqual(10, pool1['weight'])
|
||||||
|
|
||||||
def test_pool_update(self):
|
def test_pool_update(self):
|
||||||
pool_data = {'weight': 10,
|
pool_data = {'weight': 10,
|
||||||
@ -130,21 +132,22 @@ class QueuesV1_1PoolFunctionalTest(base.QueuesTestBase):
|
|||||||
'group': 'us',
|
'group': 'us',
|
||||||
'uri': 'mongodb://127.0.0.1:27017'}
|
'uri': 'mongodb://127.0.0.1:27017'}
|
||||||
|
|
||||||
self.client.pool('test', **pool_data)
|
pool = self.client.pool('FuncTestPool', **pool_data)
|
||||||
pool = self.client.pool('test')
|
resp_data = pool.get()
|
||||||
|
self.addCleanup(pool.delete)
|
||||||
|
|
||||||
self.assertEqual('test', pool.name)
|
self.assertEqual('FuncTestPool', resp_data['name'])
|
||||||
self.assertEqual(10, pool.weight)
|
self.assertEqual(10, resp_data['weight'])
|
||||||
self.assertEqual('mongodb://127.0.0.1:27017', pool.uri)
|
self.assertEqual('mongodb://127.0.0.1:27017', resp_data['uri'])
|
||||||
|
|
||||||
def test_pool_create(self):
|
def test_pool_create(self):
|
||||||
pool_data = {'weight': 10,
|
pool_data = {'weight': 10,
|
||||||
'group': 'us',
|
'group': 'us',
|
||||||
'uri': 'mongodb://127.0.0.1:27017'}
|
'uri': 'mongodb://127.0.0.1:27017'}
|
||||||
|
|
||||||
pool = self.client.pool('test', **pool_data)
|
pool = self.client.pool('FuncTestPool', **pool_data)
|
||||||
self.addCleanup(pool.delete)
|
self.addCleanup(pool.delete)
|
||||||
self.assertEqual('test', pool.name)
|
self.assertEqual('FuncTestPool', pool.name)
|
||||||
self.assertEqual(10, pool.weight)
|
self.assertEqual(10, pool.weight)
|
||||||
|
|
||||||
def test_pool_update(self):
|
def test_pool_update(self):
|
||||||
@ -152,7 +155,7 @@ class QueuesV1_1PoolFunctionalTest(base.QueuesTestBase):
|
|||||||
'group': 'us',
|
'group': 'us',
|
||||||
'uri': 'mongodb://127.0.0.1:27017'}
|
'uri': 'mongodb://127.0.0.1:27017'}
|
||||||
|
|
||||||
pool = self.client.pool('test', **pool_data)
|
pool = self.client.pool('FuncTestPool', **pool_data)
|
||||||
self.addCleanup(pool.delete)
|
self.addCleanup(pool.delete)
|
||||||
pool.update({'weight': 20})
|
pool.update({'weight': 20})
|
||||||
self.assertEqual(20, pool.weight)
|
self.assertEqual(20, pool.weight)
|
||||||
@ -161,7 +164,7 @@ class QueuesV1_1PoolFunctionalTest(base.QueuesTestBase):
|
|||||||
pool_data = {'weight': 10,
|
pool_data = {'weight': 10,
|
||||||
'group': 'us',
|
'group': 'us',
|
||||||
'uri': 'mongodb://127.0.0.1:27017'}
|
'uri': 'mongodb://127.0.0.1:27017'}
|
||||||
pool = self.client.pool('test', **pool_data)
|
pool = self.client.pool('FuncTestPool', **pool_data)
|
||||||
self.addCleanup(pool.delete)
|
self.addCleanup(pool.delete)
|
||||||
|
|
||||||
pools = self.client.pools()
|
pools = self.client.pools()
|
||||||
@ -173,7 +176,7 @@ class QueuesV1_1PoolFunctionalTest(base.QueuesTestBase):
|
|||||||
'group': 'us',
|
'group': 'us',
|
||||||
'uri': 'mongodb://127.0.0.1:27017'}
|
'uri': 'mongodb://127.0.0.1:27017'}
|
||||||
|
|
||||||
pool = self.client.pool('test', **pool_data)
|
pool = self.client.pool('FuncTestPool', **pool_data)
|
||||||
pool.delete()
|
pool.delete()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user