Permalink
Browse files

FEATURE: Support parsing Mellanox 3.6.8010 IB partition output

INTERNAL: Added smarts to deterine if we are parsing the old or new format of
'show ib partition' output and parse the rest appropriately.

Added new test files to exercise the new behavior.
  • Loading branch information...
ryancausey authored and bsanders committed Jan 8, 2019
1 parent 9f57695 commit fcb3504800ef944019b7e62ccb1c933cc5476ddd
@@ -16,7 +16,8 @@ def remove_blank_lines(lines):
return [line for line in lines if line.strip()]


partition_name = re.compile(' [a-z0-9]', re.IGNORECASE)
# Needs to handle the old (< 3.6.8010) and new (>= 3.6.8010) formatting
partition_name = re.compile(r'(?P<format_1> [a-z0-9]+\s*$)|(?P<format_2>[a-z0-9]+:\s*$)', re.IGNORECASE)
members_header = re.compile(' members', re.IGNORECASE)
# a GUID is a like a MAC, but 8 pairs
guid_format = re.compile("([0-9a-f]{2}:){7}[0-9a-f]{2}|ALL", re.IGNORECASE)
@@ -197,13 +198,28 @@ def partitions(self):

partitions = {}
cur_partition = None
for line in self.proc.ask('show ib partition'):
new_console_format = None
for line in remove_blank_lines(lines = self.proc.ask('show ib partition')):
if re.match(members_header, line):
# drop the 'members' line, because it can look like partition names
# lord help us if someone names their partition 'members'
continue
if re.match(partition_name, line):
cur_partition = line.strip()

header_match = re.match(partition_name, line)
if header_match:
# This should be the first thing we encounter when looping through the console
# response, so we use it to set the format for the rest of the loop
if new_console_format is None:
if header_match.group("format_1"):
new_console_format = False
elif header_match.group("format_2"):
new_console_format = True
elif new_console_format and not header_match.group("format_2"):
continue
elif not new_console_format and not header_match.group("format_1"):
continue

cur_partition = line.strip().strip(":")
partitions[cur_partition] = {
'pkey': '',
'ipoib': False,
@@ -213,10 +229,10 @@ def partitions(self):

line = line.strip()
if line.startswith('PKey'):
_, key = line.split('=')
_, key = line.split(':' if new_console_format else '=')
partitions[cur_partition]['pkey'] = int(key, 16)
elif line.startswith('ipoib'):
_, ipoib = line.split('=')
_, ipoib = line.split(':' if new_console_format else '=')
partitions[cur_partition]['ipoib'] = str2bool(ipoib.strip())
elif line.startswith('GUID'):
m = re.search(guid_member_format, line)
@@ -0,0 +1,11 @@
M7800-1-350-350-9 [standalone: master] (config) # show ib partition

Default:
PKey : 0x7FFF
ipoib: yes

members:
GUID='ALL' member='full'
GUID='e4:1d:2d:03:00:15:6e:80' member='limited'

M7800-1-350-350-9 [standalone: master] (config) #
@@ -0,0 +1,11 @@
0x0123:
PKey : 0x0123
ipoib: yes

members:
GUID='e4:1d:2d:03:00:15:6e:80' member='limited'
GUID='e4:aa:2d:bb:cd:cd:ee:80' member='full'
GUID='e4:1d:b1:26:99:34:aa:80' member='limited'
GUID='e4:1d:aa:00:00:11:22:80' member='limited'

M7800-1-1-3-12 [standalone: master] (config) #
@@ -10,7 +10,9 @@

INPUT_DATA = [
['m7800_parse_partitions_input.txt', 'm7800_parse_partitions_output.json'],
['m7800_parse_partitions_input_new_format.txt', 'm7800_parse_partitions_output.json'],
['m7800_parse_partitions_with_member_named_all_input.txt', 'm7800_parse_partitions_with_member_named_all_output.json'],
['m7800_parse_partitions_with_member_named_all_input_new_format.txt', 'm7800_parse_partitions_with_member_named_all_output.json'],
]

class TestUtil:

0 comments on commit fcb3504

Please sign in to comment.