From: tierno Date: Fri, 5 Apr 2019 12:46:42 +0000 (+0000) Subject: fixing bug 665 parsing unicode openstack error messages X-Git-Tag: v6.0.0~28 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FRO.git;a=commitdiff_plain;h=refs%2Fchanges%2F89%2F7389%2F2 fixing bug 665 parsing unicode openstack error messages Change-Id: I563f65d6ed4dacf482cde5983020d36ecc040c02 Signed-off-by: tierno --- diff --git a/osm_ro/vimconn_openstack.py b/osm_ro/vimconn_openstack.py index cfeeae0d..3515ef68 100644 --- a/osm_ro/vimconn_openstack.py +++ b/osm_ro/vimconn_openstack.py @@ -398,23 +398,31 @@ class vimconnector(vimconn.vimconnector): def _format_exception(self, exception): '''Transform a keystone, nova, neutron exception into a vimconn exception''' - if isinstance(exception, (neExceptions.NetworkNotFoundClient, nvExceptions.NotFound, ksExceptions.NotFound, gl1Exceptions.HTTPNotFound)): - raise vimconn.vimconnNotFoundException(type(exception).__name__ + ": " + str(exception)) + + # Fixing bug 665 https://osm.etsi.org/bugzilla/show_bug.cgi?id=665 + # There are some openstack versions that message error are unicode with non English + message_error = exception.message + if isinstance(message_error, unicode): + message_error = message_error.encode("utf") + + if isinstance(exception, (neExceptions.NetworkNotFoundClient, nvExceptions.NotFound, ksExceptions.NotFound, + gl1Exceptions.HTTPNotFound)): + raise vimconn.vimconnNotFoundException(type(exception).__name__ + ": " + message_error) elif isinstance(exception, (HTTPException, gl1Exceptions.HTTPException, gl1Exceptions.CommunicationError, ConnectionError, ksExceptions.ConnectionError, neExceptions.ConnectionFailed)): - raise vimconn.vimconnConnectionException(type(exception).__name__ + ": " + str(exception)) + raise vimconn.vimconnConnectionException(type(exception).__name__ + ": " + message_error) elif isinstance(exception, (KeyError, nvExceptions.BadRequest, ksExceptions.BadRequest)): - raise vimconn.vimconnException(type(exception).__name__ + ": " + str(exception)) + raise vimconn.vimconnException(type(exception).__name__ + ": " + message_error) elif isinstance(exception, (nvExceptions.ClientException, ksExceptions.ClientException, neExceptions.NeutronException)): - raise vimconn.vimconnUnexpectedResponse(type(exception).__name__ + ": " + str(exception)) + raise vimconn.vimconnUnexpectedResponse(type(exception).__name__ + ": " + message_error) elif isinstance(exception, nvExceptions.Conflict): - raise vimconn.vimconnConflictException(type(exception).__name__ + ": " + str(exception)) + raise vimconn.vimconnConflictException(type(exception).__name__ + ": " + message_error) elif isinstance(exception, vimconn.vimconnException): raise exception else: # () - self.logger.error("General Exception " + str(exception), exc_info=True) - raise vimconn.vimconnConnectionException(type(exception).__name__ + ": " + str(exception)) + self.logger.error("General Exception " + message_error, exc_info=True) + raise vimconn.vimconnConnectionException(type(exception).__name__ + ": " + message_error) def _get_ids_from_name(self): """