Fix a KeyError
Fix a KeyError introduced by the recent change. [1]
The unit tests are taken from the PS1 of the original patch. [2]
Note that super's get_network doesn't fill in provider network
attributes. The ml2 version does it by explicitly calling
self.type_manager.extend_network_dict_provider.
[1] https://review.openstack.org/#/c/648522
[2] https://review.openstack.org/#/c/648522/1
Closes-Bug: #1823294
Co-Authored-By: Harald Jensås <hjensas@redhat.com>
Change-Id: I17b4df558cc7fa370a5f930746030cead6a895d9
(cherry picked from commit c760a83a5d
)
This commit is contained in:
parent
234fcd61aa
commit
0ce7f6e1b6
@ -1003,7 +1003,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
need_network_update_notify = False
|
||||
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
original_network = super(Ml2Plugin, self).get_network(context, id)
|
||||
original_network = self.get_network(context, id)
|
||||
self._update_provider_network_attributes(
|
||||
context, original_network, net_data)
|
||||
updated_network = super(Ml2Plugin, self).update_network(context,
|
||||
|
@ -2355,6 +2355,50 @@ class TestMultiSegmentNetworks(Ml2PluginV2TestCase):
|
||||
self.assertEqual(1, network['network'][pnet.SEGMENTATION_ID])
|
||||
self.assertNotIn(mpnet_apidef.SEGMENTS, network['network'])
|
||||
|
||||
def test_fail_update_network_provider_attr(self):
|
||||
data = {'network': {'name': 'net1',
|
||||
pnet.NETWORK_TYPE: 'flat',
|
||||
pnet.PHYSICAL_NETWORK: 'physnet1',
|
||||
'tenant_id': 'tenant_one'}}
|
||||
network_req = self.new_create_request('networks', data)
|
||||
network = self.deserialize(self.fmt,
|
||||
network_req.get_response(self.api))
|
||||
self.assertEqual('flat', network['network'][pnet.NETWORK_TYPE])
|
||||
self.assertEqual('physnet1', network['network'][pnet.PHYSICAL_NETWORK])
|
||||
self.assertNotIn(mpnet_apidef.SEGMENTS, network['network'])
|
||||
data = {'network': {'name': 'updated-net1',
|
||||
pnet.NETWORK_TYPE: 'flat',
|
||||
pnet.PHYSICAL_NETWORK: 'update_physnet1'}}
|
||||
network_req = self.new_update_request('networks', data,
|
||||
network['network']['id'])
|
||||
network = self.deserialize(self.fmt,
|
||||
network_req.get_response(self.api))
|
||||
self.assertIn('NeutronError', network)
|
||||
self.assertIn(('Invalid input for operation: Plugin does not '
|
||||
'support updating the following provider network '
|
||||
'attributes: '),
|
||||
network['NeutronError']['message'])
|
||||
|
||||
def test_update_network_provider_attr_no_change(self):
|
||||
data = {'network': {'name': 'net1',
|
||||
pnet.NETWORK_TYPE: 'flat',
|
||||
pnet.PHYSICAL_NETWORK: 'physnet1',
|
||||
'tenant_id': 'tenant_one'}}
|
||||
network_req = self.new_create_request('networks', data)
|
||||
network = self.deserialize(self.fmt,
|
||||
network_req.get_response(self.api))
|
||||
self.assertEqual('flat', network['network'][pnet.NETWORK_TYPE])
|
||||
self.assertEqual('physnet1', network['network'][pnet.PHYSICAL_NETWORK])
|
||||
self.assertNotIn(mpnet_apidef.SEGMENTS, network['network'])
|
||||
data = {'network': {'name': 'updated-net1',
|
||||
pnet.NETWORK_TYPE: 'flat',
|
||||
pnet.PHYSICAL_NETWORK: 'physnet1'}}
|
||||
network_req = self.new_update_request('networks', data,
|
||||
network['network']['id'])
|
||||
network = self.deserialize(self.fmt,
|
||||
network_req.get_response(self.api))
|
||||
self.assertEqual('updated-net1', network['network']['name'])
|
||||
|
||||
def test_create_network_single_multiprovider(self):
|
||||
data = {'network': {'name': 'net1',
|
||||
mpnet_apidef.SEGMENTS:
|
||||
|
Loading…
Reference in New Issue
Block a user