Handle OSError cases in multistore_file (#517)

This change fixes an exception in multistore_file that occurs when
the lock file is under conection. Windows may raise an OSError in
this case, where other platforms typically raise in IOError.
This commit is contained in:
thobrla
2016-06-06 14:15:53 -07:00
committed by Jon Wayne Parrott
parent a3cbf51bc9
commit f5ae963b7c
2 changed files with 12 additions and 9 deletions

View File

@@ -298,7 +298,7 @@ class _MultiStore(object):
self._thread_lock.acquire()
try:
self._file.open_and_lock()
except IOError as e:
except (IOError, OSError) as e:
if e.errno == errno.ENOSYS:
logger.warn('File system does not support locking the '
'credentials file.')

View File

@@ -34,14 +34,15 @@ os.close(_filehandle)
class _MockLockedFile(object):
def __init__(self, filename_str, error_code):
def __init__(self, filename_str, error_class, error_code):
self.filename_str = filename_str
self.error_class = error_class
self.error_code = error_code
self.open_and_lock_called = False
def open_and_lock(self):
self.open_and_lock_called = True
raise IOError(self.error_code, '')
raise self.error_class(self.error_code, '')
def is_locked(self):
return False
@@ -110,9 +111,11 @@ class MultistoreFileTests(unittest2.TestCase):
try:
for error_code in (errno.EDEADLK, errno.ENOSYS, errno.ENOLCK,
errno.EACCES):
for error_class in (IOError, OSError):
multistore = multistore_file._MultiStore(filename)
multistore._file = _MockLockedFile(filename, error_code)
# Should not raise even though the underlying file class did.
multistore._file = _MockLockedFile(
filename, error_class, error_code)
# Should not raise though the underlying file class did.
multistore._lock()
self.assertTrue(multistore._file.open_and_lock_called)
finally:
@@ -124,7 +127,7 @@ class MultistoreFileTests(unittest2.TestCase):
try:
multistore = multistore_file._MultiStore(filename)
multistore._file = _MockLockedFile(filename, errno.EBUSY)
multistore._file = _MockLockedFile(filename, IOError, errno.EBUSY)
self.assertRaises(IOError, multistore._lock)
self.assertTrue(multistore._file.open_and_lock_called)
finally: