mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Some improvements to parsing cmd output in list_
* Properly ignore "header" lines which indicate output in "CHS" or "CYL" * Raise salt.exceptions.CommandExecutionError on unexpected parsing failures * Always check for correct len of cols array before unpacking by index
This commit is contained in:
parent
1ad50f7dc6
commit
b41dac3072
@ -122,7 +122,7 @@ def list_(device, unit=None):
|
||||
ret = {'info': {}, 'partitions': {}}
|
||||
mode = 'info'
|
||||
for line in out:
|
||||
if line.startswith('BYT'):
|
||||
if line in ('BYT;', 'CHS;', 'CYL;'):
|
||||
continue
|
||||
cols = line.replace(';', '').split(':')
|
||||
if mode == 'info':
|
||||
@ -142,15 +142,22 @@ def list_(device, unit=None):
|
||||
# line. In these cases we just leave this field out of the
|
||||
# return dict.
|
||||
mode = 'partitions'
|
||||
else:
|
||||
raise CommandExecutionError(
|
||||
'Problem encountered while parsing output from parted')
|
||||
else:
|
||||
ret['partitions'][cols[0]] = {
|
||||
'number': cols[0],
|
||||
'start': cols[1],
|
||||
'end': cols[2],
|
||||
'size': cols[3],
|
||||
'type': cols[4],
|
||||
'file system': cols[5],
|
||||
'flags': cols[6]}
|
||||
if len(cols) == 7:
|
||||
ret['partitions'][cols[0]] = {
|
||||
'number': cols[0],
|
||||
'start': cols[1],
|
||||
'end': cols[2],
|
||||
'size': cols[3],
|
||||
'type': cols[4],
|
||||
'file system': cols[5],
|
||||
'flags': cols[6]}
|
||||
else:
|
||||
raise CommandExecutionError(
|
||||
'Problem encountered while parsing output from parted')
|
||||
return ret
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user