diff --git a/vmware_nsx/plugins/nsx_v/plugin.py b/vmware_nsx/plugins/nsx_v/plugin.py index 22dee1f3ee..5e61ccbcd6 100644 --- a/vmware_nsx/plugins/nsx_v/plugin.py +++ b/vmware_nsx/plugins/nsx_v/plugin.py @@ -2857,7 +2857,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, # Toggling router type is supported only for non-distributed router elif 'router_type' in router['router']: r = self.get_router(context, router_id) - if r['router_type'] != router['router']['router_type']: + if r.get('router_type') != router['router']['router_type']: if r["distributed"]: err_msg = _('Unable to update distributed mode') raise n_exc.InvalidInput(error_message=err_msg) diff --git a/vmware_nsx/tests/unit/nsx_v/test_plugin.py b/vmware_nsx/tests/unit/nsx_v/test_plugin.py index d8b3fbbb11..3dd2005e5c 100644 --- a/vmware_nsx/tests/unit/nsx_v/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v/test_plugin.py @@ -3778,6 +3778,30 @@ class TestVdrTestCase(L3NatTest, L3NatTestCaseBase, with self.subnet(network=net, enable_dhcp=False): self._make_floatingip(self.fmt, net_id) + def test_router_update_type_fails(self): + """Check distributed router cannot change it's type + """ + # create a distributed router + tenant_id = _uuid() + res = self._create_router(self.fmt, tenant_id, distributed=True) + r = self.deserialize(self.fmt, res) + router_id = r['router']['id'] + + # make sure changing the type fails + self._update('routers', router_id, + {'router': {'router_type': 'shared'}}, + expected_code=400) + self._update('routers', router_id, + {'router': {'router_type': 'exclusive'}}, + expected_code=400) + self._update('routers', router_id, + {'router': {'distributed': False}}, + expected_code=400) + # make sure keeping the type is ok + self._update('routers', router_id, + {'router': {'distributed': True}}, + expected_code=200) + def test_router_add_interface_multiple_ipv4_subnets(self): self.skipTest('TBD')