mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-13 20:08:55 +00:00
Fix tests checking the local flag
This commit is contained in:
parent
ea94731418
commit
74695efe90
@ -206,10 +206,10 @@ def test_close(vm, port_manager, loop):
|
|||||||
assert vm.is_running() is False
|
assert vm.is_running() is False
|
||||||
|
|
||||||
|
|
||||||
def test_path(vm, fake_iou_bin):
|
def test_path(vm, fake_iou_bin, config):
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
config.set_section_config("Server", {"local": True})
|
||||||
vm.path = fake_iou_bin
|
vm.path = fake_iou_bin
|
||||||
assert vm.path == fake_iou_bin
|
assert vm.path == fake_iou_bin
|
||||||
|
|
||||||
|
|
||||||
def test_path_relative(vm, fake_iou_bin, tmpdir):
|
def test_path_relative(vm, fake_iou_bin, tmpdir):
|
||||||
@ -218,17 +218,17 @@ def test_path_relative(vm, fake_iou_bin, tmpdir):
|
|||||||
assert vm.path == fake_iou_bin
|
assert vm.path == fake_iou_bin
|
||||||
|
|
||||||
|
|
||||||
def test_path_invalid_bin(vm, tmpdir):
|
def test_path_invalid_bin(vm, tmpdir, config):
|
||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
config.set_section_config("Server", {"local": True})
|
||||||
path = str(tmpdir / "test.bin")
|
path = str(tmpdir / "test.bin")
|
||||||
|
|
||||||
with open(path, "w+") as f:
|
with open(path, "w+") as f:
|
||||||
f.write("BUG")
|
f.write("BUG")
|
||||||
|
|
||||||
with pytest.raises(IOUError):
|
with pytest.raises(IOUError):
|
||||||
vm.path = path
|
vm.path = path
|
||||||
vm._check_requirements()
|
vm._check_requirements()
|
||||||
|
|
||||||
|
|
||||||
def test_create_netmap_config(vm):
|
def test_create_netmap_config(vm):
|
||||||
|
@ -88,7 +88,7 @@ def test_create_node_old_topology(loop, project, tmpdir, vpcs):
|
|||||||
assert f.read() == "1"
|
assert f.read() == "1"
|
||||||
|
|
||||||
|
|
||||||
def test_get_abs_image_path(qemu, tmpdir):
|
def test_get_abs_image_path(qemu, tmpdir, config):
|
||||||
os.makedirs(str(tmpdir / "QEMU"))
|
os.makedirs(str(tmpdir / "QEMU"))
|
||||||
path1 = force_unix_path(str(tmpdir / "test1.bin"))
|
path1 = force_unix_path(str(tmpdir / "test1.bin"))
|
||||||
open(path1, 'w+').close()
|
open(path1, 'w+').close()
|
||||||
@ -96,15 +96,15 @@ def test_get_abs_image_path(qemu, tmpdir):
|
|||||||
path2 = force_unix_path(str(tmpdir / "QEMU" / "test2.bin"))
|
path2 = force_unix_path(str(tmpdir / "QEMU" / "test2.bin"))
|
||||||
open(path2, 'w+').close()
|
open(path2, 'w+').close()
|
||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
|
config.set_section_config("Server", {"images_path": str(tmpdir)})
|
||||||
assert qemu.get_abs_image_path(path1) == path1
|
assert qemu.get_abs_image_path(path1) == path1
|
||||||
assert qemu.get_abs_image_path("test1.bin") == path1
|
assert qemu.get_abs_image_path("test1.bin") == path1
|
||||||
assert qemu.get_abs_image_path(path2) == path2
|
assert qemu.get_abs_image_path(path2) == path2
|
||||||
assert qemu.get_abs_image_path("test2.bin") == path2
|
assert qemu.get_abs_image_path("test2.bin") == path2
|
||||||
assert qemu.get_abs_image_path("../test1.bin") == path1
|
assert qemu.get_abs_image_path("../test1.bin") == path1
|
||||||
|
|
||||||
|
|
||||||
def test_get_abs_image_path_non_local(qemu, tmpdir):
|
def test_get_abs_image_path_non_local(qemu, tmpdir, config):
|
||||||
path1 = tmpdir / "images" / "QEMU" / "test1.bin"
|
path1 = tmpdir / "images" / "QEMU" / "test1.bin"
|
||||||
path1.write("1", ensure=True)
|
path1.write("1", ensure=True)
|
||||||
path1 = force_unix_path(str(path1))
|
path1 = force_unix_path(str(path1))
|
||||||
@ -114,18 +114,18 @@ def test_get_abs_image_path_non_local(qemu, tmpdir):
|
|||||||
path2 = force_unix_path(str(path2))
|
path2 = force_unix_path(str(path2))
|
||||||
|
|
||||||
# If non local we can't use path outside images directory
|
# If non local we can't use path outside images directory
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir / "images"), "local": False}):
|
config.set_section_config("Server", {"images_path": str(tmpdir / "images"), "local": False})
|
||||||
assert qemu.get_abs_image_path(path1) == path1
|
assert qemu.get_abs_image_path(path1) == path1
|
||||||
with pytest.raises(NodeError):
|
with pytest.raises(NodeError):
|
||||||
qemu.get_abs_image_path(path2)
|
qemu.get_abs_image_path(path2)
|
||||||
with pytest.raises(NodeError):
|
with pytest.raises(NodeError):
|
||||||
qemu.get_abs_image_path("C:\\test2.bin")
|
qemu.get_abs_image_path("C:\\test2.bin")
|
||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir / "images"), "local": True}):
|
config.set_section_config("Server", {"images_path": str(tmpdir / "images"), "local": True})
|
||||||
assert qemu.get_abs_image_path(path2) == path2
|
assert qemu.get_abs_image_path(path2) == path2
|
||||||
|
|
||||||
|
|
||||||
def test_get_abs_image_additional_image_paths(qemu, tmpdir):
|
def test_get_abs_image_additional_image_paths(qemu, tmpdir, config):
|
||||||
path1 = tmpdir / "images1" / "QEMU" / "test1.bin"
|
path1 = tmpdir / "images1" / "QEMU" / "test1.bin"
|
||||||
path1.write("1", ensure=True)
|
path1.write("1", ensure=True)
|
||||||
path1 = force_unix_path(str(path1))
|
path1 = force_unix_path(str(path1))
|
||||||
@ -134,20 +134,21 @@ def test_get_abs_image_additional_image_paths(qemu, tmpdir):
|
|||||||
path2.write("1", ensure=True)
|
path2.write("1", ensure=True)
|
||||||
path2 = force_unix_path(str(path2))
|
path2 = force_unix_path(str(path2))
|
||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={
|
config.set_section_config("Server", {
|
||||||
"images_path": str(tmpdir / "images1"),
|
"images_path": str(tmpdir / "images1"),
|
||||||
"additional_images_path": "/tmp/null24564;{}".format(str(tmpdir / "images2")),
|
"additional_images_path": "/tmp/null24564;{}".format(str(tmpdir / "images2")),
|
||||||
"local": False}):
|
"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
|
|
||||||
|
|
||||||
with pytest.raises(ImageMissingError):
|
assert qemu.get_abs_image_path("test1.bin") == path1
|
||||||
qemu.get_abs_image_path("test4.bin")
|
assert qemu.get_abs_image_path("test2.bin") == path2
|
||||||
|
# Absolute path
|
||||||
|
assert qemu.get_abs_image_path(str(path2)) == path2
|
||||||
|
|
||||||
|
with pytest.raises(ImageMissingError):
|
||||||
|
qemu.get_abs_image_path("test4.bin")
|
||||||
|
|
||||||
|
|
||||||
def test_get_abs_image_recursive(qemu, tmpdir):
|
def test_get_abs_image_recursive(qemu, tmpdir, config):
|
||||||
path1 = tmpdir / "images1" / "QEMU" / "demo" / "test1.bin"
|
path1 = tmpdir / "images1" / "QEMU" / "demo" / "test1.bin"
|
||||||
path1.write("1", ensure=True)
|
path1.write("1", ensure=True)
|
||||||
path1 = force_unix_path(str(path1))
|
path1 = force_unix_path(str(path1))
|
||||||
@ -156,16 +157,16 @@ def test_get_abs_image_recursive(qemu, tmpdir):
|
|||||||
path2.write("1", ensure=True)
|
path2.write("1", ensure=True)
|
||||||
path2 = force_unix_path(str(path2))
|
path2 = force_unix_path(str(path2))
|
||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={
|
config.set_section_config("Server", {
|
||||||
"images_path": str(tmpdir / "images1"),
|
"images_path": str(tmpdir / "images1"),
|
||||||
"local": False}):
|
"local": False})
|
||||||
assert qemu.get_abs_image_path("test1.bin") == path1
|
assert qemu.get_abs_image_path("test1.bin") == path1
|
||||||
assert qemu.get_abs_image_path("test2.bin") == path2
|
assert qemu.get_abs_image_path("test2.bin") == path2
|
||||||
# Absolute path
|
# Absolute path
|
||||||
assert qemu.get_abs_image_path(str(path1)) == path1
|
assert qemu.get_abs_image_path(str(path1)) == path1
|
||||||
|
|
||||||
|
|
||||||
def test_get_abs_image_recursive_ova(qemu, tmpdir):
|
def test_get_abs_image_recursive_ova(qemu, tmpdir, config):
|
||||||
path1 = tmpdir / "images1" / "QEMU" / "demo" / "test.ova" / "test1.bin"
|
path1 = tmpdir / "images1" / "QEMU" / "demo" / "test.ova" / "test1.bin"
|
||||||
path1.write("1", ensure=True)
|
path1.write("1", ensure=True)
|
||||||
path1 = force_unix_path(str(path1))
|
path1 = force_unix_path(str(path1))
|
||||||
@ -174,16 +175,16 @@ def test_get_abs_image_recursive_ova(qemu, tmpdir):
|
|||||||
path2.write("1", ensure=True)
|
path2.write("1", ensure=True)
|
||||||
path2 = force_unix_path(str(path2))
|
path2 = force_unix_path(str(path2))
|
||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={
|
config.set_section_config("Server", {
|
||||||
"images_path": str(tmpdir / "images1"),
|
"images_path": str(tmpdir / "images1"),
|
||||||
"local": False}):
|
"local": False})
|
||||||
assert qemu.get_abs_image_path("test.ova/test1.bin") == path1
|
assert qemu.get_abs_image_path("test.ova/test1.bin") == path1
|
||||||
assert qemu.get_abs_image_path("test.ova/test2.bin") == path2
|
assert qemu.get_abs_image_path("test.ova/test2.bin") == path2
|
||||||
# Absolute path
|
# Absolute path
|
||||||
assert qemu.get_abs_image_path(str(path1)) == path1
|
assert qemu.get_abs_image_path(str(path1)) == path1
|
||||||
|
|
||||||
|
|
||||||
def test_get_relative_image_path(qemu, tmpdir):
|
def test_get_relative_image_path(qemu, tmpdir, config):
|
||||||
os.makedirs(str(tmpdir / "images1" / "QEMU"))
|
os.makedirs(str(tmpdir / "images1" / "QEMU"))
|
||||||
path1 = force_unix_path(str(tmpdir / "images1" / "test1.bin"))
|
path1 = force_unix_path(str(tmpdir / "images1" / "test1.bin"))
|
||||||
open(path1, 'w+').close()
|
open(path1, 'w+').close()
|
||||||
@ -195,26 +196,28 @@ def test_get_relative_image_path(qemu, tmpdir):
|
|||||||
path3 = force_unix_path(str(tmpdir / "images2" / "test3.bin"))
|
path3 = force_unix_path(str(tmpdir / "images2" / "test3.bin"))
|
||||||
open(path3, 'w+').close()
|
open(path3, 'w+').close()
|
||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={
|
config.set_section_config("Server", {
|
||||||
"images_path": str(tmpdir / "images1"),
|
"images_path": str(tmpdir / "images1"),
|
||||||
"additional_images_path": str(tmpdir / "images2")
|
"additional_images_path": str(tmpdir / "images2")
|
||||||
}):
|
})
|
||||||
assert qemu.get_relative_image_path(path1) == "test1.bin"
|
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("test1.bin") == "test1.bin"
|
||||||
assert qemu.get_relative_image_path(path2) == "test2.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("test2.bin") == "test2.bin"
|
||||||
assert qemu.get_relative_image_path("../test1.bin") == "test1.bin"
|
assert qemu.get_relative_image_path("../test1.bin") == "test1.bin"
|
||||||
assert qemu.get_relative_image_path("test3.bin") == "test3.bin"
|
assert qemu.get_relative_image_path("test3.bin") == "test3.bin"
|
||||||
|
|
||||||
|
|
||||||
def test_get_relative_image_path_ova(qemu, tmpdir):
|
def test_get_relative_image_path_ova(qemu, tmpdir, config):
|
||||||
os.makedirs(str(tmpdir / "QEMU" / "test.ova"))
|
os.makedirs(str(tmpdir / "QEMU" / "test.ova"))
|
||||||
path = str(tmpdir / "QEMU" / "test.ova" / "test.bin")
|
path = str(tmpdir / "QEMU" / "test.ova" / "test.bin")
|
||||||
open(path, 'w+').close()
|
open(path, 'w+').close()
|
||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
|
config.set_section_config("Server", {
|
||||||
assert qemu.get_relative_image_path(path) == os.path.join("test.ova", "test.bin")
|
"images_path": str(tmpdir)
|
||||||
assert qemu.get_relative_image_path(os.path.join("test.ova", "test.bin")) == os.path.join("test.ova", "test.bin")
|
})
|
||||||
|
assert qemu.get_relative_image_path(path) == os.path.join("test.ova", "test.bin")
|
||||||
|
assert qemu.get_relative_image_path(os.path.join("test.ova", "test.bin")) == os.path.join("test.ova", "test.bin")
|
||||||
|
|
||||||
|
|
||||||
def test_list_images(loop, qemu, tmpdir):
|
def test_list_images(loop, qemu, tmpdir):
|
||||||
|
Loading…
Reference in New Issue
Block a user