Fix az parameter handling in Nova API-GW and External Network

1.What is the problem:
If availability zone (az in short) does not exit in the server creation
request or extenal network, 400 bad request was given in current handling,
this handling is inconsistent with Nova and Neutron.In Nova and Neutron,
az is one optional parameter, i.e, even the az is not speficied in the
request, a scheduled az should be used for the creation, but not
return 400 bad request.

2.What's need to be fixed:
To fix the issue, server creation should allow no az parameter in
the request, and select one default bottom pod to continue the server
creation.

3.What is the purpose of this patch set:
To make the az handling behavior is consistent with that in Nova and
Neutron.

Change-Id: I9281914bad482573c6540bf2a14e51e7ca4d744c
Signed-off-by: joehuang <joehuang@huawei.com>
This commit is contained in:
joehuang 2016-08-07 09:13:59 -04:00
parent 1e495007ea
commit 419e02e786
3 changed files with 41 additions and 15 deletions

View File

@ -173,13 +173,21 @@ class TricirclePlugin(db_base_plugin_v2.NeutronDbPluginV2,
attributes.NETWORKS, ['_extend_availability_zone'])
@staticmethod
def _ensure_az_set_for_external_network(req_data):
def _ensure_az_set_for_external_network(context, req_data):
external = req_data.get(external_net.EXTERNAL)
external_set = attributes.is_attr_set(external)
if not external_set or not external:
return False
if az_ext.AZ_HINTS in req_data and req_data[az_ext.AZ_HINTS]:
return True
t_ctx = t_context.get_context_from_neutron_context(context)
pod, pod_az = az_ag.get_pod_by_az_tenant(
t_ctx,
az_name='',
tenant_id=req_data['tenant_id'])
if pod:
req_data[az_ext.AZ_HINTS] = [pod['pod_name']]
return True
raise t_exceptions.ExternalNetPodNotSpecify()
def _create_bottom_external_network(self, context, net, top_id):
@ -234,7 +242,8 @@ class TricirclePlugin(db_base_plugin_v2.NeutronDbPluginV2,
def create_network(self, context, network):
net_data = network[attributes.NETWORK]
tenant_id = net_data['tenant_id']
is_external = self._ensure_az_set_for_external_network(net_data)
is_external = self._ensure_az_set_for_external_network(context,
net_data)
if az_ext.AZ_HINTS in net_data:
self._validate_availability_zones(context,
net_data[az_ext.AZ_HINTS],

View File

@ -127,12 +127,10 @@ class ServerController(rest.RestController):
return utils.format_nova_error(
400, _('server is not set'))
if 'availability_zone' not in kw['server']:
return utils.format_nova_error(
400, _('availability zone is not set'))
az = kw['server'].get('availability_zone', '')
pod, b_az = az_ag.get_pod_by_az_tenant(
context, kw['server']['availability_zone'], self.project_id)
context, az, self.project_id)
if not pod:
return utils.format_nova_error(
500, _('Pod not configured or scheduling failure'))

View File

@ -1596,6 +1596,34 @@ class PluginTest(unittest.TestCase,
t_ctx, 'remove_interface', b_router_id, {'port_id': b_port_id})
mock_rpc.assert_called_with(t_ctx, t_router_id)
@patch.object(context, 'get_context_from_neutron_context')
def test_create_external_network_no_az_pod(self, mock_context):
self._basic_pod_route_setup()
fake_plugin = FakePlugin()
q_ctx = FakeNeutronContext()
t_ctx = context.get_db_context()
mock_context.return_value = t_ctx
# create external network without specifying az pod name
body = {
'network': {
'name': 'ext-net',
'admin_state_up': True,
'shared': True,
'tenant_id': 'test_tenant_id',
'router:external': True,
}
}
top_net = fake_plugin.create_network(q_ctx, body)
for net in BOTTOM1_NETS:
if net.get('router:external'):
bottom_net = net
mappings = db_api.get_bottom_mappings_by_top_id(
t_ctx, top_net['id'], constants.RT_NETWORK)
self.assertEqual(mappings[0][1], bottom_net['id'])
@patch.object(context, 'get_context_from_neutron_context')
def test_create_external_network(self, mock_context):
self._basic_pod_route_setup()
@ -1605,15 +1633,6 @@ class PluginTest(unittest.TestCase,
t_ctx = context.get_db_context()
mock_context.return_value = t_ctx
# create external network without specifying pod name
body = {
'network': {
'router:external': True,
'tenant_id': 'test_tenant_id',
}
}
self.assertRaises(exceptions.ExternalNetPodNotSpecify,
fake_plugin.create_network, q_ctx, body)
# create external network specifying az name
body = {
'network': {