Use "template" to name what we use to create new nodes.

This commit is contained in:
grossmj committed 2018-11-28 16:12:58 +07:00
1 parent 21c0a35f77
commit d7c2e16c21
262 files changed
+16588 -16863

No files matched your search

+25 -25
View File
@@ -466,7 +466,7 @@ def test_load_base_files(controller, config, tmpdir):
assert f.read() == 'test'
def test_appliance_templates(controller, async_run, tmpdir):
def test_appliances(controller, async_run, tmpdir):
my_appliance = {
"name": "My Appliance",
"status": "stable"
@@ -481,14 +481,14 @@ def test_appliance_templates(controller, async_run, tmpdir):
json.dump(my_appliance, f)
with patch("gns3server.config.Config.get_section_config", return_value={"appliances_path": str(tmpdir)}):
controller.load_appliance_templates()
assert len(controller.appliance_templates) > 0
for appliance in controller.appliance_templates.values():
controller.load_appliances()
assert len(controller.appliances) > 0
for appliance in controller.appliances.values():
assert appliance.__json__()["status"] != "broken"
assert "Alpine Linux" in [c.__json__()["name"] for c in controller.appliance_templates.values()]
assert "My Appliance" in [c.__json__()["name"] for c in controller.appliance_templates.values()]
assert "Alpine Linux" in [c.__json__()["name"] for c in controller.appliances.values()]
assert "My Appliance" in [c.__json__()["name"] for c in controller.appliances.values()]
for c in controller.appliance_templates.values():
for c in controller.appliances.values():
j = c.__json__()
if j["name"] == "Alpine Linux":
assert j["builtin"]
@@ -496,29 +496,29 @@ def test_appliance_templates(controller, async_run, tmpdir):
assert not j["builtin"]
def test_load_appliances(controller):
def test_load_templates(controller):
controller._settings = {}
controller.load_appliances()
controller.load_templates()
assert "Cloud" in [appliance.name for appliance in controller.appliances.values()]
assert "VPCS" in [appliance.name for appliance in controller.appliances.values()]
assert "Cloud" in [template.name for template in controller.templates.values()]
assert "VPCS" in [template.name for template in controller.templates.values()]
for appliance in controller.appliances.values():
if appliance.name == "VPCS":
assert appliance._settings["properties"] == {"base_script_file": "vpcs_base_config.txt"}
for template in controller.templates.values():
if template.name == "VPCS":
assert template._settings["properties"] == {"base_script_file": "vpcs_base_config.txt"}
# UUID should not change when you run again the function
for appliance in controller.appliances.values():
if appliance.name == "Test":
qemu_uuid = appliance.id
elif appliance.name == "Cloud":
cloud_uuid = appliance.id
controller.load_appliances()
for appliance in controller.appliances.values():
if appliance.name == "Test":
assert qemu_uuid == appliance.id
elif appliance.name == "Cloud":
assert cloud_uuid == appliance.id
for template in controller.templates.values():
if template.name == "Test":
qemu_uuid = template.id
elif template.name == "Cloud":
cloud_uuid = template.id
controller.load_templates()
for template in controller.templates.values():
if template.name == "Test":
assert qemu_uuid == template.id
elif template.name == "Cloud":
assert cloud_uuid == template.id
def test_autoidlepc(controller, async_run):
+2 -2
View File
@@ -122,7 +122,7 @@ def test_json(node, compute):
"compute_id": str(compute.id),
"project_id": node.project.id,
"node_id": node.id,
"appliance_id": None,
"template_id": None,
"node_type": node.node_type,
"name": "demo",
"console": node.console,
@@ -158,7 +158,7 @@ def test_json(node, compute):
assert node.__json__(topology_dump=True) == {
"compute_id": str(compute.id),
"node_id": node.id,
"appliance_id": None,
"template_id": None,
"node_type": node.node_type,
"name": "demo",
"console": node.console,
+6 -6
View File
@@ -28,7 +28,7 @@ from unittest.mock import patch
from uuid import uuid4
from gns3server.controller.project import Project
from gns3server.controller.appliance import Appliance
from gns3server.controller.template import Template
from gns3server.controller.ports.ethernet_port import EthernetPort
from gns3server.config import Config
@@ -205,7 +205,7 @@ def test_add_node_non_local(async_run, controller):
controller.notification.project_emit.assert_any_call("node.created", node.__json__())
def test_add_node_from_appliance(async_run, controller):
def test_add_node_from_template(async_run, controller):
"""
For a local server we send the project path
"""
@@ -213,20 +213,20 @@ def test_add_node_from_appliance(async_run, controller):
compute.id = "local"
project = Project(controller=controller, name="Test")
controller._notification = MagicMock()
appliance = Appliance(str(uuid.uuid4()), {
template = Template(str(uuid.uuid4()), {
"compute_id": "local",
"name": "Test",
"appliance_type": "vpcs",
"template_type": "vpcs",
"builtin": False,
})
controller._appliances[appliance.id] = appliance
controller._templates[template.id] = template
controller._computes["local"] = compute
response = MagicMock()
response.json = {"console": 2048}
compute.post = AsyncioMagicMock(return_value=response)
node = async_run(project.add_node_from_appliance(appliance.id, x=23, y=12))
node = async_run(project.add_node_from_template(template.id, x=23, y=12))
compute.post.assert_any_call('/projects', data={
"name": project._name,
"project_id": project._id,
@@ -18,11 +18,11 @@
import pytest
import jsonschema
from gns3server.controller.appliance import Appliance
from gns3server.controller.template import Template
def test_appliance_json():
a = Appliance(None, {
def test_template_json():
a = Template(None, {
"node_type": "qemu",
"name": "Test",
"default_name_format": "{name}-{0}",
@@ -32,14 +32,14 @@ def test_appliance_json():
"platform": "i386"
})
settings = a.__json__()
assert settings["appliance_id"] == a.id
assert settings["appliance_type"] == "qemu"
assert settings["template_id"] == a.id
assert settings["template_type"] == "qemu"
assert settings["builtin"] == False
def test_appliance_json_with_not_known_category():
def test_template_json_with_not_known_category():
with pytest.raises(jsonschema.ValidationError):
a = Appliance(None, {
a = Template(None, {
"node_type": "qemu",
"name": "Test",
"default_name_format": "{name}-{0}",
@@ -50,8 +50,8 @@ def test_appliance_json_with_not_known_category():
})
def test_appliance_json_with_platform():
a = Appliance(None, {
def test_template_json_with_platform():
a = Template(None, {
"node_type": "dynamips",
"name": "Test",
"default_name_format": "{name}-{0}",
@@ -62,18 +62,18 @@ def test_appliance_json_with_platform():
"platform": "c3725"
})
settings = a.__json__()
assert settings["appliance_id"] == a.id
assert settings["appliance_type"] == "dynamips"
assert settings["template_id"] == a.id
assert settings["template_type"] == "dynamips"
assert settings["builtin"] == False
assert settings["platform"] == "c3725"
def test_appliance_fix_linked_base():
def test_template_fix_linked_base():
"""
Version of the gui before 2.1 use linked_base and the server
linked_clone
"""
a = Appliance(None, {
a = Template(None, {
"node_type": "qemu",
"name": "Test",
"default_name_format": "{name}-{0}",
+1 -965
View File
@@ -16,973 +16,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import uuid
import pytest
from unittest.mock import MagicMock
from tests.utils import asyncio_patch
def test_appliances_list(http_controller, controller, async_run):
from gns3server.controller import Controller
from gns3server.controller.appliance import Appliance
@pytest.fixture
def compute(http_controller, async_run):
compute = MagicMock()
compute.id = "example.com"
compute.host = "example.org"
Controller.instance()._computes = {"example.com": compute}
return compute
@pytest.fixture
def project(http_controller, async_run):
return async_run(Controller.instance().add_project(name="Test"))
def test_appliance_list(http_controller, controller):
id = str(uuid.uuid4())
controller.load_appliances()
controller._appliances[id] = Appliance(id, {
"appliance_type": "qemu",
"category": 0,
"name": "test",
"symbol": "guest.svg",
"default_name_format": "{name}-{0}",
"compute_id": "local"
})
response = http_controller.get("/appliances", example=True)
assert response.status == 200
assert response.route == "/appliances"
assert len(response.json) > 0
def test_appliance_templates_list(http_controller, controller, async_run):
controller.load_appliance_templates()
response = http_controller.get("/appliances/templates", example=True)
assert response.status == 200
assert len(response.json) > 0
def test_cr(http_controller, controller, async_run):
controller.load_appliance_templates()
response = http_controller.get("/appliances/templates", example=True)
assert response.status == 200
assert len(response.json) > 0
def test_appliance_create_without_id(http_controller, controller):
params = {"base_script_file": "vpcs_base_config.txt",
"category": "guest",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS_TEST",
"compute_id": "local",
"symbol": ":/symbols/vpcs_guest.svg",
"appliance_type": "vpcs"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.route == "/appliances"
assert response.json["appliance_id"] is not None
assert len(controller.appliances) == 1
def test_appliance_create_with_id(http_controller, controller):
params = {"appliance_id": str(uuid.uuid4()),
"base_script_file": "vpcs_base_config.txt",
"category": "guest",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS_TEST",
"compute_id": "local",
"symbol": ":/symbols/vpcs_guest.svg",
"appliance_type": "vpcs"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.route == "/appliances"
assert response.json["appliance_id"] is not None
assert len(controller.appliances) == 1
def test_appliance_create_wrong_type(http_controller, controller):
params = {"appliance_id": str(uuid.uuid4()),
"base_script_file": "vpcs_base_config.txt",
"category": "guest",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS_TEST",
"compute_id": "local",
"symbol": ":/symbols/vpcs_guest.svg",
"appliance_type": "invalid_appliance_type"}
response = http_controller.post("/appliances", params)
assert response.status == 400
assert len(controller.appliances) == 0
def test_appliance_get(http_controller, controller):
appliance_id = str(uuid.uuid4())
params = {"appliance_id": appliance_id,
"base_script_file": "vpcs_base_config.txt",
"category": "guest",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS_TEST",
"compute_id": "local",
"symbol": ":/symbols/vpcs_guest.svg",
"appliance_type": "vpcs"}
response = http_controller.post("/appliances", params)
assert response.status == 201
response = http_controller.get("/appliances/{}".format(appliance_id), example=True)
assert response.status == 200
assert response.json["appliance_id"] == appliance_id
def test_appliance_update(http_controller, controller):
appliance_id = str(uuid.uuid4())
params = {"appliance_id": appliance_id,
"base_script_file": "vpcs_base_config.txt",
"category": "guest",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS_TEST",
"compute_id": "local",
"symbol": ":/symbols/vpcs_guest.svg",
"appliance_type": "vpcs"}
response = http_controller.post("/appliances", params)
assert response.status == 201
response = http_controller.get("/appliances/{}".format(appliance_id))
assert response.status == 200
assert response.json["appliance_id"] == appliance_id
params["name"] = "VPCS_TEST_RENAMED"
response = http_controller.put("/appliances/{}".format(appliance_id), params, example=True)
assert response.status == 200
assert response.json["name"] == "VPCS_TEST_RENAMED"
def test_appliance_delete(http_controller, controller):
appliance_id = str(uuid.uuid4())
params = {"appliance_id": appliance_id,
"base_script_file": "vpcs_base_config.txt",
"category": "guest",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS_TEST",
"compute_id": "local",
"symbol": ":/symbols/vpcs_guest.svg",
"appliance_type": "vpcs"}
response = http_controller.post("/appliances", params)
assert response.status == 201
response = http_controller.get("/appliances")
assert len(response.json) == 1
assert len(controller.appliances) == 1
response = http_controller.delete("/appliances/{}".format(appliance_id), example=True)
assert response.status == 204
response = http_controller.get("/appliances")
assert len(response.json) == 0
assert len(controller.appliances) == 0
def test_appliance_duplicate(http_controller, controller):
appliance_id = str(uuid.uuid4())
params = {"appliance_id": appliance_id,
"base_script_file": "vpcs_base_config.txt",
"category": "guest",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS_TEST",
"compute_id": "local",
"symbol": ":/symbols/vpcs_guest.svg",
"appliance_type": "vpcs"}
response = http_controller.post("/appliances", params)
assert response.status == 201
response = http_controller.post("/appliances/{}/duplicate".format(appliance_id), example=True)
assert response.status == 201
assert response.json["appliance_id"] != appliance_id
params.pop("appliance_id")
for param, value in params.items():
assert response.json[param] == value
response = http_controller.get("/appliances")
assert len(response.json) == 2
assert len(controller.appliances) == 2
def test_c7200_dynamips_appliance_create(http_controller):
params = {"name": "Cisco c7200 appliance",
"platform": "c7200",
"compute_id": "local",
"image": "c7200-adventerprisek9-mz.124-24.T5.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c7200-adventerprisek9-mz.124-24.T5.image",
"mac_addr": "",
"midplane": "vxr",
"mmap": True,
"name": "Cisco c7200 appliance",
"npe": "npe-400",
"nvram": 512,
"platform": "c7200",
"private_config": "",
"ram": 512,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c3745_dynamips_appliance_create(http_controller):
params = {"name": "Cisco c3745 appliance",
"platform": "c3745",
"compute_id": "local",
"image": "c3745-adventerprisek9-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c3745-adventerprisek9-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c3745 appliance",
"iomem": 5,
"nvram": 256,
"platform": "c3745",
"private_config": "",
"ram": 256,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c3725_dynamips_appliance_create(http_controller):
params = {"name": "Cisco c3725 appliance",
"platform": "c3725",
"compute_id": "local",
"image": "c3725-adventerprisek9-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c3725-adventerprisek9-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c3725 appliance",
"iomem": 5,
"nvram": 256,
"platform": "c3725",
"private_config": "",
"ram": 128,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c3600_dynamips_appliance_create(http_controller):
params = {"name": "Cisco c3600 appliance",
"platform": "c3600",
"chassis": "3660",
"compute_id": "local",
"image": "c3660-a3jk9s-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c3660-a3jk9s-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c3600 appliance",
"iomem": 5,
"nvram": 128,
"platform": "c3600",
"chassis": "3660",
"private_config": "",
"ram": 192,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c3600_dynamips_appliance_create_wrong_chassis(http_controller):
params = {"name": "Cisco c3600 appliance",
"platform": "c3600",
"chassis": "3650",
"compute_id": "local",
"image": "c3660-a3jk9s-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 400
def test_c2691_dynamips_appliance_create(http_controller):
params = {"name": "Cisco c2691 appliance",
"platform": "c2691",
"compute_id": "local",
"image": "c2691-adventerprisek9-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c2691-adventerprisek9-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c2691 appliance",
"iomem": 5,
"nvram": 256,
"platform": "c2691",
"private_config": "",
"ram": 192,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c2600_dynamips_appliance_create(http_controller):
params = {"name": "Cisco c2600 appliance",
"platform": "c2600",
"chassis": "2651XM",
"compute_id": "local",
"image": "c2600-adventerprisek9-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c2600-adventerprisek9-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c2600 appliance",
"iomem": 15,
"nvram": 128,
"platform": "c2600",
"chassis": "2651XM",
"private_config": "",
"ram": 160,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c2600_dynamips_appliance_create_wrong_chassis(http_controller):
params = {"name": "Cisco c2600 appliance",
"platform": "c2600",
"chassis": "2660XM",
"compute_id": "local",
"image": "c2600-adventerprisek9-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 400
def test_c1700_dynamips_appliance_create(http_controller):
params = {"name": "Cisco c1700 appliance",
"platform": "c1700",
"chassis": "1760",
"compute_id": "local",
"image": "c1700-adventerprisek9-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c1700-adventerprisek9-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c1700 appliance",
"iomem": 15,
"nvram": 128,
"platform": "c1700",
"chassis": "1760",
"private_config": "",
"ram": 160,
"sparsemem": False,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c1700_dynamips_appliance_create_wrong_chassis(http_controller):
params = {"name": "Cisco c1700 appliance",
"platform": "c1700",
"chassis": "1770",
"compute_id": "local",
"image": "c1700-adventerprisek9-mz.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 400
def test_dynamips_appliance_create_wrong_platform(http_controller):
params = {"name": "Cisco c3900 appliance",
"platform": "c3900",
"compute_id": "local",
"image": "c3900-test.124-25d.image",
"appliance_type": "dynamips"}
response = http_controller.post("/appliances", params)
assert response.status == 400
def test_iou_appliance_create(http_controller):
params = {"name": "IOU appliance",
"compute_id": "local",
"path": "/path/to/i86bi_linux-ipbase-ms-12.4.bin",
"appliance_type": "iou"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "iou",
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "IOU{0}",
"ethernet_adapters": 2,
"name": "IOU appliance",
"nvram": 128,
"path": "/path/to/i86bi_linux-ipbase-ms-12.4.bin",
"private_config": "",
"ram": 256,
"serial_adapters": 2,
"startup_config": "iou_l3_base_startup-config.txt",
"symbol": ":/symbols/multilayer_switch.svg",
"use_default_iou_values": True,
"l1_keepalives": False}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_docker_appliance_create(http_controller):
params = {"name": "Docker appliance",
"compute_id": "local",
"image": "gns3/endhost:latest",
"appliance_type": "docker"}
response = http_controller.post("/appliances", params)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"adapters": 1,
"appliance_type": "docker",
"builtin": False,
"category": "guest",
"compute_id": "local",
"console_auto_start": False,
"console_http_path": "/",
"console_http_port": 80,
"console_resolution": "1024x768",
"console_type": "telnet",
"default_name_format": "{name}-{0}",
"environment": "",
"extra_hosts": "",
"image": "gns3/endhost:latest",
"name": "Docker appliance",
"start_command": "",
"symbol": ":/symbols/docker_guest.svg",
"custom_adapters": []}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_qemu_appliance_create(http_controller):
params = {"name": "Qemu appliance",
"compute_id": "local",
"platform": "i386",
"hda_disk_image": "IOSvL2-15.2.4.0.55E.qcow2",
"ram": 512,
"appliance_type": "qemu"}
response = http_controller.post("/appliances", params, example=True)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"adapter_type": "e1000",
"adapters": 1,
"appliance_type": "qemu",
"bios_image": "",
"boot_priority": "c",
"builtin": False,
"category": "guest",
"cdrom_image": "",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"cpu_throttling": 0,
"cpus": 1,
"default_name_format": "{name}-{0}",
"first_port_name": "",
"hda_disk_image": "IOSvL2-15.2.4.0.55E.qcow2",
"hda_disk_interface": "ide",
"hdb_disk_image": "",
"hdb_disk_interface": "ide",
"hdc_disk_image": "",
"hdc_disk_interface": "ide",
"hdd_disk_image": "",
"hdd_disk_interface": "ide",
"initrd": "",
"kernel_command_line": "",
"kernel_image": "",
"legacy_networking": False,
"linked_clone": True,
"mac_address": "",
"name": "Qemu appliance",
"on_close": "power_off",
"options": "",
"platform": "i386",
"port_name_format": "Ethernet{0}",
"port_segment_size": 0,
"process_priority": "normal",
"qemu_path": "",
"ram": 512,
"symbol": ":/symbols/qemu_guest.svg",
"usage": "",
"custom_adapters": []}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_vmware_appliance_create(http_controller):
params = {"name": "VMware appliance",
"compute_id": "local",
"appliance_type": "vmware",
"vmx_path": "/path/to/vm.vmx"}
response = http_controller.post("/appliances", params)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"adapter_type": "e1000",
"adapters": 1,
"appliance_type": "vmware",
"builtin": False,
"category": "guest",
"compute_id": "local",
"console_auto_start": False,
"console_type": "none",
"default_name_format": "{name}-{0}",
"first_port_name": "",
"headless": False,
"linked_clone": False,
"name": "VMware appliance",
"on_close": "power_off",
"port_name_format": "Ethernet{0}",
"port_segment_size": 0,
"symbol": ":/symbols/vmware_guest.svg",
"use_any_adapter": False,
"vmx_path": "/path/to/vm.vmx",
"custom_adapters": []}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_virtualbox_appliance_create(http_controller):
params = {"name": "VirtualBox appliance",
"compute_id": "local",
"appliance_type": "virtualbox",
"vmname": "My VirtualBox VM"}
response = http_controller.post("/appliances", params)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"adapter_type": "Intel PRO/1000 MT Desktop (82540EM)",
"adapters": 1,
"appliance_type": "virtualbox",
"builtin": False,
"category": "guest",
"compute_id": "local",
"console_auto_start": False,
"console_type": "none",
"default_name_format": "{name}-{0}",
"first_port_name": "",
"headless": False,
"linked_clone": False,
"name": "VirtualBox appliance",
"on_close": "power_off",
"port_name_format": "Ethernet{0}",
"port_segment_size": 0,
"ram": 256,
"symbol": ":/symbols/vbox_guest.svg",
"use_any_adapter": False,
"vmname": "My VirtualBox VM",
"custom_adapters": []}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_vpcs_appliance_create(http_controller):
params = {"name": "VPCS appliance",
"compute_id": "local",
"appliance_type": "vpcs"}
response = http_controller.post("/appliances", params)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "vpcs",
"base_script_file": "vpcs_base_config.txt",
"builtin": False,
"category": "guest",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS appliance",
"symbol": ":/symbols/vpcs_guest.svg"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_ethernet_switch_appliance_create(http_controller):
params = {"name": "Ethernet switch appliance",
"compute_id": "local",
"appliance_type": "ethernet_switch"}
response = http_controller.post("/appliances", params)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "ethernet_switch",
"builtin": False,
"category": "switch",
"compute_id": "local",
"console_type": "telnet",
"default_name_format": "Switch{0}",
"name": "Ethernet switch appliance",
"ports_mapping": [{"ethertype": "",
"name": "Ethernet0",
"port_number": 0,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet1",
"port_number": 1,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet2",
"port_number": 2,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet3",
"port_number": 3,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet4",
"port_number": 4,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet5",
"port_number": 5,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet6",
"port_number": 6,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet7",
"port_number": 7,
"type": "access",
"vlan": 1
}],
"symbol": ":/symbols/ethernet_switch.svg"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_cloud_appliance_create(http_controller):
params = {"name": "Cloud appliance",
"compute_id": "local",
"appliance_type": "cloud"}
response = http_controller.post("/appliances", params)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"appliance_type": "cloud",
"builtin": False,
"category": "guest",
"compute_id": "local",
"default_name_format": "Cloud{0}",
"name": "Cloud appliance",
"symbol": ":/symbols/cloud.svg"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_ethernet_hub_appliance_create(http_controller):
params = {"name": "Ethernet hub appliance",
"compute_id": "local",
"appliance_type": "ethernet_hub"}
response = http_controller.post("/appliances", params)
assert response.status == 201
assert response.json["appliance_id"] is not None
expected_response = {"ports_mapping": [{"port_number": 0,
"name": "Ethernet0"
},
{"port_number": 1,
"name": "Ethernet1"
},
{"port_number": 2,
"name": "Ethernet2"
},
{"port_number": 3,
"name": "Ethernet3"
},
{"port_number": 4,
"name": "Ethernet4"
},
{"port_number": 5,
"name": "Ethernet5"
},
{"port_number": 6,
"name": "Ethernet6"
},
{"port_number": 7,
"name": "Ethernet7"
}],
"compute_id": "local",
"name": "Ethernet hub appliance",
"symbol": ":/symbols/hub.svg",
"default_name_format": "Hub{0}",
"appliance_type": "ethernet_hub",
"category": "switch",
"builtin": False}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_create_node_from_appliance(http_controller, controller, project, compute):
id = str(uuid.uuid4())
controller._appliances = {id: Appliance(id, {
"appliance_type": "qemu",
"category": 0,
"name": "test",
"symbol": "guest.svg",
"default_name_format": "{name}-{0}",
"compute_id": "example.com"
})}
with asyncio_patch("gns3server.controller.project.Project.add_node_from_appliance") as mock:
response = http_controller.post("/projects/{}/appliances/{}".format(project.id, id), {
"x": 42,
"y": 12
})
mock.assert_called_with(id, x=42, y=12, compute_id=None)
assert response.route == "/projects/{project_id}/appliances/{appliance_id}"
assert response.status == 201
@@ -0,0 +1,971 @@
#!/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/>.
import uuid
import pytest
from unittest.mock import MagicMock
from tests.utils import asyncio_patch
from gns3server.controller import Controller
from gns3server.controller.template import Template
def test_template_list(http_controller, controller):
id = str(uuid.uuid4())
controller.load_templates()
controller._templates[id] = Template(id, {
"template_type": "qemu",
"category": 0,
"name": "test",
"symbol": "guest.svg",
"default_name_format": "{name}-{0}",
"compute_id": "local"
})
response = http_controller.get("/templates", example=True)
assert response.status == 200
assert response.route == "/templates"
assert len(response.json) > 0
def test_template_create_without_id(http_controller, controller):
params = {"base_script_file": "vpcs_base_config.txt",
"category": "guest",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS_TEST",
"compute_id": "local",
"symbol": ":/symbols/vpcs_guest.svg",
"template_type": "vpcs"}
response = http_controller.post("/templates", params, example=True)
assert response.status == 201
assert response.route == "/templates"
assert response.json["template_id"] is not None
assert len(controller.templates) == 1
def test_template_create_with_id(http_controller, controller):
params = {"template_id": str(uuid.uuid4()),
"base_script_file": "vpcs_base_config.txt",
"category": "guest",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS_TEST",
"compute_id": "local",
"symbol": ":/symbols/vpcs_guest.svg",
"template_type": "vpcs"}
response = http_controller.post("/templates", params, example=True)
assert response.status == 201
assert response.route == "/templates"
assert response.json["template_id"] is not None
assert len(controller.templates) == 1
def test_template_create_wrong_type(http_controller, controller):
params = {"template_id": str(uuid.uuid4()),
"base_script_file": "vpcs_base_config.txt",
"category": "guest",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS_TEST",
"compute_id": "local",
"symbol": ":/symbols/vpcs_guest.svg",
"template_type": "invalid_template_type"}
response = http_controller.post("/templates", params)
assert response.status == 400
assert len(controller.templates) == 0
def test_template_get(http_controller, controller):
template_id = str(uuid.uuid4())
params = {"template_id": template_id,
"base_script_file": "vpcs_base_config.txt",
"category": "guest",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS_TEST",
"compute_id": "local",
"symbol": ":/symbols/vpcs_guest.svg",
"template_type": "vpcs"}
response = http_controller.post("/templates", params)
assert response.status == 201
response = http_controller.get("/templates/{}".format(template_id), example=True)
assert response.status == 200
assert response.json["template_id"] == template_id
def test_template_update(http_controller, controller):
template_id = str(uuid.uuid4())
params = {"template_id": template_id,
"base_script_file": "vpcs_base_config.txt",
"category": "guest",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS_TEST",
"compute_id": "local",
"symbol": ":/symbols/vpcs_guest.svg",
"template_type": "vpcs"}
response = http_controller.post("/templates", params)
assert response.status == 201
response = http_controller.get("/templates/{}".format(template_id))
assert response.status == 200
assert response.json["template_id"] == template_id
params["name"] = "VPCS_TEST_RENAMED"
response = http_controller.put("/templates/{}".format(template_id), params, example=True)
assert response.status == 200
assert response.json["name"] == "VPCS_TEST_RENAMED"
def test_template_delete(http_controller, controller):
template_id = str(uuid.uuid4())
params = {"template_id": template_id,
"base_script_file": "vpcs_base_config.txt",
"category": "guest",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS_TEST",
"compute_id": "local",
"symbol": ":/symbols/vpcs_guest.svg",
"template_type": "vpcs"}
response = http_controller.post("/templates", params)
assert response.status == 201
response = http_controller.get("/templates")
assert len(response.json) == 1
assert len(controller.templates) == 1
response = http_controller.delete("/templates/{}".format(template_id), example=True)
assert response.status == 204
response = http_controller.get("/templates")
assert len(response.json) == 0
assert len(controller.templates) == 0
def test_template_duplicate(http_controller, controller):
template_id = str(uuid.uuid4())
params = {"template_id": template_id,
"base_script_file": "vpcs_base_config.txt",
"category": "guest",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS_TEST",
"compute_id": "local",
"symbol": ":/symbols/vpcs_guest.svg",
"template_type": "vpcs"}
response = http_controller.post("/templates", params)
assert response.status == 201
response = http_controller.post("/templates/{}/duplicate".format(template_id), example=True)
assert response.status == 201
assert response.json["template_id"] != template_id
params.pop("template_id")
for param, value in params.items():
assert response.json[param] == value
response = http_controller.get("/templates")
assert len(response.json) == 2
assert len(controller.templates) == 2
def test_c7200_dynamips_template_create(http_controller):
params = {"name": "Cisco c7200 template",
"platform": "c7200",
"compute_id": "local",
"image": "c7200-adventerprisek9-mz.124-24.T5.image",
"template_type": "dynamips"}
response = http_controller.post("/templates", params)
assert response.status == 201
assert response.json["template_id"] is not None
expected_response = {"template_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c7200-adventerprisek9-mz.124-24.T5.image",
"mac_addr": "",
"midplane": "vxr",
"mmap": True,
"name": "Cisco c7200 template",
"npe": "npe-400",
"nvram": 512,
"platform": "c7200",
"private_config": "",
"ram": 512,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c3745_dynamips_template_create(http_controller):
params = {"name": "Cisco c3745 template",
"platform": "c3745",
"compute_id": "local",
"image": "c3745-adventerprisek9-mz.124-25d.image",
"template_type": "dynamips"}
response = http_controller.post("/templates", params)
assert response.status == 201
assert response.json["template_id"] is not None
expected_response = {"template_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c3745-adventerprisek9-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c3745 template",
"iomem": 5,
"nvram": 256,
"platform": "c3745",
"private_config": "",
"ram": 256,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c3725_dynamips_template_create(http_controller):
params = {"name": "Cisco c3725 template",
"platform": "c3725",
"compute_id": "local",
"image": "c3725-adventerprisek9-mz.124-25d.image",
"template_type": "dynamips"}
response = http_controller.post("/templates", params)
assert response.status == 201
assert response.json["template_id"] is not None
expected_response = {"template_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c3725-adventerprisek9-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c3725 template",
"iomem": 5,
"nvram": 256,
"platform": "c3725",
"private_config": "",
"ram": 128,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c3600_dynamips_template_create(http_controller):
params = {"name": "Cisco c3600 template",
"platform": "c3600",
"chassis": "3660",
"compute_id": "local",
"image": "c3660-a3jk9s-mz.124-25d.image",
"template_type": "dynamips"}
response = http_controller.post("/templates", params)
assert response.status == 201
assert response.json["template_id"] is not None
expected_response = {"template_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c3660-a3jk9s-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c3600 template",
"iomem": 5,
"nvram": 128,
"platform": "c3600",
"chassis": "3660",
"private_config": "",
"ram": 192,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c3600_dynamips_template_create_wrong_chassis(http_controller):
params = {"name": "Cisco c3600 template",
"platform": "c3600",
"chassis": "3650",
"compute_id": "local",
"image": "c3660-a3jk9s-mz.124-25d.image",
"template_type": "dynamips"}
response = http_controller.post("/templates", params)
assert response.status == 400
def test_c2691_dynamips_template_create(http_controller):
params = {"name": "Cisco c2691 template",
"platform": "c2691",
"compute_id": "local",
"image": "c2691-adventerprisek9-mz.124-25d.image",
"template_type": "dynamips"}
response = http_controller.post("/templates", params)
assert response.status == 201
assert response.json["template_id"] is not None
expected_response = {"template_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c2691-adventerprisek9-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c2691 template",
"iomem": 5,
"nvram": 256,
"platform": "c2691",
"private_config": "",
"ram": 192,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c2600_dynamips_template_create(http_controller):
params = {"name": "Cisco c2600 template",
"platform": "c2600",
"chassis": "2651XM",
"compute_id": "local",
"image": "c2600-adventerprisek9-mz.124-25d.image",
"template_type": "dynamips"}
response = http_controller.post("/templates", params)
assert response.status == 201
assert response.json["template_id"] is not None
expected_response = {"template_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c2600-adventerprisek9-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c2600 template",
"iomem": 15,
"nvram": 128,
"platform": "c2600",
"chassis": "2651XM",
"private_config": "",
"ram": 160,
"sparsemem": True,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c2600_dynamips_template_create_wrong_chassis(http_controller):
params = {"name": "Cisco c2600 template",
"platform": "c2600",
"chassis": "2660XM",
"compute_id": "local",
"image": "c2600-adventerprisek9-mz.124-25d.image",
"template_type": "dynamips"}
response = http_controller.post("/templates", params)
assert response.status == 400
def test_c1700_dynamips_template_create(http_controller):
params = {"name": "Cisco c1700 template",
"platform": "c1700",
"chassis": "1760",
"compute_id": "local",
"image": "c1700-adventerprisek9-mz.124-25d.image",
"template_type": "dynamips"}
response = http_controller.post("/templates", params)
assert response.status == 201
assert response.json["template_id"] is not None
expected_response = {"template_type": "dynamips",
"auto_delete_disks": False,
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "R{0}",
"disk0": 0,
"disk1": 0,
"exec_area": 64,
"idlemax": 500,
"idlepc": "",
"idlesleep": 30,
"image": "c1700-adventerprisek9-mz.124-25d.image",
"mac_addr": "",
"mmap": True,
"name": "Cisco c1700 template",
"iomem": 15,
"nvram": 128,
"platform": "c1700",
"chassis": "1760",
"private_config": "",
"ram": 160,
"sparsemem": False,
"startup_config": "ios_base_startup-config.txt",
"symbol": ":/symbols/router.svg",
"system_id": "FTX0945W0MY"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_c1700_dynamips_template_create_wrong_chassis(http_controller):
params = {"name": "Cisco c1700 template",
"platform": "c1700",
"chassis": "1770",
"compute_id": "local",
"image": "c1700-adventerprisek9-mz.124-25d.image",
"template_type": "dynamips"}
response = http_controller.post("/templates", params)
assert response.status == 400
def test_dynamips_template_create_wrong_platform(http_controller):
params = {"name": "Cisco c3900 template",
"platform": "c3900",
"compute_id": "local",
"image": "c3900-test.124-25d.image",
"template_type": "dynamips"}
response = http_controller.post("/templates", params)
assert response.status == 400
def test_iou_template_create(http_controller):
params = {"name": "IOU template",
"compute_id": "local",
"path": "/path/to/i86bi_linux-ipbase-ms-12.4.bin",
"template_type": "iou"}
response = http_controller.post("/templates", params, example=True)
assert response.status == 201
assert response.json["template_id"] is not None
expected_response = {"template_type": "iou",
"builtin": False,
"category": "router",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "IOU{0}",
"ethernet_adapters": 2,
"name": "IOU template",
"nvram": 128,
"path": "/path/to/i86bi_linux-ipbase-ms-12.4.bin",
"private_config": "",
"ram": 256,
"serial_adapters": 2,
"startup_config": "iou_l3_base_startup-config.txt",
"symbol": ":/symbols/multilayer_switch.svg",
"use_default_iou_values": True,
"l1_keepalives": False}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_docker_template_create(http_controller):
params = {"name": "Docker template",
"compute_id": "local",
"image": "gns3/endhost:latest",
"template_type": "docker"}
response = http_controller.post("/templates", params)
assert response.status == 201
assert response.json["template_id"] is not None
expected_response = {"adapters": 1,
"template_type": "docker",
"builtin": False,
"category": "guest",
"compute_id": "local",
"console_auto_start": False,
"console_http_path": "/",
"console_http_port": 80,
"console_resolution": "1024x768",
"console_type": "telnet",
"default_name_format": "{name}-{0}",
"environment": "",
"extra_hosts": "",
"image": "gns3/endhost:latest",
"name": "Docker template",
"start_command": "",
"symbol": ":/symbols/docker_guest.svg",
"custom_adapters": []}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_qemu_template_create(http_controller):
params = {"name": "Qemu template",
"compute_id": "local",
"platform": "i386",
"hda_disk_image": "IOSvL2-15.2.4.0.55E.qcow2",
"ram": 512,
"template_type": "qemu"}
response = http_controller.post("/templates", params, example=True)
assert response.status == 201
assert response.json["template_id"] is not None
expected_response = {"adapter_type": "e1000",
"adapters": 1,
"template_type": "qemu",
"bios_image": "",
"boot_priority": "c",
"builtin": False,
"category": "guest",
"cdrom_image": "",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"cpu_throttling": 0,
"cpus": 1,
"default_name_format": "{name}-{0}",
"first_port_name": "",
"hda_disk_image": "IOSvL2-15.2.4.0.55E.qcow2",
"hda_disk_interface": "ide",
"hdb_disk_image": "",
"hdb_disk_interface": "ide",
"hdc_disk_image": "",
"hdc_disk_interface": "ide",
"hdd_disk_image": "",
"hdd_disk_interface": "ide",
"initrd": "",
"kernel_command_line": "",
"kernel_image": "",
"legacy_networking": False,
"linked_clone": True,
"mac_address": "",
"name": "Qemu template",
"on_close": "power_off",
"options": "",
"platform": "i386",
"port_name_format": "Ethernet{0}",
"port_segment_size": 0,
"process_priority": "normal",
"qemu_path": "",
"ram": 512,
"symbol": ":/symbols/qemu_guest.svg",
"usage": "",
"custom_adapters": []}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_vmware_template_create(http_controller):
params = {"name": "VMware template",
"compute_id": "local",
"template_type": "vmware",
"vmx_path": "/path/to/vm.vmx"}
response = http_controller.post("/templates", params)
assert response.status == 201
assert response.json["template_id"] is not None
expected_response = {"adapter_type": "e1000",
"adapters": 1,
"template_type": "vmware",
"builtin": False,
"category": "guest",
"compute_id": "local",
"console_auto_start": False,
"console_type": "none",
"default_name_format": "{name}-{0}",
"first_port_name": "",
"headless": False,
"linked_clone": False,
"name": "VMware template",
"on_close": "power_off",
"port_name_format": "Ethernet{0}",
"port_segment_size": 0,
"symbol": ":/symbols/vmware_guest.svg",
"use_any_adapter": False,
"vmx_path": "/path/to/vm.vmx",
"custom_adapters": []}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_virtualbox_template_create(http_controller):
params = {"name": "VirtualBox template",
"compute_id": "local",
"template_type": "virtualbox",
"vmname": "My VirtualBox VM"}
response = http_controller.post("/templates", params)
assert response.status == 201
assert response.json["template_id"] is not None
expected_response = {"adapter_type": "Intel PRO/1000 MT Desktop (82540EM)",
"adapters": 1,
"template_type": "virtualbox",
"builtin": False,
"category": "guest",
"compute_id": "local",
"console_auto_start": False,
"console_type": "none",
"default_name_format": "{name}-{0}",
"first_port_name": "",
"headless": False,
"linked_clone": False,
"name": "VirtualBox template",
"on_close": "power_off",
"port_name_format": "Ethernet{0}",
"port_segment_size": 0,
"ram": 256,
"symbol": ":/symbols/vbox_guest.svg",
"use_any_adapter": False,
"vmname": "My VirtualBox VM",
"custom_adapters": []}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_vpcs_template_create(http_controller):
params = {"name": "VPCS template",
"compute_id": "local",
"template_type": "vpcs"}
response = http_controller.post("/templates", params)
assert response.status == 201
assert response.json["template_id"] is not None
expected_response = {"template_type": "vpcs",
"base_script_file": "vpcs_base_config.txt",
"builtin": False,
"category": "guest",
"compute_id": "local",
"console_auto_start": False,
"console_type": "telnet",
"default_name_format": "PC{0}",
"name": "VPCS template",
"symbol": ":/symbols/vpcs_guest.svg"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_ethernet_switch_template_create(http_controller):
params = {"name": "Ethernet switch template",
"compute_id": "local",
"template_type": "ethernet_switch"}
response = http_controller.post("/templates", params)
assert response.status == 201
assert response.json["template_id"] is not None
expected_response = {"template_type": "ethernet_switch",
"builtin": False,
"category": "switch",
"compute_id": "local",
"console_type": "telnet",
"default_name_format": "Switch{0}",
"name": "Ethernet switch template",
"ports_mapping": [{"ethertype": "",
"name": "Ethernet0",
"port_number": 0,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet1",
"port_number": 1,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet2",
"port_number": 2,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet3",
"port_number": 3,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet4",
"port_number": 4,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet5",
"port_number": 5,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet6",
"port_number": 6,
"type": "access",
"vlan": 1
},
{"ethertype": "",
"name": "Ethernet7",
"port_number": 7,
"type": "access",
"vlan": 1
}],
"symbol": ":/symbols/ethernet_switch.svg"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_cloud_template_create(http_controller):
params = {"name": "Cloud template",
"compute_id": "local",
"template_type": "cloud"}
response = http_controller.post("/templates", params)
assert response.status == 201
assert response.json["template_id"] is not None
expected_response = {"template_type": "cloud",
"builtin": False,
"category": "guest",
"compute_id": "local",
"default_name_format": "Cloud{0}",
"name": "Cloud template",
"symbol": ":/symbols/cloud.svg"}
for item, value in expected_response.items():
assert response.json.get(item) == value
def test_ethernet_hub_template_create(http_controller):
params = {"name": "Ethernet hub template",
"compute_id": "local",
"template_type": "ethernet_hub"}
response = http_controller.post("/templates", params)
assert response.status == 201
assert response.json["template_id"] is not None
expected_response = {"ports_mapping": [{"port_number": 0,
"name": "Ethernet0"
},
{"port_number": 1,
"name": "Ethernet1"
},
{"port_number": 2,
"name": "Ethernet2"
},
{"port_number": 3,
"name": "Ethernet3"
},
{"port_number": 4,
"name": "Ethernet4"
},
{"port_number": 5,
"name": "Ethernet5"
},
{"port_number": 6,
"name": "Ethernet6"
},
{"port_number": 7,
"name": "Ethernet7"
}],
"compute_id": "local",
"name": "Ethernet hub template",
"symbol": ":/symbols/hub.svg",
"default_name_format": "Hub{0}",
"template_type": "ethernet_hub",
"category": "switch",
"builtin": False}
for item, value in expected_response.items():
assert response.json.get(item) == value
@pytest.fixture
def compute(http_controller, async_run):
compute = MagicMock()
compute.id = "example.com"
compute.host = "example.org"
Controller.instance()._computes = {"example.com": compute}
return compute
@pytest.fixture
def project(http_controller, async_run):
return async_run(Controller.instance().add_project(name="Test"))
def test_create_node_from_template(http_controller, controller, project, compute):
id = str(uuid.uuid4())
controller._templates = {id: Template(id, {
"template_type": "qemu",
"category": 0,
"name": "test",
"symbol": "guest.svg",
"default_name_format": "{name}-{0}",
"compute_id": "example.com"
})}
with asyncio_patch("gns3server.controller.project.Project.add_node_from_template") as mock:
response = http_controller.post("/projects/{}/templates/{}".format(project.id, id), {
"x": 42,
"y": 12
})
mock.assert_called_with(id, x=42, y=12, compute_id=None)
assert response.route == "/projects/{project_id}/templates/{template_id}"
assert response.status == 201