]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix error while creating l2 gateway services in nvp
authorarmando-migliaccio <amigliaccio@nicira.com>
Thu, 24 Oct 2013 15:17:17 +0000 (08:17 -0700)
committerarmando-migliaccio <amigliaccio@nicira.com>
Fri, 25 Oct 2013 23:35:08 +0000 (16:35 -0700)
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
neutron/plugins/nicira/common/exceptions.py
neutron/tests/unit/nicira/test_nicira_plugin.py

index f9d84d2fd176435cea3d0d3a804abe990e3feb73..d1a60de8e5b6776c9568aadb6c5af0ccad2bc6c0 100644 (file)
@@ -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)
index e26a49acabaaab757883a9cdf46042eeba9277f7..bc7c4f5c0b41700ff2c5f72fbee7fcf933f3029a 100644 (file)
@@ -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")
 
index dbbbf8f1d12eeaad189e052d8cbc48c1771b6d93..da2cf87859774bf4fcfdea0e42b6e5f4752ce92c 100644 (file)
@@ -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: