From 98aa3db7af835058598d18db17d116334c267e26 Mon Sep 17 00:00:00 2001 From: MD NADEEM Date: Wed, 13 Jan 2016 15:35:25 +0530 Subject: [PATCH] Update flavor on flavor create if it exists As of now on PUT, zaqar server updates flavor 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. Closes-Bug: #1532776 Change-Id: Ica8532375ed81828d09c3bdbab0fa911c155bf1a --- zaqarclient/queues/v1/flavor.py | 22 ++++++++++------------ zaqarclient/tests/queues/flavor.py | 19 +++++++++---------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/zaqarclient/queues/v1/flavor.py b/zaqarclient/queues/v1/flavor.py index 3671a000..ae59cd3f 100644 --- a/zaqarclient/queues/v1/flavor.py +++ b/zaqarclient/queues/v1/flavor.py @@ -14,7 +14,6 @@ # limitations under the License. from zaqarclient.queues.v1 import core -from zaqarclient.transport import errors class Flavor(object): @@ -39,19 +38,18 @@ class Flavor(object): right after it was called. """ req, trans = self.client._request_and_transport() + # As of now on PUT, zaqar server updates flavor 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: - flavor = core.flavor_get(trans, req, self.name) - self.pool = flavor["pool"] - self.capabilities = flavor.get("capabilities", {}) + data = {'pool': self.pool} + if self.client.api_version <= 1.1: + data['capabilities'] = self.capabilities - except errors.ResourceNotFound: - data = {'pool': self.pool} - if self.client.api_version <= 1.1: - data['capabilities'] = self.capabilities - - req, trans = self.client._request_and_transport() - core.flavor_create(trans, req, self.name, data) + req, trans = self.client._request_and_transport() + core.flavor_create(trans, req, self.name, data) def update(self, flavor_data): req, trans = self.client._request_and_transport() diff --git a/zaqarclient/tests/queues/flavor.py b/zaqarclient/tests/queues/flavor.py index 28d3eb20..7f7bc53a 100644 --- a/zaqarclient/tests/queues/flavor.py +++ b/zaqarclient/tests/queues/flavor.py @@ -18,7 +18,6 @@ import mock from zaqarclient.queues.v1 import iterator from zaqarclient.tests.queues import base -from zaqarclient.transport import errors from zaqarclient.transport import response @@ -31,7 +30,7 @@ class QueuesV1_1FlavorUnitTest(base.QueuesTestBase): autospec=True) as send_method: resp = response.Response(None, None) - send_method.side_effect = iter([errors.ResourceNotFound, resp]) + send_method.return_value = resp # NOTE(flaper87): This will call # ensure exists in the client instance @@ -41,7 +40,7 @@ class QueuesV1_1FlavorUnitTest(base.QueuesTestBase): self.assertEqual('stomach', flavor.pool) def test_flavor_get(self): - flavor_data = {'pool': 'stomach'} + flavor_data = {'name': 'test', 'pool': 'stomach'} with mock.patch.object(self.transport, 'send', autospec=True) as send_method: @@ -53,8 +52,9 @@ class QueuesV1_1FlavorUnitTest(base.QueuesTestBase): # ensure exists in the client instance # since auto_create's default is True flavor = self.client.flavor('test') - self.assertEqual('test', flavor.name) - self.assertEqual('stomach', flavor.pool) + flavor1 = flavor.get() + self.assertEqual('test', flavor1['name']) + self.assertEqual('stomach', flavor1['pool']) def test_flavor_update(self): flavor_data = {'pool': 'stomach'} @@ -131,18 +131,17 @@ class QueuesV1_1FlavorFunctionalTest(base.QueuesTestBase): pool_data = {'weight': 10, 'group': 'us', 'uri': 'mongodb://127.0.0.1:27017'} - self.client.pool('stomach', **pool_data) pool = self.client.pool('stomach', **pool_data) self.addCleanup(pool.delete) flavor_data = {'pool': 'us'} - self.client.flavor('tasty', **flavor_data) - flavor = self.client.flavor('tasty') + flavor = self.client.flavor('tasty', **flavor_data) + resp_data = flavor.get() self.addCleanup(flavor.delete) - self.assertEqual('tasty', flavor.name) - self.assertEqual('us', flavor.pool) + self.assertEqual('tasty', resp_data['name']) + self.assertEqual('us', resp_data['pool']) def test_flavor_update(self): pool_data = {'weight': 10,