From: armando-migliaccio Date: Mon, 9 Sep 2013 21:54:32 +0000 (-0700) Subject: Avoid KeyError 'distributed' exception when using NVP <3.x X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=5281b806d2e54f6b8a589e1e4acde3d434b31723;p=openstack-build%2Fneutron-build.git Avoid KeyError 'distributed' exception when using NVP <3.x This patch fixes an issue found when creating routers with NVP plugin and NVP platform 2.2 Fixes bug 1220931 Change-Id: Ia7b358b59e48a723c07efec015bb650accaa3322 --- diff --git a/neutron/plugins/nicira/NeutronPlugin.py b/neutron/plugins/nicira/NeutronPlugin.py index 3f74ac1d3..cf49b4c69 100644 --- a/neutron/plugins/nicira/NeutronPlugin.py +++ b/neutron/plugins/nicira/NeutronPlugin.py @@ -1420,8 +1420,9 @@ class NvpPluginV2(addr_pair_db.AllowedAddressPairsMixin, r['id'] = lrouter['uuid'] # Update 'distributed' with value returned from NVP # This will be useful for setting the value if the API request - # did not specify any value for the 'distributed' attribute - r['distributed'] = lrouter['distributed'] + # did not specify any value for the 'distributed' attribute. + # Platforms older than 3.x do not support the attribute + r['distributed'] = lrouter.get('distributed', False) except nvp_exc.NvpInvalidVersion: msg = _("Cannot create a distributed router with the NVP " "platform currently in execution. Please, try " diff --git a/neutron/tests/unit/nicira/test_nicira_plugin.py b/neutron/tests/unit/nicira/test_nicira_plugin.py index 2be1b37f7..467eb6a84 100644 --- a/neutron/tests/unit/nicira/test_nicira_plugin.py +++ b/neutron/tests/unit/nicira/test_nicira_plugin.py @@ -548,6 +548,17 @@ class TestNiciraL3NatTestCase(test_l3_plugin.L3NatDBTestCase, def test_router_create_distributed_returns_400(self): self._test_router_create_with_distributed(True, None, '3.0', 400) + def test_router_create_on_obsolete_platform(self): + + def obsolete_response(*args, **kwargs): + response = nvplib._create_implicit_routing_lrouter(*args, **kwargs) + response.pop('distributed') + return response + + with mock.patch.object( + nvplib, 'create_lrouter', new=obsolete_response): + self._test_router_create_with_distributed(None, False, '2.2') + def test_router_create_nvp_error_returns_500(self, vlan_id=None): with mock.patch.object(nvplib, 'create_router_lport',