Merge branch '2.1' into embed_appliances

This commit is contained in:
Julien Duponchelle committed 2017-02-28 14:55:33 +01:00
commit 5a399b90fe
68 files changed
+1527 -484

No files matched your search

+19 -5
View File
@@ -39,7 +39,7 @@ def test_save(controller, controller_config_path):
assert data["gns3vm"] == controller.gns3vm.__json__()
def test_load(controller, controller_config_path, async_run):
def test_load_controller_settings(controller, controller_config_path, async_run):
controller.save()
with open(controller_config_path) as f:
data = json.load(f)
@@ -57,7 +57,7 @@ def test_load(controller, controller_config_path, async_run):
data["gns3vm"] = {"vmname": "Test VM"}
with open(controller_config_path, "w+") as f:
json.dump(data, f)
async_run(controller.load())
async_run(controller._load_controller_settings())
assert controller.settings["IOU"]
assert controller.computes["test1"].__json__() == {
"compute_id": "test1",
@@ -101,7 +101,7 @@ def test_import_computes_1_x(controller, controller_config_path, async_run):
with open(os.path.join(config_dir, "gns3_gui.conf"), "w+") as f:
json.dump(gns3_gui_conf, f)
async_run(controller.load())
async_run(controller._load_controller_settings())
for compute in controller.computes.values():
if compute.id != "local":
assert len(compute.id) == 36
@@ -143,7 +143,7 @@ def test_import_gns3vm_1_x(controller, controller_config_path, async_run):
json.dump(gns3_gui_conf, f)
controller.gns3vm.settings["engine"] = None
async_run(controller.load())
async_run(controller._load_controller_settings())
assert controller.gns3vm.settings["engine"] == "vmware"
assert controller.gns3vm.settings["enable"]
assert controller.gns3vm.settings["headless"]
@@ -199,7 +199,7 @@ def test_import_remote_gns3vm_1_x(controller, controller_config_path, async_run)
json.dump(gns3_gui_conf, f)
with asyncio_patch("gns3server.controller.compute.Compute.connect"):
async_run(controller.load())
async_run(controller._load_controller_settings())
assert controller.gns3vm.settings["engine"] == "remote"
assert controller.gns3vm.settings["vmname"] == "http://127.0.0.1:3081"
@@ -466,3 +466,17 @@ def test_get_free_project_name(controller, async_run):
def test_appliance_templates(controller):
assert len(controller.appliance_templates) > 0
def test_load_base_files(controller, config, tmpdir):
config.set_section_config("Server", {"configs_path": str(tmpdir)})
with open(str(tmpdir / 'iou_l2_base_startup-config.txt'), 'w+') as f:
f.write('test')
controller.load_base_files()
assert os.path.exists(str(tmpdir / 'iou_l3_base_startup-config.txt'))
# Check is the file has not been overwrite
with open(str(tmpdir / 'iou_l2_base_startup-config.txt')) as f:
assert f.read() == 'test'
+35 -15
View File
@@ -33,7 +33,9 @@ from gns3server.controller.export_project import export_project, _filter_files
@pytest.fixture
def project(controller):
return Project(controller=controller, name="Test")
p = Project(controller=controller, name="Test")
p.dump = MagicMock()
return p
@pytest.fixture
@@ -190,9 +192,9 @@ def test_export_disallow_some_type(tmpdir, project, async_run):
topology = {
"topology": {
"nodes": [
{
"node_type": "virtualbox"
}
{
"node_type": "cloud"
}
]
}
}
@@ -202,6 +204,24 @@ def test_export_disallow_some_type(tmpdir, project, async_run):
with pytest.raises(aiohttp.web.HTTPConflict):
z = async_run(export_project(project, str(tmpdir)))
z = async_run(export_project(project, str(tmpdir), allow_all_nodes=True))
# VirtualBox is always disallowed
topology = {
"topology": {
"nodes": [
{
"node_type": "virtualbox",
"properties": {
"linked_clone": True
}
}
]
}
}
with open(os.path.join(path, "test.gns3"), 'w+') as f:
json.dump(topology, f)
with pytest.raises(aiohttp.web.HTTPConflict):
z = async_run(export_project(project, str(tmpdir), allow_all_nodes=True))
@@ -215,18 +235,18 @@ def test_export_fix_path(tmpdir, project, async_run):
topology = {
"topology": {
"nodes": [
{
"properties": {
"image": "/tmp/c3725-adventerprisek9-mz.124-25d.image"
},
"node_type": "dynamips"
},
{
"properties": {
"image": "gns3/webterm:lastest"
},
"node_type": "docker"
}
"properties": {
"image": "/tmp/c3725-adventerprisek9-mz.124-25d.image"
},
"node_type": "dynamips"
},
{
"properties": {
"image": "gns3/webterm:lastest"
},
"node_type": "docker"
}
]
}
}
+24 -13
View File
@@ -88,19 +88,6 @@ def test_eq(compute, project, node, controller):
assert node != Node(Project(str(uuid.uuid4()), controller=controller), compute, "demo3", node_id=node.id, node_type="qemu")
def test_properties_filter(project, compute):
"""
Some properties are private and should not be exposed
"""
node = Node(project, compute, "demo",
node_id=str(uuid.uuid4()),
node_type="vpcs",
console_type="vnc",
properties={"startup_script": "echo test", "iourc_content": "test"})
assert node._properties == {"startup_script": "echo test", "iourc_content": "test"}
assert node._filter_properties() == {"startup_script": "echo test"}
def test_json(node, compute):
assert node.__json__() == {
"compute_id": str(compute.id),
@@ -207,6 +194,30 @@ def test_create_image_missing(node, compute, project, async_run):
node._upload_missing_image.called is True
def test_create_base_script(node, config, compute, tmpdir, async_run):
config.set_section_config("Server", {"configs_path": str(tmpdir)})
with open(str(tmpdir / 'test.txt'), 'w+') as f:
f.write('hostname test')
node._properties = {"base_script_file": "test.txt"}
node._console = 2048
response = MagicMock()
response.json = {"console": 2048}
compute.post = AsyncioMagicMock(return_value=response)
assert async_run(node.create()) is True
data = {
"console": 2048,
"console_type": "vnc",
"node_id": node.id,
"startup_script": "hostname test",
"name": "demo"
}
compute.post.assert_called_with("/projects/{}/vpcs/nodes".format(node.project.id), data=data, timeout=120)
def test_symbol(node, symbols_dir):
"""
Change symbol should change the node size
+5 -5
View File
@@ -137,7 +137,7 @@ def test_add_node_local(async_run, controller):
response.json = {"console": 2048}
compute.post = AsyncioMagicMock(return_value=response)
node = async_run(project.add_node(compute, "test", None, node_type="vpcs", properties={"startup_config": "test.cfg"}))
node = async_run(project.add_node(compute, "test", None, node_type="vpcs", properties={"startup_script": "test.cfg"}))
assert node.id in project._nodes
compute.post.assert_any_call('/projects', data={
@@ -147,7 +147,7 @@ def test_add_node_local(async_run, controller):
})
compute.post.assert_any_call('/projects/{}/vpcs/nodes'.format(project.id),
data={'node_id': node.id,
'startup_config': 'test.cfg',
'startup_script': 'test.cfg',
'name': 'test'},
timeout=120)
assert compute in project._project_created_on_compute
@@ -167,7 +167,7 @@ def test_add_node_non_local(async_run, controller):
response.json = {"console": 2048}
compute.post = AsyncioMagicMock(return_value=response)
node = async_run(project.add_node(compute, "test", None, node_type="vpcs", properties={"startup_config": "test.cfg"}))
node = async_run(project.add_node(compute, "test", None, node_type="vpcs", properties={"startup_script": "test.cfg"}))
compute.post.assert_any_call('/projects', data={
"name": project._name,
@@ -175,7 +175,7 @@ def test_add_node_non_local(async_run, controller):
})
compute.post.assert_any_call('/projects/{}/vpcs/nodes'.format(project.id),
data={'node_id': node.id,
'startup_config': 'test.cfg',
'startup_script': 'test.cfg',
'name': 'test'},
timeout=120)
assert compute in project._project_created_on_compute
@@ -427,7 +427,7 @@ def test_duplicate(project, async_run, controller):
remote_vpcs = async_run(project.add_node(compute, "test", None, node_type="vpcs", properties={"startup_config": "test.cfg"}))
# We allow node not allowed for standard import / export
remote_virtualbox = async_run(project.add_node(compute, "test", None, node_type="virtualbox", properties={"startup_config": "test.cfg"}))
remote_virtualbox = async_run(project.add_node(compute, "test", None, node_type="vmware", properties={"startup_config": "test.cfg"}))
new_project = async_run(project.duplicate(name="Hello"))
assert new_project.id != project.id
-2
View File
@@ -106,7 +106,6 @@ def demo_topology():
"node_type": "vpcs",
"properties": {
"startup_script": "",
"startup_script_path": "startup.vpc"
},
"symbol": ":/symbols/computer.svg",
"width": 65,
@@ -131,7 +130,6 @@ def demo_topology():
"node_type": "vpcs",
"properties": {
"startup_script": "",
"startup_script_path": "startup.vpc"
},
"symbol": ":/symbols/computer.svg",
"width": 65,