Skip to content

Commit

Permalink
Update test_ipv6_nexthop_global.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-shirshov authored Nov 24, 2020
1 parent 5b8a376 commit 85e6ce2
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/sonic-bgpcfgd/tests/test_ipv6_nexthop_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,34 @@ def extract_rm_from_peer_group(path, peer_group_name):
def check_routemap_in_file(filename, route_map_name):
route_map_re = re.compile(r'^route-map\s+%s\s+permit\s+(\d+)' % route_map_name)
set_re = re.compile(r'set ipv6 next-hop prefer-global')
next_re = re.compile(r'on-match next')
with open(filename) as fp:
lines = [line.strip() for line in fp if not line.strip().startswith('!') and line.strip() != '']
found_entry = False
found_seq_no = None
route_map_entries = {}
for line in lines:
if found_entry:
route_map_entries[found_seq_no] = set_re.match(line) is not None
found_entry = False
found_seq_no = None
if set_re.match(line):
route_map_entries[found_seq_no][0] = True
elif next_re.match(line):
route_map_entries[found_seq_no][1] = True
else:
found_entry = False
found_seq_no = None
if route_map_re.match(line):
found_seq_no = None
seq_n_txt = route_map_re.match(line).group(1)
assert seq_n_txt.isdigit(), "wrong sequence number for line '%s'" % line
found_seq_no = int(seq_n_txt)
assert found_seq_no not in route_map_entries, "Route-map has duplicate entries: %s - %d" % (route_map_name, found_seq_no)
found_entry = True
route_map_entries[found_seq_no] = [False, False]
results = [route_map_entries[seq] for seq in sorted(route_map_entries.keys())]
if len(results):
err_msg = "route-map %s doesn't have mandatory permit entry for 'set ipv6 next-hop prefer-global" % route_map_name
assert results[0], err_msg
return len(results) > 0
err_msg = "route-map %s doesn't have mandatory permit entry for 'set ipv6 next-hop prefer-global" % route_map_name
assert len(results), err_msg
assert all(results[0]), "first ipv6 route-map entry doesn't have set ipv6 nexthop"
return True

def check_routemap(path, route_map_name):
result_files = load_results(path, "policies.conf")
Expand Down

0 comments on commit 85e6ce2

Please sign in to comment.