mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
1 parent
4f1b738ef5
commit
9dc6f0f486
11 files changed
+432
-27
No files matched your search
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2016 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/>.
|
||||
|
||||
from gns3server.controller.appliance import Appliance
|
||||
|
||||
|
||||
def test_appliance_json():
|
||||
a = Appliance(None, {
|
||||
"node_type": "qemu",
|
||||
"name": "Test",
|
||||
"default_name_format": "{name}-{0}",
|
||||
"category": 0,
|
||||
"symbol": "qemu.svg",
|
||||
"server": "local"
|
||||
})
|
||||
assert a.__json__() == {
|
||||
"appliance_id": a.id,
|
||||
"node_type": "qemu",
|
||||
"builtin": False,
|
||||
"name": "Test",
|
||||
"default_name_format": "{name}-{0}",
|
||||
"category": "router",
|
||||
"symbol": "qemu.svg",
|
||||
"compute_id": "local"
|
||||
}
|
||||
@@ -53,7 +53,7 @@ def test_load_controller_settings(controller, controller_config_path, async_run)
|
||||
"compute_id": "test1"
|
||||
}
|
||||
]
|
||||
data["settings"] = {"IOU": True}
|
||||
data["settings"] = {"IOU": {"test": True}}
|
||||
data["gns3vm"] = {"vmname": "Test VM"}
|
||||
with open(controller_config_path, "w+") as f:
|
||||
json.dump(data, f)
|
||||
@@ -468,3 +468,23 @@ def test_load_base_files(controller, config, tmpdir):
|
||||
# Check is the file has not been overwrite
|
||||
with open(str(tmpdir / 'iou_l2_base_startup-config.txt')) as f:
|
||||
assert f.read() == 'test'
|
||||
|
||||
|
||||
def test_appliance_templates(controller, async_run):
|
||||
controller.load_appliances()
|
||||
assert len(controller.appliance_templates) > 0
|
||||
|
||||
|
||||
def test_load_appliances(controller):
|
||||
controller._settings = {
|
||||
"Qemu": {
|
||||
"vms": [
|
||||
{
|
||||
"name": "Test"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
controller.load_appliances()
|
||||
assert "Test" in [appliance.name for appliance in controller.appliances.values()]
|
||||
assert "Cloud" in [appliance.name for appliance in controller.appliances.values()]
|
||||
@@ -18,17 +18,15 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
import uuid
|
||||
import json
|
||||
import pytest
|
||||
import aiohttp
|
||||
import zipfile
|
||||
from unittest.mock import MagicMock
|
||||
from tests.utils import AsyncioMagicMock, asyncio_patch
|
||||
from unittest.mock import patch
|
||||
from uuid import uuid4
|
||||
|
||||
from gns3server.controller.project import Project
|
||||
from gns3server.controller.appliance import Appliance
|
||||
from gns3server.controller.ports.ethernet_port import EthernetPort
|
||||
from gns3server.config import Config
|
||||
|
||||
@@ -182,6 +180,42 @@ def test_add_node_non_local(async_run, controller):
|
||||
controller.notification.emit.assert_any_call("node.created", node.__json__())
|
||||
|
||||
|
||||
def test_add_node_from_appliance(async_run, controller):
|
||||
"""
|
||||
For a local server we send the project path
|
||||
"""
|
||||
compute = MagicMock()
|
||||
compute.id = "local"
|
||||
project = Project(controller=controller, name="Test")
|
||||
controller._notification = MagicMock()
|
||||
controller._appliances["fakeid"] = Appliance("fakeid", {
|
||||
"server": "local",
|
||||
"name": "Test",
|
||||
"default_name_format": "{name}-{0}",
|
||||
"node_type": "vpcs"
|
||||
|
||||
})
|
||||
controller._computes["local"] = compute
|
||||
|
||||
response = MagicMock()
|
||||
response.json = {"console": 2048}
|
||||
compute.post = AsyncioMagicMock(return_value=response)
|
||||
|
||||
node = async_run(project.add_node_from_appliance("fakeid", x=23, y=12))
|
||||
|
||||
compute.post.assert_any_call('/projects', data={
|
||||
"name": project._name,
|
||||
"project_id": project._id,
|
||||
"path": project._path
|
||||
})
|
||||
compute.post.assert_any_call('/projects/{}/vpcs/nodes'.format(project.id),
|
||||
data={'node_id': node.id,
|
||||
'name': 'Test-1'},
|
||||
timeout=120)
|
||||
assert compute in project._project_created_on_compute
|
||||
controller.notification.emit.assert_any_call("node.created", node.__json__())
|
||||
|
||||
|
||||
def test_create_iou_on_multiple_node(async_run, controller):
|
||||
"""
|
||||
Due to mac address collision you can't create an IOU node
|
||||
|
||||
Reference in new issue
Block a user