Merge "Update rebuilding status in ApiLayer"
This commit is contained in:
commit
32adf119b0
@ -820,9 +820,12 @@ class ContainersController(base.Controller):
|
||||
container.image_driver = kwargs.get('image_driver')
|
||||
LOG.debug('Calling compute.container_rebuild with %s',
|
||||
container.uuid)
|
||||
run = True if container.status == consts.RUNNING else False
|
||||
context = pecan.request.context
|
||||
container.status = consts.REBUILDING
|
||||
container.save(context)
|
||||
compute_api = pecan.request.compute_api
|
||||
compute_api.container_rebuild(context, container)
|
||||
compute_api.container_rebuild(context, container, run)
|
||||
pecan.response.status = 202
|
||||
|
||||
@pecan.expose('json')
|
||||
|
@ -106,10 +106,10 @@ class API(object):
|
||||
def container_show(self, context, container):
|
||||
return self.rpcapi.container_show(context, container)
|
||||
|
||||
def container_rebuild(self, context, container):
|
||||
def container_rebuild(self, context, container, run):
|
||||
self._record_action_start(context, container,
|
||||
container_actions.REBUILD)
|
||||
return self.rpcapi.container_rebuild(context, container)
|
||||
return self.rpcapi.container_rebuild(context, container, run)
|
||||
|
||||
def container_reboot(self, context, container, *args):
|
||||
self._record_action_start(context, container, container_actions.REBOOT)
|
||||
|
@ -635,24 +635,22 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
container.status = container_status
|
||||
container.save(context)
|
||||
|
||||
def container_rebuild(self, context, container):
|
||||
def container_rebuild(self, context, container, run):
|
||||
@utils.synchronized(container.uuid)
|
||||
def do_container_rebuild():
|
||||
self._do_container_rebuild(context, container)
|
||||
self._do_container_rebuild(context, container, run)
|
||||
|
||||
utils.spawn_n(do_container_rebuild)
|
||||
|
||||
@wrap_container_event(prefix='compute')
|
||||
def _do_container_rebuild(self, context, container):
|
||||
def _do_container_rebuild(self, context, container, run):
|
||||
LOG.info("start to rebuild container: %s", container.uuid)
|
||||
ori_status = container.status
|
||||
vol_info = self._get_vol_info(context, container)
|
||||
try:
|
||||
network_info = self._get_network_info(context, container)
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self._fail_container(context, container, six.text_type(e))
|
||||
self._update_container_state(context, container, consts.REBUILDING)
|
||||
if self.driver.check_container_exist(container):
|
||||
for addr in container.addresses.values():
|
||||
for port in addr:
|
||||
@ -685,7 +683,7 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
self._fail_container(context, container, six.text_type(e))
|
||||
|
||||
LOG.info("rebuild container: %s success", created_container.uuid)
|
||||
if ori_status == consts.RUNNING:
|
||||
if run:
|
||||
self._do_container_start(context, created_container)
|
||||
|
||||
def _get_vol_info(self, context, container):
|
||||
|
@ -75,8 +75,9 @@ class API(rpc_service.API):
|
||||
return self._call(container.host, 'container_show',
|
||||
container=container)
|
||||
|
||||
def container_rebuild(self, context, container):
|
||||
self._cast(container.host, 'container_rebuild', container=container)
|
||||
def container_rebuild(self, context, container, run):
|
||||
self._cast(container.host, 'container_rebuild', container=container,
|
||||
run=run)
|
||||
|
||||
def container_reboot(self, context, container, timeout):
|
||||
self._cast(container.host, 'container_reboot', container=container,
|
||||
|
@ -767,7 +767,8 @@ class TestManager(base.TestCase):
|
||||
mock_get_network_info.return_value = []
|
||||
mock_get_vol_info.return_value = []
|
||||
mock_check.return_value = True
|
||||
self.compute_manager._do_container_rebuild(self.context, container)
|
||||
self.compute_manager._do_container_rebuild(
|
||||
self.context, container, False)
|
||||
mock_save.assert_called_with(self.context)
|
||||
self.assertTrue(mock_create.called)
|
||||
mock_delete.assert_called_once_with(self.context, container, True)
|
||||
@ -793,7 +794,7 @@ class TestManager(base.TestCase):
|
||||
container = Container(self.context, **utils.get_test_container())
|
||||
self.assertRaises(exception.PortNotFound,
|
||||
self.compute_manager._do_container_rebuild,
|
||||
self.context, container)
|
||||
self.context, container, True)
|
||||
mock_fail.assert_called_with(self.context,
|
||||
container, str(fake_exc))
|
||||
mock_event_start.assert_called_once()
|
||||
|
Loading…
Reference in New Issue
Block a user