Mention RAPI client in documentation
[ganeti-local] / lib / jstore.py
index 7424b7b..cc1bb4c 100644 (file)
 
 """Module implementing the job queue handling."""
 
-import os
-import logging
 import errno
-import re
 
 from ganeti import constants
 from ganeti import errors
@@ -81,16 +78,11 @@ def InitAndVerifyQueue(must_lock):
            locking mode.
 
   """
-  # Make sure our directories exists
-  for path in (constants.QUEUE_DIR, constants.JOB_QUEUE_ARCHIVE_DIR):
-    try:
-      os.mkdir(path, 0700)
-    except OSError, err:
-      if err.errno not in (errno.EEXIST, ):
-        raise
+  dirs = [(d, constants.JOB_QUEUE_DIRS_MODE) for d in constants.JOB_QUEUE_DIRS]
+  utils.EnsureDirs(dirs)
 
   # Lock queue
-  queue_lock = utils.FileLock(constants.JOB_QUEUE_LOCK_FILE)
+  queue_lock = utils.FileLock.Open(constants.JOB_QUEUE_LOCK_FILE)
   try:
     # The queue needs to be locked in exclusive mode to write to the serial and
     # version files.
@@ -132,7 +124,13 @@ def InitAndVerifyQueue(must_lock):
 
       if serial is None:
         # There must be a serious problem
-        raise errors.JobQueueError("Can't read/parse the job queue serial file")
+        raise errors.JobQueueError("Can't read/parse the job queue"
+                                   " serial file")
+
+      if not must_lock:
+        # There's no need for more error handling. Closing the lock
+        # file below in case of an error will unlock it anyway.
+        queue_lock.Unlock()
 
   except:
     queue_lock.Close()