Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[config] Add portchannel support for static route #1857

Merged
merged 6 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,9 +890,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