1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 11:18:11 +00:00

Catch OSError exception for subprocess calls.

This commit is contained in:
Jeremy 2014-12-11 12:15:24 -07:00
parent acb5103119
commit 7f37f649da
6 changed files with 13 additions and 13 deletions

View File

@ -212,7 +212,7 @@ class Hypervisor(DynamipsHypervisor):
cwd=self._working_dir) cwd=self._working_dir)
log.info("Dynamips started PID={}".format(self._process.pid)) log.info("Dynamips started PID={}".format(self._process.pid))
self._started = True self._started = True
except subprocess.SubprocessError as e: except (OSError, subprocess.SubprocessError) as e:
log.error("could not start Dynamips: {}".format(e)) log.error("could not start Dynamips: {}".format(e))
raise DynamipsError("could not start Dynamips: {}".format(e)) raise DynamipsError("could not start Dynamips: {}".format(e))

View File

@ -509,7 +509,7 @@ class IOUDevice(object):
cwd=self._working_dir) cwd=self._working_dir)
log.info("iouyap started PID={}".format(self._iouyap_process.pid)) log.info("iouyap started PID={}".format(self._iouyap_process.pid))
except subprocess.SubprocessError as e: except (OSError, subprocess.SubprocessError) as e:
iouyap_stdout = self.read_iouyap_stdout() iouyap_stdout = self.read_iouyap_stdout()
log.error("could not start iouyap: {}\n{}".format(e, iouyap_stdout)) log.error("could not start iouyap: {}\n{}".format(e, iouyap_stdout))
raise IOUError("Could not start iouyap: {}\n{}".format(e, iouyap_stdout)) raise IOUError("Could not start iouyap: {}\n{}".format(e, iouyap_stdout))
@ -583,7 +583,7 @@ class IOUDevice(object):
self._started = True self._started = True
except FileNotFoundError as e: except FileNotFoundError as e:
raise IOUError("could not start IOU: {}: 32-bit binary support is probably not installed".format(e)) raise IOUError("could not start IOU: {}: 32-bit binary support is probably not installed".format(e))
except subprocess.SubprocessError as e: except (OSError, subprocess.SubprocessError) as e:
iou_stdout = self.read_iou_stdout() iou_stdout = self.read_iou_stdout()
log.error("could not start IOU {}: {}\n{}".format(self._path, e, iou_stdout)) log.error("could not start IOU {}: {}\n{}".format(self._path, e, iou_stdout))
raise IOUError("could not start IOU {}: {}\n{}".format(self._path, e, iou_stdout)) raise IOUError("could not start IOU {}: {}\n{}".format(self._path, e, iou_stdout))
@ -761,7 +761,7 @@ class IOUDevice(object):
command.extend(["-l"]) command.extend(["-l"])
else: else:
raise IOUError("layer 1 keepalive messages are not supported by {}".format(os.path.basename(self._path))) raise IOUError("layer 1 keepalive messages are not supported by {}".format(os.path.basename(self._path)))
except subprocess.SubprocessError as e: except (OSError, subprocess.SubprocessError) as e:
log.warn("could not determine if layer 1 keepalive messages are supported by {}: {}".format(os.path.basename(self._path), e)) log.warn("could not determine if layer 1 keepalive messages are supported by {}: {}".format(os.path.basename(self._path), e))
def _build_command(self): def _build_command(self):

View File

@ -678,7 +678,7 @@ class QemuVM(object):
priority = 0 priority = 0
try: try:
subprocess.call(['renice', '-n', str(priority), '-p', str(self._process.pid)]) subprocess.call(['renice', '-n', str(priority), '-p', str(self._process.pid)])
except subprocess.SubprocessError as e: except (OSError, subprocess.SubprocessError) as e:
log.error("could not change process priority for QEMU VM {}: {}".format(self._name, e)) log.error("could not change process priority for QEMU VM {}: {}".format(self._name, e))
def _stop_cpulimit(self): def _stop_cpulimit(self):
@ -710,7 +710,7 @@ class QemuVM(object):
log.info("CPU throttled to {}%".format(self._cpu_throttling)) log.info("CPU throttled to {}%".format(self._cpu_throttling))
except FileNotFoundError: except FileNotFoundError:
raise QemuError("cpulimit could not be found, please install it or deactivate CPU throttling") raise QemuError("cpulimit could not be found, please install it or deactivate CPU throttling")
except subprocess.SubprocessError as e: except (OSError, subprocess.SubprocessError) as e:
raise QemuError("Could not throttle CPU: {}".format(e)) raise QemuError("Could not throttle CPU: {}".format(e))
def start(self): def start(self):
@ -796,7 +796,7 @@ class QemuVM(object):
cwd=self._working_dir) cwd=self._working_dir)
log.info("QEMU VM instance {} started PID={}".format(self._id, self._process.pid)) log.info("QEMU VM instance {} started PID={}".format(self._id, self._process.pid))
self._started = True self._started = True
except subprocess.SubprocessError as e: except (OSError, subprocess.SubprocessError) as e:
stdout = self.read_stdout() stdout = self.read_stdout()
log.error("could not start QEMU {}: {}\n{}".format(self._qemu_path, e, stdout)) log.error("could not start QEMU {}: {}\n{}".format(self._qemu_path, e, stdout))
raise QemuError("could not start QEMU {}: {}\n{}".format(self._qemu_path, e, stdout)) raise QemuError("could not start QEMU {}: {}\n{}".format(self._qemu_path, e, stdout))
@ -971,7 +971,7 @@ class QemuVM(object):
retcode = subprocess.call([qemu_img_path, "create", "-f", "qcow2", hda_disk, "128M"]) retcode = subprocess.call([qemu_img_path, "create", "-f", "qcow2", hda_disk, "128M"])
log.info("{} returned with {}".format(qemu_img_path, retcode)) log.info("{} returned with {}".format(qemu_img_path, retcode))
except subprocess.SubprocessError as e: except (OSError, subprocess.SubprocessError) as e:
raise QemuError("Could not create disk image {}".format(e)) raise QemuError("Could not create disk image {}".format(e))
options.extend(["-hda", hda_disk]) options.extend(["-hda", hda_disk])
@ -983,7 +983,7 @@ class QemuVM(object):
"backing_file={}".format(self._hdb_disk_image), "backing_file={}".format(self._hdb_disk_image),
"-f", "qcow2", hdb_disk]) "-f", "qcow2", hdb_disk])
log.info("{} returned with {}".format(qemu_img_path, retcode)) log.info("{} returned with {}".format(qemu_img_path, retcode))
except subprocess.SubprocessError as e: except (OSError, subprocess.SubprocessError) as e:
raise QemuError("Could not create disk image {}".format(e)) raise QemuError("Could not create disk image {}".format(e))
options.extend(["-hdb", hdb_disk]) options.extend(["-hdb", hdb_disk])

View File

@ -722,7 +722,7 @@ class VirtualBox(IModule):
try: try:
result = subprocess.check_output(command, stderr=subprocess.STDOUT, timeout=30) result = subprocess.check_output(command, stderr=subprocess.STDOUT, timeout=30)
except subprocess.SubprocessError as e: except (OSError, subprocess.SubprocessError) as e:
raise VirtualBoxError("Could not execute VBoxManage {}".format(e)) raise VirtualBoxError("Could not execute VBoxManage {}".format(e))
return result.decode("utf-8") return result.decode("utf-8")

View File

@ -558,7 +558,7 @@ class VirtualBoxVM(object):
raise VirtualBoxError("{}".format(virtualbox_error)) raise VirtualBoxError("{}".format(virtualbox_error))
else: else:
raise VirtualBoxError("{}".format(e)) raise VirtualBoxError("{}".format(e))
except subprocess.SubprocessError as e: except (OSError, subprocess.SubprocessError) as e:
raise VirtualBoxError("Could not execute VBoxManage: {}".format(e)) raise VirtualBoxError("Could not execute VBoxManage: {}".format(e))
return result.decode("utf-8").splitlines() return result.decode("utf-8").splitlines()

View File

@ -346,7 +346,7 @@ class VPCSDevice(object):
raise VPCSError("VPCS executable version must be >= 0.5b1") raise VPCSError("VPCS executable version must be >= 0.5b1")
else: else:
raise VPCSError("Could not determine the VPCS version for {}".format(self._path)) raise VPCSError("Could not determine the VPCS version for {}".format(self._path))
except subprocess.SubprocessError as e: except (OSError, subprocess.SubprocessError) as e:
raise VPCSError("Error while looking for the VPCS version: {}".format(e)) raise VPCSError("Error while looking for the VPCS version: {}".format(e))
def start(self): def start(self):
@ -386,7 +386,7 @@ class VPCSDevice(object):
creationflags=flags) creationflags=flags)
log.info("VPCS instance {} started PID={}".format(self._id, self._process.pid)) log.info("VPCS instance {} started PID={}".format(self._id, self._process.pid))
self._started = True self._started = True
except subprocess.SubprocessError as e: except (OSError, subprocess.SubprocessError) as e:
vpcs_stdout = self.read_vpcs_stdout() vpcs_stdout = self.read_vpcs_stdout()
log.error("could not start VPCS {}: {}\n{}".format(self._path, e, vpcs_stdout)) log.error("could not start VPCS {}: {}\n{}".format(self._path, e, vpcs_stdout))
raise VPCSError("could not start VPCS {}: {}\n{}".format(self._path, e, vpcs_stdout)) raise VPCSError("could not start VPCS {}: {}\n{}".format(self._path, e, vpcs_stdout))