Merge "Migrate ExceptionHelper to test utilities"
This commit is contained in:
@@ -1343,7 +1343,7 @@ class ComputeVolumeTestCase(BaseTestCase):
|
||||
self.compute.volume_snapshot_create, self.context,
|
||||
self.instance_object, 'fake_id', {})
|
||||
|
||||
self.compute = utils.ExceptionHelper(self.compute)
|
||||
self.compute = test_utils.ExceptionHelper(self.compute)
|
||||
|
||||
self.assertRaises(NotImplementedError,
|
||||
self.compute.volume_snapshot_create, self.context,
|
||||
@@ -1365,7 +1365,7 @@ class ComputeVolumeTestCase(BaseTestCase):
|
||||
self.compute.volume_snapshot_delete, self.context,
|
||||
self.instance_object, uuids.volume, uuids.snapshot, {})
|
||||
|
||||
self.compute = utils.ExceptionHelper(self.compute)
|
||||
self.compute = test_utils.ExceptionHelper(self.compute)
|
||||
|
||||
self.assertRaises(NotImplementedError,
|
||||
self.compute.volume_snapshot_delete, self.context,
|
||||
@@ -4395,7 +4395,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.compute.get_console_output, self.context,
|
||||
instance, 0)
|
||||
|
||||
self.compute = utils.ExceptionHelper(self.compute)
|
||||
self.compute = test_utils.ExceptionHelper(self.compute)
|
||||
|
||||
self.assertRaises(NotImplementedError,
|
||||
self.compute.get_console_output, self.context,
|
||||
@@ -4418,7 +4418,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.compute.get_console_output, self.context,
|
||||
instance, 0)
|
||||
|
||||
self.compute = utils.ExceptionHelper(self.compute)
|
||||
self.compute = test_utils.ExceptionHelper(self.compute)
|
||||
|
||||
self.assertRaises(exception.InstanceNotFound,
|
||||
self.compute.get_console_output, self.context,
|
||||
@@ -4531,7 +4531,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.compute.get_vnc_console,
|
||||
self.context, 'invalid', instance=instance)
|
||||
|
||||
self.compute = utils.ExceptionHelper(self.compute)
|
||||
self.compute = test_utils.ExceptionHelper(self.compute)
|
||||
|
||||
self.assertRaises(exception.ConsoleTypeInvalid,
|
||||
self.compute.get_vnc_console,
|
||||
@@ -4552,7 +4552,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.compute.get_vnc_console,
|
||||
self.context, None, instance=instance)
|
||||
|
||||
self.compute = utils.ExceptionHelper(self.compute)
|
||||
self.compute = test_utils.ExceptionHelper(self.compute)
|
||||
|
||||
self.assertRaises(exception.ConsoleTypeInvalid,
|
||||
self.compute.get_vnc_console,
|
||||
@@ -4572,7 +4572,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.compute.get_vnc_console,
|
||||
self.context, 'novnc', instance=instance)
|
||||
|
||||
self.compute = utils.ExceptionHelper(self.compute)
|
||||
self.compute = test_utils.ExceptionHelper(self.compute)
|
||||
|
||||
self.assertRaises(NotImplementedError,
|
||||
self.compute.get_vnc_console,
|
||||
@@ -4615,7 +4615,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.compute.get_spice_console,
|
||||
self.context, 'invalid', instance=instance)
|
||||
|
||||
self.compute = utils.ExceptionHelper(self.compute)
|
||||
self.compute = test_utils.ExceptionHelper(self.compute)
|
||||
|
||||
self.assertRaises(exception.ConsoleTypeInvalid,
|
||||
self.compute.get_spice_console,
|
||||
@@ -4637,7 +4637,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.compute.get_spice_console,
|
||||
self.context, 'spice-html5', instance=instance)
|
||||
|
||||
self.compute = utils.ExceptionHelper(self.compute)
|
||||
self.compute = test_utils.ExceptionHelper(self.compute)
|
||||
|
||||
self.assertRaises(NotImplementedError,
|
||||
self.compute.get_spice_console,
|
||||
@@ -4657,7 +4657,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.compute.get_spice_console,
|
||||
self.context, None, instance=instance)
|
||||
|
||||
self.compute = utils.ExceptionHelper(self.compute)
|
||||
self.compute = test_utils.ExceptionHelper(self.compute)
|
||||
|
||||
self.assertRaises(exception.ConsoleTypeInvalid,
|
||||
self.compute.get_spice_console,
|
||||
@@ -4677,7 +4677,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.stub_out("nova.virt.fake.FakeDriver.get_vnc_console",
|
||||
fake_driver_get_console)
|
||||
|
||||
self.compute = utils.ExceptionHelper(self.compute)
|
||||
self.compute = test_utils.ExceptionHelper(self.compute)
|
||||
|
||||
self.assertRaises(exception.InstanceNotReady,
|
||||
self.compute.get_vnc_console, self.context, 'novnc',
|
||||
@@ -4695,7 +4695,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.stub_out("nova.virt.fake.FakeDriver.get_spice_console",
|
||||
fake_driver_get_console)
|
||||
|
||||
self.compute = utils.ExceptionHelper(self.compute)
|
||||
self.compute = test_utils.ExceptionHelper(self.compute)
|
||||
|
||||
self.assertRaises(exception.InstanceNotReady,
|
||||
self.compute.get_spice_console, self.context, 'spice-html5',
|
||||
@@ -4706,7 +4706,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
instance = self._create_fake_instance_obj(
|
||||
params={'vm_state': vm_states.BUILDING})
|
||||
|
||||
self.compute = utils.ExceptionHelper(self.compute)
|
||||
self.compute = test_utils.ExceptionHelper(self.compute)
|
||||
|
||||
self.assertRaises(exception.ConsoleTypeUnavailable,
|
||||
self.compute.get_vnc_console, self.context, 'novnc',
|
||||
@@ -4717,7 +4717,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
instance = self._create_fake_instance_obj(
|
||||
params={'vm_state': vm_states.BUILDING})
|
||||
|
||||
self.compute = utils.ExceptionHelper(self.compute)
|
||||
self.compute = test_utils.ExceptionHelper(self.compute)
|
||||
|
||||
self.assertRaises(exception.ConsoleTypeUnavailable,
|
||||
self.compute.get_spice_console, self.context, 'spice-html5',
|
||||
|
||||
@@ -3650,7 +3650,7 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
inst_obj = objects.Instance._from_db_object(
|
||||
self.context, objects.Instance(), instance, [])
|
||||
mock_execute.side_effect = ex
|
||||
self.conductor = utils.ExceptionHelper(self.conductor)
|
||||
self.conductor = test_utils.ExceptionHelper(self.conductor)
|
||||
|
||||
self.assertRaises(type(ex),
|
||||
self.conductor.migrate_server, self.context, inst_obj,
|
||||
@@ -3679,7 +3679,7 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
ex = exc.InvalidCPUInfo(reason="invalid cpu info.")
|
||||
mock_execute.side_effect = ex
|
||||
|
||||
self.conductor = utils.ExceptionHelper(self.conductor)
|
||||
self.conductor = test_utils.ExceptionHelper(self.conductor)
|
||||
|
||||
self.assertRaises(exc.InvalidCPUInfo,
|
||||
self.conductor.migrate_server, self.context, inst_obj,
|
||||
|
||||
@@ -14,11 +14,14 @@
|
||||
|
||||
import collections
|
||||
import errno
|
||||
import functools
|
||||
import platform
|
||||
import socket
|
||||
import sys
|
||||
from unittest import mock
|
||||
|
||||
import oslo_messaging as messaging
|
||||
|
||||
from nova.compute import flavors
|
||||
import nova.conf
|
||||
import nova.context
|
||||
@@ -368,3 +371,23 @@ def assert_legacy_instance_delete_notification_by_uuid(
|
||||
assert call[0][1].db_connection is not None
|
||||
else:
|
||||
assert call[0][1].db_connection is None
|
||||
|
||||
|
||||
class ExceptionHelper(object):
|
||||
"""Class to wrap another and translate the ClientExceptions raised by its
|
||||
function calls to the actual ones.
|
||||
"""
|
||||
|
||||
def __init__(self, target):
|
||||
self._target = target
|
||||
|
||||
def __getattr__(self, name):
|
||||
func = getattr(self._target, name)
|
||||
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except messaging.ExpectedException as e:
|
||||
raise e.exc_info[1]
|
||||
return wrapper
|
||||
|
||||
@@ -41,7 +41,6 @@ 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
|
||||
import oslo_messaging as messaging
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import importutils
|
||||
from oslo_utils import strutils
|
||||
@@ -513,26 +512,6 @@ def expects_func_args(*args):
|
||||
return _decorator_checker
|
||||
|
||||
|
||||
class ExceptionHelper(object):
|
||||
"""Class to wrap another and translate the ClientExceptions raised by its
|
||||
function calls to the actual ones.
|
||||
"""
|
||||
|
||||
def __init__(self, target):
|
||||
self._target = target
|
||||
|
||||
def __getattr__(self, name):
|
||||
func = getattr(self._target, name)
|
||||
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except messaging.ExpectedException as e:
|
||||
raise e.exc_info[1]
|
||||
return wrapper
|
||||
|
||||
|
||||
def check_string_length(value, name=None, min_length=0, max_length=None):
|
||||
"""Check the length of specified string
|
||||
:param value: the value of the string
|
||||
|
||||
Reference in New Issue
Block a user