NVP: propagate net-gw update to backend

When a network gateway's name is updated, propagate the
update to the backend.

Closes-Bug: #1261334
Change-Id: Icaae84e7f5373946e8c82e0e519528409925dd9d
This commit is contained in:
Salvatore Orlando 2013-12-13 14:49:00 -08:00
parent 22886eb49f
commit a3bd88c21c
2 changed files with 45 additions and 0 deletions

View 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)

View 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