1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-29 02:08:10 +00:00

Delete volume when dropping the container

Fix #567
This commit is contained in:
Julien Duponchelle 2016-06-13 17:39:04 +02:00
parent e183e7da27
commit 4f03c3011e
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 8 additions and 6 deletions

View File

@ -583,7 +583,9 @@ class DockerVM(BaseVM):
state = yield from self._get_container_state()
if state == "paused" or state == "running":
yield from self.stop()
yield from self.manager.query("DELETE", "containers/{}".format(self._cid), params={"force": 1})
# v 1/True/true or 0/False/false, Remove the volumes associated to the container. Default false.
# force - 1/True/true or 0/False/false, Kill then remove the container. Default false.
yield from self.manager.query("DELETE", "containers/{}".format(self._cid), params={"force": 1, "v": 1})
log.info("Docker container '{name}' [{image}] removed".format(
name=self._name, image=self._image))

View File

@ -520,7 +520,7 @@ def test_update(loop, vm):
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock_query:
loop.run_until_complete(asyncio.async(vm.update()))
mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1})
mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
mock_query.assert_any_call("POST", "containers/create", data={
"Tty": True,
"OpenStdin": True,
@ -588,7 +588,7 @@ def test_update_running(loop, vm):
with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock_query:
loop.run_until_complete(asyncio.async(vm.update()))
mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1})
mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
mock_query.assert_any_call("POST", "containers/create", data={
"Tty": True,
"OpenStdin": True,
@ -624,7 +624,7 @@ def test_delete(loop, vm):
with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.async(vm.delete()))
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1})
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
def test_close(loop, vm, port_manager):
@ -638,7 +638,7 @@ def test_close(loop, vm, port_manager):
with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.async(vm.close()))
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1})
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
assert vm._closed is True
assert "4242" not in port_manager.udp_ports
@ -653,7 +653,7 @@ def test_close_vnc(loop, vm, port_manager):
with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.modules.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.async(vm.close()))
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1})
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
assert vm._closed is True
assert vm._xvfb_process.terminate.called