Rewrote image search

This code is more generic and support all cases. Previously
we had bug where the user lost his image path if the image
was not located in image directory.
This commit is contained in:
Julien Duponchelle committed 2015-04-14 18:46:55 +02:00
1 parent e51a129216
commit aa2472fb30
9 files changed
+124 -70

No files matched your search

+16
View File
@@ -17,7 +17,9 @@
import pytest
from unittest.mock import patch
import uuid
import os
from gns3server.modules.iou import IOU
@@ -25,6 +27,15 @@ from gns3server.modules.iou.iou_error import IOUError
from gns3server.modules.project_manager import ProjectManager
@pytest.fixture(scope="function")
def iou(port_manager):
# Cleanup the IOU object
IOU._instance = None
iou = IOU.instance()
iou.port_manager = port_manager
return iou
def test_get_application_id(loop, project, port_manager):
# Cleanup the IOU object
IOU._instance = None
@@ -71,3 +82,8 @@ def test_get_application_id_no_id_available(loop, project, port_manager):
vm_id = str(uuid.uuid4())
loop.run_until_complete(iou.create_vm("PC {}".format(i), project.id, vm_id))
assert iou.get_application_id(vm_id) == i
def test_get_images_directory(iou, tmpdir):
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
assert iou.get_images_directory() == str(tmpdir / "IOU")
+31
View File
@@ -22,6 +22,7 @@ from unittest.mock import patch
from gns3server.modules.vpcs import VPCS
from gns3server.modules.iou import IOU
def test_create_vm_new_topology(loop, project, port_manager):
@@ -82,3 +83,33 @@ def test_create_vm_old_topology(loop, project, tmpdir, port_manager):
vm_dir = os.path.join(project_dir, "project-files", "vpcs", vm.id)
with open(os.path.join(vm_dir, "startup.vpc")) as f:
assert f.read() == "1"
def test_get_abs_image_path(iou, tmpdir):
os.makedirs(str(tmpdir / "IOU"))
path1 = str(tmpdir / "test1.bin")
open(path1, 'w+').close()
path2 = str(tmpdir / "IOU" / "test2.bin")
open(path2, 'w+').close()
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
assert iou.get_abs_image_path(path1) == path1
assert iou.get_abs_image_path(path2) == path2
assert iou.get_abs_image_path("test2.bin") == path2
assert iou.get_abs_image_path("../test1.bin") == path1
def test_get_relative_image_path(iou, tmpdir):
os.makedirs(str(tmpdir / "IOU"))
path1 = str(tmpdir / "test1.bin")
open(path1, 'w+').close()
path2 = str(tmpdir / "IOU" / "test2.bin")
open(path2, 'w+').close()
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
assert iou.get_relative_image_path(path1) == path1
assert iou.get_relative_image_path(path2) == "test2.bin"
assert iou.get_relative_image_path("test2.bin") == "test2.bin"
assert iou.get_relative_image_path("../test1.bin") == path1