mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Raise an error if image is missing on compute
This commit is contained in:
23 files changed
+108
-108
No files matched your search
@@ -72,11 +72,10 @@ def iourc_file(tmpdir):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_iou_bin(tmpdir):
|
||||
def fake_iou_bin(images_dir):
|
||||
"""Create a fake IOU image on disk"""
|
||||
|
||||
os.makedirs(str(tmpdir / "IOU"), exist_ok=True)
|
||||
path = str(tmpdir / "IOU" / "iou.bin")
|
||||
path = os.path.join(images_dir, "iou.bin")
|
||||
with open(path, "w+") as f:
|
||||
f.write('\x7fELF\x01\x01\x01')
|
||||
os.chmod(path, stat.S_IREAD | stat.S_IEXEC)
|
||||
@@ -97,11 +96,11 @@ def test_vm_startup_config_content(project, manager):
|
||||
assert vm.id == "00010203-0405-0607-0808-0a0b0c0d0e0f"
|
||||
|
||||
|
||||
@patch("gns3server.config.Config.get_section_config", return_value={"iouyap_path": "/bin/test_fake"})
|
||||
@patch("gns3server.compute.iou.iou_vm.IOUVM._config", return_value={"iouyap_path": "/bin/test_fake"})
|
||||
def test_vm_invalid_iouyap_path(project, manager, loop, fake_iou_bin):
|
||||
with pytest.raises(IOUError):
|
||||
vm = IOUVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0e", project, manager)
|
||||
vm.path = "iou.bin"
|
||||
vm.path = fake_iou_bin
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
|
||||
|
||||
@@ -213,20 +212,8 @@ 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
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||
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()
|
||||
config.set("Server", "images_path", str(tmpdir))
|
||||
vm.path = "iou.bin"
|
||||
assert vm.path == fake_iou_bin
|
||||
|
||||
@@ -235,9 +222,6 @@ def test_path_invalid_bin(vm, tmpdir):
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||
path = str(tmpdir / "test.bin")
|
||||
with pytest.raises(IOUError):
|
||||
vm.path = path
|
||||
vm._check_requirements()
|
||||
|
||||
with open(path, "w+") as f:
|
||||
f.write("BUG")
|
||||
|
||||
@@ -506,52 +506,52 @@ def test_build_command_with_invalid_options(vm, loop, fake_qemu_binary):
|
||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
||||
|
||||
|
||||
def test_hda_disk_image(vm, tmpdir):
|
||||
def test_hda_disk_image(vm, images_dir):
|
||||
|
||||
vm.manager.config.set("Server", "images_path", str(tmpdir))
|
||||
|
||||
vm.hda_disk_image = str(tmpdir / "test1")
|
||||
assert vm.hda_disk_image == force_unix_path(str(tmpdir / "test1"))
|
||||
open(os.path.join(images_dir, "test1"), "w+").close()
|
||||
vm.hda_disk_image = os.path.join(images_dir, "test1")
|
||||
assert vm.hda_disk_image == force_unix_path(os.path.join(images_dir, "test1"))
|
||||
open(os.path.join(images_dir, "QEMU", "test2"), "w+").close()
|
||||
vm.hda_disk_image = "test2"
|
||||
assert vm.hda_disk_image == force_unix_path(str(tmpdir / "QEMU" / "test2"))
|
||||
assert vm.hda_disk_image == force_unix_path(os.path.join(images_dir, "QEMU", "test2"))
|
||||
|
||||
|
||||
def test_hda_disk_image_ova(vm, tmpdir):
|
||||
|
||||
vm.manager.config.set("Server", "images_path", str(tmpdir))
|
||||
def test_hda_disk_image_ova(vm, images_dir):
|
||||
|
||||
os.makedirs(os.path.join(images_dir, "QEMU", "test.ovf"))
|
||||
open(os.path.join(images_dir, "QEMU", "test.ovf", "test.vmdk"), "w+").close()
|
||||
vm.hda_disk_image = "test.ovf/test.vmdk"
|
||||
assert vm.hda_disk_image == force_unix_path(str(tmpdir / "QEMU" / "test.ovf" / "test.vmdk"))
|
||||
assert vm.hda_disk_image == force_unix_path(os.path.join(images_dir, "QEMU", "test.ovf", "test.vmdk"))
|
||||
|
||||
|
||||
def test_hdb_disk_image(vm, tmpdir):
|
||||
def test_hdb_disk_image(vm, images_dir):
|
||||
|
||||
vm.manager.config.set("Server", "images_path", str(tmpdir))
|
||||
|
||||
vm.hdb_disk_image = str(tmpdir / "test")
|
||||
assert vm.hdb_disk_image == force_unix_path(str(tmpdir / "test"))
|
||||
vm.hdb_disk_image = "test"
|
||||
assert vm.hdb_disk_image == force_unix_path(str(tmpdir / "QEMU" / "test"))
|
||||
open(os.path.join(images_dir, "test1"), "w+").close()
|
||||
vm.hdb_disk_image = os.path.join(images_dir, "test1")
|
||||
assert vm.hdb_disk_image == force_unix_path(os.path.join(images_dir, "test1"))
|
||||
open(os.path.join(images_dir, "QEMU", "test2"), "w+").close()
|
||||
vm.hdb_disk_image = "test2"
|
||||
assert vm.hdb_disk_image == force_unix_path(os.path.join(images_dir, "QEMU", "test2"))
|
||||
|
||||
|
||||
def test_hdc_disk_image(vm, tmpdir):
|
||||
def test_hdc_disk_image(vm, images_dir):
|
||||
|
||||
vm.manager.config.set("Server", "images_path", str(tmpdir))
|
||||
|
||||
vm.hdc_disk_image = str(tmpdir / "test")
|
||||
assert vm.hdc_disk_image == force_unix_path(str(tmpdir / "test"))
|
||||
vm.hdc_disk_image = "test"
|
||||
assert vm.hdc_disk_image == force_unix_path(str(tmpdir / "QEMU" / "test"))
|
||||
open(os.path.join(images_dir, "test1"), "w+").close()
|
||||
vm.hdc_disk_image = os.path.join(images_dir, "test1")
|
||||
assert vm.hdc_disk_image == force_unix_path(os.path.join(images_dir, "test1"))
|
||||
open(os.path.join(images_dir, "QEMU", "test2"), "w+").close()
|
||||
vm.hdc_disk_image = "test2"
|
||||
assert vm.hdc_disk_image == force_unix_path(os.path.join(images_dir, "QEMU", "test2"))
|
||||
|
||||
|
||||
def test_hdd_disk_image(vm, tmpdir):
|
||||
def test_hdd_disk_image(vm, images_dir):
|
||||
|
||||
vm.manager.config.set("Server", "images_path", str(tmpdir))
|
||||
|
||||
vm.hdd_disk_image = str(tmpdir / "test")
|
||||
assert vm.hdd_disk_image == force_unix_path(str(tmpdir / "test"))
|
||||
vm.hdd_disk_image = "test"
|
||||
assert vm.hdd_disk_image == force_unix_path(str(tmpdir / "QEMU" / "test"))
|
||||
open(os.path.join(images_dir, "test1"), "w+").close()
|
||||
vm.hdd_disk_image = os.path.join(images_dir, "test1")
|
||||
assert vm.hdd_disk_image == force_unix_path(os.path.join(images_dir, "test1"))
|
||||
open(os.path.join(images_dir, "QEMU", "test2"), "w+").close()
|
||||
vm.hdd_disk_image = "test2"
|
||||
assert vm.hdd_disk_image == force_unix_path(os.path.join(images_dir, "QEMU", "test2"))
|
||||
|
||||
|
||||
def test_initrd(vm, tmpdir):
|
||||
|
||||
@@ -26,7 +26,7 @@ from unittest.mock import patch, MagicMock
|
||||
from gns3server.compute.vpcs.vpcs_vm import VPCSVM
|
||||
from gns3server.compute.docker.docker_vm import DockerVM
|
||||
from gns3server.compute.vpcs.vpcs_error import VPCSError
|
||||
from gns3server.compute.node_error import NodeError
|
||||
from gns3server.compute.error import NodeError
|
||||
from gns3server.compute.vpcs import VPCS
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ from unittest.mock import patch
|
||||
|
||||
from gns3server.compute.vpcs import VPCS
|
||||
from gns3server.compute.qemu import Qemu
|
||||
from gns3server.compute.node_error import NodeError
|
||||
from gns3server.compute.error import NodeError, ImageMissingError
|
||||
from gns3server.utils import force_unix_path
|
||||
|
||||
|
||||
@@ -165,8 +165,8 @@ def test_get_abs_image_additional_image_paths(qemu, tmpdir):
|
||||
# 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")
|
||||
with pytest.raises(ImageMissingError):
|
||||
qemu.get_abs_image_path("test4.bin")
|
||||
|
||||
|
||||
def test_get_abs_image_recursive(qemu, tmpdir):
|
||||
|
||||
Reference in new issue
Block a user