Merge pull request #250 from Solvik/fix/hp-raid-ignore-errors-3

refactor hp raid errors handling
This commit is contained in:
Cyril Levis 2022-11-16 15:48:28 +01:00 committed by GitHub
commit fde6211f5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -33,17 +33,21 @@ def ssacli(sub_command):
lines = list(filter(None, lines)) lines = list(filter(None, lines))
return lines return lines
def _test_if_valid_line(line):
ignore_patterns = ['Note:', 'Error:', 'is not loaded', 'README', 'failure', 'cache']
for pattern in ignore_patterns:
if not line or pattern in line:
return None
return line
def _parse_ctrl_output(lines): def _parse_ctrl_output(lines):
controllers = {} controllers = {}
current_ctrl = None current_ctrl = None
ignore_patterns = ['Note:', 'Error:', 'is not loaded', 'README']
ignore_match = False
for line in lines: for line in lines:
for pattern in ignore_patterns: line = line.strip()
if not line or pattern in line: line = _test_if_valid_line(line)
ignore_match = True if line is None:
break
if ignore_match:
continue continue
ctrl = REGEXP_CONTROLLER_HP.search(line) ctrl = REGEXP_CONTROLLER_HP.search(line)
if ctrl is not None: if ctrl is not None:
@ -52,6 +56,9 @@ def _parse_ctrl_output(lines):
if 'Embedded' not in line: if 'Embedded' not in line:
controllers[current_ctrl]['External'] = True controllers[current_ctrl]['External'] = True
continue continue
if ': ' not in line:
continue
attr, val = line.split(': ', 1) attr, val = line.split(': ', 1)
attr = attr.strip() attr = attr.strip()
val = val.strip() val = val.strip()
@ -66,9 +73,8 @@ def _parse_pd_output(lines):
for line in lines: for line in lines:
line = line.strip() line = line.strip()
if not line or line.startswith('Note:'): line = _test_if_valid_line(line)
continue if line is None:
if 'cache' in line or 'reboot' in line:
continue continue
# Parses the Array the drives are in # Parses the Array the drives are in
if line.startswith('Array'): if line.startswith('Array'):
@ -83,10 +89,13 @@ def _parse_pd_output(lines):
if ': ' not in line: if ': ' not in line:
continue continue
attr, val = line.split(': ', 1) attr, val = line.split(': ', 1)
attr = attr.strip()
val = val.strip()
drives.setdefault(current_drv, {})[attr] = val drives.setdefault(current_drv, {})[attr] = val
return drives return drives
def _parse_ld_output(lines): def _parse_ld_output(lines):
drives = {} drives = {}
current_array = None current_array = None
@ -94,7 +103,8 @@ def _parse_ld_output(lines):
for line in lines: for line in lines:
line = line.strip() line = line.strip()
if not line or line.startswith('Note:'): line = _test_if_valid_line(line)
if line is None:
continue continue
# Parses the Array the drives are in # Parses the Array the drives are in
if line.startswith('Array'): if line.startswith('Array'):