Fix logic in test_db_loadbalancer

Fix code to check HTTP error code before attempt to deserialize body

fixes bug 1180113

Change-Id: I1d75e0fe739dfa70ef415602e669319797af026f
This commit is contained in:
Eugene Nikanorov 2013-05-15 01:14:30 +04:00
parent 391108a014
commit 2648314b4c
2 changed files with 18 additions and 9 deletions

View 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

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