diff --git a/zun/api/controllers/v1/containers.py b/zun/api/controllers/v1/containers.py index 856a5959a..6e82d4746 100644 --- a/zun/api/controllers/v1/containers.py +++ b/zun/api/controllers/v1/containers.py @@ -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') diff --git a/zun/compute/api.py b/zun/compute/api.py index 1da08a60d..16ec61a9b 100644 --- a/zun/compute/api.py +++ b/zun/compute/api.py @@ -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) diff --git a/zun/compute/manager.py b/zun/compute/manager.py index 0f4d23137..030944f5a 100644 --- a/zun/compute/manager.py +++ b/zun/compute/manager.py @@ -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): diff --git a/zun/compute/rpcapi.py b/zun/compute/rpcapi.py index 1ead4dbb4..b1b4f519b 100644 --- a/zun/compute/rpcapi.py +++ b/zun/compute/rpcapi.py @@ -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, diff --git a/zun/tests/unit/compute/test_compute_manager.py b/zun/tests/unit/compute/test_compute_manager.py index 09add12d7..5f8c233fd 100644 --- a/zun/tests/unit/compute/test_compute_manager.py +++ b/zun/tests/unit/compute/test_compute_manager.py @@ -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()