mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
prevent KeyError by checking whether partition even exists
This commit is contained in:
parent
c542cd49d0
commit
0511f611bb
1 changed files with 12 additions and 9 deletions
|
@ -58,9 +58,9 @@ def usage(args=None):
|
|||
'''
|
||||
flags = _clean_flags(args, 'disk.usage')
|
||||
if not os.path.isfile('/etc/mtab') and __grains__['kernel'] == 'Linux':
|
||||
log.warn('df cannot run without /etc/mtab')
|
||||
log.error('df cannot run without /etc/mtab')
|
||||
if __grains__.get('virtual_subtype') == 'LXC':
|
||||
log.warn('df command failed and LXC detected. If you are running '
|
||||
log.error('df command failed and LXC detected. If you are running '
|
||||
'a Docker container, consider linking /proc/mounts to '
|
||||
'/etc/mtab or consider running Docker with -privileged')
|
||||
return {}
|
||||
|
@ -112,7 +112,7 @@ def usage(args=None):
|
|||
'capacity': comps[4],
|
||||
}
|
||||
except IndexError:
|
||||
log.warn('Problem parsing disk usage information')
|
||||
log.error('Problem parsing disk usage information')
|
||||
ret = {}
|
||||
return ret
|
||||
|
||||
|
@ -159,7 +159,7 @@ def inodeusage(args=None):
|
|||
'filesystem': comps[0],
|
||||
}
|
||||
except (IndexError, ValueError):
|
||||
log.warn('Problem parsing inode usage information')
|
||||
log.error('Problem parsing inode usage information')
|
||||
ret = {}
|
||||
return ret
|
||||
|
||||
|
@ -197,18 +197,21 @@ def percent(args=None):
|
|||
else:
|
||||
ret[comps[5]] = comps[4]
|
||||
except IndexError:
|
||||
log.warn('Problem parsing disk usage information')
|
||||
log.error('Problem parsing disk usage information')
|
||||
ret = {}
|
||||
if args:
|
||||
if args and args not in ret:
|
||||
log.error('Problem parsing disk usage information: Partition \'{0}\' does not exist!'.format(args))
|
||||
ret = {}
|
||||
elif args:
|
||||
return ret[args]
|
||||
else:
|
||||
return ret
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
@decorators.which('blkid')
|
||||
def blkid(device=None):
|
||||
'''
|
||||
Return block device attributes: UUID, LABEL, etc. This function only works
|
||||
Return block device attributes: UUID, LABEL, etc. This function only works
|
||||
on systems where blkid is available.
|
||||
|
||||
CLI Example:
|
||||
|
|
Loading…
Add table
Reference in a new issue