From 5b7c69fab973f502aecf00b28e4fa114dbb64d13 Mon Sep 17 00:00:00 2001 From: Fei Long Wang Date: Wed, 5 Apr 2017 19:56:33 +1200 Subject: [PATCH] Automatically get pools capabilities for flavor For Zaqar API v2, admin user can't set the capabilities for flavor manually. So the field was always empty. This patch fixes the issue. Closes-Bug: #1679891 Change-Id: I2c9068c849cbfc7b5d2651627a5db7f9025d1473 --- zaqar/tests/unit/transport/wsgi/v2_0/test_flavors.py | 7 +++---- zaqar/transport/wsgi/v2_0/flavors.py | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) 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 d1b57c840..180ba78ab 100644 --- a/zaqar/tests/unit/transport/wsgi/v2_0/test_flavors.py +++ b/zaqar/tests/unit/transport/wsgi/v2_0/test_flavors.py @@ -132,12 +132,11 @@ class TestFlavorsMongoDB(base.V2Base): body=jsonutils.dumps({'pool_group': pool_group})) self.assertEqual(falcon.HTTP_400, self.srmock.status) - @ddt.data(-1, 'wee', []) - def test_put_raises_if_invalid_capabilities(self, capabilities): + def test_put_auto_get_capabilities(self): path = self.url_prefix + '/flavors/' + str(uuid.uuid1()) - doc = {'pool_group': 'a', 'capabilities': capabilities} + doc = {'pool_group': self.pool_group} self.simulate_put(path, body=jsonutils.dumps(doc)) - self.assertEqual(falcon.HTTP_400, self.srmock.status) + self.assertEqual(falcon.HTTP_201, self.srmock.status) def test_put_existing_overwrites(self): # NOTE(cabrera): setUp creates default flavor diff --git a/zaqar/transport/wsgi/v2_0/flavors.py b/zaqar/transport/wsgi/v2_0/flavors.py index ffbb3b377..cfb719789 100644 --- a/zaqar/transport/wsgi/v2_0/flavors.py +++ b/zaqar/transport/wsgi/v2_0/flavors.py @@ -182,10 +182,12 @@ class Resource(object): data = wsgi_utils.load(request) wsgi_utils.validate(self._validators['create'], data) pool_group = data.get('pool_group') or data.get('pool') + capabilities = self._pools_ctrl.capabilities(pool_group) try: self._ctrl.create(flavor, pool_group=pool_group, - project=project_id) + project=project_id, + capabilities=capabilities) response.status = falcon.HTTP_201 response.location = request.path except errors.PoolGroupDoesNotExist as ex: