1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-15 21:08:55 +00:00

If image is not found in VM directory look in images folder

This commit is contained in:
Julien Duponchelle 2015-05-04 10:57:08 +02:00
parent 3467b42ab5
commit 0dea63c9ea
2 changed files with 17 additions and 1 deletions

View File

@ -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):

View File

@ -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