From 04b71d19af2c0b49c9601996d30d96c8de32a944 Mon Sep 17 00:00:00 2001 From: Ade Lee Date: Thu, 5 Sep 2013 17:03:43 -0400 Subject: Catch all exceptions when checking for status. python-requests now throws a ProxyError if the server is not yet up. Previously only connect exceptions were seen. To ensure that we are not broken again when python-requests and the underlying libraries are changed, we will catch and log all exceptions. If the connection ultimately fails, we will time out in any case. Also fixed some new warnings from Pylint 1.0 Ticket 717 --- .../python/pki/server/deployment/pkihelper.py | 22 ++++++++++++++-------- .../python/pki/server/deployment/pkimanifest.py | 4 ++-- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'base/server/python') diff --git a/base/server/python/pki/server/deployment/pkihelper.py b/base/server/python/pki/server/deployment/pkihelper.py index e72af1652..9bbe81010 100644 --- a/base/server/python/pki/server/deployment/pkihelper.py +++ b/base/server/python/pki/server/deployment/pkihelper.py @@ -27,7 +27,6 @@ import os import fileinput import random import re -import requests import shutil from shutil import Error, WindowsError import string @@ -125,7 +124,7 @@ def pki_copytree(src, dst, symlinks=False, ignore=None): else: errors.extend((src, dst, str(why))) if errors: - raise Error, errors + raise Error(errors) class Identity: """PKI Deployment Identity Class""" @@ -1036,6 +1035,10 @@ class Instance: subsystem=self.master_dict['pki_subsystem_type'], accept='application/xml') + # catching all exceptions because we do not want to break if underlying + # requests or urllib3 use a different exception. + # If the connection fails, we will time out in any case + # pylint: disable-msg=W0703 try: client = pki.system.SystemStatusClient(connection) response = client.getStatus() @@ -1045,8 +1048,11 @@ class Instance: root = ET.fromstring(response) status = root.findtext("Status") return status - except requests.exceptions.ConnectionError: - config.pki_log.debug("No connection", + except Exception as exc: + config.pki_log.debug("No connection - server may still be down", + extra=config.PKI_INDENTATION_LEVEL_3) + config.pki_log.debug("No connection - exception thrown: " +\ + str(exc), extra=config.PKI_INDENTATION_LEVEL_3) return None @@ -2014,7 +2020,7 @@ class Password: log.PKIHELPER_PASSWORD_CONF_1, path, extra=config.PKI_INDENTATION_LEVEL_2) # overwrite the existing 'password.conf' file - with open(path, "wt") as fd: + with open(path, "w") as fd: if pin_sans_token == True: fd.write(str(pin)) elif self.master_dict['pki_subsystem'] in\ @@ -2028,7 +2034,7 @@ class Password: config.pki_log.info(log.PKIHELPER_PASSWORD_CONF_1, path, extra=config.PKI_INDENTATION_LEVEL_2) # create a new 'password.conf' file - with open(path, "wt") as fd: + with open(path, "w") as fd: if pin_sans_token == True: fd.write(str(pin)) elif self.master_dict['pki_subsystem'] in\ @@ -2054,13 +2060,13 @@ class Password: log.PKIHELPER_PASSWORD_CONF_1, path, extra=config.PKI_INDENTATION_LEVEL_2) # overwrite the existing 'pkcs12_password.conf' file - with open(path, "wt") as fd: + with open(path, "w") as fd: fd.write(self.master_dict['pki_client_pkcs12_password']) else: config.pki_log.info(log.PKIHELPER_PASSWORD_CONF_1, path, extra=config.PKI_INDENTATION_LEVEL_2) # create a new 'pkcs12_password.conf' file - with open(path, "wt") as fd: + with open(path, "w") as fd: fd.write(self.master_dict['pki_client_pkcs12_password']) except OSError as exc: config.pki_log.error(log.PKI_OSERROR_1, exc, diff --git a/base/server/python/pki/server/deployment/pkimanifest.py b/base/server/python/pki/server/deployment/pkimanifest.py index dea2af275..8ba60dd8b 100644 --- a/base/server/python/pki/server/deployment/pkimanifest.py +++ b/base/server/python/pki/server/deployment/pkimanifest.py @@ -82,7 +82,7 @@ class File: def write(self): try: - with open(self.filename, "wt") as fd: + with open(self.filename, "w") as fd: c = csv.writer(fd) for record in self.database: c.writerow(tuple(record)) @@ -93,7 +93,7 @@ class File: def read(self): try: - with open(self.filename, "rt") as fd: + with open(self.filename, "r") as fd: cr = csv.reader(fd) for row in cr: print tuple(row) -- cgit