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.stubs = stubout.StubOutForTesting()
self.injected = [] self.injected = []
self._services = [] self._services = []
FLAGS.set_override('fatal_exception_format_errors', True)
def tearDown(self): def tearDown(self):
"""Runs after each test method to tear down test environment.""" """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 test_no_instance_passthrough_404(self):
def fake_snapshot_get(*args, **kwargs): 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) self.stubs.Set(volume.api.API, 'get_snapshot', fake_snapshot_get)
url = '/v2/fake/snapshots/70f6db34-de8d-4fbd-aafb-4065bdfa6115' 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 test_copy_volume_to_image_invalidvolume(self):
def stub_upload_volume_to_image_service_raise(self, context, volume, def stub_upload_volume_to_image_service_raise(self, context, volume,
metadata, force): metadata, force):
raise exception.InvalidVolume raise exception.InvalidVolume(reason='blah')
self.stubs.Set(volume_api.API, self.stubs.Set(volume_api.API,
"copy_volume_to_image", "copy_volume_to_image",
stub_upload_volume_to_image_service_raise) stub_upload_volume_to_image_service_raise)

View File

@ -70,6 +70,9 @@ class CinderExceptionTestCase(test.TestCase):
self.assertEquals(unicode(exc), 'default message: 500') self.assertEquals(unicode(exc), 'default message: 500')
def test_error_msg_exception_with_kwargs(self): 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): class FakeCinderException(exception.CinderException):
message = "default message: %(mispelled_code)s" message = "default message: %(mispelled_code)s"

View File

@ -28,6 +28,8 @@ class ExceptionTestCase(test.TestCase):
raise exc() raise exc()
def test_exceptions_raise(self): 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): for name in dir(exception):
exc = getattr(exception, name) exc = getattr(exception, name)
if isinstance(exc, type): if isinstance(exc, type):

View File

@ -203,7 +203,8 @@ class VolumeTestCase(test.TestCase):
self.mox.StubOutWithMock(self.volume.driver, 'delete_volume') self.mox.StubOutWithMock(self.volume.driver, 'delete_volume')
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() self.mox.ReplayAll()
res = self.volume.delete_volume(self.context, volume_id) res = self.volume.delete_volume(self.context, volume_id)
self.assertEqual(True, res) self.assertEqual(True, res)
@ -472,7 +473,8 @@ class VolumeTestCase(test.TestCase):
self.mox.StubOutWithMock(self.volume.driver, 'delete_snapshot') self.mox.StubOutWithMock(self.volume.driver, 'delete_snapshot')
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.mox.ReplayAll()
self.volume.delete_snapshot(self.context, snapshot_id) self.volume.delete_snapshot(self.context, snapshot_id)
snapshot_ref = db.snapshot_get(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() raise self.exception.NotAuthorized()
if self.xiv_info['xiv_address'] != FLAGS.san_ip: if self.xiv_info['xiv_address'] != FLAGS.san_ip:
raise self.exception.HostNotFound() raise self.exception.HostNotFound(host='fake')
def create_volume(self, volume): def create_volume(self, volume):
if volume['size'] > 100: if volume['size'] > 100:
raise self.exception.VolumeBackendAPIException() raise self.exception.VolumeBackendAPIException(data='blah')
self.volumes[volume['name']] = volume self.volumes[volume['name']] = volume
def volume_exists(self, volume): def volume_exists(self, volume):
@ -73,7 +73,7 @@ class XIVFakeProxyDriver(object):
def initialize_connection(self, volume, connector): def initialize_connection(self, volume, connector):
if not self.volume_exists(volume): if not self.volume_exists(volume):
raise self.exception.VolumeNotFound() raise self.exception.VolumeNotFound(volume_id=volume['id'])
lun_id = volume['id'] lun_id = volume['id']
self.volumes[volume['name']]['attached'] = connector self.volumes[volume['name']]['attached'] = connector
@ -94,14 +94,14 @@ class XIVFakeProxyDriver(object):
def terminate_connection(self, volume, connector): def terminate_connection(self, volume, connector):
if not self.volume_exists(volume): 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): 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'] del self.volumes[volume['name']]['attached']
def is_volume_attached(self, volume, connector): def is_volume_attached(self, volume, connector):
if not self.volume_exists(volume): 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) return (self.volumes[volume['name']].get('attached', None)
== connector) == connector)