This patch fixes two issues with job archival. First, the
LoadJobFromDisk can return 'None' for no-such-job, and we shouldn't add
None to the job list; we can't anyway, as this raises an exception:

  node1# gnt-job archive foo
  Unhandled protocol error while talking to the master daemon:
  Caught exception: cannot create weak reference to 'NoneType' object

After fixing this, job archival of missing jobs will just continue
silently, so we modify gnt-job archive to log jobs which were not
archived and to return exit code 1 for any missing jobs.
---
 lib/jqueue.py   |    2 ++
 scripts/gnt-job |    7 +++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/jqueue.py b/lib/jqueue.py
index f27eba6..ebb6bf7 100644
--- a/lib/jqueue.py
+++ b/lib/jqueue.py
@@ -1194,6 +1194,8 @@ class JobQueue(object):
 
     try:
       job = self._LoadJobFromDisk(job_id)
+      if job is None:
+        return job
     except errors.JobFileCorrupted:
       old_path = self._GetJobPath(job_id)
       new_path = self._GetArchivedJobPath(job_id)
diff --git a/scripts/gnt-job b/scripts/gnt-job
index a174200..2e71bae 100755
--- a/scripts/gnt-job
+++ b/scripts/gnt-job
@@ -134,10 +134,13 @@ def ArchiveJobs(opts, args):
   """
   client = GetClient()
 
+  rcode = 0
   for job_id in args:
-    client.ArchiveJob(job_id)
+    if not client.ArchiveJob(job_id):
+      ToStderr("Failed to archive job with ID '%s'", job_id)
+      rcode = 1
 
-  return 0
+  return rcode
 
 
 def AutoArchiveJobs(opts, args):
-- 
1.7.1

Reply via email to