Coverage for python/lsst/ctrl/bps/htcondor/htcondor_compat.py: 45%
34 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-10 09:08 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-10 09:08 +0000
1# This file is part of ctrl_bps_htcondor.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This software is dual licensed under the GNU General Public License and also
10# under a 3-clause BSD license. Recipients may choose which of these licenses
11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12# respectively. If you choose the GPL option then the following text applies
13# (but note that there is still no warranty even if you opt for BSD instead):
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 3 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <https://www.gnu.org/licenses/>.
28"""Private module managing ``htcondor`` imports."""
30from __future__ import annotations
32import sys
33from collections.abc import Callable
34from importlib.metadata import version
35from typing import TYPE_CHECKING, cast
37from htcondor2 import HTCondorException as _HTCondorException
38from htcondor2 import Submit
39from packaging.version import Version
41from lsst.utils import doImport
43HTC_VERSION = Version(version("htcondor"))
45HTCondorException = cast(type[Exception], _HTCondorException)
47if TYPE_CHECKING:
48 from classad2 import ClassAd
51def ping(ad: ClassAd) -> None:
52 """Perform a version-agnostic HTCondor ping against the specified location
53 ad.
55 Parameters
56 ----------
57 ad : ``classad2.ClassAd``
58 A location ``ClassAd`` to ping, usually a ``Collector`` or ``Schedd``.
60 Raises
61 ------
62 HTCondorException
63 Raised if the ``ping`` raises a legacy ``htcondor`` exception.
65 Note
66 ----
67 The "preview" of ``htcondor2`` in the HTCondor LTS 24.0 release does not
68 implement a ``ping`` function. This function is part of the deprecated and
69 removed ``SecMan`` API which is only available in ``htcondor``.
70 """
71 if HTC_VERSION < Version("24.1"):
72 SecMan = cast(type, doImport("htcondor.SecMan"))
73 HTCondorLocateError = cast(type[Exception], doImport("htcondor.HTCondorLocateError"))
74 HTCondorIOError = cast(type[Exception], doImport("htcondor.HTCondorIOError"))
75 secman = SecMan()
76 try:
77 secman.ping(ad["MyAddress"])
78 except HTCondorLocateError as e:
79 raise HTCondorException("Unable to locate daemon.") from e
80 except HTCondorIOError as e:
81 raise HTCondorException("Unable to connect to daemon.") from e
82 del secman
83 del HTCondorLocateError
84 del HTCondorIOError
85 del SecMan
86 del sys.modules["htcondor"]
87 else:
88 _ping = cast(Callable, doImport("htcondor2.ping"))
89 _ping(ad)
92def compat_submit_ad(ad: Submit) -> Submit:
93 """Apply compatibility details to a ``htcondor2.Submit`` ad as necessary
94 based on package version.
96 Parameters
97 ----------
98 ad : ``htcondor2.Submit``
99 A ``Submit`` ad to make compatible with ``htcondor`` version 24.0 LTS.
101 Notes
102 -----
103 In ``htcondor==24.0.*``, the ``htcondor2.Schedd.submit`` method is broken
104 and raises an ``IndexError`` if no "queue arguments" are provided. A work-
105 around is to specify explicit "queue arguments" on the ``Submit`` ad.
106 """
107 if HTC_VERSION < Version("24.1"): 107 ↛ 109line 107 didn't jump to line 109 because the condition on line 107 was always true
108 ad.setQArgs("queue 1")
109 return ad