From f0f9a20dbeb848e2555fab9547dfe14b38711b3a Mon Sep 17 00:00:00 2001 From: XiongQiu Date: Wed, 1 Jun 2016 16:34:12 +0800 Subject: [PATCH] Fix az parameter handling which blocks the integration test 1.What is the problem: If availability zone (az in short) does not exit in the volume creation request, 400 bad request was given in current handling, this handling is incorrect and will block the following integration test cases: ostestr --regex tempest.api.volume.test_volumes_list ostestr --regex tempest.api.volume.test_volumes_get Refer to https://review.openstack.org/#/c/329300/ 2.What's need to be fixed: To fix the issue, volume creation should allow no az parameter in the request, and select one default bottom pod to continue the volume creation. 3.What is the purpose of this patch set: To make the integration test being the gate test of each patch set after The Tricircle integration test Jenkins job is configured in https://review.openstack.org/#/c/329740/ Change-Id: I8ee1cd5741605fbb105e2f24258459516aa7c5c0 --- tricircle/cinder_apigw/controllers/volume.py | 7 ++----- tricircle/common/az_ag.py | 19 ++++++++++++++++--- .../cinder_apigw/controllers/test_volume.py | 4 ++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tricircle/cinder_apigw/controllers/volume.py b/tricircle/cinder_apigw/controllers/volume.py index b94dc34f..d8d15912 100644 --- a/tricircle/cinder_apigw/controllers/volume.py +++ b/tricircle/cinder_apigw/controllers/volume.py @@ -52,13 +52,10 @@ class VolumeController(rest.RestController): pecan.abort(400, _('Volume not found in request body')) return - if 'availability_zone' not in kw['volume']: - pecan.abort(400, _('Availability zone not set in request')) - return - + az = kw['volume'].get('availability_zone', '') pod, pod_az = az_ag.get_pod_by_az_tenant( context, - az_name=kw['volume']['availability_zone'], + az_name=az, tenant_id=self.tenant_id) if not pod: pecan.abort(500, _('Pod not configured or scheduling failure')) diff --git a/tricircle/common/az_ag.py b/tricircle/common/az_ag.py index a738eb71..8cabd23a 100644 --- a/tricircle/common/az_ag.py +++ b/tricircle/common/az_ag.py @@ -120,14 +120,27 @@ def get_pod_by_az_tenant(context, az_name, tenant_id): pod = core.get_resource(context, models.Pod, 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'] + 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 - 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) for pod in pods: - if pod['pod_name'] != '': + if pod['pod_name'] != '' and pod['az_name'] != '': try: with context.session.begin(): core.create_resource( diff --git a/tricircle/tests/functional/cinder_apigw/controllers/test_volume.py b/tricircle/tests/functional/cinder_apigw/controllers/test_volume.py index 30ede022..7d9e687a 100644 --- a/tricircle/tests/functional/cinder_apigw/controllers/test_volume.py +++ b/tricircle/tests/functional/cinder_apigw/controllers/test_volume.py @@ -255,7 +255,7 @@ class TestVolumeController(CinderVolumeFunctionalTest): "project_id": 'my_tenant_id', "metadata": {} }, - "expected_error": 400 + "expected_error": 202 }, # incorrect AZ parameter @@ -575,7 +575,7 @@ class TestVolumeController(CinderVolumeFunctionalTest): elif test_vol.get('volume_xxx'): response = self.app.post_json( '/v2/' + tenant_id + '/volumes', - dict(volume=test_vol['volume_xxx']), + dict(volume_xxx=test_vol['volume_xxx']), expect_errors=True) else: return