Merge "Fix Prefix delegation router deletion key error"

This commit is contained in:
Jenkins 2015-08-30 21:51:51 +00:00 committed by Gerrit Code Review
commit bce1ae72ad
2 changed files with 43 additions and 7 deletions

View File

@ -302,10 +302,17 @@ class PrefixDelegation(object):
@utils.synchronized("l3-agent-pd")
def remove_router(resource, event, l3_agent, **kwargs):
router = l3_agent.pd.routers.get(kwargs['router'].router_id)
router_id = kwargs['router'].router_id
router = l3_agent.pd.routers.get(router_id)
l3_agent.pd.delete_router_pd(router)
del l3_agent.pd.routers[router['id']]['subnets']
del l3_agent.pd.routers[router['id']]
del l3_agent.pd.routers[router_id]['subnets']
del l3_agent.pd.routers[router_id]
def get_router_entry(ns_name):
return {'gw_interface': None,
'ns_name': ns_name,
'subnets': {}}
@utils.synchronized("l3-agent-pd")
@ -313,10 +320,8 @@ def add_router(resource, event, l3_agent, **kwargs):
added_router = kwargs['router']
router = l3_agent.pd.routers.get(added_router.router_id)
if not router:
l3_agent.pd.routers[added_router.router_id] = {
'gw_interface': None,
'ns_name': added_router.ns_name,
'subnets': {}}
l3_agent.pd.routers[added_router.router_id] = (
get_router_entry(added_router.ns_name))
else:
# This will happen during l3 agent restart
router['ns_name'] = added_router.ns_name

View File

@ -0,0 +1,31 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from neutron.agent.linux import pd
from neutron.tests import base as tests_base
class FakeRouter(object):
def __init__(self, router_id):
self.router_id = router_id
class TestPrefixDelegation(tests_base.DietTestCase):
def test_remove_router(self):
l3_agent = mock.Mock()
router_id = 1
l3_agent.pd.routers = {router_id: pd.get_router_entry(None)}
pd.remove_router(None, None, l3_agent, router=FakeRouter(router_id))
self.assertTrue(l3_agent.pd.delete_router_pd.called)
self.assertEqual({}, l3_agent.pd.routers)