Merge "Fix az parameter handling which blocks the integration test"

This commit is contained in:
Jenkins 2016-06-19 04:05:00 +00:00 committed by Gerrit Code Review
commit 1f4d505b84
3 changed files with 20 additions and 10 deletions

View File

@ -52,13 +52,10 @@ class VolumeController(rest.RestController):
pecan.abort(400, _('Volume not found in request body')) pecan.abort(400, _('Volume not found in request body'))
return return
if 'availability_zone' not in kw['volume']: az = kw['volume'].get('availability_zone', '')
pecan.abort(400, _('Availability zone not set in request'))
return
pod, pod_az = az_ag.get_pod_by_az_tenant( pod, pod_az = az_ag.get_pod_by_az_tenant(
context, context,
az_name=kw['volume']['availability_zone'], az_name=az,
tenant_id=self.tenant_id) tenant_id=self.tenant_id)
if not pod: if not pod:
pecan.abort(500, _('Pod not configured or scheduling failure')) pecan.abort(500, _('Pod not configured or scheduling failure'))

View File

@ -120,14 +120,27 @@ def get_pod_by_az_tenant(context, az_name, tenant_id):
pod = core.get_resource(context, pod = core.get_resource(context,
models.Pod, models.Pod,
pod_b['pod_id']) pod_b['pod_id'])
if pod['az_name'] == az_name: if az_name and pod['az_name'] == az_name:
return pod, pod['pod_az_name'] return pod, pod['pod_az_name']
elif az_name == '' and pod['az_name'] != '':
# if the az_name is not specified, a defult bottom
# pod will be selected
return pod, pod['pod_az_name']
else:
pass
# TODO(joehuang): schedule one dynamically in the future # TODO(joehuang): schedule one dynamically in the future
filters = [{'key': 'az_name', 'comparator': 'eq', 'value': az_name}] if az_name != '':
filters = [{'key': 'az_name', 'comparator': 'eq', 'value': az_name}]
else:
filters = None
# if az_name is valid, select a pod under this az_name
# if az_name is '', select the first valid bottom pod.
# change to dynamic schedluing in the future
pods = db_api.list_pods(context, filters=filters) pods = db_api.list_pods(context, filters=filters)
for pod in pods: for pod in pods:
if pod['pod_name'] != '': if pod['pod_name'] != '' and pod['az_name'] != '':
try: try:
with context.session.begin(): with context.session.begin():
core.create_resource( core.create_resource(

View File

@ -255,7 +255,7 @@ class TestVolumeController(CinderVolumeFunctionalTest):
"project_id": 'my_tenant_id', "project_id": 'my_tenant_id',
"metadata": {} "metadata": {}
}, },
"expected_error": 400 "expected_error": 202
}, },
# incorrect AZ parameter # incorrect AZ parameter
@ -575,7 +575,7 @@ class TestVolumeController(CinderVolumeFunctionalTest):
elif test_vol.get('volume_xxx'): elif test_vol.get('volume_xxx'):
response = self.app.post_json( response = self.app.post_json(
'/v2/' + tenant_id + '/volumes', '/v2/' + tenant_id + '/volumes',
dict(volume=test_vol['volume_xxx']), dict(volume_xxx=test_vol['volume_xxx']),
expect_errors=True) expect_errors=True)
else: else:
return return