From aac3fbf0d5d660c9ec1c2041a22a624f96b83ac0 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Wed, 27 Jan 2010 11:32:28 +0100
Subject: [PATCH] utils.FileLock: handle init errors properly

If the open of the lock file fails (due to whatever reason), 'self'
won't have the 'fd' attribute, and thus we fail in Close/__del__, which
will ruin proper error reporting:

IOError: [Errno 30] Read-only file system: '/var/lib/ganeti/queue/lock'
Exception exceptions.AttributeError: "'FileLock' object has no attribute
'fd'" in <bound method FileLock.__del__ of <ganeti.utils.FileLock object
at 0x2aaaad0bebd0>> ignored

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 lib/utils.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/utils.py b/lib/utils.py
index 7f02e1ad5..bee53adcf 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -2258,7 +2258,7 @@ class FileLock(object):
     """Close the file and release the lock.
 
     """
-    if self.fd:
+    if hasattr(self, "fd") and self.fd:
       self.fd.close()
       self.fd = None
 
-- 
GitLab