mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Merge branch '2.1' into 2.2
# Conflicts: # gns3server/version.py # requirements.txt
This commit is contained in:
commit
d1ccf3bc84
24 files changed
+549
-46
No files matched your search
@@ -61,6 +61,7 @@ def test_json(vm, project):
|
||||
'console_resolution': '1024x768',
|
||||
'console_http_port': 80,
|
||||
'console_http_path': '/',
|
||||
'extra_hosts': None,
|
||||
'aux': vm.aux,
|
||||
'start_command': vm.start_command,
|
||||
'environment': vm.environment,
|
||||
@@ -202,6 +203,77 @@ def test_create_vnc(loop, project, manager):
|
||||
assert vm._console_type == "vnc"
|
||||
|
||||
|
||||
def test_create_with_extra_hosts(loop, project, manager):
|
||||
extra_hosts = "test:199.199.199.1\ntest2:199.199.199.1"
|
||||
|
||||
response = {
|
||||
"Id": "e90e34656806",
|
||||
"Warnings": []
|
||||
}
|
||||
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]):
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu", extra_hosts=extra_hosts)
|
||||
loop.run_until_complete(asyncio.async(vm.create()))
|
||||
called_kwargs = mock.call_args[1]
|
||||
assert "GNS3_EXTRA_HOSTS=199.199.199.1\ttest\n199.199.199.1\ttest2" in called_kwargs["data"]["Env"]
|
||||
assert vm._extra_hosts == extra_hosts
|
||||
|
||||
|
||||
def test_create_with_extra_hosts_wrong_format(loop, project, manager):
|
||||
extra_hosts = "test"
|
||||
|
||||
response = {
|
||||
"Id": "e90e34656806",
|
||||
"Warnings": []
|
||||
}
|
||||
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]):
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response):
|
||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu", extra_hosts=extra_hosts)
|
||||
with pytest.raises(DockerError):
|
||||
loop.run_until_complete(asyncio.async(vm.create()))
|
||||
|
||||
|
||||
def test_create_with_empty_extra_hosts(loop, project, manager):
|
||||
extra_hosts = "test:\n"
|
||||
|
||||
response = {
|
||||
"Id": "e90e34656806",
|
||||
"Warnings": []
|
||||
}
|
||||
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]):
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu", extra_hosts=extra_hosts)
|
||||
loop.run_until_complete(asyncio.async(vm.create()))
|
||||
called_kwargs = mock.call_args[1]
|
||||
assert len([ e for e in called_kwargs["data"]["Env"] if "GNS3_EXTRA_HOSTS" in e]) == 0
|
||||
|
||||
|
||||
def test_create_with_project_variables(loop, project, manager):
|
||||
response = {
|
||||
"Id": "e90e34656806",
|
||||
"Warnings": []
|
||||
}
|
||||
|
||||
project.variables = [
|
||||
{"name": "VAR1"},
|
||||
{"name": "VAR2", "value": "VAL1"},
|
||||
{"name": "VAR3", "value": "2x${VAR2}"}
|
||||
]
|
||||
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]):
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
|
||||
loop.run_until_complete(asyncio.async(vm.create()))
|
||||
called_kwargs = mock.call_args[1]
|
||||
assert "VAR1=" in called_kwargs["data"]["Env"]
|
||||
assert "VAR2=VAL1" in called_kwargs["data"]["Env"]
|
||||
assert "VAR3=2xVAL1" in called_kwargs["data"]["Env"]
|
||||
project.variables = None
|
||||
|
||||
|
||||
def test_create_start_cmd(loop, project, manager):
|
||||
|
||||
response = {
|
||||
|
||||
@@ -92,9 +92,29 @@ def test_changing_path_not_allowed(tmpdir):
|
||||
p.path = str(tmpdir)
|
||||
|
||||
|
||||
def test_variables(tmpdir):
|
||||
variables = [{"name": "VAR1", "value": "VAL1"}]
|
||||
p = Project(project_id=str(uuid4()), variables=variables)
|
||||
assert p.variables == variables
|
||||
|
||||
|
||||
def test_json(tmpdir):
|
||||
p = Project(project_id=str(uuid4()))
|
||||
assert p.__json__() == {"name": p.name, "project_id": p.id}
|
||||
assert p.__json__() == {
|
||||
"name": p.name,
|
||||
"project_id": p.id,
|
||||
"variables": None
|
||||
}
|
||||
|
||||
|
||||
def test_json_with_variables(tmpdir):
|
||||
variables = [{"name": "VAR1", "value": "VAL1"}]
|
||||
p = Project(project_id=str(uuid4()), variables=variables)
|
||||
assert p.__json__() == {
|
||||
"name": p.name,
|
||||
"project_id": p.id,
|
||||
"variables": variables
|
||||
}
|
||||
|
||||
|
||||
def test_node_working_directory(tmpdir, node):
|
||||
@@ -185,3 +205,10 @@ def test_emit(async_run):
|
||||
(action, event, context) = async_run(queue.get(0.5))
|
||||
assert action == "test"
|
||||
assert context["project_id"] == project.id
|
||||
|
||||
|
||||
def test_update_project(loop):
|
||||
variables = [{"name": "TEST", "value": "VAL"}]
|
||||
project = Project(project_id=str(uuid.uuid4()))
|
||||
loop.run_until_complete(asyncio.async(project.update(variables=variables)))
|
||||
assert project.variables == variables
|
||||
Reference in new issue
Block a user