Change in vdsm[master]: jobs: Add the PENDING state

nsoffer at redhat.com nsoffer at redhat.com
Tue Dec 15 10:07:43 UTC 2015


Nir Soffer has uploaded a new change for review.

Change subject: jobs: Add the PENDING state
......................................................................

jobs: Add the PENDING state

Storage jobs will be executed in a thread pool, so job starts now in
"pending" status by default. Job should move to "running" state when it
is actually running.

Change-Id: If569eb619d79afe9dfb5c770e014e1500f2871c8
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M lib/vdsm/jobs.py
M tests/jobsTests.py
2 files changed, 13 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/02/50502/1

diff --git a/lib/vdsm/jobs.py b/lib/vdsm/jobs.py
index 586e941..b971c46 100644
--- a/lib/vdsm/jobs.py
+++ b/lib/vdsm/jobs.py
@@ -28,6 +28,7 @@
 
 
 class STATUS:
+    PENDING = 'pending'  # Job has not started yet
     RUNNING = 'running'  # Job is running
     DONE = 'done'        # Job has finished successfully
     ABORTED = 'aborted'  # Job was aborted by user request
@@ -64,7 +65,7 @@
 
     def __init__(self, job_id, description=''):
         self._id = job_id
-        self._status = STATUS.RUNNING
+        self._status = STATUS.PENDING
         self._description = description
 
     @property
@@ -104,7 +105,7 @@
         if self.status != STATUS.DONE:
             raise JobNotDone("Job %r is %s" % (self.id, self.status))
 
-    def validate_not_running(self):
+    def validate_not_active(self):
         if self.status not in (STATUS.DONE, STATUS.ABORTED, STATUS.FAILED):
             raise JobNotDone("Job %r is %s" % (self.id, self.status))
 
@@ -125,7 +126,7 @@
 def delete(job_id):
     try:
         job = get(job_id)
-        job.validate_not_running()
+        job.validate_not_active()
         _delete(job_id)
     except ClientError as e:
         logging.info('Cannot delete job, error: %s', e)
diff --git a/tests/jobsTests.py b/tests/jobsTests.py
index 0c83e5b..86dd847 100644
--- a/tests/jobsTests.py
+++ b/tests/jobsTests.py
@@ -57,13 +57,13 @@
 
     def test_job_initial_state(self):
         job = TestingJob()
-        self.assertEqual(jobs.STATUS.RUNNING, job.status)
+        self.assertEqual(jobs.STATUS.PENDING, job.status)
         self.assertEqual('', job.description)
         self.assertEqual('testing', job.job_type)
 
     def test_job_info(self):
         job = TestingJob()
-        self.assertEqual({'status': 'running', 'progress': 0,
+        self.assertEqual({'status': jobs.STATUS.PENDING, 'progress': 0,
                           'job_type': 'testing', 'description': ''},
                          job.info())
 
@@ -126,14 +126,19 @@
         [jobs.STATUS.DONE],
         [jobs.STATUS.FAILED]
     ])
-    def test_delete_job(self, status):
+    def test_delete_inactive_job(self, status):
         job = TestingJob()
         job._status = status
         jobs.add(job)
         self.assertEqual(response.success(), jobs.delete(job.id))
 
-    def test_delete_running_job(self):
+    @permutations([
+        [jobs.STATUS.PENDING],
+        [jobs.STATUS.RUNNING],
+    ])
+    def test_delete_active_job(self, status):
         job = TestingJob()
+        job._status = status
         jobs.add(job)
         self.assertEqual(response.error(jobs.JobNotDone.name),
                          jobs.delete(job.id))


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If569eb619d79afe9dfb5c770e014e1500f2871c8
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list