Return 400 if creating a distributed router on old NVP platforms

Without checking for the right NVP support, creating a distributed
router will silently fail, i.e. ithe 'distributed' attribute will
be ignored and a centralized router will be created instead.

Supports blueprint nvp-distributed-router

Change-Id: If8e40c0907d78c30f9ba918aaaff57e58ebb8055
This commit is contained in:
armando-migliaccio 2013-08-13 14:13:14 -07:00
parent b1288b8dcb
commit e372ad4393
3 changed files with 25 additions and 8 deletions

View File

@ -1639,6 +1639,12 @@ class NvpPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
# This will be useful for setting the value if the API request
# did not specify any value for the 'distributed' attribute
r['distributed'] = lrouter['distributed']
except nvp_exc.NvpInvalidVersion:
msg = _("Cannot create a distributed router with the NVP "
"platform currently in execution. Please, try "
"without specifying the 'distributed' attribute.")
LOG.exception(msg)
raise q_exc.BadRequest(resource='router', msg=msg)
except NvpApiClient.NvpApiException:
raise nvp_exc.NvpPluginException(
err_msg=_("Unable to create logical router on NVP Platform"))

View File

@ -360,7 +360,11 @@ def create_explicit_routing_lrouter(cluster, tenant_id,
@version_dependent
def create_lrouter(cluster, *args, **kwargs):
pass
if kwargs.get('distributed', None):
v = cluster.api_client.get_nvp_version()
if (v.major < 3) or (v.major >= 3 and v.minor < 1):
raise nvp_exc.NvpInvalidVersion(version=v)
return v
def delete_lrouter(cluster, lrouter_id):

View File

@ -480,9 +480,10 @@ class TestNiciraL3NatTestCase(test_l3_plugin.L3NatDBTestCase,
def test_router_create_with_gwinfo_and_l3_ext_net_with_vlan(self):
self._test_router_create_with_gwinfo_and_l3_ext_net(444)
def _test_router_create_with_distributed(self, dist_input, dist_expected):
def _test_router_create_with_distributed(self, dist_input, dist_expected,
version='3.1', return_code=201):
self.mock_instance.return_value.get_nvp_version.return_value = (
NvpApiClient.NVPVersion('3.1'))
NvpApiClient.NVPVersion(version))
data = {'tenant_id': 'whatever'}
data['name'] = 'router1'
@ -491,12 +492,15 @@ class TestNiciraL3NatTestCase(test_l3_plugin.L3NatDBTestCase,
'routers', {'router': data}, self.fmt)
try:
res = router_req.get_response(self.ext_api)
router = self.deserialize(self.fmt, res)
self.assertIn('distributed', router['router'])
self.assertEqual(dist_expected,
router['router']['distributed'])
self.assertEqual(return_code, res.status_int)
if res.status_int == 201:
router = self.deserialize(self.fmt, res)
self.assertIn('distributed', router['router'])
self.assertEqual(dist_expected,
router['router']['distributed'])
finally:
self._delete('routers', router['router']['id'])
if res.status_int == 201:
self._delete('routers', router['router']['id'])
def test_router_create_distributed(self):
self._test_router_create_with_distributed(True, True)
@ -507,6 +511,9 @@ class TestNiciraL3NatTestCase(test_l3_plugin.L3NatDBTestCase,
def test_router_create_distributed_unspecified(self):
self._test_router_create_with_distributed(None, False)
def test_router_create_distributed_returns_400(self):
self._test_router_create_with_distributed(True, None, '3.0', 400)
def test_router_create_nvp_error_returns_500(self, vlan_id=None):
with mock.patch.object(nvplib,
'create_router_lport',