mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Support of supplier and variables in topology
This commit is contained in:
parent
e4436096c2
commit
f2700ed445
@ -85,6 +85,8 @@ def project_to_topology(project):
|
|||||||
"show_grid": project.show_grid,
|
"show_grid": project.show_grid,
|
||||||
"grid_size": project.grid_size,
|
"grid_size": project.grid_size,
|
||||||
"show_interface_labels": project.show_interface_labels,
|
"show_interface_labels": project.show_interface_labels,
|
||||||
|
"variables": project.variables,
|
||||||
|
"supplier": project.supplier,
|
||||||
"topology": {
|
"topology": {
|
||||||
"nodes": [],
|
"nodes": [],
|
||||||
"links": [],
|
"links": [],
|
||||||
|
@ -23,6 +23,8 @@ from gns3server.schemas.compute import COMPUTE_OBJECT_SCHEMA
|
|||||||
from gns3server.schemas.drawing import DRAWING_OBJECT_SCHEMA
|
from gns3server.schemas.drawing import DRAWING_OBJECT_SCHEMA
|
||||||
from gns3server.schemas.link import LINK_OBJECT_SCHEMA
|
from gns3server.schemas.link import LINK_OBJECT_SCHEMA
|
||||||
from gns3server.schemas.node import NODE_OBJECT_SCHEMA
|
from gns3server.schemas.node import NODE_OBJECT_SCHEMA
|
||||||
|
from gns3server.schemas.project import VARIABLES_OBJECT_SCHEMA
|
||||||
|
from gns3server.schemas.project import SUPPLIER_OBJECT_SCHEMA
|
||||||
|
|
||||||
|
|
||||||
TOPOLOGY_SCHEMA = {
|
TOPOLOGY_SCHEMA = {
|
||||||
@ -97,6 +99,8 @@ TOPOLOGY_SCHEMA = {
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Show interface labels on the drawing area"
|
"description": "Show interface labels on the drawing area"
|
||||||
},
|
},
|
||||||
|
"supplier": SUPPLIER_OBJECT_SCHEMA,
|
||||||
|
"variables": VARIABLES_OBJECT_SCHEMA,
|
||||||
"topology": {
|
"topology": {
|
||||||
"description": "The topology content",
|
"description": "The topology content",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
@ -81,6 +81,26 @@ def test_basic_topology(tmpdir, async_run, controller):
|
|||||||
assert topo["topology"]["drawings"][0] == drawing.__json__(topology_dump=True)
|
assert topo["topology"]["drawings"][0] == drawing.__json__(topology_dump=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_project_to_topology(tmpdir, controller):
|
||||||
|
variables = [
|
||||||
|
{"name": "TEST1"},
|
||||||
|
{"name": "TEST2", "value": "value1"}
|
||||||
|
]
|
||||||
|
supplier = {
|
||||||
|
'logo': 'logo.png',
|
||||||
|
'url': 'http://example.com'
|
||||||
|
}
|
||||||
|
|
||||||
|
project = Project(name="Test", controller=controller)
|
||||||
|
compute = Compute("my_compute", controller)
|
||||||
|
compute.http_query = MagicMock()
|
||||||
|
project.variables = variables
|
||||||
|
project.supplier = supplier
|
||||||
|
topo = project_to_topology(project)
|
||||||
|
assert topo["variables"] == variables
|
||||||
|
assert topo["supplier"] == supplier
|
||||||
|
|
||||||
|
|
||||||
def test_load_topology(tmpdir):
|
def test_load_topology(tmpdir):
|
||||||
data = {
|
data = {
|
||||||
"project_id": "69f26504-7aa3-48aa-9f29-798d44841211",
|
"project_id": "69f26504-7aa3-48aa-9f29-798d44841211",
|
||||||
@ -137,3 +157,55 @@ def test_load_newer_topology(tmpdir):
|
|||||||
json.dump(data, f)
|
json.dump(data, f)
|
||||||
with pytest.raises(aiohttp.web.HTTPConflict):
|
with pytest.raises(aiohttp.web.HTTPConflict):
|
||||||
topo = load_topology(path)
|
topo = load_topology(path)
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_topology_with_variables(tmpdir):
|
||||||
|
variables = [
|
||||||
|
{"name": "TEST1"},
|
||||||
|
{"name": "TEST2", "value": "value1"}
|
||||||
|
]
|
||||||
|
data = {
|
||||||
|
"project_id": "69f26504-7aa3-48aa-9f29-798d44841211",
|
||||||
|
"name": "Test",
|
||||||
|
"revision": GNS3_FILE_FORMAT_REVISION,
|
||||||
|
"topology": {
|
||||||
|
"nodes": [],
|
||||||
|
"links": [],
|
||||||
|
"computes": [],
|
||||||
|
"drawings": []
|
||||||
|
},
|
||||||
|
"variables": variables,
|
||||||
|
"type": "topology",
|
||||||
|
"version": __version__}
|
||||||
|
|
||||||
|
path = str(tmpdir / "test.gns3")
|
||||||
|
with open(path, "w+") as f:
|
||||||
|
json.dump(data, f)
|
||||||
|
topo = load_topology(path)
|
||||||
|
assert topo == data
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_topology_with_supplier(tmpdir):
|
||||||
|
supplier = {
|
||||||
|
'logo': 'logo.png',
|
||||||
|
'url': 'http://example.com'
|
||||||
|
}
|
||||||
|
data = {
|
||||||
|
"project_id": "69f26504-7aa3-48aa-9f29-798d44841211",
|
||||||
|
"name": "Test",
|
||||||
|
"revision": GNS3_FILE_FORMAT_REVISION,
|
||||||
|
"topology": {
|
||||||
|
"nodes": [],
|
||||||
|
"links": [],
|
||||||
|
"computes": [],
|
||||||
|
"drawings": []
|
||||||
|
},
|
||||||
|
"supplier": supplier,
|
||||||
|
"type": "topology",
|
||||||
|
"version": __version__}
|
||||||
|
|
||||||
|
path = str(tmpdir / "test.gns3")
|
||||||
|
with open(path, "w+") as f:
|
||||||
|
json.dump(data, f)
|
||||||
|
topo = load_topology(path)
|
||||||
|
assert topo == data
|
@ -104,6 +104,20 @@ def test_update_project(http_controller):
|
|||||||
assert response.json["name"] == "test2"
|
assert response.json["name"] == "test2"
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_project_with_variables(http_controller):
|
||||||
|
variables = [
|
||||||
|
{"name": "TEST1"},
|
||||||
|
{"name": "TEST2", "value": "value1"}
|
||||||
|
]
|
||||||
|
query = {"name": "test", "project_id": "10010203-0405-0607-0809-0a0b0c0d0e0f", "variables": variables}
|
||||||
|
response = http_controller.post("/projects", query)
|
||||||
|
assert response.status == 201
|
||||||
|
query = {"name": "test2"}
|
||||||
|
response = http_controller.put("/projects/10010203-0405-0607-0809-0a0b0c0d0e0f", query, example=True)
|
||||||
|
assert response.status == 200
|
||||||
|
assert response.json["variables"] == variables
|
||||||
|
|
||||||
|
|
||||||
def test_list_projects(http_controller, tmpdir):
|
def test_list_projects(http_controller, tmpdir):
|
||||||
http_controller.post("/projects", {"name": "test", "path": str(tmpdir), "project_id": "00010203-0405-0607-0809-0a0b0c0d0e0f"})
|
http_controller.post("/projects", {"name": "test", "path": str(tmpdir), "project_id": "00010203-0405-0607-0809-0a0b0c0d0e0f"})
|
||||||
response = http_controller.get("/projects", example=True)
|
response = http_controller.get("/projects", example=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user