Refactor container recovery logic

Do minor tweak of the code to reduce the complexity.

Change-Id: Id54c284bd2b73a43be2c3c28e850f18e9c7d1085
This commit is contained in:
Hongbin Lu 2018-02-19 02:59:41 +00:00
parent dfdc8e1b1b
commit f3889db8d7
2 changed files with 8 additions and 13 deletions

View File

@ -52,25 +52,22 @@ class Manager(periodic_task.PeriodicTasks):
else:
self.use_sandbox = False
def restore_running_container(self, context, container, local_container):
def restore_running_container(self, context, container, current_status):
if (container.status == consts.RUNNING and
local_container.status == consts.STOPPED):
current_status == consts.STOPPED):
self.container_reboot(context, container, 10)
def init_containers(self, context):
containers = objects.Container.list_by_host(context, self.host)
local_containers = self.driver.list(context)
local_container_map = {container.container_id: container
for container in local_containers
if container.container_id is not None}
uuid_to_status_map = {container.uuid: container.status
for container in self.driver.list(context)}
for container in containers:
current_status = uuid_to_status_map[container.uuid]
self._init_container(context, container)
if CONF.compute.resume_container_state and \
container.container_id is not None:
local_container = local_container_map[container.container_id]
if CONF.compute.resume_container_state:
self.restore_running_container(context,
container,
local_container)
current_status)
def _init_container(self, context, container):
'''Initialize this container during zun-compute init.'''

View File

@ -116,12 +116,10 @@ class TestManager(base.TestCase):
def test_container_reboot_after_host_reboot(self, mock_save,
mock_container_reboot):
container_1 = Container(self.context, **utils.get_test_container())
container_2 = Container(self.context, **utils.get_test_container())
container_1.status = consts.RUNNING
container_2.status = consts.STOPPED
self.compute_manager.restore_running_container(self.context,
container_1,
container_2)
consts.STOPPED)
mock_container_reboot.assert_called_once_with(self.context,
container_1,
10)