diff --git a/neutron/plugins/nicira/NeutronPlugin.py b/neutron/plugins/nicira/NeutronPlugin.py index e3c3f79b10..473819a66f 100644 --- a/neutron/plugins/nicira/NeutronPlugin.py +++ b/neutron/plugins/nicira/NeutronPlugin.py @@ -1914,11 +1914,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 e26a49acab..bc7c4f5c0b 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 4272d45016..b278f8ac2d 100644 --- a/neutron/tests/unit/nicira/test_nicira_plugin.py +++ b/neutron/tests/unit/nicira/test_nicira_plugin.py @@ -1389,6 +1389,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: