diff --git a/gns3server/modules/docker/docker_vm.py b/gns3server/modules/docker/docker_vm.py index 31b9766c..847a9386 100644 --- a/gns3server/modules/docker/docker_vm.py +++ b/gns3server/modules/docker/docker_vm.py @@ -189,11 +189,15 @@ class DockerVM(BaseVM): """ Destroy an recreate the container with the new settings """ - # We need to save the console port and restore it + # We need to save the console and state and restore it console = self.console + state = yield from self._get_container_state() + yield from self.remove() yield from self.create() self.console = console + if state == "running": + yield from self.start() @asyncio.coroutine def start(self): diff --git a/tests/modules/docker/test_docker_vm.py b/tests/modules/docker/test_docker_vm.py index 0dabf8cb..1704c4ca 100644 --- a/tests/modules/docker/test_docker_vm.py +++ b/tests/modules/docker/test_docker_vm.py @@ -392,6 +392,43 @@ def test_update(loop, vm): assert vm.console == original_console +def test_update_running(loop, vm): + + response = { + "Id": "e90e34656806", + "Warnings": [] + } + + original_console = vm.console + vm.start = MagicMock() + + with asyncio_patch("gns3server.modules.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images: + with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="running"): + 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("POST", "containers/create", data={ + "Tty": True, + "OpenStdin": True, + "StdinOnce": False, + "HostConfig": + { + "CapAdd": ["ALL"], + "Binds": [], + "Privileged": True + }, + "Volumes": {}, + "NetworkDisabled": True, + "Name": "test", + "Hostname": "test", + "Image": "ubuntu" + }) + + assert vm.console == original_console + assert vm.start.called + + def test_remove(loop, vm): with asyncio_patch("gns3server.modules.docker.DockerVM._get_container_state", return_value="stopped"):