Change in vdsm[master]: jobs: Autodelete

2016-09-15 Thread automation
gerrit-hooks has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 10:

* Update tracker: IGNORE, no Bug-Url found
* Set MODIFIED::IGNORE, no Bug-Url found.

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 10
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: Piotr Kliczewski 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-15 Thread nsoffer
Nir Soffer has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 9: Code-Review+2

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 9
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: Piotr Kliczewski 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-15 Thread nsoffer
Nir Soffer has submitted this change and it was merged.

Change subject: jobs: Autodelete
..


jobs: Autodelete

For storage jobs we like to delete finished jobs automatically after
some delay, giving engine enough time to discover the job completion
state in most cases, and allowing easy inspection of job state.  The Job
class implements now both run() and abort(), managing the state changes
and auto-deleting the job when done. Subclasses should implement _run()
and _abort().

To intergate with v2v code using old jobs framework, v2v code will have
to use _run() instead of run(). Subclass that want to enable autodelete
must override the autodelete class attribute and set it to True.

class AutodeletingJob(jobs.Job):
autodelete = True

This feature is not relevant now for v2v jobs since engine is deleting
these jobs.

Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Signed-off-by: Adam Litke 
Signed-off-by: Nir Soffer 
Reviewed-on: https://gerrit.ovirt.org/62002
Continuous-Integration: Jenkins CI
Reviewed-by: Francesco Romani 
Reviewed-by: Piotr Kliczewski 
---
M lib/vdsm/config.py.in
M lib/vdsm/jobs.py
M tests/jobsTests.py
M vdsm/storage/sdm/api/base.py
4 files changed, 87 insertions(+), 2 deletions(-)

Approvals:
  Piotr Kliczewski: Looks good to me, but someone else must approve
  Nir Soffer: Looks good to me, approved
  Adam Litke: Verified
  Jenkins CI: Passed CI tests
  Francesco Romani: Looks good to me, but someone else must approve



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

Gerrit-MessageType: merged
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 10
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: Piotr Kliczewski 
Gerrit-Reviewer: gerrit-hooks 
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-15 Thread piotr . kliczewski
Piotr Kliczewski has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 9: Code-Review+1

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 9
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: Piotr Kliczewski 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-15 Thread fromani
Francesco Romani has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 9: Code-Review+1

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 9
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: Piotr Kliczewski 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-14 Thread nsoffer
Nir Soffer has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 9: Code-Review+1

Waiting for more reviews.

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 9
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: Piotr Kliczewski 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-14 Thread automation
gerrit-hooks has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 9:

* Update tracker: IGNORE, no Bug-Url found
* Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' 
and is a valid url.
* Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 
'ovirt-4.0'])

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 9
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: Piotr Kliczewski 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-14 Thread alitke
Adam Litke has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 9: Verified+1

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 9
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: Piotr Kliczewski 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-14 Thread alitke
Adam Litke has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 8:

(1 comment)

https://gerrit.ovirt.org/#/c/62002/8/lib/vdsm/jobs.py
File lib/vdsm/jobs.py:

Line 117
Line 118
Line 119
Line 120
Line 121
> Please add a comment that we must not autodelete a job if _abort() failed. 
Done


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 8
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: Piotr Kliczewski 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: Yes
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-14 Thread nsoffer
Nir Soffer has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 8:

(1 comment)

https://gerrit.ovirt.org/#/c/62002/8/lib/vdsm/jobs.py
File lib/vdsm/jobs.py:

Line 117
Line 118
Line 119
Line 120
Line 121
Please add a comment that we must not autodelete a job if _abort() failed. 
Otherwise I see the patch adding dangerous try-finally here to make sure we 
auto delete the job :-)


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 8
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: Piotr Kliczewski 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: Yes
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-14 Thread automation
gerrit-hooks has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 8:

* Update tracker: IGNORE, no Bug-Url found
* Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' 
and is a valid url.
* Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 
'ovirt-4.0'])

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 8
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: Piotr Kliczewski 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-14 Thread alitke
Adam Litke has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 7:

(2 comments)

https://gerrit.ovirt.org/#/c/62002/7/lib/vdsm/jobs.py
File lib/vdsm/jobs.py:

Line 117
Line 118
Line 119
Line 120
Line 121
> We have major error here - switching state to ABORTED before the job was ab
Ok.  Handling in a precursor patch.


Line 135
Line 136
Line 137
Line 138
Line 139
> We must document here that:
Created a precursor patch for this.


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 7
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: Piotr Kliczewski 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: Yes
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-14 Thread nsoffer
Nir Soffer has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 7: Code-Review-1

(2 comments)

https://gerrit.ovirt.org/#/c/62002/7/lib/vdsm/jobs.py
File lib/vdsm/jobs.py:

Line 117
Line 118
Line 119
Line 120
Line 121
> Please add a comment explaining why we *must* not delete the job if _abort(
We have major error here - switching state to ABORTED before the job was 
aborted.

If _abort() fails, we already switch states, and we cannot abort again (in the 
next patch we fixed state switching to prevent that).

Even worse, when engine will check job status, it will be ABORTED, while we are 
still accessing storage. This is the worst bug we can have.

There is also smaller issue, if _abort is not implemented by a subclass, it 
will raise, but the job will be in ABORTED state.

I think we should change this to:

def abort(self):
   logging.info('Job %r aborting...', self._id)
   self._abort()
   self._status = STATUS.ABORTED
   if self.autodelete:
   self._autodelete()

If abort failed, we are still in running state, and engine can try again.

If engine cannot abort a job, it can fence vdsm or the host, or just wait for 
the job.


Line 135
Line 136
Line 137
Line 138
Line 139
We must document here that:

- _abort must raise if the job could not be aborted
- _abort must not raise if the job was aborted (so the job would not leak)


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 7
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: Piotr Kliczewski 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: Yes
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-14 Thread alitke
Adam Litke has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 7: Verified+1

Functional tests and copy_data verb

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 7
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: Piotr Kliczewski 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-13 Thread nsoffer
Nir Soffer has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 7:

(1 comment)

https://gerrit.ovirt.org/#/c/62002/7/lib/vdsm/jobs.py
File lib/vdsm/jobs.py:

Line 117
Line 118
Line 119
Line 120
Line 121
Please add a comment explaining why we *must* not delete the job if _abort() 
fails.

One issue - if _abort() failed after stopping the job we are leaking the job. 
If engine try to abort again we are doing nothing because the state is ABORTED.


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 7
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: Piotr Kliczewski 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: Yes
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-13 Thread nsoffer
Nir Soffer has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 7: Code-Review+1

Looks good, waiting for more reviews.

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 7
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-13 Thread automation
gerrit-hooks has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 7:

* Update tracker: IGNORE, no Bug-Url found
* Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' 
and is a valid url.
* Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 
'ovirt-4.0'])

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 7
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-13 Thread alitke
Adam Litke has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 6:

(6 comments)

https://gerrit.ovirt.org/#/c/62002/3/tests/jobsTests.py
File tests/jobsTests.py:

Line 277: job = TestingJob(exception=exception.VdsmException())
Line 278: self.run_job(job)
Line 279: self.assertEqual(jobs.STATUS.FAILED, job.status)
Line 280: self.assertIsInstance(job.error, exception.VdsmException)
Line 281: 
> Fragile, use fake scheduler instead.
Done
Line 282: @permutations(((None, ), (Exception(),)))
Line 283: def test_autodelete_when_finished(self, error):
Line 284: cfg = make_config([('jobs', 'autodelete_delay', '10')])
Line 285: job = AutodeleteJob(exception=error)


https://gerrit.ovirt.org/#/c/62002/5/tests/jobsTests.py
File tests/jobsTests.py:

Line 75: class FakeScheduler(object):
Line 76: 
Line 77: def __init__(self):
Line 78: self.calls = []
Line 79: 
> This works, but this does not test that callable will delete job.
Good idea.  Changed.
Line 80: def schedule(self, delay, callable):
Line 81: self.calls.append((delay, callable))
Line 82: return schedule.ScheduledCall(delay, callable)
Line 83: 


Line 281: 
Line 282: @permutations(((None, ), (Exception(),)))
Line 283: def test_autodelete_when_finished(self, error):
Line 284: cfg = make_config([('jobs', 'autodelete_delay', '10')])
Line 285: job = AutodeleteJob(exception=error)
> This does not verify that the job was removed after the configured delay.
Applied your suggestion from above.
Line 286: jobs.add(job)
Line 287: with MonkeyPatchScope([(jobs, 'config', cfg)]):
Line 288: self.run_job(job)
Line 289: self.assertEqual(1, len(self.scheduler.calls))


Line 289: self.assertEqual(1, len(self.scheduler.calls))
Line 290: delay, callable = self.scheduler.calls[0]
Line 291: self.assertEqual(10, delay)
Line 292: self.assertIn(job.id, jobs.info())
Line 293: callable()
> Same
Same.
Line 294: self.assertNotIn(job.id, jobs.info())
Line 295: 
Line 296: def test_autodelete_when_aborted(self):
Line 297: cfg = make_config([('jobs', 'autodelete_delay', '10')])


https://gerrit.ovirt.org/#/c/62002/6/tests/jobsTests.py
File tests/jobsTests.py:

Line 290: delay, callable = self.scheduler.calls[0]
Line 291: self.assertEqual(10, delay)
Line 292: self.assertIn(job.id, jobs.info())
Line 293: callable()
Line 294: self.assertNotIn(job.id, jobs.info())
> Nice tests
Thanks!
Line 295: 
Line 296: def test_autodelete_when_aborted(self):
Line 297: cfg = make_config([('jobs', 'autodelete_delay', '10')])
Line 298: job = AutodeleteJob()


Line 303: delay, callable = self.scheduler.calls[0]
Line 304: self.assertEqual(10, delay)
Line 305: self.assertIn(job.id, jobs.info())
Line 306: callable()
Line 307: self.assertNotIn(job.id, jobs.info())
> Both tests are exactly the same except the line when we run or abort the jo
done.
Line 308: 
Line 309: def test_autodelete_disabled(self):
Line 310: cfg = make_config([('jobs', 'autodelete_delay', '-1')])
Line 311: job = AutodeleteJob()


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 6
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: Yes
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-12 Thread nsoffer
Nir Soffer has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 6: Code-Review-1

(2 comments)

https://gerrit.ovirt.org/#/c/62002/6/tests/jobsTests.py
File tests/jobsTests.py:

Line 290: delay, callable = self.scheduler.calls[0]
Line 291: self.assertEqual(10, delay)
Line 292: self.assertIn(job.id, jobs.info())
Line 293: callable()
Line 294: self.assertNotIn(job.id, jobs.info())
Nice tests
Line 295: 
Line 296: def test_autodelete_when_aborted(self):
Line 297: cfg = make_config([('jobs', 'autodelete_delay', '10')])
Line 298: job = AutodeleteJob()


Line 303: delay, callable = self.scheduler.calls[0]
Line 304: self.assertEqual(10, delay)
Line 305: self.assertIn(job.id, jobs.info())
Line 306: callable()
Line 307: self.assertNotIn(job.id, jobs.info())
Both tests are exactly the same except the line when we run or abort the job. 
We can refactor the common parts, maybe the code for checking that autodelete 
was called?
Line 308: 
Line 309: def test_autodelete_disabled(self):
Line 310: cfg = make_config([('jobs', 'autodelete_delay', '-1')])
Line 311: job = AutodeleteJob()


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 6
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: Yes
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-12 Thread automation
gerrit-hooks has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 6:

* Update tracker: IGNORE, no Bug-Url found
* Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' 
and is a valid url.
* Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 
'ovirt-4.0'])

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 6
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-12 Thread nsoffer
Nir Soffer has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 5: Code-Review-1

(6 comments)

https://gerrit.ovirt.org/#/c/62002/5/lib/vdsm/jobs.py
File lib/vdsm/jobs.py:

Line 160
Line 161
Line 162
Line 163
Line 164
This may cause pending timeout to fail in _delete since the job does not exist.

It would be best to cancel pending timeouts before stopping, maybe introducing 
stop() or clear() interface for jobs, and canceling the timeout.

However canceling timeouts is racy, and the timeout is submitted in another 
thread. If the timeout function was already called in the scheduler thread 
there is no way to cancel it. We may avoid useless exceptions by introducing a 
new state (CLEARED) - if a job is cleared, we don't need to delete it, and we 
can just log debug message that job was cleared.


Line 120: def active(self):
Line 121: return self.status in (STATUS.PENDING, STATUS.RUNNING)
Line 122: 
Line 123: def abort(self):
Line 124: # TODO: Don't abort if not pending and not running
We need to resolve this todo now, the code is not correct as is.
Line 125: self._status = STATUS.ABORTED
Line 126: logging.info('Job %r aborting...', self._id)
Line 127: self._abort()
Line 128: if self.autodelete:


Line 128: if self.autodelete:
Line 129: self._autodelete()
Line 130: 
Line 131: def run(self):
Line 132: # TODO: Don't run if aborted or not pending
Same
Line 133: self._status = STATUS.RUNNING
Line 134: try:
Line 135: self._run()
Line 136: except Exception as e:


https://gerrit.ovirt.org/#/c/62002/5/tests/jobsTests.py
File tests/jobsTests.py:

Line 75: 
Line 76: class FakeScheduler(object):
Line 77: 
Line 78: def schedule(self, delay, callable):
Line 79: callable()
This works, but this does not test that callable will delete job.

I think we better do:

def __init__(self):
self.calls = []

def schedule(self, delay, callable):
self.calls.append((delay, callable))
return ScheduledCall(...)

Note that schedule must return a object with a cancel method, so the user can 
cancel it. Otherwise canceling the timeout in the job will raise AttributeError 
when you try to call None.cancel().

Now we can test that running a job scheduled a callable with the correct delay:

job.run()

# Check number of scheduled calls...
delay, callable = self.scheduler.calls[0]
# check delay...
# Check that job exists...
callable()
# Check that job was removed...
Line 80: 
Line 81: 
Line 82: @expandPermutations
Line 83: class JobsTests(VdsmTestCase):


Line 281: job = AutodeleteJob(exception=error)
Line 282: jobs.add(job)
Line 283: with MonkeyPatchScope([(jobs, 'config', cfg)]):
Line 284: self.run_job(job)
Line 285: self.assertRaises(jobs.NoSuchJob, jobs.get, job.id)
This does not verify that the job was removed after the configured delay.
Line 286: 
Line 287: def test_autodelete_when_aborted(self):
Line 288: cfg = make_config([('jobs', 'autodelete_delay', '0')])
Line 289: job = AutodeleteJob()


Line 289: job = AutodeleteJob()
Line 290: jobs.add(job)
Line 291: with MonkeyPatchScope([(jobs, 'config', cfg)]):
Line 292: job.abort()
Line 293: self.assertRaises(jobs.NoSuchJob, jobs.get, job.id)
Same
Line 294: 
Line 295: def test_autodelete_disabled(self):
Line 296: cfg = make_config([('jobs', 'autodelete_delay', '-1')])
Line 297: job = AutodeleteJob()


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 5
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: Yes
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-12 Thread automation
gerrit-hooks has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 5:

* Update tracker: IGNORE, no Bug-Url found
* Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' 
and is a valid url.
* Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 
'ovirt-4.0'])

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 5
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-09 Thread automation
gerrit-hooks has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 4:

* Update tracker: IGNORE, no Bug-Url found
* Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' 
and is a valid url.
* Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 
'ovirt-4.0'])

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 4
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-08 Thread nsoffer
Nir Soffer has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 3: Code-Review-1

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 3
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-09-08 Thread nsoffer
Nir Soffer has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 3:

(3 comments)

Mostly good, we have to implement state changes and make it thread safe (next 
patch?)

https://gerrit.ovirt.org/#/c/62002/3/lib/vdsm/jobs.py
File lib/vdsm/jobs.py:

Line 120: def active(self):
Line 121: return self.status in (STATUS.PENDING, STATUS.RUNNING)
Line 122: 
Line 123: def abort(self):
Line 124: # TODO: Don't abort if not pending and not running
We should do this now
Line 125: self._status = STATUS.ABORTED
Line 126: logging.info('Job %r aborting...', self._id)
Line 127: self._abort()
Line 128: if self.autodelete:


Line 128: if self.autodelete:
Line 129: self._autodelete()
Line 130: 
Line 131: def run(self):
Line 132: # TODO: Don't run if aborted or not pending
We should do this now - you can submit this in another patch to keep this patch 
small if you like.
Line 133: self._status = STATUS.RUNNING
Line 134: try:
Line 135: self._run()
Line 136: except Exception as e:


https://gerrit.ovirt.org/#/c/62002/3/tests/jobsTests.py
File tests/jobsTests.py:

Line 277: job = AutodeleteJob(exception=error)
Line 278: jobs.add(job)
Line 279: with MonkeyPatchScope([(jobs, 'config', cfg)]):
Line 280: self.run_job(job)
Line 281: time.sleep(0.1)  # Wait for the scheduler
Fragile, use fake scheduler instead.
Line 282: self.assertRaises(jobs.NoSuchJob, jobs.get, job.id)
Line 283: 
Line 284: def test_autodelete_when_aborted(self):
Line 285: cfg = make_config([('jobs', 'autodelete_delay', '0')])


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 3
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: Yes
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-08-08 Thread automation
gerrit-hooks has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 3:

* Update tracker: IGNORE, no Bug-Url found
* Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' 
and is a valid url.
* Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 
'ovirt-4.0'])

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 3
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-08-08 Thread alitke
Adam Litke has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 2: Verified+1

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-08-08 Thread automation
gerrit-hooks has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 2:

* Update tracker: IGNORE, no Bug-Url found
* Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' 
and is a valid url.
* Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 
'ovirt-4.0'])

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Francesco Romani 
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-08-05 Thread automation
gerrit-hooks has posted comments on this change.

Change subject: jobs: Autodelete
..


Patch Set 1:

* Update tracker: IGNORE, no Bug-Url found
* Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' 
and is a valid url.
* Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 
'ovirt-4.0'])

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke 
Gerrit-Reviewer: Nir Soffer 
Gerrit-Reviewer: gerrit-hooks 
Gerrit-HasComments: No
___
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org


Change in vdsm[master]: jobs: Autodelete

2016-08-05 Thread alitke
Hello Nir Soffer,

I'd like you to do a code review.  Please visit

https://gerrit.ovirt.org/62002

to review the following change.

Change subject: jobs: Autodelete
..

jobs: Autodelete

For storage jobs we like to delete finished jobs automatically after some
delay, giving engine enough time to discover the job completion state in most
cases, and allowing easy inspection of job state.  The Job class implements now
both run() and abort(), managing the state changes and auto-deleting the job
when done. Subclasses should implement _run() and _abort().

To intergate with v2v code using old jobs framework, v2v code will have to use
_run() instead of run(). Subclass that want to enable autodelete must override
the autodelete class attribute and set it to True.

class AutodeletingJob(jobs.Job):
autodelete = True

This feature is not relevant now for v2v jobs since engine is deleting these
jobs.

Change-Id: I4aafd2271397bd9bc4289dc1aab723398d475add
Signed-off-by: Adam Litke 
Signed-off-by: Nir Soffer 
---
M lib/vdsm/config.py.in
M lib/vdsm/jobs.py
M tests/jobsTests.py
3 files changed, 67 insertions(+), 0 deletions(-)


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

diff --git a/lib/vdsm/config.py.in b/lib/vdsm/config.py.in
index 9813fe5..50282e3 100644
--- a/lib/vdsm/config.py.in
+++ b/lib/vdsm/config.py.in
@@ -394,6 +394,14 @@
 '/sys/block//queue/discard_max_bytes is not zero.'),
 ]),
 
+# Section: [jobs]
+('jobs', [
+('autodelete_delay', '3600',
+'Automatically delete completed jobs from memory after the '
+'specified delay (in seconds).  When this value is negative '
+'autodelete will be disabled.'),
+]),
+
 # Section: [addresses]
 ('addresses', [
 
diff --git a/lib/vdsm/jobs.py b/lib/vdsm/jobs.py
index 21b6cb0..d6b3416 100644
--- a/lib/vdsm/jobs.py
+++ b/lib/vdsm/jobs.py
@@ -22,6 +22,7 @@
 import logging
 import threading
 
+from vdsm import config
 from vdsm import exception
 from vdsm import response
 
@@ -68,6 +69,10 @@
 
 class Job(object):
 _JOB_TYPE = None
+
+# If set to True, jobs of this class will be automatically deleted when
+# aborted or finished after a configurable delay.
+autodelete = False
 
 def __init__(self, job_id, description=''):
 self._id = job_id
@@ -118,11 +123,15 @@
 return self.status in (STATUS.PENDING, STATUS.RUNNING)
 
 def abort(self):
+# TODO: Don't abort if not pending and not running
 self._status = STATUS.ABORTED
 logging.info('Job %r aborting...', self._id)
 self._abort()
+if self.autodelete:
+self._autodelete()
 
 def run(self):
+# TODO: Don't run if aborted or not pending
 self._status = STATUS.RUNNING
 vars.job_id = self.id
 try:
@@ -138,6 +147,8 @@
 self._status = STATUS.DONE
 finally:
 vars.job_id = None
+if self.autodelete:
+self._autodelete()
 
 def _abort(self):
 """
@@ -151,6 +162,18 @@
 """
 raise NotImplementedError()
 
+def _autodelete(self):
+timeout = config.getint("jobs", "autodelete_delay")
+if timeout >= 0:
+_scheduler.schedule(timeout, self._delete)
+
+def _delete(self):
+logging.info("Autodeleting job %r", self.info())
+try:
+_delete(self._id)
+except Exception:
+logging.exception("Cannot delete job %s", self._id)
+
 def __repr__(self):
 s = "<{self.__class__.__name__} id={self.id} status={self.status} "
 if self.progress is not None:
diff --git a/tests/jobsTests.py b/tests/jobsTests.py
index dce6535..1781dba 100644
--- a/tests/jobsTests.py
+++ b/tests/jobsTests.py
@@ -17,12 +17,15 @@
 # Refer to the README and COPYING files for full details of the license
 #
 
+import time
 import uuid
 
 from vdsm import exception, jobs, response, schedule
 from vdsm.storage.threadlocal import vars
 
+from monkeypatch import MonkeyPatchScope
 from testlib import VdsmTestCase, expandPermutations, permutations
+from testlib import make_config
 from testlib import wait_for_job
 
 
@@ -53,6 +56,10 @@
 _JOB_TYPE = 'bar'
 
 
+class AutodeleteJob(TestingJob):
+autodelete = True
+
+
 class ProgressingJob(jobs.Job):
 
 def __init__(self):
@@ -74,6 +81,7 @@
 
 def setUp(self):
 scheduler = schedule.Scheduler()
+scheduler.start()
 jobs.start(scheduler)
 
 def tearDown(self):
@@ -266,3 +274,31 @@
 self.run_job(job)
 self.assertEqual(jobs.STATUS.FAILED, job.status)
 self.assertIsInstance(job.error, exception.VdsmException)
+
+@permutations(((None, ), (Exception(),)))
+def test_autodelete_when_finished(self, error):
+cfg = make_config([('jobs', 'autodelete_delay', '0')])