Always log if disconnect from docker swarm

Currently, docker conductor conditionally log the exception. It could
cause lose of debug information.

Change-Id: I13d8a15e4731e5a4bae8d6cb80b054baf5a3dd42
Related-Bug: #1521395
This commit is contained in:
Hongbin Lu 2015-12-05 23:40:17 -05:00
parent bca8bbcf95
commit 97a37e8eef
2 changed files with 15 additions and 11 deletions

View File

@ -30,12 +30,16 @@ def wrap_container_exception(f):
try:
return f(self, context, *args, **kwargs)
except Exception as e:
container_uuid = kwargs.get('container_uuid')
if container_uuid is not None:
LOG.exception(_LE("Error while connect to docker "
"container %(name)s: %(error)s"),
{'name': container_uuid,
'error': str(e)})
container_uuid = None
if 'container_uuid' in kwargs:
container_uuid = kwargs.get('container_uuid')
elif 'container' in kwargs:
container_uuid = kwargs.get('container').uuid
LOG.exception(_LE("Error while connect to docker "
"container %(name)s: %(error)s"),
{'name': container_uuid,
'error': str(e)})
raise exception.ContainerException(
"Docker internal Error: %s" % str(e))
return functools.wraps(f)(wrapped)

View File

@ -150,7 +150,7 @@ class TestDockerHandler(base.BaseTestCase):
'test_image',
tag='some_tag')
self.assertFalse(self.mock_docker.create_container.called)
mock_init.assert_called_once_with()
mock_init.assert_called_with()
self.assertEqual(fields.ContainerStatus.ERROR,
mock_container.status)
@ -204,7 +204,7 @@ class TestDockerHandler(base.BaseTestCase):
mock_docker_id)
mock_find_container.assert_called_once_with(self.mock_docker,
mock_container_uuid)
mock_init.assert_called_once_with()
mock_init.assert_called_with()
@mock.patch.object(objects.Container, 'get_by_uuid')
@mock.patch.object(docker_conductor.Handler, '_find_container_by_name')
@ -249,7 +249,7 @@ class TestDockerHandler(base.BaseTestCase):
docker_func.assert_called_once_with(mock_docker_id)
mock_find_container.assert_called_once_with(self.mock_docker,
mock_container_uuid)
mock_init.assert_called_once_with()
mock_init.assert_called_with()
@mock.patch.object(objects.Container, 'get_by_uuid')
@mock.patch.object(docker_conductor.Handler, '_find_container_by_name')
@ -487,7 +487,7 @@ class TestDockerHandler(base.BaseTestCase):
mock_docker_id, 'ls', True, True, False)
mock_find_container.assert_called_once_with(self.mock_docker,
mock_container_uuid)
mock_init.assert_called_once_with()
mock_init.assert_called_with()
@mock.patch.object(docker_conductor.Handler, '_find_container_by_name')
def test_container_exec_with_failure(self, mock_find_container):
@ -525,7 +525,7 @@ class TestDockerHandler(base.BaseTestCase):
mock_docker_id)
mock_find_container.assert_called_once_with(self.mock_docker,
mock_container_uuid)
mock_init.assert_called_once_with()
mock_init.assert_called_with()
def test_container_common_exception(self):
self.dfc_context_manager.__enter__.side_effect = Exception("So bad")