From 1f615430aea63c40384358fdc041d4e25a43590e Mon Sep 17 00:00:00 2001 From: Jeremy Date: Wed, 24 Dec 2014 17:19:42 -0700 Subject: [PATCH] Checks for broken symbolic links. --- gns3server/modules/dynamips/nodes/router.py | 7 +++++-- gns3server/modules/iou/iou_device.py | 5 ++++- gns3server/modules/qemu/qemu_vm.py | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/gns3server/modules/dynamips/nodes/router.py b/gns3server/modules/dynamips/nodes/router.py index eb665d7f..d0d1aef3 100644 --- a/gns3server/modules/dynamips/nodes/router.py +++ b/gns3server/modules/dynamips/nodes/router.py @@ -354,8 +354,11 @@ class Router(object): self.resume() elif status == "inactive": - if not os.path.isfile(self._image): - raise DynamipsError("IOS image '{}' is not accessible".format(self._image)) + if not os.path.isfile(self._image) or not os.path.exists(self._image): + if os.path.islink(self._image): + raise DynamipsError("IOS image '{}' linked to '{}' is not accessible".format(self._image, os.path.realpath(self._image))) + else: + raise DynamipsError("IOS image '{}' is not accessible".format(self._image)) try: with open(self._image, "rb") as f: diff --git a/gns3server/modules/iou/iou_device.py b/gns3server/modules/iou/iou_device.py index 2fa89905..a593863e 100644 --- a/gns3server/modules/iou/iou_device.py +++ b/gns3server/modules/iou/iou_device.py @@ -539,7 +539,10 @@ class IOUDevice(object): if not self.is_running(): if not os.path.isfile(self._path) or not os.path.exists(self._path): - raise IOUError("IOU image '{}' is not accessible".format(self._path)) + if os.path.islink(self._path): + raise IOUError("IOU image '{}' linked to '{}' is not accessible".format(self._path, os.path.realpath(self._path))) + else: + raise IOUError("IOU image '{}' is not accessible".format(self._path)) try: with open(self._path, "rb") as f: diff --git a/gns3server/modules/qemu/qemu_vm.py b/gns3server/modules/qemu/qemu_vm.py index 77db25e3..13df91bc 100644 --- a/gns3server/modules/qemu/qemu_vm.py +++ b/gns3server/modules/qemu/qemu_vm.py @@ -1087,6 +1087,11 @@ class QemuVM(object): try: if self._hda_disk_image: + if not os.path.isfile(self._hda_disk_image) or not os.path.exists(self._hda_disk_image): + if os.path.islink(self._hda_disk_image): + raise QemuError("hda disk image '{}' linked to '{}' is not accessible".format(self._hda_disk_image, os.path.realpath(self._hda_disk_image))) + else: + raise QemuError("hda disk image '{}' is not accessible".format(self._hda_disk_image)) hda_disk = os.path.join(self._working_dir, "hda_disk.qcow2") if not os.path.exists(hda_disk): retcode = subprocess.call([qemu_img_path, "create", "-o", @@ -1105,6 +1110,11 @@ class QemuVM(object): options.extend(["-hda", hda_disk]) if self._hdb_disk_image: + if not os.path.isfile(self._hdb_disk_image) or not os.path.exists(self._hdb_disk_image): + if os.path.islink(self._hdb_disk_image): + raise QemuError("hdb disk image '{}' linked to '{}' is not accessible".format(self._hdb_disk_image, os.path.realpath(self._hdb_disk_image))) + else: + raise QemuError("hdb disk image '{}' is not accessible".format(self._hdb_disk_image)) hdb_disk = os.path.join(self._working_dir, "hdb_disk.qcow2") if not os.path.exists(hdb_disk): try: @@ -1122,8 +1132,18 @@ class QemuVM(object): options = [] if self._initrd: + if not os.path.isfile(self._initrd) or not os.path.exists(self._initrd): + if os.path.islink(self._initrd): + raise QemuError("initrd file '{}' linked to '{}' is not accessible".format(self._initrd, os.path.realpath(self._initrd))) + else: + raise QemuError("initrd file '{}' is not accessible".format(self._initrd)) options.extend(["-initrd", self._initrd]) if self._kernel_image: + if not os.path.isfile(self._kernel_image) or not os.path.exists(self._kernel_image): + if os.path.islink(self._kernel_image): + raise QemuError("kernel image '{}' linked to '{}' is not accessible".format(self._kernel_image, os.path.realpath(self._kernel_image))) + else: + raise QemuError("kernel image '{}' is not accessible".format(self._kernel_image)) options.extend(["-kernel", self._kernel_image]) if self._kernel_command_line: options.extend(["-append", self._kernel_command_line])