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 = []