From 0dea63c9ea16c1f7cb72c64c5ff732219663892a Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Mon, 4 May 2015 10:57:08 +0200 Subject: [PATCH] If image is not found in VM directory look in images folder --- gns3server/modules/base_manager.py | 11 ++++++++++- tests/modules/test_manager.py | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gns3server/modules/base_manager.py b/gns3server/modules/base_manager.py index 378b45d9..e5ce2f8a 100644 --- a/gns3server/modules/base_manager.py +++ b/gns3server/modules/base_manager.py @@ -386,7 +386,16 @@ class BaseManager: img_directory = self.get_images_directory() if not os.path.isabs(path): s = os.path.split(path) - return os.path.normpath(os.path.join(img_directory, *s)) + path = os.path.normpath(os.path.join(img_directory, *s)) + + # Compatibility with old topologies we look in parent directory + # We look at first in new location + if not os.path.exists(path): + old_path = os.path.normpath(os.path.join(img_directory, '..', *s)) + if os.path.exists(old_path): + return old_path + + return path return path def get_relative_image_path(self, path): diff --git a/tests/modules/test_manager.py b/tests/modules/test_manager.py index b75927dd..6eb49dae 100644 --- a/tests/modules/test_manager.py +++ b/tests/modules/test_manager.py @@ -103,10 +103,16 @@ def test_get_abs_image_path(qemu, tmpdir): with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}): assert qemu.get_abs_image_path(path1) == path1 + assert qemu.get_abs_image_path("test1.bin") == path1 assert qemu.get_abs_image_path(path2) == path2 assert qemu.get_abs_image_path("test2.bin") == path2 assert qemu.get_abs_image_path("../test1.bin") == path1 + # We look at first in new location + path2 = str(tmpdir / "QEMU" / "test1.bin") + open(path2, 'w+').close() + assert qemu.get_abs_image_path("test1.bin") == path2 + def test_get_relative_image_path(qemu, tmpdir): os.makedirs(str(tmpdir / "QEMU")) @@ -118,6 +124,7 @@ def test_get_relative_image_path(qemu, tmpdir): with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}): assert qemu.get_relative_image_path(path1) == path1 + assert qemu.get_relative_image_path("test1.bin") == path1 assert qemu.get_relative_image_path(path2) == "test2.bin" assert qemu.get_relative_image_path("test2.bin") == "test2.bin" assert qemu.get_relative_image_path("../test1.bin") == path1