Skip to content

feat: Migrate HTCondor submission to native Python API (Fixes #336) ; - #510

Open
gluonparticle wants to merge 3 commits into
HEP-FCC:masterfrom
gluonparticle:issue-336-htcondor-api
Open

feat: Migrate HTCondor submission to native Python API (Fixes #336) ;#510
gluonparticle wants to merge 3 commits into
HEP-FCC:masterfrom
gluonparticle:issue-336-htcondor-api

Conversation

@gluonparticle

Copy link
Copy Markdown

This PR migrates the batch submission system from legacy shell-scripting to the native HTCondor Python API. This fixes #336 while improves stability, security, and portability across different operating systems.

Key Changes:

  • Native API: Switched to htcondor.Submit and htcondor.Schedd for job dispatching.

  • Security (Critical): Eliminated a Shell Injection risk by removing subprocess calls with shell=True. Sample names and configuration strings are now handled as Python objects, preventing potential command execution through malicious input.

  • Atomic Transactions: Wrapped submissions in schedd.transaction() for ensuring grid state consistency.

  • Portability Fix: Patched a hardcoded OS check that caused FileNotFoundError on non-RHEL systems (Arch, Ubuntu, macOS).

Verification & Tests:

I have verified the logic locally using the included mock suite on Arch Linux and also included a local regression test in tests/unit/batch/.

Note:

Since I developed this on a non-CERN environment, I included a mock-based test suite to verify the retry logic and transactional flow. If you prefer to keep the tests/ directory strictly for integration tests, I am happy to move these to a gist or remove them before merging.

I am happy to spin up an AlmaLinux container to verify the bindings against the specific glibc version used in the Key4hep stack ;

- Replaced legacy subprocess shell calls with native htcondor.Submit objects.
- Implemented Schedd.transaction() for atomic, reliable job submission.
- Patched determine_os() to prevent FileNotFoundError on non-RHEL systems.
- Added mock-based unit tests to verify retry logic and error handling.
- Moved 'import htcondor' inside functions to prevent ModuleNotFoundError
  in lightweight CI environments that lack grid bindings.
@kjvbrt

kjvbrt commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Hi @gluonparticle, this is cool :)

Can you explain what is the reason behind removing the comments?

@gluonparticle

Copy link
Copy Markdown
Author

Hi @gluonparticle, this is cool :)

Can you explain what is the reason behind removing the comments?

Hi @kjvbrt , thanks! Glad you like the native API approach.

To be honest. as I was testing CI fixes, I just got a bit carried away with 'cleaning up' the file.

As I was trying to pursue a minimalistic approach on the format , I endeed up removing some comments which might hinder code readability.

Looking at the diff, I realize I might've made things harder to review. My bad!

Please let me know if I should revert those comments and if you need anything else from my side. Thanks! ;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use htcondor python bindings for batch submission

2 participants