From 7f37f649da70867bc9c15f42edcaf64fd80e2535 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 11 Dec 2014 12:15:24 -0700 Subject: [PATCH] Catch OSError exception for subprocess calls. --- gns3server/modules/dynamips/hypervisor.py | 2 +- gns3server/modules/iou/iou_device.py | 6 +++--- gns3server/modules/qemu/qemu_vm.py | 10 +++++----- gns3server/modules/virtualbox/__init__.py | 2 +- gns3server/modules/virtualbox/virtualbox_vm.py | 2 +- gns3server/modules/vpcs/vpcs_device.py | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/gns3server/modules/dynamips/hypervisor.py b/gns3server/modules/dynamips/hypervisor.py index ac9af618..88c577d7 100644 --- a/gns3server/modules/dynamips/hypervisor.py +++ b/gns3server/modules/dynamips/hypervisor.py @@ -212,7 +212,7 @@ class Hypervisor(DynamipsHypervisor): cwd=self._working_dir) log.info("Dynamips started PID={}".format(self._process.pid)) self._started = True - except subprocess.SubprocessError as e: + except (OSError, subprocess.SubprocessError) as e: log.error("could not start Dynamips: {}".format(e)) raise DynamipsError("could not start Dynamips: {}".format(e)) diff --git a/gns3server/modules/iou/iou_device.py b/gns3server/modules/iou/iou_device.py index 0988f226..2fa89905 100644 --- a/gns3server/modules/iou/iou_device.py +++ b/gns3server/modules/iou/iou_device.py @@ -509,7 +509,7 @@ class IOUDevice(object): cwd=self._working_dir) 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() log.error("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 except FileNotFoundError as 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() 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)) @@ -761,7 +761,7 @@ class IOUDevice(object): command.extend(["-l"]) else: 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)) def _build_command(self): diff --git a/gns3server/modules/qemu/qemu_vm.py b/gns3server/modules/qemu/qemu_vm.py index 45fa483c..5d715689 100644 --- a/gns3server/modules/qemu/qemu_vm.py +++ b/gns3server/modules/qemu/qemu_vm.py @@ -678,7 +678,7 @@ class QemuVM(object): priority = 0 try: 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)) def _stop_cpulimit(self): @@ -710,7 +710,7 @@ class QemuVM(object): log.info("CPU throttled to {}%".format(self._cpu_throttling)) except FileNotFoundError: 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)) def start(self): @@ -796,7 +796,7 @@ class QemuVM(object): cwd=self._working_dir) log.info("QEMU VM instance {} started PID={}".format(self._id, self._process.pid)) self._started = True - except subprocess.SubprocessError as e: + except (OSError, subprocess.SubprocessError) as e: stdout = self.read_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)) @@ -971,7 +971,7 @@ class QemuVM(object): retcode = subprocess.call([qemu_img_path, "create", "-f", "qcow2", hda_disk, "128M"]) 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)) options.extend(["-hda", hda_disk]) @@ -983,7 +983,7 @@ class QemuVM(object): "backing_file={}".format(self._hdb_disk_image), "-f", "qcow2", hdb_disk]) 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)) options.extend(["-hdb", hdb_disk]) diff --git a/gns3server/modules/virtualbox/__init__.py b/gns3server/modules/virtualbox/__init__.py index 4a3fb40f..f84afd64 100644 --- a/gns3server/modules/virtualbox/__init__.py +++ b/gns3server/modules/virtualbox/__init__.py @@ -722,7 +722,7 @@ class VirtualBox(IModule): try: 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)) return result.decode("utf-8") diff --git a/gns3server/modules/virtualbox/virtualbox_vm.py b/gns3server/modules/virtualbox/virtualbox_vm.py index cf1dc3a6..27ae75eb 100644 --- a/gns3server/modules/virtualbox/virtualbox_vm.py +++ b/gns3server/modules/virtualbox/virtualbox_vm.py @@ -558,7 +558,7 @@ class VirtualBoxVM(object): raise VirtualBoxError("{}".format(virtualbox_error)) else: raise VirtualBoxError("{}".format(e)) - except subprocess.SubprocessError as e: + except (OSError, subprocess.SubprocessError) as e: raise VirtualBoxError("Could not execute VBoxManage: {}".format(e)) return result.decode("utf-8").splitlines() diff --git a/gns3server/modules/vpcs/vpcs_device.py b/gns3server/modules/vpcs/vpcs_device.py index 377e9bf0..65664f39 100644 --- a/gns3server/modules/vpcs/vpcs_device.py +++ b/gns3server/modules/vpcs/vpcs_device.py @@ -346,7 +346,7 @@ class VPCSDevice(object): raise VPCSError("VPCS executable version must be >= 0.5b1") else: 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)) def start(self): @@ -386,7 +386,7 @@ class VPCSDevice(object): creationflags=flags) log.info("VPCS instance {} started PID={}".format(self._id, self._process.pid)) self._started = True - except subprocess.SubprocessError as e: + except (OSError, subprocess.SubprocessError) as e: vpcs_stdout = self.read_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))