From 4f03c3011eb69dc5ec72c0e3158211bae8094694 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Mon, 13 Jun 2016 17:39:04 +0200 Subject: [PATCH] Delete volume when dropping the container Fix #567 --- gns3server/modules/docker/docker_vm.py | 4 +++- tests/modules/docker/test_docker_vm.py | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gns3server/modules/docker/docker_vm.py b/gns3server/modules/docker/docker_vm.py index 4c360d15..12f0efab 100644 --- a/gns3server/modules/docker/docker_vm.py +++ b/gns3server/modules/docker/docker_vm.py @@ -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)) diff --git a/tests/modules/docker/test_docker_vm.py b/tests/modules/docker/test_docker_vm.py index 5e6151f7..b3bffd88 100644 --- a/tests/modules/docker/test_docker_vm.py +++ b/tests/modules/docker/test_docker_vm.py @@ -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