Skip to content

Commit 397e9eb

Browse files
committed
Allow Jobs to force the keeping of the sandbox
1 parent d039656 commit 397e9eb

5 files changed

Lines changed: 24 additions & 17 deletions

File tree

cms/grading/Job.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Job(object):
7878
def __init__(self, operation=None,
7979
task_type=None, task_type_parameters=None,
8080
language=None, multithreaded_sandbox=False,
81-
shard=None, sandboxes=None, info=None,
81+
shard=None, keep_sandbox=False, sandboxes=None, info=None,
8282
success=None, text=None,
8383
files=None, managers=None, executables=None):
8484
"""Initialization.
@@ -92,6 +92,9 @@ def __init__(self, operation=None,
9292
multithreaded_sandbox (boolean): whether the sandbox should
9393
allow multithreading.
9494
shard (int|None): the shard of the Worker completing this job.
95+
keep_sandbox (bool): whether to forcefully keep the sandbox,
96+
even if other conditions (the config, the sandbox status)
97+
don't warrant it.
9598
sandboxes ([string]|None): the paths of the sandboxes used in
9699
the Worker during the execution of the job.
97100
info (string|None): a human readable description of the job.
@@ -126,6 +129,7 @@ def __init__(self, operation=None,
126129
self.language = language
127130
self.multithreaded_sandbox = multithreaded_sandbox
128131
self.shard = shard
132+
self.keep_sandbox = keep_sandbox
129133
self.sandboxes = sandboxes
130134
self.info = info
131135

@@ -147,6 +151,7 @@ def export_to_dict(self):
147151
'language': self.language,
148152
'multithreaded_sandbox': self.multithreaded_sandbox,
149153
'shard': self.shard,
154+
'keep_sandbox': self.keep_sandbox,
150155
'sandboxes': self.sandboxes,
151156
'info': self.info,
152157
'success': self.success,
@@ -250,7 +255,7 @@ class CompilationJob(Job):
250255

251256
def __init__(self, operation=None, task_type=None,
252257
task_type_parameters=None,
253-
shard=None, sandboxes=None, info=None,
258+
shard=None, keep_sandbox=False, sandboxes=None, info=None,
254259
language=None, multithreaded_sandbox=False,
255260
files=None, managers=None,
256261
success=None, compilation_success=None,
@@ -267,7 +272,7 @@ def __init__(self, operation=None, task_type=None,
267272

268273
Job.__init__(self, operation, task_type, task_type_parameters,
269274
language, multithreaded_sandbox,
270-
shard, sandboxes, info, success, text,
275+
shard, keep_sandbox, sandboxes, info, success, text,
271276
files, managers, executables)
272277
self.compilation_success = compilation_success
273278
self.plus = plus
@@ -436,7 +441,7 @@ class EvaluationJob(Job):
436441
"""
437442
def __init__(self, operation=None, task_type=None,
438443
task_type_parameters=None, shard=None,
439-
sandboxes=None, info=None,
444+
keep_sandbox=False, sandboxes=None, info=None,
440445
language=None, multithreaded_sandbox=False,
441446
files=None, managers=None, executables=None,
442447
input=None, output=None,
@@ -468,7 +473,7 @@ def __init__(self, operation=None, task_type=None,
468473
"""
469474
Job.__init__(self, operation, task_type, task_type_parameters,
470475
language, multithreaded_sandbox,
471-
shard, sandboxes, info, success, text,
476+
shard, keep_sandbox, sandboxes, info, success, text,
472477
files, managers, executables)
473478
self.input = input
474479
self.output = output

cms/grading/tasktypes/Batch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def compile(self, job, file_cacher):
252252
Executable(executable_filename, digest)
253253

254254
# Cleanup.
255-
delete_sandbox(sandbox, job.success)
255+
delete_sandbox(sandbox, job.success, job.keep_sandbox)
256256

257257
def evaluate(self, job, file_cacher):
258258
"""See TaskType.evaluate."""
@@ -361,4 +361,4 @@ def evaluate(self, job, file_cacher):
361361
job.text = text
362362
job.plus = stats
363363

364-
delete_sandbox(sandbox, job.success)
364+
delete_sandbox(sandbox, job.success, job.keep_sandbox)

cms/grading/tasktypes/Communication.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def compile(self, job, file_cacher):
243243
Executable(executable_filename, digest)
244244

245245
# Cleanup.
246-
delete_sandbox(sandbox, job.success)
246+
delete_sandbox(sandbox, job.success, job.keep_sandbox)
247247

248248
def evaluate(self, job, file_cacher):
249249
"""See TaskType.evaluate."""
@@ -427,9 +427,9 @@ def evaluate(self, job, file_cacher):
427427
job.text = text
428428
job.plus = stats_user
429429

430-
delete_sandbox(sandbox_mgr, job.success)
430+
delete_sandbox(sandbox_mgr, job.success, job.keep_sandbox)
431431
for s in sandbox_user:
432-
delete_sandbox(s, job.success)
433-
if not config.keep_sandbox:
432+
delete_sandbox(s, job.success, job.keep_sandbox)
433+
if job.success and not config.keep_sandbox and not job.keep_sandbox:
434434
for d in fifo_dir:
435435
rmtree(d)

cms/grading/tasktypes/TwoSteps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def compile(self, job, file_cacher):
217217
Executable(executable_filename, digest)
218218

219219
# Cleanup
220-
delete_sandbox(sandbox, job.success)
220+
delete_sandbox(sandbox, job.success, job.keep_sandbox)
221221

222222
def evaluate(self, job, file_cacher):
223223
"""See TaskType.evaluate."""
@@ -352,5 +352,5 @@ def evaluate(self, job, file_cacher):
352352
job.text = text
353353
job.plus = stats
354354

355-
delete_sandbox(first_sandbox, job.success)
356-
delete_sandbox(second_sandbox, job.success)
355+
delete_sandbox(first_sandbox, job.success, job.keep_sandbox)
356+
delete_sandbox(second_sandbox, job.success, job.keep_sandbox)

cms/grading/tasktypes/util.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,21 @@ def create_sandbox(file_cacher, name=None):
7676
return sandbox
7777

7878

79-
def delete_sandbox(sandbox, success=True):
79+
def delete_sandbox(sandbox, success=True, keep_sandbox=False):
8080
"""Delete the sandbox, if the configuration and job was ok.
8181
8282
sandbox (Sandbox): the sandbox to delete.
8383
success (boolean): if the job succeeded (no system errors).
84+
keep_sandbox (bool): whether to keep the sandbox regardless of other
85+
conditions.
8486
8587
"""
8688
# If the job was not successful, we keep the sandbox around.
8789
if not success:
8890
logger.warning("Sandbox %s kept around because job did not succeeded.",
8991
sandbox.get_root_path())
9092

91-
delete = success and not config.keep_sandbox
93+
delete = success and not config.keep_sandbox and not keep_sandbox
9294
try:
9395
sandbox.cleanup(delete=delete)
9496
except (IOError, OSError):
@@ -265,7 +267,7 @@ def eval_output(file_cacher, job, checker_codename,
265267
sandbox, checker_digest, job.input, job.output,
266268
EVAL_USER_OUTPUT_FILENAME)
267269

268-
delete_sandbox(sandbox, success)
270+
delete_sandbox(sandbox, success, job.keep_sandbox)
269271
return success, outcome, text
270272

271273
else:

0 commit comments

Comments
 (0)