Skip populating container's state on tasks

If there is a task acting on this container, skip syncing its
state on _populate_container_state to avoid conflicts.

Change-Id: I8b1bcc6c0399b163e26619db893b118f93d6ba9a
This commit is contained in:
Hongbin Lu 2019-04-13 19:10:09 +00:00
parent 9f98a16566
commit 9205710912
2 changed files with 10 additions and 5 deletions

View File

@ -633,6 +633,11 @@ class DockerDriver(driver.ContainerDriver):
container.runtime = hostconfig.get('Runtime')
def _populate_container_state(self, container, state):
if container.task_state:
# NOTE(hongbin): we don't want to populate container state
# if another thread is doing task on this container.
return
if not state:
LOG.warning('Receive unexpected state from docker: %s', state)
container.status = consts.UNKNOWN

View File

@ -553,7 +553,7 @@ class TestDockerDriver(base.DriverTestCase):
self.mock_docker.inspect_container = mock.Mock(
return_value={'State': 'created',
'Config': {'Cmd': ['fake_command']}})
mock_container = mock.MagicMock()
mock_container = mock.MagicMock(task_state=None)
mock_container.status = consts.CREATING
self.driver.show(self.context, mock_container)
self.mock_docker.inspect_container.assert_called_once_with(
@ -598,8 +598,8 @@ class TestDockerDriver(base.DriverTestCase):
'FinishedAt': '0001-01-01T00:00:00Z',
}}
)
mock_container = mock.MagicMock()
mock_container.status = 'existed'
mock_container = mock.MagicMock(task_state=None)
mock_container.status = 'Created'
mock_container.Error = 'Container start error.'
self.driver.show(self.context, mock_container)
self.mock_docker.inspect_container.assert_called_once_with(
@ -615,8 +615,8 @@ class TestDockerDriver(base.DriverTestCase):
'FinishedAt': '0001-01-01T00:00:00Z',
}}
)
mock_container = mock.MagicMock()
mock_container.status = 'UNKNOWN'
mock_container = mock.MagicMock(task_state=None)
mock_container.status = 'Running'
mock_container.Error = 'Container run error.'
self.driver.show(self.context, mock_container)
self.mock_docker.inspect_container.assert_called_once_with(