Log a message if we fail to read or write auth token from file.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/25c414e3 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/25c414e3 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/25c414e3 Branch: refs/heads/trunk Commit: 25c414e33526bb647f93db4f2adb8ad0120b4957 Parents: 2f02aec Author: Tomaz Muraus <[email protected]> Authored: Sat Jul 30 13:06:08 2016 +0200 Committer: Tomaz Muraus <[email protected]> Committed: Sat Jul 30 13:10:53 2016 +0200 ---------------------------------------------------------------------- libcloud/common/google.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/25c414e3/libcloud/common/google.py ---------------------------------------------------------------------- diff --git a/libcloud/common/google.py b/libcloud/common/google.py index 4b896c6..96a0acb 100644 --- a/libcloud/common/google.py +++ b/libcloud/common/google.py @@ -72,6 +72,7 @@ try: except ImportError: import json +import logging import base64 import errno import time @@ -101,6 +102,8 @@ except ImportError: UTC_TIMESTAMP_FORMAT = '%Y-%m-%dT%H:%M:%SZ' +LOG = logging.getLogger(__name__) + def _utcnow(): """ @@ -680,7 +683,10 @@ class GoogleOAuth2Credential(object): except (IOError, ValueError): # Note: File related errors (IOError) and errors related to json # parsing of the data (ValueError) are not fatal. - pass + e = sys.exc_info()[1] + LOG.info('Failed to read cached auth token from file "%s": %s', + filename, str(e)) + return token def _write_token_to_file(self): @@ -688,9 +694,10 @@ class GoogleOAuth2Credential(object): Write token to credential file. Mocked in libcloud.test.common.google.GoogleTestCase. """ + filename = os.path.expanduser(self.credential_file) + filename = os.path.realpath(filename) + try: - filename = os.path.expanduser(self.credential_file) - filename = os.path.realpath(filename) data = json.dumps(self.token) write_flags = os.O_CREAT | os.O_WRONLY | os.O_TRUNC with os.fdopen(os.open(filename, write_flags, @@ -700,7 +707,9 @@ class GoogleOAuth2Credential(object): # Note: Failed to write (cache) token in a file is not fatal. It # simply means degraded performance since we will need to acquire a # new token each time script runs. - pass + e = sys.exc_info()[1] + LOG.info('Failed to write auth token to file "%s": %s', + filename, str(e)) class GoogleBaseConnection(ConnectionUserAndKey, PollingConnection):
