Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4008,7 +4008,8 @@ def add_route(ctx, command_str):

# If defined intf name, check if it belongs to interface
if 'ifname' in route:
if (not route['ifname'] in config_db.get_keys('VLAN_INTERFACE') and
if (not route['ifname'] in config_db.get_keys('VLAN') and
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break the assumption made as part of PR #1535 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this will allow configuring a route to ifname without ip, but this seems to be the only way to solve this problem.

not route['ifname'] in config_db.get_keys('VLAN_INTERFACE') and
not route['ifname'] in config_db.get_keys('INTERFACE') and
not route['ifname'] in config_db.get_keys('PORTCHANNEL_INTERFACE') and
not route['ifname'] == 'null'):
Expand Down Expand Up @@ -4054,6 +4055,9 @@ def add_route(ctx, command_str):
# Check if exist entry with key
keys = config_db.get_keys('STATIC_ROUTE')
if key in keys:
if 'null' in route['ifname']:
ctx.fail("this route is already configured on nexthop, remove it before configuring to black hole")

# If exist update current entry
current_entry = config_db.get_entry('STATIC_ROUTE', key)

Expand Down
67 changes: 67 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_BLACKHOLE = '''
Error: this route is already configured on nexthop, remove it before configuring to black hole
'''


class TestStaticRoutes(object):
Expand Down Expand Up @@ -358,6 +361,70 @@ def test_del_entire_ECMP_static_route(self):
print(result.exit_code, result.output)
assert not '14.2.3.4/32' in db.cfgdb.get_table('STATIC_ROUTE')

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

# config route add prefix 15.2.3.4/32 nexthop 30.0.0.5
result = runner.invoke(config.config.commands["route"].commands["add"], \
["prefix", "15.2.3.4/32", "nexthop", "30.0.0.5"], obj=obj)
print(result.exit_code, result.output)
assert ('15.2.3.4/32') in db.cfgdb.get_table('STATIC_ROUTE')
assert db.cfgdb.get_entry('STATIC_ROUTE', '15.2.3.4/32') == {'nexthop': '30.0.0.5', 'blackhole': 'false', 'distance': '0', 'ifname': '', 'nexthop-vrf': ''}

# config route add prefix 15.2.3.4/32 dev null
result = runner.invoke(config.config.commands["route"].commands["add"], \
["prefix", "15.2.3.4/32", "nexthop", "dev", "null"], obj=obj)
print(result.exit_code, result.output)
assert ERROR_BLACKHOLE in result.output

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

# config route add prefix 16.2.3.4/32 nexthop dev Ethernet0
result = runner.invoke(config.config.commands["route"].commands["add"], \
["prefix", "16.2.3.4/32", "nexthop", "dev", "Ethernet0"], obj=obj)
print(result.exit_code, result.output)
assert ('16.2.3.4/32') in db.cfgdb.get_table('STATIC_ROUTE')
assert db.cfgdb.get_entry('STATIC_ROUTE', '16.2.3.4/32') == {'nexthop': '', 'blackhole': 'false', 'distance': '0', 'ifname': 'Ethernet0', 'nexthop-vrf': ''}

# config route del prefix 16.2.3.4/32 nexthop dev Ethernet0
result = runner.invoke(config.config.commands["route"].commands["del"], \
["prefix", "16.2.3.4/32", "nexthop", "dev", "Ethernet0"], obj=obj)
print(result.exit_code, result.output)
assert not '16.2.3.4/32' in db.cfgdb.get_table('STATIC_ROUTE')

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

# config vlan add 40
result = runner.invoke(config.config.commands["vlan"].commands["add"], ["4016"], obj=db)
print(result.exit_code, result.output)
assert ('Vlan4016') in db.cfgdb.get_table('VLAN')

# config route add prefix 16.2.3.4/32 nexthop dev Vlan4016
result = runner.invoke(config.config.commands["route"].commands["add"], \
["prefix", "16.2.3.4/32", "nexthop", "dev", "Vlan4016"], obj=obj)
print(result.exit_code, result.output)
assert ('16.2.3.4/32') in db.cfgdb.get_table('STATIC_ROUTE')
assert db.cfgdb.get_entry('STATIC_ROUTE', '16.2.3.4/32') == {'nexthop': '', 'blackhole': 'false', 'distance': '0', 'ifname': 'Vlan4016', 'nexthop-vrf': ''}

# config route del prefix 16.2.3.4/32 nexthop dev Vlan4016
result = runner.invoke(config.config.commands["route"].commands["del"], \
["prefix", "16.2.3.4/32", "nexthop", "dev", "Vlan4016"], obj=obj)
print(result.exit_code, result.output)
assert not '16.2.3.4/32' in db.cfgdb.get_table('STATIC_ROUTE')

# config vlan del 4016
result = runner.invoke(config.config.commands["vlan"].commands["del"], ["4016"], obj=db)
print(result.exit_code, result.output)
assert not ('Vlan4016') in db.cfgdb.get_table('VLAN')

@classmethod
def teardown_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "0"
Expand Down