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

pull/1309/head
ziajka 6 years ago
parent 7beae4e451
commit e79e27a73f

@ -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)

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

Loading…
Cancel
Save