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

pull/184/head
Julien Duponchelle 9 years ago
parent 3467b42ab5
commit 0dea63c9ea

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

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

Loading…
Cancel
Save