refactor hp raid errors handling #250
1 changed files with 21 additions and 11 deletions
|
@ -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:
|
||||||
|
@ -51,7 +55,10 @@ def _parse_ctrl_output(lines):
|
||||||
controllers[current_ctrl] = {'Slot': ctrl.group(2)}
|
controllers[current_ctrl] = {'Slot': ctrl.group(2)}
|
||||||
if 'Embedded' not in line:
|
if 'Embedded' not in line:
|
||||||
controllers[current_ctrl]['External'] = True
|
controllers[current_ctrl]['External'] = True
|
||||||
|
continue
|
||||||
|
if ': ' not in line:
|
||||||
continue
|
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'):
|
||||||
|
|
Loading…
Add table
Reference in a new issue