Skip to content
Permalink
Browse files

Merge pull request #497 from kyleam/jobs-no-local-dir

  • Loading branch information
kyleam committed Jan 3, 2020
2 parents f307fba + c7fdb3b commit a74de9afeef51cdc3d5a2f7490ddc923ad1ed5a5
Showing with 29 additions and 5 deletions.
  1. +12 −3 reproman/interface/jobs.py
  2. +17 −2 reproman/interface/tests/test_run.py
@@ -72,7 +72,16 @@ def match(query_id, jobids):

def _resurrect_orc(job):
resource = get_manager().get_resource(job["resource_id"], "id")
with chpwd(job["local_directory"]):
try:
# Create chpwd separately so that this try-except block doesn't cover
# the context manager suite below.
cd = chpwd(job["local_directory"])
except FileNotFoundError:
raise OrchestratorError(
"local directory for job {} no longer exists: {}"
.format(job["_jobid"], job["local_directory"]))

with cd:
orchestrator_class = ORCHESTRATORS[job["orchestrator"]]
orc = orchestrator_class(resource, job["submitter"], job,
resurrection=True)
@@ -216,7 +225,7 @@ def __call__(queries, action="auto", all_=False, status=False):
try:
fn(job)
except OrchestratorError as exc:
lgr.error("job %s failed: %s", job, exc_str(exc))
except ResourceNotFoundError as exc:
lgr.error("job %s failed: %s", job["_jobid"], exc_str(exc))
except ResourceNotFoundError:
lgr.error("Resource %s (%s) no longer exists",
job["resource_id"], job["resource_name"])
@@ -13,6 +13,7 @@
from unittest.mock import patch
import os
import os.path as op
import shutil
import time

import pytest
@@ -183,14 +184,16 @@ def context(tmpdir, resource_manager, job_registry):
- directory: temporary path that is the current directory when run_fn is
called.
"""
path = str(tmpdir)
home = str(tmpdir)
path = op.join(home, "local")
os.makedirs(path, exist_ok=True)

def run_fn(*args, **kwargs):
with contextlib.ExitStack() as stack:
stack.enter_context(chpwd(path))
# Patch home to avoid populating testing machine with jobs when
# using local shell.
stack.enter_context(patch.dict(os.environ, {"HOME": path}))
stack.enter_context(patch.dict(os.environ, {"HOME": home}))
stack.enter_context(patch("reproman.interface.run.get_manager",
return_value=resource_manager))
stack.enter_context(patch("reproman.interface.run.LocalRegistry",
@@ -453,6 +456,18 @@ def test_jobs_deleted_resource(context):
assert "myshell" in output.out


def test_jobs_deleted_local_directory(context):
path = context["directory"]
run = context["run_fn"]
jobs = context["jobs_fn"]

run(command=["touch", "ok"], outputs=["ok"], resref="myshell")
shutil.rmtree(path)
with swallow_logs(new_level=logging.ERROR) as log:
jobs(queries=[], status=True)
assert "no longer exists" in log.out


def test_jobs_orc_error(context):
run = context["run_fn"]
jobs = context["jobs_fn"]

0 comments on commit a74de9a

Please sign in to comment.
You can’t perform that action at this time.