From da65b568164c0882448fa93dc2addc545716f930 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Fri, 6 Apr 2018 03:23:44 +0000 Subject: [PATCH] Fix an issue on deleteing container Closes-Bug: #1762091 Change-Id: I3dd708b2b84e1cbdd5172bf0617b0db5d9ee508e --- zun/container/docker/driver.py | 13 +++++++++++++ .../unit/container/docker/test_docker_driver.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/zun/container/docker/driver.py b/zun/container/docker/driver.py index eae46bf70..3a662e5f7 100644 --- a/zun/container/docker/driver.py +++ b/zun/container/docker/driver.py @@ -47,6 +47,17 @@ def is_not_found(e): return '404' in str(e) +def is_not_connected(e): + # Test the following exception: + # + # 500 Server Error: Internal Server Error ("container XXX is not + # connected to the network XXX") + # + # Note(hongbin): Docker should response a 4xx instead of 500. This looks + # like a bug from docker side: https://github.com/moby/moby/issues/35888 + return ' is not connected to the network ' in str(e) + + def is_conflict(e): conflict_infos = ['not running', 'not paused', 'paused'] for info in conflict_infos: @@ -376,6 +387,8 @@ class DockerDriver(driver.ContainerDriver): except errors.APIError as api_error: if is_not_found(api_error): return + if is_not_connected(api_error): + return raise @wrap_docker_error diff --git a/zun/tests/unit/container/docker/test_docker_driver.py b/zun/tests/unit/container/docker/test_docker_driver.py index a2f762dab..a6f1ee1fd 100644 --- a/zun/tests/unit/container/docker/test_docker_driver.py +++ b/zun/tests/unit/container/docker/test_docker_driver.py @@ -254,7 +254,7 @@ class TestDockerDriver(base.DriverTestCase): True) self.mock_docker.remove_container.assert_called_once_with( mock_container.container_id, force=True) - self.assertEqual(1, mock_init.call_count) + self.assertEqual(2, mock_init.call_count) def test_list(self): self.mock_docker.list_containers.return_value = []