Adam Litke has uploaded a new change for review. Change subject: sdm: Jobs may be run only when status=pending ......................................................................
sdm: Jobs may be run only when status=pending An SDM Job begins its lifecycle in pending state and at some point a scheduler will call its run() method to run it. The job should not run from any state other than pending. If a job was aborted while waiting to be executed we should print a message and return. If the job is in any other state we have a bug and an exception should be raised. Change-Id: I601f6db19527635c1a00c3a4c2910eac4ac5371b Signed-off-by: Adam Litke <[email protected]> --- M tests/storage_sdm_api_test.py M vdsm/storage/sdm/api/base.py 2 files changed, 32 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/38/61138/1 diff --git a/tests/storage_sdm_api_test.py b/tests/storage_sdm_api_test.py index c8d93d2..3306c30 100644 --- a/tests/storage_sdm_api_test.py +++ b/tests/storage_sdm_api_test.py @@ -21,6 +21,7 @@ import uuid from testlib import VdsmTestCase +from testlib import expandPermutations, permutations from sdmtestlib import wait_for_job from vdsm import jobs @@ -30,6 +31,7 @@ from storage.sdm.api import base +@expandPermutations class ApiBaseTests(VdsmTestCase): def run_job(self, job): @@ -58,6 +60,20 @@ self.assertEqual(jobs.STATUS.FAILED, job.status) self.assertIsInstance(job.error, exception.VdsmException) + def test_run_aborted_job(self): + job = TestingJob() + job.abort() + job.run() + self.assertEqual(jobs.STATUS.ABORTED, job.status) + + @permutations(( + (jobs.STATUS.DONE,), (jobs.STATUS.RUNNING,), (jobs.STATUS.FAILED,) + )) + def test_run_from_invalid_state(self, status): + job = TestingJob() + job.set_status(status) + self.assertRaises(base.CannotRunJob, job.run) + class TestingJob(base.Job): @@ -66,6 +82,12 @@ super(TestingJob, self).__init__(job_id, 'testing_job', 'host_id') self.exception = exception + def set_status(self, value): + self._status = value + + def _abort(self): + pass + def _run(self): assert(self.status == jobs.STATUS.RUNNING) assert(vars.job_id == self.id) diff --git a/vdsm/storage/sdm/api/base.py b/vdsm/storage/sdm/api/base.py index a342300..eb88f35 100644 --- a/vdsm/storage/sdm/api/base.py +++ b/vdsm/storage/sdm/api/base.py @@ -27,6 +27,10 @@ from vdsm.storage.threadlocal import vars +class CannotRunJob(Exception): + pass + + class Job(jobs.Job): _JOB_TYPE = "storage" log = logging.getLogger('storage.sdmjob') @@ -37,6 +41,12 @@ self.host_id = host_id def run(self): + if self._status == jobs.STATUS.ABORTED: + self.log.info("Job id=%s aborted while pending", self.id) + return + if self._status != jobs.STATUS.PENDING: + raise CannotRunJob("Job id=%s cannot be started from %r status", + self.id, self.status) self._status = jobs.STATUS.RUNNING vars.job_id = self.id try: -- To view, visit https://gerrit.ovirt.org/61138 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I601f6db19527635c1a00c3a4c2910eac4ac5371b 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/admin/lists/[email protected]
