def test_convert_exception_to_http_exc_multiple_same_codes(self): e = n_exc.MultipleExceptions([ exceptions.NetworkNotFound(net_id='nid'), exceptions.PortNotFound(port_id='pid') ]) conv = common.convert_exception_to_http_exc(e, base_v2.FAULT_MAP, None) self.assertIsInstance(conv, exc.HTTPNotFound) self.assertEqual( "Network nid could not be found.\nPort pid could not be found.", jsonutils.loads(conv.body)['NeutronError']['message'])
def test_convert_exception_to_http_exc_multiple_different_codes(self): e = n_exc.MultipleExceptions([ exceptions.NetworkInUse(net_id='nid'), exceptions.PortNotFound(port_id='pid') ]) conv = common.convert_exception_to_http_exc(e, base_v2.FAULT_MAP, None) self.assertIsInstance(conv, exc.HTTPConflict) self.assertEqual( ("HTTP 409 NetworkInUse: Unable to complete operation on network " "nid. There are one or more ports still in use on the network.\n" "HTTP 404 PortNotFound: Port pid could not be found."), jsonutils.loads(conv.body)['NeutronError']['message'])
def test_multi_exception_raised_on_exceed(self): e = exceptions.MultipleExceptions([ValueError(), db_exc.DBDeadlock()]) with testtools.ExpectedException(exceptions.MultipleExceptions): self._decorated_function(db_api.MAX_RETRIES + 1, e)
def test_multi_nested_exception_contains_deadlock(self): i = exceptions.MultipleExceptions([ValueError(), db_exc.DBDeadlock()]) e = exceptions.MultipleExceptions([ValueError(), i]) self.assertIsNone(self._decorated_function(1, e))
def test_multi_exception_contains_retry(self): e = exceptions.MultipleExceptions( [ValueError(), db_exc.RetryRequest(TypeError())]) self.assertIsNone(self._decorated_function(1, e))
def test_retries_on_multi_exception_containing_target(self): with testtools.ExpectedException(db_exc.RetryRequest): with db_api.exc_to_retry(ValueError): e = exceptions.MultipleExceptions([ValueError(), TypeError()]) raise e
def test_convert_exception_to_http_exc_multiple_empty_inner(self): e = n_exc.MultipleExceptions([]) conv = common.convert_exception_to_http_exc(e, base_v2.FAULT_MAP, None) self.assertIsInstance(conv, exc.HTTPInternalServerError)