From e2b4a7ba70d96f47ba2ac7a4c0384ff66a9400a5 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Mon, 17 Sep 2012 18:28:55 +0200 Subject: [PATCH] Migrate lib/{jqueue,jstore}.py from constants to pathutils File system paths moved from constants to pathutils. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/jqueue.py | 11 ++++++----- lib/jstore.py | 17 +++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/jqueue.py b/lib/jqueue.py index af0e3595e..f4d58f4e7 100644 --- a/lib/jqueue.py +++ b/lib/jqueue.py @@ -59,6 +59,7 @@ from ganeti import compat from ganeti import ht from ganeti import query from ganeti import qlang +from ganeti import pathutils JOBQUEUE_THREADS = 25 @@ -1680,7 +1681,7 @@ class JobQueue(object): files = [self._GetJobPath(job_id) for job_id in self._GetJobIDsUnlocked()] # Upload current serial file - files.append(constants.JOB_QUEUE_SERIAL_FILE) + files.append(pathutils.JOB_QUEUE_SERIAL_FILE) # Static address list addrs = [node.primary_ip] @@ -1813,7 +1814,7 @@ class JobQueue(object): serial = self._last_serial + count # Write to file - self._UpdateJobQueueFile(constants.JOB_QUEUE_SERIAL_FILE, + self._UpdateJobQueueFile(pathutils.JOB_QUEUE_SERIAL_FILE, "%s\n" % serial, True) result = [jstore.FormatJobID(v) @@ -1836,7 +1837,7 @@ class JobQueue(object): @return: the path to the job file """ - return utils.PathJoin(constants.QUEUE_DIR, "job-%s" % job_id) + return utils.PathJoin(pathutils.QUEUE_DIR, "job-%s" % job_id) @staticmethod def _GetArchivedJobPath(job_id): @@ -1848,7 +1849,7 @@ class JobQueue(object): @return: the path to the archived job file """ - return utils.PathJoin(constants.JOB_QUEUE_ARCHIVE_DIR, + return utils.PathJoin(pathutils.JOB_QUEUE_ARCHIVE_DIR, jstore.GetArchiveDirectory(job_id), "job-%s" % job_id) @@ -1867,7 +1868,7 @@ class JobQueue(object): """ jlist = [] - for filename in utils.ListVisibleFiles(constants.QUEUE_DIR): + for filename in utils.ListVisibleFiles(pathutils.QUEUE_DIR): m = constants.JOB_FILE_RE.match(filename) if m: jlist.append(int(m.group(1))) diff --git a/lib/jstore.py b/lib/jstore.py index 26be6caaf..320a0341d 100644 --- a/lib/jstore.py +++ b/lib/jstore.py @@ -28,6 +28,7 @@ from ganeti import constants from ganeti import errors from ganeti import runtime from ganeti import utils +from ganeti import pathutils JOBS_PER_ARCHIVE_DIRECTORY = 10000 @@ -54,7 +55,7 @@ def ReadSerial(): The queue should be locked while this function is called. """ - return _ReadNumericFile(constants.JOB_QUEUE_SERIAL_FILE) + return _ReadNumericFile(pathutils.JOB_QUEUE_SERIAL_FILE) def ReadVersion(): @@ -63,7 +64,7 @@ def ReadVersion(): The queue should be locked while this function is called. """ - return _ReadNumericFile(constants.JOB_QUEUE_VERSION_FILE) + return _ReadNumericFile(pathutils.JOB_QUEUE_VERSION_FILE) def InitAndVerifyQueue(must_lock): @@ -81,7 +82,7 @@ def InitAndVerifyQueue(must_lock): getents = runtime.GetEnts() # Lock queue - queue_lock = utils.FileLock.Open(constants.JOB_QUEUE_LOCK_FILE) + queue_lock = utils.FileLock.Open(pathutils.JOB_QUEUE_LOCK_FILE) try: # The queue needs to be locked in exclusive mode to write to the serial and # version files. @@ -102,7 +103,7 @@ def InitAndVerifyQueue(must_lock): version = ReadVersion() if version is None: # Write new version file - utils.WriteFile(constants.JOB_QUEUE_VERSION_FILE, + utils.WriteFile(pathutils.JOB_QUEUE_VERSION_FILE, uid=getents.masterd_uid, gid=getents.masterd_gid, data="%s\n" % constants.JOB_QUEUE_VERSION) @@ -116,7 +117,7 @@ def InitAndVerifyQueue(must_lock): serial = ReadSerial() if serial is None: # Write new serial file - utils.WriteFile(constants.JOB_QUEUE_SERIAL_FILE, + utils.WriteFile(pathutils.JOB_QUEUE_SERIAL_FILE, uid=getents.masterd_uid, gid=getents.masterd_gid, data="%s\n" % 0) @@ -150,7 +151,7 @@ def CheckDrainFlag(): @return: True if the job queue is marked drained """ - return os.path.exists(constants.JOB_QUEUE_DRAIN_FILE) + return os.path.exists(pathutils.JOB_QUEUE_DRAIN_FILE) def SetDrainFlag(drain_flag): @@ -165,10 +166,10 @@ def SetDrainFlag(drain_flag): getents = runtime.GetEnts() if drain_flag: - utils.WriteFile(constants.JOB_QUEUE_DRAIN_FILE, data="", + utils.WriteFile(pathutils.JOB_QUEUE_DRAIN_FILE, data="", uid=getents.masterd_uid, gid=getents.masterd_gid) else: - utils.RemoveFile(constants.JOB_QUEUE_DRAIN_FILE) + utils.RemoveFile(pathutils.JOB_QUEUE_DRAIN_FILE) assert (not drain_flag) ^ CheckDrainFlag() -- GitLab