Allow provider net attr in update if no change
If provider net attributes are in update request body, do an additional check to see if the values are actually different. Only raise exception if values are different. Closes-Bug: #1822100 Co-Authored-By: Rodolfo Alonso Hernandez <ralonsoh@redhat.com> Change-Id: I4ac11299375d1d3a7d2013f1fdc1742920d884a9
This commit is contained in:
parent
6f26f4026b
commit
20743350b9
|
@ -841,16 +841,19 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
|||
This function will raise an exception if the provider network attribute
|
||||
update is not supported.
|
||||
"""
|
||||
if net_data.get(provider_net.SEGMENTATION_ID):
|
||||
self._update_segmentation_id(context, network, net_data)
|
||||
|
||||
provider_net_attrs = (set(provider_net.ATTRIBUTES) -
|
||||
{provider_net.SEGMENTATION_ID})
|
||||
if any(validators.is_attr_set(net_data.get(a))
|
||||
for a in provider_net_attrs):
|
||||
msg = (_('Plugin does not support updating the following provider '
|
||||
'network attributes: %s') % ', '.join(provider_net_attrs))
|
||||
raise exc.InvalidInput(error_message=msg)
|
||||
requested_provider_net_attrs = set(net_data) & provider_net_attrs
|
||||
for attr in requested_provider_net_attrs:
|
||||
if (validators.is_attr_set(net_data.get(attr)) and
|
||||
net_data.get(attr) != network[attr]):
|
||||
msg = (_('Plugin does not support updating the following '
|
||||
'provider network attributes: %s') %
|
||||
', '.join(provider_net_attrs))
|
||||
raise exc.InvalidInput(error_message=msg)
|
||||
|
||||
if net_data.get(provider_net.SEGMENTATION_ID):
|
||||
self._update_segmentation_id(context, network, net_data)
|
||||
|
||||
def _delete_objects(self, context, resource, objects):
|
||||
delete_op = getattr(self, 'delete_%s' % resource)
|
||||
|
|
|
@ -421,11 +421,18 @@ class TestMl2NetworksV2(test_plugin.TestNetworksV2,
|
|||
self.assertEqual(3, f.call_count)
|
||||
retry_fixture.cleanUp()
|
||||
|
||||
def test__update_provider_network_attributes_no_segmentation_id(self):
|
||||
def test__update_provider_network_attributes_update_attrs(self):
|
||||
plugin = directory.get_plugin()
|
||||
with self.network() as net:
|
||||
kwargs = {'arg_list': (pnet.NETWORK_TYPE, ),
|
||||
pnet.NETWORK_TYPE: 'vlan'}
|
||||
with self.network(**kwargs) as net:
|
||||
for attribute in set(pnet.ATTRIBUTES) - {pnet.SEGMENTATION_ID}:
|
||||
net_data = {attribute: 'attribute_value'}
|
||||
net_data = {attribute: net['network'][attribute]}
|
||||
self.assertIsNone(
|
||||
plugin._update_provider_network_attributes(
|
||||
self.context, net['network'], net_data))
|
||||
|
||||
net_data = {attribute: 'other_value'}
|
||||
self.assertRaises(
|
||||
exc.InvalidInput,
|
||||
plugin._update_provider_network_attributes,
|
||||
|
|
Loading…
Reference in New Issue