1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 16:28:11 +00:00

Fix IOU tests.

This commit is contained in:
grossmj 2018-01-31 16:12:55 +07:00
parent e5c76750b1
commit 0ee87c9110
2 changed files with 17 additions and 20 deletions

View File

@ -19,7 +19,6 @@
import pytest
from unittest.mock import patch
import uuid
import os
import sys
pytestmark = pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
@ -40,18 +39,17 @@ def iou(port_manager):
return iou
def test_get_application_id(loop, project, iou):
def test_application_id(loop, project, iou):
vm1_id = str(uuid.uuid4())
vm2_id = str(uuid.uuid4())
vm3_id = str(uuid.uuid4())
loop.run_until_complete(iou.create_node("PC 1", project.id, vm1_id))
loop.run_until_complete(iou.create_node("PC 2", project.id, vm2_id))
assert iou.get_application_id(vm1_id) == 1
assert iou.get_application_id(vm1_id) == 1
assert iou.get_application_id(vm2_id) == 2
vm1 = loop.run_until_complete(iou.create_node("PC 1", project.id, vm1_id))
vm2 = loop.run_until_complete(iou.create_node("PC 2", project.id, vm2_id))
assert vm1.application_id == 1
assert vm2.application_id == 2
loop.run_until_complete(iou.delete_node(vm1_id))
loop.run_until_complete(iou.create_node("PC 3", project.id, vm3_id))
assert iou.get_application_id(vm3_id) == 1
vm3 = loop.run_until_complete(iou.create_node("PC 3", project.id, vm3_id))
assert vm3.application_id == 1
def test_get_application_id_multiple_project(loop, iou):
@ -60,20 +58,20 @@ def test_get_application_id_multiple_project(loop, iou):
vm3_id = str(uuid.uuid4())
project1 = ProjectManager.instance().create_project(project_id=str(uuid.uuid4()))
project2 = ProjectManager.instance().create_project(project_id=str(uuid.uuid4()))
loop.run_until_complete(iou.create_node("PC 1", project1.id, vm1_id))
loop.run_until_complete(iou.create_node("PC 2", project1.id, vm2_id))
loop.run_until_complete(iou.create_node("PC 2", project2.id, vm3_id))
assert iou.get_application_id(vm1_id) == 1
assert iou.get_application_id(vm2_id) == 2
assert iou.get_application_id(vm3_id) == 3
vm1 = loop.run_until_complete(iou.create_node("PC 1", project1.id, vm1_id))
vm2 = loop.run_until_complete(iou.create_node("PC 2", project1.id, vm2_id))
vm3 = loop.run_until_complete(iou.create_node("PC 2", project2.id, vm3_id))
assert vm1.application_id == 1
assert vm2.application_id == 2
assert vm3.application_id == 3
def test_get_application_id_no_id_available(loop, project, iou):
with pytest.raises(IOUError):
for i in range(1, 513):
node_id = str(uuid.uuid4())
loop.run_until_complete(iou.create_node("PC {}".format(i), project.id, node_id))
assert iou.get_application_id(node_id) == i
vm = loop.run_until_complete(iou.create_node("PC {}".format(i), project.id, node_id))
assert vm.application_id == i
def test_get_images_directory(iou, tmpdir):

View File

@ -48,7 +48,7 @@ def manager(port_manager):
@pytest.fixture(scope="function")
def vm(project, manager, tmpdir, fake_iou_bin, iourc_file):
vm = IOUVM("test", str(uuid.uuid4()), project, manager)
vm = IOUVM("test", str(uuid.uuid4()), project, manager, application_id=1)
config = manager.config.get_section_config("IOU")
config["iourc_path"] = iourc_file
manager.config.set_section_config("IOU", config)
@ -84,7 +84,7 @@ def test_vm(project, manager):
def test_vm_startup_config_content(project, manager):
vm = IOUVM("test", "00010203-0405-0607-0808-0a0b0c0d0e0f", project, manager)
vm = IOUVM("test", "00010203-0405-0607-0808-0a0b0c0d0e0f", project, manager, application_id=1)
vm.startup_config_content = "hostname %h"
assert vm.name == "test"
assert vm.startup_config_content == "hostname test"
@ -94,7 +94,6 @@ def test_vm_startup_config_content(project, manager):
def test_start(loop, vm):
mock_process = MagicMock()
vm._check_requirements = AsyncioMagicMock(return_value=True)
vm._check_iou_licence = AsyncioMagicMock(return_value=True)
vm._start_ubridge = AsyncioMagicMock(return_value=True)