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
This commit is contained in:
Fei Long Wang 2017-04-05 19:56:33 +12:00
parent 14d730a0f4
commit 5b7c69fab9
2 changed files with 6 additions and 5 deletions

View File

@ -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

View File

@ -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: