From 1c4a0599820338b06b7df1ea6bd21784263ed8e0 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 7 Apr 2015 15:25:53 +0200 Subject: [PATCH] Look in old IOU images location in order to smooth transition Fix #141 --- gns3server/modules/iou/iou_vm.py | 10 ++++++++++ tests/modules/iou/test_iou_vm.py | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/gns3server/modules/iou/iou_vm.py b/gns3server/modules/iou/iou_vm.py index 1bfa2e6d..90378855 100644 --- a/gns3server/modules/iou/iou_vm.py +++ b/gns3server/modules/iou/iou_vm.py @@ -146,6 +146,16 @@ class IOUVM(BaseVM): path = relative_path self._path = path + + # In 1.2 users uploaded images to the images roots + # after the migration their images are inside images/IOU + # but old topologies use old path + if "IOU" not in self._path: + location, filename = os.path.split(self._path) + fix_path = os.path.join(location, "IOU", filename) + if os.path.isfile(fix_path): + self._path = fix_path + if not os.path.isfile(self._path) or not os.path.exists(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))) diff --git a/tests/modules/iou/test_iou_vm.py b/tests/modules/iou/test_iou_vm.py index 7885fd6c..8ee3a21f 100644 --- a/tests/modules/iou/test_iou_vm.py +++ b/tests/modules/iou/test_iou_vm.py @@ -202,6 +202,15 @@ def test_path(vm, fake_iou_bin): assert vm.path == fake_iou_bin +def test_path_12_location(vm, fake_iou_bin): + + # In 1.2 users uploaded images to the images roots + # after the migration their images are inside images/IOU + # but old topologies use old path + vm.path = fake_iou_bin.replace("/IOU", "") + assert vm.path == fake_iou_bin + + def test_path_relative(vm, fake_iou_bin, tmpdir): config = Config.instance()