Log a message if we fail to read or write auth token from file.
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 @@
except ImportError:
import json
+import logging
import base64
import errno
import time
@@ -101,6 +102,8 @@
UTC_TIMESTAMP_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
+LOG = logging.getLogger(__name__)
+
def _utcnow():
"""
@@ -680,7 +683,10 @@
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 @@
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 @@
# 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):