Skip to content

mgr: set sys.executable in PyConfig for subprocess spawning - #69239

Open
NitzanMordhai wants to merge 1 commit into
ceph:mainfrom
NitzanMordhai:wip-nitzan-mgr-sys-executable-config
Open

NitzanMordhai wants to merge 1 commit into
ceph:mainfrom
NitzanMordhai:wip-nitzan-mgr-sys-executable-config

Conversation

@NitzanMordhai

@NitzanMordhai NitzanMordhai commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

The PyO3 workaround for cryptographic functions spawns a separate Python interpreter to avoid subinterpreter conflicts. Previously, it used hardcoded 'python3' from PATH, which breaks in environments like NixOS where Python is not in PATH or when multiple Python versions are installed.

This commit fixes the issue in two parts:

  1. PyModuleRegistry.cc: Set py_config.executable during Python initialization using PyConfig_SetBytesString. This ensures sys.executable is properly populated in the mgr Python environment.

  2. cryptotools/remote.py: Use sys.executable as the primary source for the Python interpret path.

Fixes: https://tracker.ceph.com/issues/75768

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

The PyO3 workaround for cryptographic functions spawns a separate
Python interpreter to avoid subinterpreter conflicts. Previously,
it used hardcoded 'python3' from PATH, which breaks in environments
like NixOS where Python is not in PATH or when multiple Python
versions are installed.

This commit fixes the issue in two parts:

1. PyModuleRegistry.cc: Set py_config.executable during Python
   initialization using PyConfig_SetBytesString. This ensures
   sys.executable is properly populated in the mgr Python environment.

2. cryptotools/remote.py: Use sys.executable as the primary
   source for the Python interpret path.

Fixes: https://tracker.ceph.com/issues/75768
Signed-off-by: Nitzan Mordechai <[email protected]>
_input = input_data.encode()
cmd = ['python3', '-m', _ctmodule] + list(args)
# Use sys.executable if available, otherwise fall back to python3
python_exe = sys.executable or shutil.which('python3') or 'python3'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we test something like this? Or are we just bound to have to wing it? :-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phlogistonjohn i missed that PR that is already fixing that #67904
it will be hard to automate tests like that. I tried to use PyEnv locally and test it - build with python3.9 use pyenv to switch local python to 3.11 and check the python_exe that is actually 3.9

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's what I was afraid of.

WRT #67904 - I much prefer the more targeted fixes in this current pr here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WRT #67904 - I much prefer the more targeted fixes in this current pr here.

As is mentioned in the PR over there, the first two commits from that PR can be easily cherry-picked.

Comment on lines 73 to +74
status = PyConfig_SetString(&py_config, &py_config.program_name, WCHAR(MGR_PYTHON_EXECUTABLE));
ceph_assertf(!PyStatus_Exception(status), "PyConfig_SetString: %s:%s", status.func, status.err_msg);
ceph_assertf(!PyStatus_Exception(status), "PyConfig_SetString(program_name): %s:%s", status.func, status.err_msg);

@benaryorg benaryorg Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm mistaken, won't this still set py_config.program_name to the literal string MGR_PYTHON_EXECUTABLE1?

Footnotes

  1. as per the commit message of one of the commits over in the other PR fixing this ↩

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That IS the case.

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions github-actions Bot added the stale label Sep 13, 2026
@github-actions github-actions Bot removed the stale label Sep 30, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions github-actions Bot added the stale label Nov 29, 2026
@RaminNietzsche

Copy link
Copy Markdown
Member

Ceph PR triage — related open PRs

Queried #69239 against KB snapshot 2026-11-10T06:02:21 in 0.2s.
Signals are candidates for human review, not merge blockers.

Category Confidence Other PR(s) Note
competing-fix medium #67904 different authors, same tracker ticket, overlapping code; text sim 0.707; file Jaccard 0.4; 2 overlapping hunks; same tracker 75768; authors NitzanMordhai / ben

This comment is updated in place when the workflow re-runs (hidden HTML marker). Data: read-only GitHub + local git analysis; no labels or merges were changed.

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants