Merge "Cleanup the reraise parameter in manager"

This commit is contained in:
Zuul 2018-02-05 03:37:49 +00:00 committed by Gerrit Code Review
commit b7ac6127a6
2 changed files with 23 additions and 35 deletions

View File

@ -380,7 +380,7 @@ class Manager(periodic_task.PeriodicTasks):
self._fail_container(context, container, six.text_type(e))
@wrap_container_event(prefix='compute')
def _do_container_start(self, context, container, reraise=False):
def _do_container_start(self, context, container):
LOG.debug('Starting container: %s', container.uuid)
self._update_task_state(context, container, consts.CONTAINER_STARTING)
try:
@ -388,12 +388,12 @@ class Manager(periodic_task.PeriodicTasks):
self._update_task_state(context, container, None)
return container
except exception.DockerError as e:
with excutils.save_and_reraise_exception(reraise=reraise):
with excutils.save_and_reraise_exception(reraise=False):
LOG.error("Error occurred while calling Docker start 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=reraise):
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))
@ -515,7 +515,7 @@ class Manager(periodic_task.PeriodicTasks):
raise
@wrap_container_event(prefix='compute')
def _do_container_reboot(self, context, container, timeout, reraise=False):
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:
@ -523,12 +523,12 @@ class Manager(periodic_task.PeriodicTasks):
self._update_task_state(context, container, None)
return container
except exception.DockerError as e:
with excutils.save_and_reraise_exception(reraise=reraise):
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))
except Exception as e:
with excutils.save_and_reraise_exception(reraise=reraise):
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))
@ -541,7 +541,7 @@ class Manager(periodic_task.PeriodicTasks):
utils.spawn_n(do_container_reboot)
@wrap_container_event(prefix='compute')
def _do_container_stop(self, context, container, timeout, reraise=False):
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:
@ -549,12 +549,12 @@ class Manager(periodic_task.PeriodicTasks):
self._update_task_state(context, container, None)
return container
except exception.DockerError as e:
with excutils.save_and_reraise_exception(reraise=reraise):
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))
except Exception as e:
with excutils.save_and_reraise_exception(reraise=reraise):
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))
@ -574,19 +574,19 @@ class Manager(periodic_task.PeriodicTasks):
utils.spawn_n(do_container_start)
@wrap_container_event(prefix='compute')
def _do_container_pause(self, context, container, reraise=False):
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=reraise):
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))
except Exception as e:
with excutils.save_and_reraise_exception(reraise=reraise):
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))
@ -599,20 +599,20 @@ class Manager(periodic_task.PeriodicTasks):
utils.spawn_n(do_container_pause)
@wrap_container_event(prefix='compute')
def _do_container_unpause(self, context, container, reraise=False):
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=reraise):
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))
except Exception as e:
with excutils.save_and_reraise_exception(reraise=reraise):
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))
@ -676,14 +676,14 @@ class Manager(periodic_task.PeriodicTasks):
raise
@wrap_container_event(prefix='compute')
def _do_container_kill(self, context, container, signal, reraise=False):
def _do_container_kill(self, context, container, signal):
LOG.debug('Killing a container: %s', container.uuid)
try:
container = self.driver.kill(context, container, signal)
container.save(context)
return container
except exception.DockerError as e:
with excutils.save_and_reraise_exception(reraise=reraise):
with excutils.save_and_reraise_exception(reraise=False):
LOG.error("Error occurred while calling Docker kill API: %s",
six.text_type(e))
self._fail_container(context, container, six.text_type(e))

View File

@ -714,9 +714,7 @@ class TestManager(base.TestCase):
container = Container(self.context, **utils.get_test_container())
mock_reboot.side_effect = exception.DockerError(
message="Docker Error occurred")
self.assertRaises(exception.DockerError,
self.compute_manager._do_container_reboot,
self.context, container, 10, reraise=True)
self.compute_manager._do_container_reboot(self.context, container, 10)
mock_save.assert_called_with(self.context)
mock_fail.assert_called_with(self.context,
container, 'Docker Error occurred')
@ -742,9 +740,7 @@ class TestManager(base.TestCase):
container = Container(self.context, **utils.get_test_container())
mock_stop.side_effect = exception.DockerError(
message="Docker Error occurred")
self.assertRaises(exception.DockerError,
self.compute_manager._do_container_stop,
self.context, container, 10, reraise=True)
self.compute_manager._do_container_stop(self.context, container, 10)
mock_save.assert_called_with(self.context)
mock_fail.assert_called_with(self.context,
container, 'Docker Error occurred')
@ -771,9 +767,7 @@ class TestManager(base.TestCase):
container = Container(self.context, **utils.get_test_container())
mock_start.side_effect = exception.DockerError(
message="Docker Error occurred")
self.assertRaises(exception.DockerError,
self.compute_manager._do_container_start,
self.context, container, reraise=True)
self.compute_manager._do_container_start(self.context, container)
mock_save.assert_called_with(self.context)
mock_fail.assert_called_with(self.context,
container, 'Docker Error occurred')
@ -796,9 +790,7 @@ class TestManager(base.TestCase):
container = Container(self.context, **utils.get_test_container())
mock_pause.side_effect = exception.DockerError(
message="Docker Error occurred")
self.assertRaises(exception.DockerError,
self.compute_manager._do_container_pause,
self.context, container, reraise=True)
self.compute_manager._do_container_pause(self.context, container)
mock_fail.assert_called_with(self.context,
container, 'Docker Error occurred')
@ -820,9 +812,7 @@ class TestManager(base.TestCase):
container = Container(self.context, **utils.get_test_container())
mock_unpause.side_effect = exception.DockerError(
message="Docker Error occurred")
self.assertRaises(exception.DockerError,
self.compute_manager._do_container_unpause,
self.context, container, reraise=True)
self.compute_manager._do_container_unpause(self.context, container)
mock_fail.assert_called_with(self.context,
container, 'Docker Error occurred')
@ -882,9 +872,7 @@ class TestManager(base.TestCase):
container = Container(self.context, **utils.get_test_container())
mock_kill.side_effect = exception.DockerError(
message="Docker Error occurred")
self.assertRaises(exception.DockerError,
self.compute_manager._do_container_kill,
self.context, container, None, reraise=True)
self.compute_manager._do_container_kill(self.context, container, None)
mock_fail.assert_called_with(self.context,
container, 'Docker Error occurred')