Skip to content

Commit

Permalink
Add exception handling to get_disk_info
Browse files Browse the repository at this point in the history
Similar to 92305eb, except instead of
handling the error in the callers of get_disk_info, fix it in the
function directly since all but one of the callers were checking for
empty results anyway.
  • Loading branch information
bryteise committed Dec 20, 2017
1 parent 2face3e commit acafa4b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions ister_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ def get_disk_info(disk):
"""Return dictionary with disk information"""
info = {'partitions': []}
cmd = ['/usr/bin/fdisk', '-l', disk]
output = subprocess.check_output(cmd).decode('utf-8')
try:
output = subprocess.check_output(cmd).decode('utf-8')
except:
return info
lines = output.split('\n')
expr = re.compile('^Device')
# discard header...
Expand Down Expand Up @@ -1236,13 +1239,11 @@ def _mount_host_disk(self, config):
for disk in disks:
if disk in self.current or root_part:
continue
try:
part_info = get_disk_info('/dev/{}'.format(disk))
except:
continue
root_part = self._get_part(part_info,
'Linux root',
self.target_dir)
part_info = get_disk_info('/dev/{}'.format(disk))
if part_info["partitions"]:
root_part = self._get_part(part_info,
'Linux root',
self.target_dir)
# only look for a boot partition on the same disk as the root
# partition and only if a root partition is found
if root_part:
Expand Down

0 comments on commit acafa4b

Please sign in to comment.