DVS Plugin: Add Support for updating a network

Change-Id: I89d9fae3711a71c8840cd7a8be6894b61b4eec05
This commit is contained in:
Adit Sarfaty 2016-07-27 15:19:27 +03:00
parent b1ec19bd67
commit b82da5e9cb
2 changed files with 58 additions and 3 deletions

View File

@ -43,7 +43,6 @@ from neutron_lib import exceptions as n_exc
import vmware_nsx
from vmware_nsx._i18n import _, _LE, _LW
from vmware_nsx.common import config # noqa
from vmware_nsx.common import exceptions as nsx_exc
from vmware_nsx.common import nsx_constants
from vmware_nsx.common import utils as c_utils
from vmware_nsx.db import db as nsx_db
@ -271,8 +270,18 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
[self._fields(network, fields) for network in networks])
def update_network(self, context, id, network):
raise nsx_exc.NsxPluginException(
err_msg=_("Unable to update DVS network"))
net_attrs = network['network']
pnet._raise_if_updates_provider_attributes(net_attrs)
with context.session.begin(subtransactions=True):
net_res = super(NsxDvsV2, self).update_network(context, id,
network)
# Process port security extension
self._process_network_port_security_update(
context, net_attrs, net_res)
self._extend_network_dict_provider(context, net_res)
return net_res
def create_port(self, context, port):
# If PORTSECURITY is not the default value ATTR_NOT_SPECIFIED

View File

@ -244,3 +244,49 @@ class NeutronSimpleDvsTest(test_plugin.NeutronDbPluginV2TestCase):
'id': id}
expected = '%s-%s' % (name[:43], id)
self.assertEqual(expected, self._plugin._dvs_get_id(net))
def test_update_dvs_network(self):
"""Test update of a DVS network
"""
params = {'provider:network_type': 'flat',
'admin_state_up': True,
'name': 'test_net',
'tenant_id': 'fake_tenant',
'shared': False,
'port_security_enabled': False}
with mock.patch.object(self._plugin._dvs, 'add_port_group'):
ctx = context.get_admin_context()
# create the initial network
network = self._plugin.create_network(ctx, {'network': params})
id = network['id']
# update the different attributes of the DVS network
# cannot update the provider type
self.assertRaises(
exp.InvalidInput,
self._plugin.update_network,
ctx, id,
{'network': {'provider:network_type': 'vlan'}})
# update the Shared attribute
self.assertEqual(False, network['shared'])
updated_net = self._plugin.update_network(
ctx, id,
{'network': {'shared': True}})
self.assertEqual(True, updated_net['shared'])
# Update the description attribute
self.assertEqual(None, network['description'])
updated_net = self._plugin.update_network(
ctx, id,
{'network': {'description': 'test'}})
self.assertEqual('test', updated_net['description'])
# update the port security attribute
self.assertEqual(False, network['port_security_enabled'])
updated_net = self._plugin.update_network(
ctx, id,
{'network': {'port_security_enabled': True}})
self.assertEqual(True, updated_net['port_security_enabled'])