1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-01 04:38:12 +00:00

Handle docker env with last empty line, Fixes: #2420

This commit is contained in:
ziajka 2018-02-27 16:33:55 +01:00
parent 7beae4e451
commit e79e27a73f
2 changed files with 32 additions and 30 deletions

View File

@ -314,7 +314,7 @@ class DockerVM(BaseNode):
params["Env"].append("GNS3_VOLUMES={}".format(":".join(self._volumes))) params["Env"].append("GNS3_VOLUMES={}".format(":".join(self._volumes)))
if self._environment: if self._environment:
for e in self._environment.split("\n"): for e in self._environment.strip().split("\n"):
e = e.strip() e = e.strip()
if not e.startswith("GNS3_"): if not e.startswith("GNS3_"):
params["Env"].append(e) params["Env"].append(e)

View File

@ -257,35 +257,37 @@ def test_create_environment(loop, project, manager):
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu") vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
vm.environment = "YES=1\nNO=0\nGNS3_MAX_ETHERNET=eth2" vm.environment = "YES=1\nNO=0\nGNS3_MAX_ETHERNET=eth2"
loop.run_until_complete(asyncio.async(vm.create())) loop.run_until_complete(asyncio.async(vm.create()))
mock.assert_called_with("POST", "containers/create", data={ assert mock.call_args[1]['data']['Env'] == [
"Tty": True,
"OpenStdin": True,
"StdinOnce": False,
"HostConfig":
{
"CapAdd": ["ALL"],
"Binds": [
"{}:/gns3:ro".format(get_resource("compute/docker/resources")),
"{}:/gns3volumes/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network"))
],
"Privileged": True
},
"Env": [
"container=docker", "container=docker",
"GNS3_MAX_ETHERNET=eth0", "GNS3_MAX_ETHERNET=eth0",
"GNS3_VOLUMES=/etc/network", "GNS3_VOLUMES=/etc/network",
"YES=1", "YES=1",
"NO=0" "NO=0"
], ]
"Volumes": {},
"NetworkDisabled": True,
"Name": "test", def test_create_environment_with_last_new_line_character(loop, project, manager):
"Hostname": "test", """
"Image": "ubuntu:latest", Allow user to pass an environnement. User can't override our
"Entrypoint": ["/gns3/init.sh"], internal variables
"Cmd": ["/bin/sh"] """
})
assert vm._cid == "e90e34656806" 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")
vm.environment = "YES=1\nNO=0\nGNS3_MAX_ETHERNET=eth2\n"
loop.run_until_complete(asyncio.async(vm.create()))
assert mock.call_args[1]['data']['Env'] == [
"container=docker",
"GNS3_MAX_ETHERNET=eth0",
"GNS3_VOLUMES=/etc/network",
"YES=1",
"NO=0"
]
def test_create_image_not_available(loop, project, manager): def test_create_image_not_available(loop, project, manager):