Merge 2.1 into 2.2 branch

This commit is contained in:
grossmj committed 2018-03-12 13:38:50 +07:00
1 parent 2a5f3221b9
commit 658aa4bae9
69 files changed
+846 -448

No files matched your search

+15 -17
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):
+3 -4
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)
@@ -440,7 +439,7 @@ def test_application_id(project, manager):
"""
Checks if uses local manager to get application_id when not set
"""
vm = IOUVM("test", str(uuid.uuid4()), project, manager)
vm = IOUVM("test", str(uuid.uuid4()), project, manager, application_id=1)
assert vm.application_id == 1
vm.application_id = 3
@@ -1,38 +0,0 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017 GNS3 Technologies Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
from unittest.mock import MagicMock
from gns3server.compute.iou.utils.application_id import get_next_application_id, IOUError
def test_get_next_application_id():
# test first node
assert get_next_application_id([]) == 1
# test second node
nodes = [
MagicMock(node_type='different'),
MagicMock(node_type='iou', properties=dict(application_id=1))
]
assert get_next_application_id(nodes) == 2
# test reach out the limit
nodes = [MagicMock(node_type='iou', properties=dict(application_id=i)) for i in range(1, 512)]
with pytest.raises(IOUError):
get_next_application_id(nodes)
+49 -1
View File
@@ -510,7 +510,9 @@ def test_load_appliances(controller):
"Qemu": {
"vms": [
{
"name": "Test"
"name": "Test",
"node_type": "qemu",
"category": "router"
}
]
}
@@ -538,6 +540,52 @@ def test_load_appliances(controller):
assert cloud_uuid == appliance.id
def test_load_appliances_deprecated_features_default_symbol(controller):
controller._settings = {
"Qemu": {
"vms": [
{
"name": "Test",
"node_type": "qemu",
"category": "router",
"default_symbol": ":/symbols/iosv_virl.normal.svg",
"hover_symbol": ":/symbols/iosv_virl.selected.svg",
}
]
}
}
controller.load_appliances()
appliances = dict([(a.name, a) for a in controller.appliances.values()])
assert appliances["Test"].__json__()["symbol"] == ":/symbols/computer.svg"
assert "default_symbol" not in appliances["Test"].data.keys()
assert "hover_symbol" not in appliances["Test"].data.keys()
def test_load_appliances_deprecated_features_default_symbol_with_symbol(controller):
controller._settings = {
"Qemu": {
"vms": [
{
"name": "Test",
"node_type": "qemu",
"category": "router",
"default_symbol": ":/symbols/iosv_virl.normal.svg",
"hover_symbol": ":/symbols/iosv_virl.selected.svg",
"symbol": ":/symbols/my-symbol.svg"
}
]
}
}
controller.load_appliances()
appliances = dict([(a.name, a) for a in controller.appliances.values()])
assert appliances["Test"].__json__()["symbol"] == ":/symbols/my-symbol.svg"
assert "default_symbol" not in appliances["Test"].data.keys()
assert "hover_symbol" not in appliances["Test"].data.keys()
def test_autoidlepc(controller, async_run):
controller._computes["local"] = AsyncioMagicMock()
node_mock = AsyncioMagicMock()
+2 -2
View File
@@ -517,8 +517,8 @@ def test_get_port(node):
assert port.port_number == 0
port = node.get_port(1, 0)
assert port.adapter_number == 1
with pytest.raises(aiohttp.web.HTTPNotFound):
port = node.get_port(42, 0)
port = node.get_port(42, 0)
assert port is None
def test_parse_node_response(node, async_run):
-21
View File
@@ -646,27 +646,6 @@ def test_node_name(project, async_run):
assert node.name == "R3"
def test_add_iou_node_and_check_if_gets_application_id(project, async_run):
compute = MagicMock()
compute.id = "local"
response = MagicMock()
response.json = {"console": 2048}
compute.post = AsyncioMagicMock(return_value=response)
# tests if get_next_application_id is called
with patch('gns3server.controller.project.get_next_application_id', return_value=222) as mocked_get_app_id:
node = async_run(project.add_node(
compute, "test", None, node_type="iou", properties={"startup_config": "test.cfg"}))
assert mocked_get_app_id.called
assert node.properties['application_id'] == 222
# tests if we can send property and it will be used
node = async_run(project.add_node(
compute, "test", None, node_type="iou", application_id=333, properties={"startup_config": "test.cfg"}))
assert mocked_get_app_id.called
assert node.properties['application_id'] == 333
def test_duplicate_node(project, async_run):
compute = MagicMock()
compute.id = "local"