Refactor container recovery logic
Do minor tweak of the code to reduce the complexity. Change-Id: Id54c284bd2b73a43be2c3c28e850f18e9c7d1085
This commit is contained in:
parent
dfdc8e1b1b
commit
f3889db8d7
@ -52,25 +52,22 @@ class Manager(periodic_task.PeriodicTasks):
|
|||||||
else:
|
else:
|
||||||
self.use_sandbox = False
|
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
|
if (container.status == consts.RUNNING and
|
||||||
local_container.status == consts.STOPPED):
|
current_status == consts.STOPPED):
|
||||||
self.container_reboot(context, container, 10)
|
self.container_reboot(context, container, 10)
|
||||||
|
|
||||||
def init_containers(self, context):
|
def init_containers(self, context):
|
||||||
containers = objects.Container.list_by_host(context, self.host)
|
containers = objects.Container.list_by_host(context, self.host)
|
||||||
local_containers = self.driver.list(context)
|
uuid_to_status_map = {container.uuid: container.status
|
||||||
local_container_map = {container.container_id: container
|
for container in self.driver.list(context)}
|
||||||
for container in local_containers
|
|
||||||
if container.container_id is not None}
|
|
||||||
for container in containers:
|
for container in containers:
|
||||||
|
current_status = uuid_to_status_map[container.uuid]
|
||||||
self._init_container(context, container)
|
self._init_container(context, container)
|
||||||
if CONF.compute.resume_container_state and \
|
if CONF.compute.resume_container_state:
|
||||||
container.container_id is not None:
|
|
||||||
local_container = local_container_map[container.container_id]
|
|
||||||
self.restore_running_container(context,
|
self.restore_running_container(context,
|
||||||
container,
|
container,
|
||||||
local_container)
|
current_status)
|
||||||
|
|
||||||
def _init_container(self, context, container):
|
def _init_container(self, context, container):
|
||||||
'''Initialize this container during zun-compute init.'''
|
'''Initialize this container during zun-compute init.'''
|
||||||
|
@ -116,12 +116,10 @@ class TestManager(base.TestCase):
|
|||||||
def test_container_reboot_after_host_reboot(self, mock_save,
|
def test_container_reboot_after_host_reboot(self, mock_save,
|
||||||
mock_container_reboot):
|
mock_container_reboot):
|
||||||
container_1 = Container(self.context, **utils.get_test_container())
|
container_1 = Container(self.context, **utils.get_test_container())
|
||||||
container_2 = Container(self.context, **utils.get_test_container())
|
|
||||||
container_1.status = consts.RUNNING
|
container_1.status = consts.RUNNING
|
||||||
container_2.status = consts.STOPPED
|
|
||||||
self.compute_manager.restore_running_container(self.context,
|
self.compute_manager.restore_running_container(self.context,
|
||||||
container_1,
|
container_1,
|
||||||
container_2)
|
consts.STOPPED)
|
||||||
mock_container_reboot.assert_called_once_with(self.context,
|
mock_container_reboot.assert_called_once_with(self.context,
|
||||||
container_1,
|
container_1,
|
||||||
10)
|
10)
|
||||||
|
Loading…
Reference in New Issue
Block a user