Skip to content

Commit 721d847

Browse files
committed
[fib, fdb] allow fib and fdb test info files to contain empty lines and comments
While generating test info files for fib/fdb tests, some topology output file contains empty lines. This change allows these empty lines to be ignored during tests.
1 parent 8f2e672 commit 721d847

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

ansible/roles/test/files/ptftests/fdb.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from ipaddress import ip_address, ip_network
23

34
class Fdb():
@@ -6,8 +7,12 @@ def __init__(self, file_path):
67
self._arp_dict = {}
78
self._vlan_dict = {}
89

10+
# filter out empty lines and lines starting with '#'
11+
pattern = re.compile("^#.*$|^[ \t]*$")
12+
913
with open(file_path, 'r') as f:
1014
for line in f.readlines():
15+
if pattern.match(line): continue
1116
entry = line.split(' ', 1)
1217
prefix = ip_network(unicode(entry[0]))
1318
self._vlan_dict[prefix] = [int(i) for i in entry[1].split()]

ansible/roles/test/files/ptftests/fib.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ def __init__(self, file_path):
5151
for ip in EXCLUDE_IPV6_PREFIXES:
5252
self._ipv6_lpm_dict[ip] = self.NextHop()
5353

54+
# filter out empty lines and lines starting with '#'
55+
pattern = re.compile("^#.*$|^[ \t]*$")
56+
5457
with open(file_path, 'r') as f:
5558
for line in f.readlines():
56-
if line[0] == '#': continue
59+
if pattern.match(line): continue
5760
entry = line.split(' ', 1)
5861
prefix = ip_network(unicode(entry[0]))
5962
next_hop = self.NextHop(entry[1])

0 commit comments

Comments
 (0)