]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Enable cinder exception format checking in tests.
authorDan Prince <dprince@redhat.com>
Tue, 8 Jan 2013 18:24:49 +0000 (13:24 -0500)
committerDan Prince <dprince@redhat.com>
Tue, 8 Jan 2013 18:56:19 +0000 (13:56 -0500)
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

cinder/test.py
cinder/tests/api/contrib/test_extended_snapshot_attributes.py
cinder/tests/api/contrib/test_volume_actions.py
cinder/tests/test_exception.py
cinder/tests/test_misc.py
cinder/tests/test_volume.py
cinder/tests/test_xiv.py

index 29be96467548e85b4a8767918b67aa006ccc8e71..3887091d0b15c6059e042479d872fc0809244456 100644 (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."""
index d8e7ceda94606ff505f5615a1010d71e62e60457..5937ac9628944705f0e89b25e58b12ed1b9c7b67 100644 (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'
index a2b019cd0e872ed88281552ca426e6ad66afc314..aed906985d2c579e9aaba42bd9d7196cce29e6fe 100644 (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)
index 2119297a44a3aa84691d91ba122608b12e64203f..c47f116e49e5639b77310c70959b6ff093200136 100644 (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"
 
index 7dd24ca7c9f6f89a3f6079a77ceb4ed0a43cb0a6..60ad26b7ed81ffa883f8a31e860e58f3bab0f865 100644 (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):
index 1b7c95bcd493dcbb41f0bf9edc8b49fda1d22e3b..dd25fd7e8d44dc3ec5a06d5f44c8fa8b542c2209 100644 (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)
index 6484253034ed10a3c96065a462ad1e21610ace27..989b4765235e7515c7e8f70cc91257169a1bf570 100644 (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)