mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Use SubprocessError to catch Subprocess exceptions.
This commit is contained in:
parent
3bd88178a0
commit
09948a366f
@ -212,7 +212,7 @@ class Hypervisor(DynamipsHypervisor):
|
||||
cwd=self._working_dir)
|
||||
log.info("Dynamips started PID={}".format(self._process.pid))
|
||||
self._started = True
|
||||
except OSError as e:
|
||||
except subprocess.SubprocessError as e:
|
||||
log.error("could not start Dynamips: {}".format(e))
|
||||
raise DynamipsError("could not start Dynamips: {}".format(e))
|
||||
|
||||
|
@ -509,7 +509,7 @@ class IOUDevice(object):
|
||||
cwd=self._working_dir)
|
||||
|
||||
log.info("iouyap started PID={}".format(self._iouyap_process.pid))
|
||||
except OSError as e:
|
||||
except 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))
|
||||
@ -521,7 +521,7 @@ class IOUDevice(object):
|
||||
|
||||
try:
|
||||
output = subprocess.check_output(["ldd", self._path])
|
||||
except (FileNotFoundError, subprocess.CalledProcessError) as e:
|
||||
except (FileNotFoundError, subprocess.SubprocessError) as e:
|
||||
log.warn("could not determine the shared library dependencies for {}: {}".format(self._path, e))
|
||||
return
|
||||
|
||||
@ -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 OSError as e:
|
||||
except 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 (OSError, subprocess.CalledProcessError) as e:
|
||||
except 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):
|
||||
|
@ -608,7 +608,7 @@ class Qemu(IModule):
|
||||
return version
|
||||
else:
|
||||
raise QemuError("Could not determine the Qemu version for {}".format(qemu_path))
|
||||
except (OSError, subprocess.CalledProcessError) as e:
|
||||
except subprocess.SubprocessError as e:
|
||||
raise QemuError("Error while looking for the Qemu version: {}".format(e))
|
||||
|
||||
@IModule.route("qemu.qemu_list")
|
||||
|
@ -612,7 +612,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 OSError as e:
|
||||
except 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))
|
||||
@ -782,7 +782,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 OSError as e:
|
||||
except subprocess.SubprocessError as e:
|
||||
raise QemuError("Could not create disk image {}".format(e))
|
||||
|
||||
options.extend(["-hda", hda_disk])
|
||||
@ -794,7 +794,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 OSError as e:
|
||||
except subprocess.SubprocessError as e:
|
||||
raise QemuError("Could not create disk image {}".format(e))
|
||||
options.extend(["-hdb", hdb_disk])
|
||||
|
||||
|
@ -717,10 +717,8 @@ class VirtualBox(IModule):
|
||||
|
||||
try:
|
||||
result = subprocess.check_output(command, stderr=subprocess.STDOUT, universal_newlines=True, timeout=30)
|
||||
except subprocess.CalledProcessError as e:
|
||||
except subprocess.SubprocessError as e:
|
||||
raise VirtualBoxError("Could not execute VBoxManage {}".format(e))
|
||||
except subprocess.TimeoutExpired:
|
||||
raise VirtualBoxError("VBoxManage has timed out")
|
||||
return result
|
||||
|
||||
@IModule.route("virtualbox.vm_list")
|
||||
|
@ -558,8 +558,8 @@ class VirtualBoxVM(object):
|
||||
raise VirtualBoxError("{}".format(virtualbox_error))
|
||||
else:
|
||||
raise VirtualBoxError("{}".format(e))
|
||||
except subprocess.TimeoutExpired:
|
||||
raise VirtualBoxError("VBoxManage has timed out")
|
||||
except subprocess.SubprocessError as e:
|
||||
raise VirtualBoxError("Could not execute VBoxManage: {}".format(e))
|
||||
return result.splitlines()
|
||||
|
||||
def _get_vm_info(self):
|
||||
|
@ -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 (OSError, subprocess.CalledProcessError) as e:
|
||||
except 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 OSError as e:
|
||||
except 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))
|
||||
|
Loading…
Reference in New Issue
Block a user