Adam Litke has uploaded a new change for review.

Change subject: jobs: Add error property
......................................................................

jobs: Add error property

When a Job encounters an error, there should be a standardized way for
that error to be stored so that code working with Job objects has a
standard way to propagate the error.

Add an 'error' property to the job class which is None by default but
can contain an instance of utils.GeneralException or one of its
decendants.  If error is set, the dictionary returned by the call to
info() will contain an 'error' key.  The value of this key is a status
code (containing a standard vdsm code and message).

Change-Id: I3f6e27beeeecd69db1673e5168524b0ce94f2e9e
Signed-off-by: Adam Litke <[email protected]>
---
M lib/vdsm/jobs.py
M tests/jobsTests.py
2 files changed, 25 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/54/50354/1

diff --git a/lib/vdsm/jobs.py b/lib/vdsm/jobs.py
index 5949084..fc4a0c8 100644
--- a/lib/vdsm/jobs.py
+++ b/lib/vdsm/jobs.py
@@ -67,6 +67,7 @@
         self._id = job_id
         self._status = STATUS.RUNNING
         self._description = description
+        self._error = None
 
     @property
     def id(self):
@@ -88,13 +89,20 @@
     def job_type(self):
         return self._JOB_TYPE
 
+    @property
+    def error(self):
+        return self._error
+
     def info(self):
-        return {
-            'status': self.status,
-            'description': self.description,
-            'progress': self.progress,
-            'job_type': self.job_type
-        }
+        ret = {'status': self.status,
+               'description': self.description,
+               'progress': self.progress,
+               'job_type': self.job_type}
+
+        if self.error:
+            ret['error'] = self.error.response()
+
+        return ret
 
     def abort(self):
         self._status = STATUS.ABORTED
diff --git a/tests/jobsTests.py b/tests/jobsTests.py
index 373c916..4bd6343 100644
--- a/tests/jobsTests.py
+++ b/tests/jobsTests.py
@@ -19,7 +19,7 @@
 
 import uuid
 
-from vdsm import jobs, response
+from vdsm import jobs, response, utils
 
 from testlib import VdsmTestCase, expandPermutations, permutations
 
@@ -135,3 +135,13 @@
     def test_delete_unknown_job(self):
         self.assertEqual(response.error(jobs.NoSuchJob.name),
                          jobs.delete('foo'))
+
+    def test_job_get_error(self):
+        job = TestingJob()
+        self.assertIsNone(job.error)
+        self.assertNotIn('error', job.info())
+
+        error = utils.GeneralException()
+        job._error = error
+        self.assertEqual(job.error, error)
+        self.assertEqual(error.response(), job.info()['error'])


-- 
To view, visit https://gerrit.ovirt.org/50354
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3f6e27beeeecd69db1673e5168524b0ce94f2e9e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to