Merge "Consolidate exception handling in manager"
This commit is contained in:
commit
51df54a2a7
@ -25,6 +25,7 @@ from oslo_concurrency import lockutils
|
||||
from oslo_concurrency import processutils
|
||||
from oslo_context import context as common_context
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import strutils
|
||||
import pecan
|
||||
import six
|
||||
@ -576,3 +577,17 @@ def wrap_container_event(prefix):
|
||||
return function(self, context, *args, **kwargs)
|
||||
return decorated_function
|
||||
return helper
|
||||
|
||||
|
||||
def wrap_exception():
|
||||
def helper(function):
|
||||
|
||||
@functools.wraps(function)
|
||||
def decorated_function(self, *args, **kwargs):
|
||||
try:
|
||||
return function(self, *args, **kwargs)
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception(reraise=False):
|
||||
LOG.exception("Unexpected exception: %s", six.text_type(e))
|
||||
return decorated_function
|
||||
return helper
|
||||
|
@ -27,6 +27,7 @@ from zun.common.i18n import _
|
||||
from zun.common import utils
|
||||
from zun.common.utils import translate_exception
|
||||
from zun.common.utils import wrap_container_event
|
||||
from zun.common.utils import wrap_exception
|
||||
from zun.compute import compute_node_tracker
|
||||
import zun.conf
|
||||
from zun.container import driver
|
||||
@ -453,16 +454,13 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
|
||||
utils.spawn_n(do_add_security_group)
|
||||
|
||||
@wrap_exception()
|
||||
@wrap_container_event(prefix='compute')
|
||||
def _add_security_group(self, context, container, security_group):
|
||||
LOG.debug('Adding security_group to container: %s', container.uuid)
|
||||
try:
|
||||
self.driver.add_security_group(context, container, security_group)
|
||||
container.security_groups += [security_group]
|
||||
container.save(context)
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception(reraise=False):
|
||||
LOG.exception("Unexpected exception: %s", six.text_type(e))
|
||||
self.driver.add_security_group(context, container, security_group)
|
||||
container.security_groups += [security_group]
|
||||
container.save(context)
|
||||
|
||||
def remove_security_group(self, context, container, security_group):
|
||||
@utils.synchronized(container.uuid)
|
||||
@ -471,19 +469,16 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
|
||||
utils.spawn_n(do_remove_security_group)
|
||||
|
||||
@wrap_exception()
|
||||
@wrap_container_event(prefix='compute')
|
||||
def _remove_security_group(self, context, container, security_group):
|
||||
LOG.debug('Removing security_group from container: %s', container.uuid)
|
||||
try:
|
||||
self.driver.remove_security_group(context, container,
|
||||
security_group)
|
||||
security_groups = (set(container.security_groups)
|
||||
- set([security_group]))
|
||||
container.security_groups = list(security_groups)
|
||||
container.save(context)
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception(reraise=False):
|
||||
LOG.exception("Unexpected exception: %s", six.text_type(e))
|
||||
self.driver.remove_security_group(context, container,
|
||||
security_group)
|
||||
security_groups = (set(container.security_groups)
|
||||
- set([security_group]))
|
||||
container.security_groups = list(security_groups)
|
||||
container.save(context)
|
||||
|
||||
@translate_exception
|
||||
def container_list(self, context):
|
||||
@ -514,6 +509,7 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
LOG.exception("Unexpected exception: %s", six.text_type(e))
|
||||
raise
|
||||
|
||||
@wrap_exception()
|
||||
@wrap_container_event(prefix='compute')
|
||||
def _do_container_reboot(self, context, container, timeout):
|
||||
LOG.debug('Rebooting container: %s', container.uuid)
|
||||
@ -527,11 +523,6 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
LOG.error("Error occurred while calling Docker reboot "
|
||||
"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))
|
||||
self._fail_container(context, container, six.text_type(e))
|
||||
|
||||
def container_reboot(self, context, container, timeout):
|
||||
@utils.synchronized(container.uuid)
|
||||
@ -540,6 +531,7 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
|
||||
utils.spawn_n(do_container_reboot)
|
||||
|
||||
@wrap_exception()
|
||||
@wrap_container_event(prefix='compute')
|
||||
def _do_container_stop(self, context, container, timeout):
|
||||
LOG.debug('Stopping container: %s', container.uuid)
|
||||
@ -553,11 +545,6 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
LOG.error("Error occurred while calling Docker stop 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))
|
||||
self._fail_container(context, container, six.text_type(e))
|
||||
|
||||
def container_stop(self, context, container, timeout):
|
||||
@utils.synchronized(container.uuid)
|
||||
@ -573,6 +560,7 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
|
||||
utils.spawn_n(do_container_start)
|
||||
|
||||
@wrap_exception()
|
||||
@wrap_container_event(prefix='compute')
|
||||
def _do_container_pause(self, context, container):
|
||||
LOG.debug('Pausing container: %s', container.uuid)
|
||||
@ -585,11 +573,6 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
LOG.error("Error occurred while calling Docker pause 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))
|
||||
self._fail_container(context, container, six.text_type(e))
|
||||
|
||||
def container_pause(self, context, container):
|
||||
@utils.synchronized(container.uuid)
|
||||
@ -598,6 +581,7 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
|
||||
utils.spawn_n(do_container_pause)
|
||||
|
||||
@wrap_exception()
|
||||
@wrap_container_event(prefix='compute')
|
||||
def _do_container_unpause(self, context, container):
|
||||
LOG.debug('Unpausing container: %s', container.uuid)
|
||||
@ -611,11 +595,6 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
"Error occurred while calling Docker unpause 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))
|
||||
self._fail_container(context, container, six.text_type(e))
|
||||
|
||||
def container_unpause(self, context, container):
|
||||
@utils.synchronized(container.uuid)
|
||||
@ -1044,22 +1023,16 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
capsule.save(context)
|
||||
capsule.destroy(context)
|
||||
|
||||
@wrap_exception()
|
||||
@wrap_container_event(prefix='compute')
|
||||
def network_detach(self, context, container, network):
|
||||
LOG.debug('Detach network: %(network)s from container: %(container)s.',
|
||||
{'container': container, 'network': network})
|
||||
try:
|
||||
self.driver.network_detach(context, container, network)
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception(reraise=False):
|
||||
LOG.exception("Unexpected exception: %s", six.text_type(e))
|
||||
self.driver.network_detach(context, container, network)
|
||||
|
||||
@wrap_exception()
|
||||
@wrap_container_event(prefix='compute')
|
||||
def network_attach(self, context, container, network):
|
||||
LOG.debug('Attach network: %(network)s to container: %(container)s.',
|
||||
{'container': container, 'network': network})
|
||||
try:
|
||||
self.driver.network_attach(context, container, network)
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception(reraise=False):
|
||||
LOG.exception("Unexpected exception: %s", six.text_type(e))
|
||||
self.driver.network_attach(context, container, network)
|
||||
|
Loading…
x
Reference in New Issue
Block a user