Skip to content
Merged
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
8 changes: 6 additions & 2 deletions tests/common/portstat_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ def parse_portstat(content_lines):
header_line = ''
separation_line = ''
separation_line_number = 0
reminder_line_number = len(content_lines)
for idx, line in enumerate(content_lines):
if line.find('----') >= 0:
header_line = content_lines[idx-1]
separation_line = content_lines[idx]
separation_line_number = idx
break
if 'Reminder' in line:
reminder_line_number = idx

try:
positions = parse_column_positions(separation_line)
Expand All @@ -63,7 +65,9 @@ def parse_portstat(content_lines):
return {}

results = {}
for line in content_lines[separation_line_number+1:]:
for line in content_lines[separation_line_number+1:reminder_line_number]:
Copy link
Contributor

Choose a reason for hiding this comment

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

can we change this to:
for line in content_lines[separation_line_number+1:reminder_line_number-1]: ?

there are 3 lines I added to the print, 1st and 3rd are 2 empty lines, 2ns line is the Reminder print, the original error failed at the 1st empty line. In this case we don't need line 69-70 then

Copy link
Contributor

Choose a reason for hiding this comment

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

(Pdb) content_lines[separation_line_number+1:reminder_line_number]
...
u'Ethernet280 X 0 0.00 B/s 0.00% 0 0 0 0 0.00 B/s 0.00% 0 0 0', u'']

the last empty line will be ignored

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intentionally did not do "[separation_line_number+1:reminder_line_number-1]" to keep it generic for future.
In future release if a Reminder is added without an additional empty line, then "[separation_line_number+1:reminder_line_number-1]" will miss the last line.
Or in case someone adds an additional empty line also.
So I thought we could parse the output from first line after header till line before "Reminder" and skip any empty EOF lines seen in between

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, that makes sense to me

if line == '\n': # skip empty line
continue
portstats = []
for pos in positions:
portstat = line[pos[0]:pos[1]].strip()
Expand Down