Nir Soffer has uploaded a new change for review. Change subject: jobs: Replace validation method with a property ......................................................................
jobs: Replace validation method with a property Replace Job.validate_not_active() with an Job.active property. Change the single call site to check the property and raise. Change-Id: I23facf952529f3e811c9e179af25cfe39b2db0fe Signed-off-by: Nir Soffer <nsof...@redhat.com> --- M lib/vdsm/jobs.py M tests/jobsTests.py 2 files changed, 18 insertions(+), 5 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/16/51216/1 diff --git a/lib/vdsm/jobs.py b/lib/vdsm/jobs.py index c28ac58..cdf1fa8 100644 --- a/lib/vdsm/jobs.py +++ b/lib/vdsm/jobs.py @@ -107,14 +107,14 @@ return ret + @property + def active(self): + return self.status in (STATUS.PENDING, STATUS.RUNNING) + def abort(self): self._status = STATUS.ABORTED logging.info('Job %r aborting...', self._id) self._abort() - - 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)) def _abort(self): """ @@ -183,5 +183,6 @@ job = _jobs[job_id] except KeyError: raise NoSuchJob("No such job %r" % job_id) - job.validate_not_active() + if job.active: + raise JobNotDone("Job %r is %s" % (job_id, job.status)) del _jobs[job_id] diff --git a/tests/jobsTests.py b/tests/jobsTests.py index 7f86ba4..65f5c80 100644 --- a/tests/jobsTests.py +++ b/tests/jobsTests.py @@ -154,6 +154,18 @@ jobs.abort(job.id)) @permutations([ + [jobs.STATUS.PENDING, True], + [jobs.STATUS.RUNNING, True], + [jobs.STATUS.ABORTED, False], + [jobs.STATUS.DONE, False], + [jobs.STATUS.FAILED, False] + ]) + def test_job_active(self, status, active): + job = TestingJob() + job._status = status + self.assertEqual(active, job.active) + + @permutations([ [jobs.STATUS.ABORTED], [jobs.STATUS.DONE], [jobs.STATUS.FAILED] -- To view, visit https://gerrit.ovirt.org/51216 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I23facf952529f3e811c9e179af25cfe39b2db0fe Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Nir Soffer <nsof...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches