From 27c8ad5108208afcae8494d5bb2827edb858545e Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Wed, 4 Mar 2015 13:34:26 -0800 Subject: [PATCH] Allow plugin to specify router_id It is useful to allow the backend to specify the uuid that we want neutron to use. We currently do this same thing for networks. This patch enables the same behavior for routers as well. Change-Id: If675dfd2997217886976301270ef5f773ffa7a13 --- neutron/db/l3_db.py | 3 ++- neutron/tests/unit/extensions/test_l3.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index fbad07a13..fd69bf29b 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -158,7 +158,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase): with context.session.begin(subtransactions=True): # pre-generate id so it will be available when # configuring external gw port - router_db = Router(id=uuidutils.generate_uuid(), + router_db = Router(id=(router.get('id') or + uuidutils.generate_uuid()), tenant_id=tenant_id, name=router['name'], admin_state_up=router['admin_state_up'], diff --git a/neutron/tests/unit/extensions/test_l3.py b/neutron/tests/unit/extensions/test_l3.py index 8c824d6c0..6919220ef 100644 --- a/neutron/tests/unit/extensions/test_l3.py +++ b/neutron/tests/unit/extensions/test_l3.py @@ -2299,6 +2299,14 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): floating_ip='10.0.0.10', http_status=exc.HTTPConflict.code) + def test_router_specify_id_backend(self): + plugin = manager.NeutronManager.get_service_plugins()[ + service_constants.L3_ROUTER_NAT] + router_req = {'router': {'id': _uuid(), 'name': 'router', + 'admin_state_up': True}} + result = plugin.create_router(context.Context('', 'foo'), router_req) + self.assertEqual(result['id'], router_req['router']['id']) + class L3AgentDbTestCaseBase(L3NatTestCaseMixin): -- 2.45.2