Review connection error handling due to python3 backports

- Inclusion on future module might have changed some exception behaviors. So
  code changed following python2/3 tests.
This commit is contained in:
Uggla 2016-02-15 17:02:35 +01:00
parent 7c33c81923
commit d09a63a4c6
2 changed files with 9 additions and 24 deletions

View File

@ -39,16 +39,6 @@ class InvalidRedfishContentException(RedfishException):
' Most of the time you are not pointing to the rest API\n'
class NonTrustedCertificatException(RedfishException):
def __init__(self, message, **kwargs):
super(NonTrustedCertificatException, self).__init__(message, **kwargs)
self.advices = \
'1- Check if the url is the correct one\n' + \
'2- Check if your device has a valid trusted certificat\n' + \
' You can use openssl to validate it using the command :\n' + \
' openssl s_client -showcerts -connect <server>:443\n'
class AuthenticationFailureException(RedfishException):
def __init__(self, message, **kwargs):
super(AuthenticationFailureException, self).__init__(message, **kwargs)

View File

@ -13,6 +13,7 @@ from urllib.parse import urljoin
import requests
import simplejson
import tortilla
import ssl
from . import config
from . import mapping
from . import exception
@ -31,15 +32,17 @@ class Base(object):
try:
if connection_parameters.auth_token is None:
self.data = self.api_url.get(verify=connection_parameters.verify_cert)
self.data = self.api_url.get(
verify=connection_parameters.verify_cert)
else:
self.data = self.api_url.get(verify=connection_parameters.verify_cert,
headers={'x-auth-token': connection_parameters.auth_token}
)
except requests.ConnectionError as e:
self.data = self.api_url.get(
verify=connection_parameters.verify_cert,
headers={
'x-auth-token': connection_parameters.auth_token})
except (requests.ConnectionError, ssl.SSLError) as e:
# Log and transmit the exception.
config.logger.info('Raise a RedfishException to upper level')
msg = 'Connection error : {}\n'.format(e.message)
msg = 'Connection error : {}\n'.format(e)
raise exception.ConnectionFailureException(msg)
except simplejson.scanner.JSONDecodeError as e:
# Log and transmit the exception.
@ -48,14 +51,6 @@ class Base(object):
'Ivalid content : Content does not appear to be a valid ' + \
'Redfish json\n'
raise exception.InvalidRedfishContentException(msg)
except TypeError as e:
# This happen connecting to a manager using non trusted
# SSL certificats.
# The exception is not what could be expected in such case but this
# is the one provided by Tortilla.
config.logger.info('Raise a RedfishException to upper level')
msg = 'Connection error\n'
raise exception.NonTrustedCertificatException(msg)
config.logger.debug(self.data)
def get_link_url(self, link_type):