Enable cinder exception format checking in tests.

Updates the Cinder test runner so that it enables
'fatal_exception_format_errors' for testing.

Includes a bunch of fixes to test exceptions as well so they
will continue to pass.

Change-Id: Idd30a810fb81e8e14490644779c3e03b6af25ff3
This commit is contained in:
Dan Prince 2013-01-08 13:24:49 -05:00
parent 3cb7ee4555
commit f791565c5b
7 changed files with 18 additions and 10 deletions

View File

@ -137,6 +137,7 @@ class TestCase(unittest.TestCase):
self.stubs = stubout.StubOutForTesting()
self.injected = []
self._services = []
FLAGS.set_override('fatal_exception_format_errors', True)
def tearDown(self):
"""Runs after each test method to tear down test environment."""

View File

@ -103,7 +103,7 @@ class ExtendedSnapshotAttributesTest(test.TestCase):
def test_no_instance_passthrough_404(self):
def fake_snapshot_get(*args, **kwargs):
raise exception.InstanceNotFound()
raise exception.InstanceNotFound(instance_id='fake')
self.stubs.Set(volume.api.API, 'get_snapshot', fake_snapshot_get)
url = '/v2/fake/snapshots/70f6db34-de8d-4fbd-aafb-4065bdfa6115'

View File

@ -187,7 +187,7 @@ class VolumeImageActionsTest(test.TestCase):
def test_copy_volume_to_image_invalidvolume(self):
def stub_upload_volume_to_image_service_raise(self, context, volume,
metadata, force):
raise exception.InvalidVolume
raise exception.InvalidVolume(reason='blah')
self.stubs.Set(volume_api.API,
"copy_volume_to_image",
stub_upload_volume_to_image_service_raise)

View File

@ -70,6 +70,9 @@ class CinderExceptionTestCase(test.TestCase):
self.assertEquals(unicode(exc), 'default message: 500')
def test_error_msg_exception_with_kwargs(self):
# NOTE(dprince): disable format errors for this test
self.flags(fatal_exception_format_errors=False)
class FakeCinderException(exception.CinderException):
message = "default message: %(mispelled_code)s"

View File

@ -28,6 +28,8 @@ class ExceptionTestCase(test.TestCase):
raise exc()
def test_exceptions_raise(self):
# NOTE(dprince): disable format errors since we are not passing kwargs
self.flags(fatal_exception_format_errors=False)
for name in dir(exception):
exc = getattr(exception, name)
if isinstance(exc, type):

View File

@ -203,7 +203,8 @@ class VolumeTestCase(test.TestCase):
self.mox.StubOutWithMock(self.volume.driver, 'delete_volume')
self.volume.driver.delete_volume(
mox.IgnoreArg()).AndRaise(exception.VolumeIsBusy)
mox.IgnoreArg()).AndRaise(exception.VolumeIsBusy(
volume_name='fake'))
self.mox.ReplayAll()
res = self.volume.delete_volume(self.context, volume_id)
self.assertEqual(True, res)
@ -472,7 +473,8 @@ class VolumeTestCase(test.TestCase):
self.mox.StubOutWithMock(self.volume.driver, 'delete_snapshot')
self.volume.driver.delete_snapshot(
mox.IgnoreArg()).AndRaise(exception.SnapshotIsBusy)
mox.IgnoreArg()).AndRaise(
exception.SnapshotIsBusy(snapshot_name='fake'))
self.mox.ReplayAll()
self.volume.delete_snapshot(self.context, snapshot_id)
snapshot_ref = db.snapshot_get(self.context, snapshot_id)

View File

@ -57,11 +57,11 @@ class XIVFakeProxyDriver(object):
raise self.exception.NotAuthorized()
if self.xiv_info['xiv_address'] != FLAGS.san_ip:
raise self.exception.HostNotFound()
raise self.exception.HostNotFound(host='fake')
def create_volume(self, volume):
if volume['size'] > 100:
raise self.exception.VolumeBackendAPIException()
raise self.exception.VolumeBackendAPIException(data='blah')
self.volumes[volume['name']] = volume
def volume_exists(self, volume):
@ -73,7 +73,7 @@ class XIVFakeProxyDriver(object):
def initialize_connection(self, volume, connector):
if not self.volume_exists(volume):
raise self.exception.VolumeNotFound()
raise self.exception.VolumeNotFound(volume_id=volume['id'])
lun_id = volume['id']
self.volumes[volume['name']]['attached'] = connector
@ -94,14 +94,14 @@ class XIVFakeProxyDriver(object):
def terminate_connection(self, volume, connector):
if not self.volume_exists(volume):
raise self.exception.VolumeNotFound()
raise self.exception.VolumeNotFound(volume_id=volume['id'])
if not self.is_volume_attached(volume, connector):
raise self.exception.VolumeNotFoundForInstance()
raise self.exception.VolumeNotFoundForInstance(instance_id='fake')
del self.volumes[volume['name']]['attached']
def is_volume_attached(self, volume, connector):
if not self.volume_exists(volume):
raise self.exception.VolumeNotFound()
raise self.exception.VolumeNotFound(volume_id=volume['id'])
return (self.volumes[volume['name']].get('attached', None)
== connector)