diff --git a/zun/common/utils.py b/zun/common/utils.py index d96ba9753..1c9b27f18 100644 --- a/zun/common/utils.py +++ b/zun/common/utils.py @@ -583,9 +583,14 @@ def wrap_exception(): def helper(function): @functools.wraps(function) - def decorated_function(self, *args, **kwargs): + def decorated_function(self, context, container, *args, **kwargs): try: - return function(self, *args, **kwargs) + return function(self, context, container, *args, **kwargs) + except exception.DockerError as e: + with excutils.save_and_reraise_exception(reraise=False): + LOG.error("Error occurred while calling Docker API: %s", + six.text_type(e)) + self._fail_container(context, container, six.text_type(e)) except Exception as e: with excutils.save_and_reraise_exception(reraise=False): LOG.exception("Unexpected exception: %s", six.text_type(e)) diff --git a/zun/compute/manager.py b/zun/compute/manager.py index d2a7a8c9d..90738cf5c 100644 --- a/zun/compute/manager.py +++ b/zun/compute/manager.py @@ -514,15 +514,9 @@ class Manager(periodic_task.PeriodicTasks): def _do_container_reboot(self, context, container, timeout): LOG.debug('Rebooting container: %s', container.uuid) self._update_task_state(context, container, consts.CONTAINER_REBOOTING) - try: - container = self.driver.reboot(context, container, timeout) - self._update_task_state(context, container, None) - return container - except exception.DockerError as e: - with excutils.save_and_reraise_exception(reraise=False): - LOG.error("Error occurred while calling Docker reboot " - "API: %s", six.text_type(e)) - self._fail_container(context, container, six.text_type(e)) + container = self.driver.reboot(context, container, timeout) + self._update_task_state(context, container, None) + return container def container_reboot(self, context, container, timeout): @utils.synchronized(container.uuid) @@ -536,15 +530,9 @@ class Manager(periodic_task.PeriodicTasks): def _do_container_stop(self, context, container, timeout): LOG.debug('Stopping container: %s', container.uuid) self._update_task_state(context, container, consts.CONTAINER_STOPPING) - try: - container = self.driver.stop(context, container, timeout) - self._update_task_state(context, container, None) - return container - except exception.DockerError as e: - with excutils.save_and_reraise_exception(reraise=False): - LOG.error("Error occurred while calling Docker stop API: %s", - six.text_type(e)) - self._fail_container(context, container, six.text_type(e)) + container = self.driver.stop(context, container, timeout) + self._update_task_state(context, container, None) + return container def container_stop(self, context, container, timeout): @utils.synchronized(container.uuid) @@ -564,15 +552,9 @@ class Manager(periodic_task.PeriodicTasks): @wrap_container_event(prefix='compute') def _do_container_pause(self, context, container): LOG.debug('Pausing container: %s', container.uuid) - try: - container = self.driver.pause(context, container) - container.save(context) - return container - except exception.DockerError as e: - with excutils.save_and_reraise_exception(reraise=False): - LOG.error("Error occurred while calling Docker pause API: %s", - six.text_type(e)) - self._fail_container(context, container, six.text_type(e)) + container = self.driver.pause(context, container) + container.save(context) + return container def container_pause(self, context, container): @utils.synchronized(container.uuid) @@ -585,16 +567,9 @@ class Manager(periodic_task.PeriodicTasks): @wrap_container_event(prefix='compute') def _do_container_unpause(self, context, container): LOG.debug('Unpausing container: %s', container.uuid) - try: - container = self.driver.unpause(context, container) - container.save(context) - return container - except exception.DockerError as e: - with excutils.save_and_reraise_exception(reraise=False): - LOG.error( - "Error occurred while calling Docker unpause API: %s", - six.text_type(e)) - self._fail_container(context, container, six.text_type(e)) + container = self.driver.unpause(context, container) + container.save(context) + return container def container_unpause(self, context, container): @utils.synchronized(container.uuid)