From 94950eeb22c95da6b2115ea99f6131700decaa09 Mon Sep 17 00:00:00 2001 From: armando-migliaccio Date: Thu, 24 Oct 2013 08:17:17 -0700 Subject: [PATCH] Fix error while creating l2 gateway services in nvp Ensure that Conflict errors are not masked; also ensure that coding errors do not mask NVP API errors. Fixes bug #1244259 Change-Id: I27586d72af89fd39f6443dbab33f0e4e762b0c99 --- neutron/plugins/nicira/NeutronPlugin.py | 11 ++++++----- neutron/plugins/nicira/common/exceptions.py | 4 ++++ neutron/tests/unit/nicira/test_nicira_plugin.py | 9 +++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/neutron/plugins/nicira/NeutronPlugin.py b/neutron/plugins/nicira/NeutronPlugin.py index f9d84d2fd..d1a60de8e 100644 --- a/neutron/plugins/nicira/NeutronPlugin.py +++ b/neutron/plugins/nicira/NeutronPlugin.py @@ -1913,11 +1913,12 @@ class NvpPluginV2(addr_pair_db.AllowedAddressPairsMixin, nvp_res = nvplib.create_l2_gw_service(self.cluster, tenant_id, gw_data['name'], devices) nvp_uuid = nvp_res.get('uuid') - except Exception: - raise nvp_exc.NvpPluginException( - err_msg=_("Create_l2_gw_service did not " - "return an uuid for the newly " - "created resource:%s") % nvp_res) + except NvpApiClient.Conflict: + raise nvp_exc.NvpL2GatewayAlreadyInUse(gateway=gw_data['name']) + except NvpApiClient.NvpApiException: + err_msg = _("Unable to create l2_gw_service for: %s") % gw_data + LOG.exception(err_msg) + raise nvp_exc.NvpPluginException(err_msg=err_msg) gw_data['id'] = nvp_uuid return super(NvpPluginV2, self).create_network_gateway(context, network_gateway) diff --git a/neutron/plugins/nicira/common/exceptions.py b/neutron/plugins/nicira/common/exceptions.py index e26a49aca..bc7c4f5c0 100644 --- a/neutron/plugins/nicira/common/exceptions.py +++ b/neutron/plugins/nicira/common/exceptions.py @@ -70,6 +70,10 @@ class NvpServicePluginException(q_exc.NeutronException): "in the NVP Service Plugin: %(err_msg)s") +class NvpL2GatewayAlreadyInUse(q_exc.Conflict): + message = _("Gateway Service %(gateway)s is already in use") + + class NvpServiceOverQuota(q_exc.Conflict): message = _("Quota exceeded for Vcns resource: %(overs)s: %(err_msg)s") diff --git a/neutron/tests/unit/nicira/test_nicira_plugin.py b/neutron/tests/unit/nicira/test_nicira_plugin.py index dbbbf8f1d..da2cf8785 100644 --- a/neutron/tests/unit/nicira/test_nicira_plugin.py +++ b/neutron/tests/unit/nicira/test_nicira_plugin.py @@ -1383,6 +1383,15 @@ class TestNiciraNetworkGateway(test_l2_gw.NetworkGatewayDbTestCase, devices=[{'id': uuidutils.generate_uuid()}]) self.assertEqual(500, res.status_int) + def test_create_network_gateway_nvp_error_returns_409(self): + with mock.patch.object(nvplib, + 'create_l2_gw_service', + side_effect=NvpApiClient.Conflict): + res = self._create_network_gateway( + self.fmt, 'xxx', name='yyy', + devices=[{'id': uuidutils.generate_uuid()}]) + self.assertEqual(409, res.status_int) + def test_list_network_gateways(self): with self._network_gateway(name='test-gw-1') as gw1: with self._network_gateway(name='test_gw_2') as gw2: -- 2.45.2