From: Dan Prince <dprince@redhat.com>
Date: Tue, 8 Jan 2013 18:24:49 +0000 (-0500)
Subject: Enable cinder exception format checking in tests.
X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f791565c5bff7b08bc10af538e54d0505457ef41;p=openstack-build%2Fcinder-build.git

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
---

diff --git a/cinder/test.py b/cinder/test.py
index 29be96467..3887091d0 100644
--- a/cinder/test.py
+++ b/cinder/test.py
@@ -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."""
diff --git a/cinder/tests/api/contrib/test_extended_snapshot_attributes.py b/cinder/tests/api/contrib/test_extended_snapshot_attributes.py
index d8e7ceda9..5937ac962 100644
--- a/cinder/tests/api/contrib/test_extended_snapshot_attributes.py
+++ b/cinder/tests/api/contrib/test_extended_snapshot_attributes.py
@@ -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'
diff --git a/cinder/tests/api/contrib/test_volume_actions.py b/cinder/tests/api/contrib/test_volume_actions.py
index a2b019cd0..aed906985 100644
--- a/cinder/tests/api/contrib/test_volume_actions.py
+++ b/cinder/tests/api/contrib/test_volume_actions.py
@@ -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)
diff --git a/cinder/tests/test_exception.py b/cinder/tests/test_exception.py
index 2119297a4..c47f116e4 100644
--- a/cinder/tests/test_exception.py
+++ b/cinder/tests/test_exception.py
@@ -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"
 
diff --git a/cinder/tests/test_misc.py b/cinder/tests/test_misc.py
index 7dd24ca7c..60ad26b7e 100644
--- a/cinder/tests/test_misc.py
+++ b/cinder/tests/test_misc.py
@@ -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):
diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py
index 1b7c95bcd..dd25fd7e8 100644
--- a/cinder/tests/test_volume.py
+++ b/cinder/tests/test_volume.py
@@ -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)
diff --git a/cinder/tests/test_xiv.py b/cinder/tests/test_xiv.py
index 648425303..989b47652 100644
--- a/cinder/tests/test_xiv.py
+++ b/cinder/tests/test_xiv.py
@@ -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)