From 2648314b4cb884fe317e246fd418d2674fc0192e Mon Sep 17 00:00:00 2001 From: Eugene Nikanorov Date: Wed, 15 May 2013 01:14:30 +0400 Subject: [PATCH] Fix logic in test_db_loadbalancer Fix code to check HTTP error code before attempt to deserialize body fixes bug 1180113 Change-Id: I1d75e0fe739dfa70ef415602e669319797af026f --- .../db/loadbalancer/test_db_loadbalancer.py | 25 +++++++++++++------ quantum/tests/unit/test_servicetype.py | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/quantum/tests/unit/db/loadbalancer/test_db_loadbalancer.py b/quantum/tests/unit/db/loadbalancer/test_db_loadbalancer.py index 75aeabe69..8628fb906 100644 --- a/quantum/tests/unit/db/loadbalancer/test_db_loadbalancer.py +++ b/quantum/tests/unit/db/loadbalancer/test_db_loadbalancer.py @@ -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 diff --git a/quantum/tests/unit/test_servicetype.py b/quantum/tests/unit/test_servicetype.py index 1871ed394..556f0e3f8 100644 --- a/quantum/tests/unit/test_servicetype.py +++ b/quantum/tests/unit/test_servicetype.py @@ -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: -- 2.45.2