Return 400 status code if l3_ext network type is misused

The l3_ext network type can be used exclusively for external
networks. If used on a standard tenant network the system
currently returns a 500 error because this results in a backend
failure.

This patch improves the validation routine for provider attributes
so that the request is not processed at all if l3_ext is not used
with an external network, and a 400 error code is returned to the
user.

Change-Id: I0e63ae71309f6a1be573e7f9f49775571733dfa0
Closes-Bug: #1468824
This commit is contained in:
Salvatore Orlando 2015-06-25 09:45:14 -07:00
parent b1d15d00cc
commit 1f973b98e9
2 changed files with 21 additions and 0 deletions

View File

@ -802,6 +802,10 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
{'segmentation_id': segmentation_id,
'min_id': plugin_const.MIN_VLAN_TAG,
'max_id': plugin_const.MAX_VLAN_TAG})
# Network must be external
if not network.get(ext_net_extn.EXTERNAL):
err_msg = (_("The l3_ext provide network type can be "
"used with external networks only"))
else:
err_msg = (_("%(net_type_param)s %(net_type_value)s not "
"supported") %

View File

@ -268,6 +268,23 @@ class TestNetworksV2(test_plugin.TestNetworksV2, NsxPluginV2TestCase):
self._test_create_bridge_network(vlan_id=5000)
self.assertEqual(ctx_manager.exception.code, 400)
def test_create_l3_ext_network_fails_if_not_external(self):
net_type = 'l3_ext'
name = 'l3_ext_net'
providernet_args = {pnet.NETWORK_TYPE: net_type,
pnet.PHYSICAL_NETWORK: 'l3gwuuid',
pnet.SEGMENTATION_ID: 123}
with testlib_api.ExpectedException(
webob.exc.HTTPClientError) as ctx_manager:
with self.network(name=name,
providernet_args=providernet_args,
arg_list=(pnet.NETWORK_TYPE,
pnet.PHYSICAL_NETWORK,
pnet.SEGMENTATION_ID)):
pass
self.assertEqual(ctx_manager.exception.code,
webob.exc.HTTPBadRequest.code)
def test_list_networks_filter_by_id(self):
# We add this unit test to cover some logic specific to the
# nsx plugin