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