Merge "Fix the state setting logic on state sync"
This commit is contained in:
@@ -373,28 +373,35 @@ class DockerDriver(driver.ContainerDriver):
|
||||
started_at = self.format_status_detail(state.get('StartedAt'))
|
||||
finished_at = self.format_status_detail(
|
||||
state.get('FinishedAt'))
|
||||
if started_at == "":
|
||||
if started_at == "" and container.status == consts.CREATING:
|
||||
container.status = consts.CREATED
|
||||
container.status_detail = "Created"
|
||||
elif finished_at == "":
|
||||
elif (started_at == "" and
|
||||
container.status in (consts.CREATED, consts.ERROR)):
|
||||
pass
|
||||
elif started_at != "" and finished_at == "":
|
||||
container.status = consts.UNKNOWN
|
||||
container.status_detail = ""
|
||||
else:
|
||||
elif started_at != "" and finished_at != "":
|
||||
container.status = consts.STOPPED
|
||||
container.status_detail = "Exited({}) {} ago ".format(
|
||||
state.get('ExitCode'), finished_at)
|
||||
if status_detail is None:
|
||||
container.status_detail = None
|
||||
else:
|
||||
if state.lower() == 'created':
|
||||
state = state.lower()
|
||||
if state == 'created' and container.status == consts.CREATING:
|
||||
container.status = consts.CREATED
|
||||
elif state.lower() == 'paused':
|
||||
elif (state == 'created' and
|
||||
container.status in (consts.CREATED, consts.ERROR)):
|
||||
pass
|
||||
elif state == 'ERROR':
|
||||
container.status = consts.PAUSED
|
||||
elif state.lower() == 'running':
|
||||
elif state == 'running':
|
||||
container.status = consts.RUNNING
|
||||
elif state.lower() == 'dead':
|
||||
elif state == 'dead':
|
||||
container.status = consts.ERROR
|
||||
elif state.lower() in ('restarting', 'exited', 'removing'):
|
||||
elif state in ('restarting', 'exited', 'removing'):
|
||||
container.status = consts.STOPPED
|
||||
else:
|
||||
container.status = consts.UNKNOWN
|
||||
|
||||
@@ -199,6 +199,28 @@ class TestDockerDriver(base.DriverTestCase):
|
||||
mock_container.container_id)
|
||||
self.assertIsNone(mock_container.command)
|
||||
|
||||
def test_show_container_created(self):
|
||||
self.mock_docker.inspect_container = mock.Mock(
|
||||
return_value={'State': 'created',
|
||||
'Config': {'Cmd': ['fake_command']}})
|
||||
mock_container = mock.MagicMock()
|
||||
mock_container.status = consts.CREATING
|
||||
self.driver.show(self.context, mock_container)
|
||||
self.mock_docker.inspect_container.assert_called_once_with(
|
||||
mock_container.container_id)
|
||||
self.assertEqual(consts.CREATED, mock_container.status)
|
||||
|
||||
def test_show_container_create_failed(self):
|
||||
self.mock_docker.inspect_container = mock.Mock(
|
||||
return_value={'State': 'created',
|
||||
'Config': {'Cmd': ['fake_command']}})
|
||||
mock_container = mock.MagicMock()
|
||||
mock_container.status = consts.ERROR
|
||||
self.driver.show(self.context, mock_container)
|
||||
self.mock_docker.inspect_container.assert_called_once_with(
|
||||
mock_container.container_id)
|
||||
self.assertEqual(consts.ERROR, mock_container.status)
|
||||
|
||||
def test_show_fail_container_id_is_none(self):
|
||||
mock_container = mock.MagicMock()
|
||||
mock_container.container_id = None
|
||||
|
||||
Reference in New Issue
Block a user