]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
NVP: propagate net-gw update to backend
authorSalvatore Orlando <salv.orlando@gmail.com>
Fri, 13 Dec 2013 22:49:00 +0000 (14:49 -0800)
committerSalvatore Orlando <salv.orlando@gmail.com>
Mon, 16 Dec 2013 14:16:12 +0000 (06:16 -0800)
When a network gateway's name is updated, propagate the
update to the backend.

Closes-Bug: #1261334
Change-Id: Icaae84e7f5373946e8c82e0e519528409925dd9d

neutron/plugins/nicira/NeutronPlugin.py
neutron/tests/unit/nicira/test_nicira_plugin.py

index 0eb4147d98e062285903902dbc0ef8995c820b1d..e75e27715117a8b54015799a685079ee69582236 100644 (file)
@@ -2005,6 +2005,16 @@ class NvpPluginV2(addr_pair_db.AllowedAddressPairsMixin,
     def update_network_gateway(self, context, id, network_gateway):
         # Ensure the default gateway in the config file is in sync with the db
         self._ensure_default_network_gateway()
+        # Update gateway on backend when there's a name change
+        name = network_gateway[networkgw.RESOURCE_NAME].get('name')
+        if name:
+            try:
+                nvplib.update_l2_gw_service(self.cluster, id, name)
+            except NvpApiClient.NvpApiException:
+                # Consider backend failures as non-fatal, but still warn
+                # because this might indicate something dodgy is going on
+                LOG.warn(_("Unable to update name on NVP backend "
+                           "for network gateway: %s"), id)
         return super(NvpPluginV2, self).update_network_gateway(
             context, id, network_gateway)
 
index a239235becbec644f0b8af1f2552abd15ddc5329..3ade5d18404dd0536ba39d3c923904891fe7c21b 100644 (file)
@@ -1377,6 +1377,41 @@ class TestNiciraNetworkGateway(test_l2_gw.NetworkGatewayDbTestCase,
             # Assert Neutron name is not truncated
             self.assertEqual(nw_gw[self.resource]['name'], name)
 
+    def test_update_network_gateway_with_name_calls_backend(self):
+        with mock.patch.object(
+            nvplib, 'update_l2_gw_service') as mock_update_gw:
+            with self._network_gateway(name='cavani') as nw_gw:
+                nw_gw_id = nw_gw[self.resource]['id']
+                self._update(nvp_networkgw.COLLECTION_NAME, nw_gw_id,
+                             {self.resource: {'name': 'higuain'}})
+                mock_update_gw.assert_called_once_with(
+                    mock.ANY, nw_gw_id, 'higuain')
+
+    def test_update_network_gateway_without_name_does_not_call_backend(self):
+        with mock.patch.object(
+            nvplib, 'update_l2_gw_service') as mock_update_gw:
+            with self._network_gateway(name='something') as nw_gw:
+                nw_gw_id = nw_gw[self.resource]['id']
+                self._update(nvp_networkgw.COLLECTION_NAME, nw_gw_id,
+                             {self.resource: {}})
+                self.assertEqual(mock_update_gw.call_count, 0)
+
+    def test_update_network_gateway_name_exceeds_40_chars(self):
+        new_name = 'this_is_a_gateway_whose_name_is_longer_than_40_chars'
+        with self._network_gateway(name='something') as nw_gw:
+            nw_gw_id = nw_gw[self.resource]['id']
+            self._update(nvp_networkgw.COLLECTION_NAME, nw_gw_id,
+                         {self.resource: {'name': new_name}})
+            req = self.new_show_request(nvp_networkgw.COLLECTION_NAME,
+                                        nw_gw_id)
+            res = self.deserialize('json', req.get_response(self.ext_api))
+            # Assert Neutron name is not truncated
+            self.assertEqual(new_name, res[self.resource]['name'])
+            # Assert NVP name is truncated
+            self.assertEqual(
+                new_name[:40],
+                self.fc._fake_gatewayservice_dict[nw_gw_id]['display_name'])
+
     def test_create_network_gateway_nvp_error_returns_500(self):
         def raise_nvp_api_exc(*args, **kwargs):
             raise NvpApiClient.NvpApiException