Merge pull request #27238 from bechtoldt/fix_disk_percent_keyerror

salt.modules.disk.percent() throws KeyError when partition doesn't exist
This commit is contained in:
Colton Myers 2015-09-18 13:37:00 -06:00
commit 652b2998af

View file

@ -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: