mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
3 files changed
+99
-30
No files matched your search
@@ -510,10 +510,10 @@ def test_hda_disk_image(vm, tmpdir):
|
||||
|
||||
vm.manager.config.set("Server", "images_path", str(tmpdir))
|
||||
|
||||
vm.hda_disk_image = str(tmpdir / "test")
|
||||
assert vm.hda_disk_image == force_unix_path(str(tmpdir / "test"))
|
||||
vm.hda_disk_image = "test"
|
||||
assert vm.hda_disk_image == force_unix_path(str(tmpdir / "QEMU" / "test"))
|
||||
vm.hda_disk_image = str(tmpdir / "test1")
|
||||
assert vm.hda_disk_image == force_unix_path(str(tmpdir / "test1"))
|
||||
vm.hda_disk_image = "test2"
|
||||
assert vm.hda_disk_image == force_unix_path(str(tmpdir / "QEMU" / "test2"))
|
||||
|
||||
|
||||
def test_hda_disk_image_ova(vm, tmpdir):
|
||||
|
||||
@@ -88,6 +88,28 @@ def test_create_node_old_topology(loop, project, tmpdir, vpcs):
|
||||
assert f.read() == "1"
|
||||
|
||||
|
||||
def test_images_directories(qemu, tmpdir):
|
||||
path1 = tmpdir / "images1" / "QEMU" / "test1.bin"
|
||||
path1.write("1", ensure=True)
|
||||
path1 = force_unix_path(str(path1))
|
||||
|
||||
path2 = tmpdir / "images2" / "test2.bin"
|
||||
path2.write("1", ensure=True)
|
||||
path2 = force_unix_path(str(path2))
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={
|
||||
"images_path": str(tmpdir / "images1"),
|
||||
"additional_images_path": "/tmp/null24564:{}".format(tmpdir / "images2"),
|
||||
"local": False}):
|
||||
|
||||
# /tmp/null24564 is ignored because doesn't exists
|
||||
res = qemu.images_directories()
|
||||
assert res[0] == str(tmpdir / "images1" / "QEMU")
|
||||
assert res[1] == str(tmpdir / "images2")
|
||||
assert res[2] == str(tmpdir / "images1")
|
||||
assert len(res) == 3
|
||||
|
||||
|
||||
def test_get_abs_image_path(qemu, tmpdir):
|
||||
os.makedirs(str(tmpdir / "QEMU"))
|
||||
path1 = force_unix_path(str(tmpdir / "test1.bin"))
|
||||
@@ -125,20 +147,50 @@ def test_get_abs_image_path_non_local(qemu, tmpdir):
|
||||
assert qemu.get_abs_image_path(path2) == path2
|
||||
|
||||
|
||||
def test_get_abs_image_additional_image_paths(qemu, tmpdir):
|
||||
path1 = tmpdir / "images1" / "QEMU" / "test1.bin"
|
||||
path1.write("1", ensure=True)
|
||||
path1 = force_unix_path(str(path1))
|
||||
|
||||
path2 = tmpdir / "images2" / "test2.bin"
|
||||
path2.write("1", ensure=True)
|
||||
path2 = force_unix_path(str(path2))
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={
|
||||
"images_path": str(tmpdir / "images1"),
|
||||
"additional_images_path": "/tmp/null24564:{}".format(tmpdir / "images2"),
|
||||
"local": False}):
|
||||
assert qemu.get_abs_image_path("test1.bin") == path1
|
||||
assert qemu.get_abs_image_path("test2.bin") == path2
|
||||
# Absolute path
|
||||
assert qemu.get_abs_image_path(str(path2)) == path2
|
||||
|
||||
# If not found return the default path
|
||||
assert qemu.get_abs_image_path("test4.bin") == os.path.join(qemu.get_images_directory(), "test4.bin")
|
||||
|
||||
|
||||
def test_get_relative_image_path(qemu, tmpdir):
|
||||
os.makedirs(str(tmpdir / "QEMU"))
|
||||
path1 = force_unix_path(str(tmpdir / "test1.bin"))
|
||||
os.makedirs(str(tmpdir / "images1" / "QEMU"))
|
||||
path1 = force_unix_path(str(tmpdir / "images1" / "test1.bin"))
|
||||
open(path1, 'w+').close()
|
||||
|
||||
path2 = force_unix_path(str(tmpdir / "QEMU" / "test2.bin"))
|
||||
path2 = force_unix_path(str(tmpdir / "images1" / "QEMU" / "test2.bin"))
|
||||
open(path2, 'w+').close()
|
||||
|
||||
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
|
||||
os.makedirs(str(tmpdir / "images2"))
|
||||
path3 = force_unix_path(str(tmpdir / "images2" / "test3.bin"))
|
||||
open(path3, 'w+').close()
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={
|
||||
"images_path": str(tmpdir / "images1"),
|
||||
"additional_images_path": str(tmpdir / "images2")
|
||||
}):
|
||||
assert qemu.get_relative_image_path(path1) == "test1.bin"
|
||||
assert qemu.get_relative_image_path("test1.bin") == "test1.bin"
|
||||
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
|
||||
assert qemu.get_relative_image_path("../test1.bin") == "test1.bin"
|
||||
assert qemu.get_relative_image_path("test3.bin") == "test3.bin"
|
||||
|
||||
|
||||
def test_get_relative_image_path_ova(qemu, tmpdir):
|
||||
|
||||
Reference in new issue
Block a user