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
This commit is contained in:
YAMAMOTO Takashi 2019-04-08 09:35:43 +09:00
parent 1f6c48b1f2
commit c760a83a5d
2 changed files with 45 additions and 1 deletions

View File

@ -1047,7 +1047,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)

View File

@ -2424,6 +2424,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: