From 5ba0c3d25df1e92bd04c666142d9495dbfd1fc55 Mon Sep 17 00:00:00 2001 From: xuexu6666 Date: Wed, 9 Sep 2026 10:05:25 -0500 Subject: [PATCH] Run crud module via -m to fix azure SDK namespace shadowing 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 #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. --- steps/engine/crud/k8s/collect.yml | 3 +-- steps/engine/crud/k8s/execute.yml | 19 +++++++------------ steps/engine/machine/k8s/collect.yml | 3 +-- steps/engine/machine/k8s/execute.yml | 5 ++--- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/steps/engine/crud/k8s/collect.yml b/steps/engine/crud/k8s/collect.yml index 05f0021ee7..5798d0d7de 100644 --- a/steps/engine/crud/k8s/collect.yml +++ b/steps/engine/crud/k8s/collect.yml @@ -9,12 +9,11 @@ steps: - script: | set -eo pipefail - PYTHONPATH=$PYTHONPATH:$(pwd) python3 $PYTHON_SCRIPT_FILE collect + PYTHONPATH=$PYTHONPATH:$(pwd) python3 -m crud.main collect displayName: 'Collect K8s CRUD Operations data for ${{ parameters.cloud }}' workingDirectory: modules/python env: - PYTHON_SCRIPT_FILE: $(Pipeline.Workspace)/s/modules/python/crud/main.py RESULT_DIR: $(System.DefaultWorkingDirectory)/$(RUN_ID) RUN_URL: $(System.TeamFoundationCollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)&view=logs&j=$(System.JobId) REGION: ${{ parameters.region }} diff --git a/steps/engine/crud/k8s/execute.yml b/steps/engine/crud/k8s/execute.yml index 5ee588cf0c..09f7cdbf48 100644 --- a/steps/engine/crud/k8s/execute.yml +++ b/steps/engine/crud/k8s/execute.yml @@ -6,7 +6,7 @@ steps: set -eo pipefail # Create Node Pool - PYTHONPATH=$PYTHONPATH:$(pwd) python3 "$PYTHON_SCRIPT_FILE" create \ + PYTHONPATH=$PYTHONPATH:$(pwd) python3 -m crud.main create \ --cloud "$CLOUD" \ --run-id "$RUN_ID" \ --result-dir "$RESULT_DIR" \ @@ -21,7 +21,7 @@ steps: --capacity-type "${CAPACITY_TYPE:-ON_DEMAND}" # Scale Up Node Pool - PYTHONPATH=$PYTHONPATH:$(pwd) python3 "$PYTHON_SCRIPT_FILE" scale \ + PYTHONPATH=$PYTHONPATH:$(pwd) python3 -m crud.main scale \ --cloud "$CLOUD" \ --run-id "$RUN_ID" \ --result-dir "$RESULT_DIR" \ @@ -38,7 +38,6 @@ steps: displayName: 'Execute K8s Create & Scale Up Operations for ${{ parameters.cloud }}' workingDirectory: modules/python env: - PYTHON_SCRIPT_FILE: $(Pipeline.Workspace)/s/modules/python/crud/main.py VM_SIZE: $(VM_SIZE) CREATE_NODE_COUNT: $(CREATE_NODE_COUNT) SCALE_NODE_COUNT: $(SCALE_NODE_COUNT) @@ -60,7 +59,7 @@ steps: set -eo pipefail # Deploy Workloads - PYTHONPATH=$PYTHONPATH:$(pwd) python3 "$PYTHON_SCRIPT_FILE" deployment \ + PYTHONPATH=$PYTHONPATH:$(pwd) python3 -m crud.main deployment \ --cloud "$CLOUD" \ --run-id "$RUN_ID" \ --result-dir "$RESULT_DIR" \ @@ -74,7 +73,6 @@ steps: displayName: 'Execute K8s Workload operations for ${{ parameters.cloud }}' workingDirectory: modules/python env: - PYTHON_SCRIPT_FILE: $(Pipeline.Workspace)/s/modules/python/crud/main.py POOL_NAME: $(POOL_NAME) CLOUD: ${{ parameters.cloud }} STEP_TIME_OUT: $(STEP_TIME_OUT) @@ -89,7 +87,7 @@ steps: set -eo pipefail # Deploy StatefulSets - PYTHONPATH=$PYTHONPATH:$(pwd) python3 "$PYTHON_SCRIPT_FILE" statefulset \ + PYTHONPATH=$PYTHONPATH:$(pwd) python3 -m crud.main statefulset \ --cloud "$CLOUD" \ --run-id "$RUN_ID" \ --result-dir "$RESULT_DIR" \ @@ -103,7 +101,6 @@ steps: displayName: 'Execute K8s StatefulSet operations for ${{ parameters.cloud }}' workingDirectory: modules/python env: - PYTHON_SCRIPT_FILE: $(Pipeline.Workspace)/s/modules/python/crud/main.py POOL_NAME: $(POOL_NAME) CLOUD: ${{ parameters.cloud }} STEP_TIME_OUT: $(STEP_TIME_OUT) @@ -118,7 +115,7 @@ steps: set -eo pipefail # Deploy Jobs - PYTHONPATH=$PYTHONPATH:$(pwd) python3 "$PYTHON_SCRIPT_FILE" job \ + PYTHONPATH=$PYTHONPATH:$(pwd) python3 -m crud.main job \ --cloud "$CLOUD" \ --run-id "$RUN_ID" \ --result-dir "$RESULT_DIR" \ @@ -132,7 +129,6 @@ steps: displayName: 'Execute K8s Job operations for ${{ parameters.cloud }}' workingDirectory: modules/python env: - PYTHON_SCRIPT_FILE: $(Pipeline.Workspace)/s/modules/python/crud/main.py POOL_NAME: $(POOL_NAME) CLOUD: ${{ parameters.cloud }} STEP_TIME_OUT: $(STEP_TIME_OUT) @@ -147,7 +143,7 @@ steps: set -eo pipefail # Scale Down Node Pool - PYTHONPATH=$PYTHONPATH:$(pwd) python3 "$PYTHON_SCRIPT_FILE" scale \ + PYTHONPATH=$PYTHONPATH:$(pwd) python3 -m crud.main scale \ --cloud "$CLOUD" \ --run-id "$RUN_ID" \ --result-dir "$RESULT_DIR" \ @@ -162,7 +158,7 @@ steps: $([[ "${ENABLE_MANAGED_GPU,,}" == "true" && "${GPU_MIG_STRATEGY}" =~ ^(mixed|single)$ ]] && echo "--gpu-mig-strategy ${GPU_MIG_STRATEGY}" || true) # Delete Node Pool - PYTHONPATH=$PYTHONPATH:$(pwd) python3 "$PYTHON_SCRIPT_FILE" delete \ + PYTHONPATH=$PYTHONPATH:$(pwd) python3 -m crud.main delete \ --cloud "$CLOUD" \ --run-id "$RUN_ID" \ --result-dir "$RESULT_DIR" \ @@ -172,7 +168,6 @@ steps: condition: always() workingDirectory: modules/python env: - PYTHON_SCRIPT_FILE: $(Pipeline.Workspace)/s/modules/python/crud/main.py VM_SIZE: $(VM_SIZE) CREATE_NODE_COUNT: $(CREATE_NODE_COUNT) SCALE_NODE_COUNT: $(SCALE_NODE_COUNT) diff --git a/steps/engine/machine/k8s/collect.yml b/steps/engine/machine/k8s/collect.yml index f0119d6d7e..feff233941 100644 --- a/steps/engine/machine/k8s/collect.yml +++ b/steps/engine/machine/k8s/collect.yml @@ -10,12 +10,11 @@ steps: region: ${{ parameters.region }} - script: | set -eo pipefail - PYTHONPATH=$PYTHONPATH:$(pwd) python3 "$PYTHON_SCRIPT_FILE" collect + PYTHONPATH=$PYTHONPATH:$(pwd) python3 -m crud.main collect workingDirectory: modules/python displayName: "Collect Machine API results" condition: always() env: - PYTHON_SCRIPT_FILE: $(Pipeline.Workspace)/s/modules/python/crud/main.py RUN_ID: $(RUN_ID) REGION: ${{ parameters.region }} RESULT_DIR: $(System.DefaultWorkingDirectory)/$(RUN_ID) diff --git a/steps/engine/machine/k8s/execute.yml b/steps/engine/machine/k8s/execute.yml index d4f2fb020b..33d52e990e 100644 --- a/steps/engine/machine/k8s/execute.yml +++ b/steps/engine/machine/k8s/execute.yml @@ -6,7 +6,7 @@ steps: - script: | set -eo pipefail - PYTHONPATH=$PYTHONPATH:$(pwd) python3 "$PYTHON_SCRIPT_FILE" create-machine \ + PYTHONPATH=$PYTHONPATH:$(pwd) python3 -m crud.main create-machine \ --cloud "$CLOUD" \ --run-id "$RUN_ID" \ --node-pool-name "$POOL_NAME" \ @@ -19,7 +19,7 @@ steps: use_batch_args+=(--use-batch-api) fi - PYTHONPATH=$PYTHONPATH:$(pwd) python3 "$PYTHON_SCRIPT_FILE" scale-machine \ + PYTHONPATH=$PYTHONPATH:$(pwd) python3 -m crud.main scale-machine \ --cloud "$CLOUD" \ --run-id "$RUN_ID" \ --node-pool-name "$POOL_NAME" \ @@ -33,7 +33,6 @@ steps: workingDirectory: modules/python displayName: "Execute Machine API CRUD" env: - PYTHON_SCRIPT_FILE: $(Pipeline.Workspace)/s/modules/python/crud/main.py CLOUD: ${{ parameters.cloud }} VM_SIZE: $(VM_SIZE) POOL_NAME: $(POOL_NAME)