Skip to content

Commit

Permalink
[config] Add portchannel support for static route (#1857)
Browse files Browse the repository at this point in the history
* Added portchannels support for static routes.
* Added check if nexthop is a portchannel and verify if this portchannel exists in config db.

Signed-off-by: d-dashkov <Dmytro_Dashkov@Jabil.com>
  • Loading branch information
d-dashkov authored Dec 7, 2021
1 parent 54cc370 commit 7c34b79
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 9 additions & 3 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,9 +906,15 @@ def cli_sroute_to_config(ctx, command_str, strict_nh = True):
try:
ipaddress.ip_network(ip_prefix)
if 'nexthop' in config_entry:
nh = config_entry['nexthop'].split(',')
for ip in nh:
ipaddress.ip_address(ip)
nh_list = config_entry['nexthop'].split(',')
for nh in nh_list:
# Nexthop to portchannel
if nh.startswith('PortChannel'):
config_db = ctx.obj['config_db']
if not nh in config_db.get_keys('PORTCHANNEL'):
ctx.fail("portchannel does not exist.")
else:
ipaddress.ip_address(nh)
except ValueError:
ctx.fail("ip address is not valid.")

Expand Down
14 changes: 14 additions & 0 deletions tests/static_routes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
ERROR_INVALID_IP = '''
Error: ip address is not valid.
'''
ERROR_INVALID_PORTCHANNEL = '''
Error: portchannel does not exist.
'''


class TestStaticRoutes(object):
Expand All @@ -51,6 +54,17 @@ def test_simple_static_route(self):
print(result.exit_code, result.output)
assert not '1.2.3.4/32' in db.cfgdb.get_table('STATIC_ROUTE')

def test_invalid_portchannel_static_route(self):
db = Db()
runner = CliRunner()
obj = {'config_db':db.cfgdb}

# config route add prefix 1.2.3.4/32 nexthop PortChannel0101
result = runner.invoke(config.config.commands["route"].commands["add"], \
["prefix", "1.2.3.4/32", "nexthop", "PortChannel0101"], obj=obj)
print(result.exit_code, result.output)
assert ERROR_INVALID_PORTCHANNEL in result.output

def test_static_route_invalid_prefix_ip(self):
db = Db()
runner = CliRunner()
Expand Down

0 comments on commit 7c34b79

Please sign in to comment.