Commit c2fb1ab6 authored by Peter V. Saveliev's avatar Peter V. Saveliev

ipdb: fix prioritized routes replacement

parent ce1fa119
......@@ -393,6 +393,9 @@ class BaseRoute(Transactional):
old_key = self.make_key(self)
new_key = self.make_key(transaction)
if old_key != new_key:
# delete old record
if devop == 'set':'del', **dict(old_key._asdict()))
# assume we can not move routes between tables (yet ;)
if self['family'] == AF_MPLS:
route_index = self.ipdb.routes.tables['mpls'].idx
......@@ -401,15 +404,16 @@ class BaseRoute(Transactional):
.tables[self['table'] or 254]
if new_key not in route_index:
# re-link the route record
if new_key in route_index:
raise CommitException('route idx conflict')
route_index[new_key] = {'key': new_key,
'route': self}
raise CommitException('route idx conflict'), **transaction)
del route_index[old_key]
else:, **transaction)
# wipe the old key, if needed
if old_key in route_index:
del route_index[old_key], **transaction)
for key in ('metrics', 'via'):
if transaction[key] and transaction[key]._targets:
......@@ -997,6 +997,26 @@ class TestExplicit(BasicSetup):
with self.ip.routes[''] as r:
def test_routes_set_priority(self):
assert '' not in self.ip.routes
with self.ip.routes.add({'dst': '',
'gateway': '',
'priority': 100}) as r:
assert '' in self.ip.routes.keys()
assert grep('ip ro', pattern='**100')
# change the priority
with self.ip.routes[''] as r:
r.priority = 287
# check the changes
assert len(grep('ip ro', pattern='*')) == 1
assert grep('ip ro', pattern='**287')
assert self.ip.routes[''].priority == 287
# delete the route
with self.ip.routes[''] as r:
def test_routes(self):
assert '' not in self.ip.routes
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment