]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix logic in test_db_loadbalancer
authorEugene Nikanorov <enikanorov@mirantis.com>
Tue, 14 May 2013 21:14:30 +0000 (01:14 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Wed, 15 May 2013 04:43:38 +0000 (08:43 +0400)
Fix code to check HTTP error code before attempt to deserialize body

fixes bug 1180113

Change-Id: I1d75e0fe739dfa70ef415602e669319797af026f

quantum/tests/unit/db/loadbalancer/test_db_loadbalancer.py
quantum/tests/unit/test_servicetype.py

index 75aeabe6973b7e1856eb8b93a80f0218205a3c0f..8628fb906965858897d772ab2d33d5ec365f1130 100644 (file)
@@ -174,10 +174,13 @@ class LoadBalancerPluginDbTestCase(test_db_plugin.QuantumDbPluginV2TestCase):
                                        admin_state_up,
                                        subnet_id=tmp_subnet['subnet']['id'],
                                        **kwargs)
-                vip = self.deserialize(fmt or self.fmt, res)
                 if res.status_int >= 400:
-                    raise webob.exc.HTTPClientError(code=res.status_int)
+                    raise webob.exc.HTTPClientError(
+                        explanation=_("Unexpected error code: %s") %
+                        res.status_int
+                    )
                 try:
+                    vip = self.deserialize(fmt or self.fmt, res)
                     yield vip
                 finally:
                     if not no_delete:
@@ -195,10 +198,12 @@ class LoadBalancerPluginDbTestCase(test_db_plugin.QuantumDbPluginV2TestCase):
                                 protocol,
                                 admin_state_up,
                                 **kwargs)
-        pool = self.deserialize(fmt or self.fmt, res)
         if res.status_int >= 400:
-            raise webob.exc.HTTPClientError(code=res.status_int)
+            raise webob.exc.HTTPClientError(
+                explanation=_("Unexpected error code: %s") % res.status_int
+            )
         try:
+            pool = self.deserialize(fmt or self.fmt, res)
             yield pool
         finally:
             if not no_delete:
@@ -214,10 +219,12 @@ class LoadBalancerPluginDbTestCase(test_db_plugin.QuantumDbPluginV2TestCase):
                                   protocol_port,
                                   admin_state_up,
                                   **kwargs)
-        member = self.deserialize(fmt or self.fmt, res)
         if res.status_int >= 400:
-            raise webob.exc.HTTPClientError(code=res.status_int)
+            raise webob.exc.HTTPClientError(
+                explanation=_("Unexpected error code: %s") % res.status_int
+            )
         try:
+            member = self.deserialize(fmt or self.fmt, res)
             yield member
         finally:
             if not no_delete:
@@ -237,10 +244,12 @@ class LoadBalancerPluginDbTestCase(test_db_plugin.QuantumDbPluginV2TestCase):
                                           max_retries,
                                           admin_state_up,
                                           **kwargs)
+        if res.status_int >= 400:
+            raise webob.exc.HTTPClientError(
+                explanation=_("Unexpected error code: %s") % res.status_int
+            )
         health_monitor = self.deserialize(fmt or self.fmt, res)
         the_health_monitor = health_monitor['health_monitor']
-        if res.status_int >= 400:
-            raise webob.exc.HTTPClientError(code=res.status_int)
         # make sure:
         # 1. When the type is HTTP/S we have HTTP related attributes in
         #    the result
index 1871ed3949bbc10d67f8cfc91b0cfd9afe656649..556f0e3f81a2fa4b163827cec4aed7d26ebbe22e 100644 (file)
@@ -257,9 +257,9 @@ class ServiceTypeManagerTestCase(ServiceTypeTestCaseBase):
             service_defs = [{'service_class': constants.DUMMY,
                              'plugin': dp.DUMMY_PLUGIN_NAME}]
         res = self._create_service_type(name, service_defs)
-        svc_type = self.deserialize(res)
         if res.status_int >= 400:
             raise webexc.HTTPClientError(code=res.status_int)
+        svc_type = self.deserialize(res)
         yield svc_type
 
         if do_delete: