diff options
author | Ade Lee <alee@redhat.com> | 2013-09-05 17:03:43 -0400 |
---|---|---|
committer | Ade Lee <alee@redhat.com> | 2013-09-06 17:17:57 -0400 |
commit | 04b71d19af2c0b49c9601996d30d96c8de32a944 (patch) | |
tree | 32d04765bf491118ac7a8e62da60f05a49887286 /base | |
parent | 8f0218b1ddf5c368f0b5ce3ea0dec064e1ec354e (diff) | |
download | pki-04b71d19af2c0b49c9601996d30d96c8de32a944.tar.gz pki-04b71d19af2c0b49c9601996d30d96c8de32a944.tar.xz pki-04b71d19af2c0b49c9601996d30d96c8de32a944.zip |
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
Diffstat (limited to 'base')
-rw-r--r-- | base/server/python/pki/server/deployment/pkihelper.py | 22 | ||||
-rw-r--r-- | base/server/python/pki/server/deployment/pkimanifest.py | 4 |
2 files changed, 16 insertions, 10 deletions
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) |