Skip to content

Commit

Permalink
Merge pull request #43 from lsst/tickets/DM-46046
Browse files Browse the repository at this point in the history
DM-46046: Update bps restart to work with relative path.
  • Loading branch information
MichelleGower authored Sep 4, 2024
2 parents 800e917 + 56acb3e commit fe78af9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/changes/DM-46046.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Updated ``bps restart`` to work with relative path as id.
Updated ``bps report --id <relpath>`` to display absolute path.
8 changes: 6 additions & 2 deletions python/lsst/ctrl/bps/htcondor/htcondor_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def restart(self, wms_workflow_id):
run_id, run_name, message = None, None, ""
with chdir(wms_path):
try:
dag_path = next(wms_path.glob("*.dag.condor.sub"))
dag_path = next(Path.cwd().glob("*.dag.condor.sub"))
except StopIteration:
message = f"DAGMan submit description file not found in '{wms_path}'"
else:
Expand Down Expand Up @@ -1193,6 +1193,10 @@ def _get_info_from_path(wms_path):
message : `str`
Message to be printed with the summary report.
"""
# Ensure path is absolute, in particular for folks helping
# debug failures that need to dig around submit files.
wms_path = Path(wms_path).resolve()

messages = []
try:
wms_workflow_id, jobs = read_dag_log(wms_path)
Expand Down Expand Up @@ -1847,7 +1851,7 @@ def _wms_id_to_dir(wms_id):
constraint = f'GlobalJobId == "{wms_id}"'
schedd_ads.extend(coll.locateAll(htcondor.DaemonTypes.Schedd))
case WmsIdType.PATH:
wms_path = Path(wms_id)
wms_path = Path(wms_id).resolve()
case WmsIdType.UNKNOWN:
raise TypeError(f"Invalid job id type: {wms_id}")
if constraint is not None:
Expand Down
54 changes: 54 additions & 0 deletions tests/test_htcondor_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import logging
import os
import unittest
from pathlib import Path
from shutil import copy2

import htcondor
Expand All @@ -39,12 +40,14 @@
HTCondorService,
JobStatus,
NodeStatus,
WmsIdType,
_get_exit_code_summary,
_get_info_from_path,
_get_state_counts_from_dag_job,
_htc_node_status_to_wms_state,
_htc_status_to_wms_state,
_translate_job_cmds,
_wms_id_to_dir,
)
from lsst.ctrl.bps.htcondor.lssthtc import MISSING_ID
from lsst.utils.tests import temporaryDirectory
Expand Down Expand Up @@ -447,3 +450,54 @@ def test_successful_run(self):
self.assertEqual(wms_workflow_id, "1163.0")
self.assertEqual(len(jobs), 6) # dag, pipetaskInit, 3 science, finalJob
self.assertEqual(message, "")

def test_relative_path(self):
orig_dir = Path.cwd()
with temporaryDirectory() as tmp_dir:
os.chdir(tmp_dir)
abs_path = Path(tmp_dir).resolve() / "subdir"
abs_path.mkdir()
copy2(f"{TESTDIR}/data/test_pipelines_check_20240727T003507Z.dag", abs_path)
copy2(f"{TESTDIR}/data/test_pipelines_check_20240727T003507Z.dag.dagman.log", abs_path)
copy2(f"{TESTDIR}/data/test_pipelines_check_20240727T003507Z.dag.dagman.out", abs_path)
copy2(f"{TESTDIR}/data/test_pipelines_check_20240727T003507Z.dag.nodes.log", abs_path)
copy2(f"{TESTDIR}/data/test_pipelines_check_20240727T003507Z.node_status", abs_path)
copy2(f"{TESTDIR}/data/test_pipelines_check_20240727T003507Z.info.json", abs_path)
wms_workflow_id, jobs, message = _get_info_from_path("subdir")
self.assertEqual(wms_workflow_id, "1163.0")
self.assertEqual(len(jobs), 6) # dag, pipetaskInit, 3 science, finalJob
self.assertEqual(message, "")
self.assertEqual(jobs["1163.0"]["Iwd"], str(abs_path))
os.chdir(orig_dir)


class WmsIdToDirTestCase(unittest.TestCase):
"""Test _wms_id_to_dir function"""

@unittest.mock.patch("lsst.ctrl.bps.htcondor.htcondor_service._wms_id_type")
def testInvalidIdType(self, _wms_id_type_mock):
_wms_id_type_mock.return_value = WmsIdType.UNKNOWN
with self.assertRaises(TypeError) as cm:
_, _ = _wms_id_to_dir("not_used")
self.assertIn("Invalid job id type", str(cm.exception))

@unittest.mock.patch("lsst.ctrl.bps.htcondor.htcondor_service._wms_id_type")
def testAbsPathId(self, mock_wms_id_type):
mock_wms_id_type.return_value = WmsIdType.PATH
with temporaryDirectory() as tmp_dir:
wms_path, id_type = _wms_id_to_dir(tmp_dir)
self.assertEqual(id_type, WmsIdType.PATH)
self.assertEqual(Path(tmp_dir).resolve(), wms_path)

@unittest.mock.patch("lsst.ctrl.bps.htcondor.htcondor_service._wms_id_type")
def testRelPathId(self, _wms_id_type_mock):
_wms_id_type_mock.return_value = WmsIdType.PATH
orig_dir = Path.cwd()
with temporaryDirectory() as tmp_dir:
os.chdir(tmp_dir)
abs_path = Path(tmp_dir) / "newdir"
abs_path.mkdir()
wms_path, id_type = _wms_id_to_dir("newdir")
self.assertEqual(id_type, WmsIdType.PATH)
self.assertEqual(abs_path.resolve(), wms_path)
os.chdir(orig_dir)

0 comments on commit fe78af9

Please sign in to comment.