GNS3 / gns3-gui

GNS3 Graphical Network Simulator
http://www.gns3.com
GNU General Public License v3.0
2.17k stars 436 forks source link

Docker error prevents loading of a project #2683

Open ghost opened 5 years ago

ghost commented 5 years ago

https://gns3.com/community/discussion/gns3-critical-error

Somehow that user added a = into the docker environment of a node (that's simple) and then managed to get that saved into the project file, something I wasn't able to reproduce. So to further analyze this, I manually edited the project file. I set "environment": "=", in one docker node.

The main issue is, that the docker nodes are created, when the project is loaded. When anything gets wrong with that creation, the loading aborts and the user has no change to fix the project. The whole project is lost.

The error message on the console is not really helpful: Docker has returned an error: 500 invalid environment variable: =

The log clearly shows, whats wrong:

2019-01-24 22:24:45 INFO project.py:81 Project a55442ec-cebe-418d-b763-98248dd85585 with path '/opt/gns3/projects/a55442ec-cebe-418d-b763-98248dd85585' created
2019-01-24 22:24:45 INFO helpers.py:534 192.168.1.10 [24/Jan/2019:21:24:45 +0000] "POST /v2/compute/projects HTTP/1.1" 201 303 "-" "Python/3.6 aiohttp/2.3.10"
2019-01-24 22:24:45 INFO docker_vm.py:945 Docker container "ipterm-1" [f2a5164c-38e1-4414-a26d-460ac2544a0a]: number of Ethernet adapters changed to 1
2019-01-24 22:24:45 ERROR route.py:210 Node error detected: DockerError
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/gns3_server-2.1.12-py3.5.egg/gns3server/web/route.py", line 195, in control_schema
    yield from func(request, response)
  File "/usr/local/lib/python3.5/dist-packages/gns3_server-2.1.12-py3.5.egg/gns3server/handlers/api/compute/docker_handler.py", line 64, in create
    extra_hosts=request.json.get("extra_hosts"))
  File "/usr/local/lib/python3.5/dist-packages/gns3_server-2.1.12-py3.5.egg/gns3server/compute/base_manager.py", line 253, in create_node
    yield from node.create()
  File "/usr/local/lib/python3.5/dist-packages/gns3_server-2.1.12-py3.5.egg/gns3server/compute/docker/docker_vm.py", line 365, in create
    result = yield from self.manager.query("POST", "containers/create", data=params)
  File "/usr/local/lib/python3.5/dist-packages/gns3_server-2.1.12-py3.5.egg/gns3server/compute/docker/__init__.py", line 106, in query
    response = yield from self.http_query(method, path, data=data, params=params)
  File "/usr/local/lib/python3.5/dist-packages/gns3_server-2.1.12-py3.5.egg/gns3server/compute/docker/__init__.py", line 166, in http_query
    raise DockerError("Docker has returned an error: {} {}".format(response.status, body))
gns3server.compute.docker.docker_error.DockerError: Docker has returned an error: 500 invalid environment variable: =
2019-01-24 22:24:45 INFO helpers.py:534 192.168.1.10 [24/Jan/2019:21:24:45 +0000] "POST /v2/compute/projects/a55442ec-cebe-418d-b763-98248dd85585/docker/nodes HTTP/1.1" 409 360 "-" "Python/3.6 aiohttp/2.3.10"
2019-01-24 22:24:45 INFO project.py:367 Project a55442ec-cebe-418d-b763-98248dd85585 with path '/opt/gns3/projects/a55442ec-cebe-418d-b763-98248dd85585' closed
2019-01-24 22:24:45 WARNING project.py:370 Project a55442ec-cebe-418d-b763-98248dd85585 has TCP ports still in use: {5000, 5001}
2019-01-24 22:24:45 INFO helpers.py:534 192.168.1.10 [24/Jan/2019:21:24:45 +0000] "POST /v2/compute/projects/a55442ec-cebe-418d-b763-98248dd85585/close HTTP/1.1" 204 224 "-" "Python/3.6 aiohttp/2.3.10"

The only way to recover that, is to edit the project file, find the offending environment setting and correct that.

I would like to propose two fixes 1) Ignore (with a warning) all environment lines with an empty variable (starting with a =). 2) Redesign the docker VM, so that it is not created, when loaded, but when first started. That way any issue with a docker node won't affect loading a project. If a docker VM is misbehaving the user can edit the node config in GNS3. In extreme cases the VM needs to be deleted and then recreated. But at least the project is not lost.

grossmj commented 5 years ago
  1. Ignore (with a warning) all environment lines with an empty variable (starting with a =).

Should have been fixed by https://github.com/GNS3/gns3-server/commit/aea4ae808f18a1031f0b438a7918658882893d6b

  1. Redesign the docker VM, so that it is not created, when loaded, but when first started. That way any issue with a docker node won't affect loading a project. If a docker VM is misbehaving the user can edit the node config in GNS3. In extreme cases the VM needs to be deleted and then recreated. But at least the project is not lost.

I agree, however I prefer to do this in our 2.2 branch since I am afraid we are likely to break something in 2.1.

ghost commented 5 years ago

As v2.2 is already in alpha and refactoring docker might be complex, even a target of v2.3 is fine for me.