Repository navigation
Fix azure SDK namespace shadowing in CRUD pipeline steps (run via -m crud.main) - #1318
Xu Xue (xuexu6666) wants to merge 1 commit into
Conversation
The crud engine/machine steps ran main.py as a file (python3 $PYTHON_SCRIPT_FILE), which puts modules/python/crud/ on sys.path[0]. After Azure#1231 added crud/azure/__init__.py, that regular package shadows the installed 'azure' SDK namespace, so 'from azure.core.exceptions import ...' fails with ModuleNotFoundError: No module named 'azure.core'. Invoke as a module instead (python3 -m crud.main) so sys.path[0] is modules/python: the azure SDK resolves from site-packages and crud.azure still imports. Drop the now-unused PYTHON_SCRIPT_FILE env var.
|
For reviewers only: reply |
There was a problem hiding this comment.
🟢 Approval recommended
The changes consistently replace file-based Python execution with module execution across all affected templates and remove the corresponding unused environment variable without leaving any remaining references.
Pull request overview
This PR fixes Azure SDK import failures in the CRUD/Machine-API Azure DevOps pipelines caused by Python namespace shadowing (crud/azure shadowing the installed azure SDK namespace) by switching pipeline invocation from running the main.py file to executing the module via python3 -m crud.main.
Changes:
- Update CRUD pipeline steps to run
python3 -m crud.main ...instead ofpython3 "$PYTHON_SCRIPT_FILE" .... - Remove the now-unused
PYTHON_SCRIPT_FILEenvironment variable from the affected steps. - Apply the same invocation fix consistently across both CRUD and Machine API execute/collect step templates.
File summaries
| File | Description |
|---|---|
| steps/engine/machine/k8s/execute.yml | Switch machine CRUD execution commands to python3 -m crud.main and remove PYTHON_SCRIPT_FILE. |
| steps/engine/machine/k8s/collect.yml | Switch machine CRUD collection command to python3 -m crud.main and remove PYTHON_SCRIPT_FILE. |
| steps/engine/crud/k8s/execute.yml | Switch k8s CRUD execution commands (create/scale/workloads/statefulset/job/delete) to python3 -m crud.main and remove PYTHON_SCRIPT_FILE. |
| steps/engine/crud/k8s/collect.yml | Switch k8s CRUD collection command to python3 -m crud.main and remove PYTHON_SCRIPT_FILE. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Superseded by #1319 (branch now on Azure/telescope directly, no fork). |
Problem
The GPU Cluster CRUD pipeline (and other CRUD/Machine-API pipelines) have failed on every run since #1231 merged. Both CRUD tasks fail immediately:
azure-coreis installed correctly by "Install Dependencies" — this is namespace shadowing, not a missing dependency.Root cause
The steps run the script as a file:
Running
python3 .../crud/main.pyputs the script's own directory —modules/python/crud/— atsys.path[0]. #1231 addedmodules/python/crud/azure/__init__.py, turningcrud/azure/into a regular package. Found first onsys.path, it shadows the installedazureSDK namespace package, soazure.corecan no longer be resolved.Unit tests didn't catch this because pytest runs with a different
sys.paththat never placescrud/atsys.path[0].Fix
Invoke the module with
-minstead of running the file.python3 -m crud.mainputsmodules/python(the working directory) onsys.path[0]instead ofcrud/, so theazureSDK resolves from site-packages whilecrud.azurestill imports. This is also what thetelescope-crudentry point registered in #1231 was intended for. The now-unusedPYTHON_SCRIPT_FILEenv var is removed.Applied to all affected engine steps:
steps/engine/crud/k8s/execute.ymlsteps/engine/crud/k8s/collect.ymlsteps/engine/machine/k8s/execute.ymlsteps/engine/machine/k8s/collect.ymlVerification
Reproduced the shadowing and confirmed the fix locally: