From 0ce7f6e1b625f50756b821c7067940f2aee0930d Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Mon, 8 Apr 2019 09:35:43 +0900 Subject: [PATCH] Fix a KeyError MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Change-Id: I17b4df558cc7fa370a5f930746030cead6a895d9 (cherry picked from commit c760a83a5d9111e48333e1aff5f6dd043cb9e68f) --- neutron/plugins/ml2/plugin.py | 2 +- neutron/tests/unit/plugins/ml2/test_plugin.py | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index efc915ee8ad..6a97325c985 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -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, diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py index 6790936376b..f3533a6b453 100644 --- a/neutron/tests/unit/plugins/ml2/test_plugin.py +++ b/neutron/tests/unit/plugins/ml2/test_plugin.py @@ -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: