From 1fdf9f30c0b7449d1ffa16b4e3d75ab10c6f001c Mon Sep 17 00:00:00 2001 From: Fabrizio Waldner Date: Fri, 10 Jul 2026 16:46:31 +0200 Subject: [PATCH 1/3] Run Slurm script unit tests in CI --- .github/workflows/one_job.yml | 15 +++++++++++++++ Makefile | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/.github/workflows/one_job.yml b/.github/workflows/one_job.yml index 6d95076cb..5557c050d 100644 --- a/.github/workflows/one_job.yml +++ b/.github/workflows/one_job.yml @@ -204,6 +204,20 @@ jobs: fi go build "${packages[@]}" + test-slurm-scripts: + needs: [changes, authorize] + if: needs.changes.outputs.should_build == 'true' + runs-on: ubuntu-24.04 + + steps: + - name: Checkout repository + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Test Slurm scripts + run: make test-slurm-scripts + build-soperator-images: needs: - changes @@ -846,6 +860,7 @@ jobs: - pre-build - lint - build-e2e + - test-slurm-scripts - build-slurm-images - build-soperator-images - manifest-populate-jail diff --git a/Makefile b/Makefile index e5d6f5044..c891f8e96 100644 --- a/Makefile +++ b/Makefile @@ -119,6 +119,17 @@ vet: ## Run go vet against code. test: manifests generate fmt vet envtest ## Run tests. go test ./... +.PHONY: test-slurm-scripts +test-slurm-scripts: ## Run Python unit tests for Slurm scripts. + @if find helm/slurm-cluster/slurm_scripts -type f -name '*_test.py' -print -quit | grep -q .; then \ + python3 -m unittest discover \ + -s helm/slurm-cluster/slurm_scripts \ + -p '*_test.py' \ + -v; \ + else \ + echo "No Slurm script unit tests found; skipping."; \ + fi + .PHONY: test-coverage test-coverage: manifests generate fmt vet envtest ## Run tests and generate test coverage. go test ./... -coverprofile cover.out From 86e90776f2e71287d890f78208e8734db0b25e6c Mon Sep 17 00:00:00 2001 From: Fabrizio Waldner Date: Wed, 15 Jul 2026 14:29:18 +0200 Subject: [PATCH 2/3] Run worker script unit tests in CI --- Makefile | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index c891f8e96..06e176d12 100644 --- a/Makefile +++ b/Makefile @@ -121,12 +121,18 @@ test: manifests generate fmt vet envtest ## Run tests. .PHONY: test-slurm-scripts test-slurm-scripts: ## Run Python unit tests for Slurm scripts. - @if find helm/slurm-cluster/slurm_scripts -type f -name '*_test.py' -print -quit | grep -q .; then \ - python3 -m unittest discover \ - -s helm/slurm-cluster/slurm_scripts \ - -p '*_test.py' \ - -v; \ - else \ + @found=false; \ + for test_dir in helm/slurm-cluster/slurm_scripts images/worker; do \ + if find "$$test_dir" -type f -name '*_test.py' -print -quit | grep -q .; then \ + found=true; \ + echo "Running Python unit tests in $$test_dir"; \ + python3 -m unittest discover \ + -s "$$test_dir" \ + -p '*_test.py' \ + -v || exit $$?; \ + fi; \ + done; \ + if [ "$$found" = false ]; then \ echo "No Slurm script unit tests found; skipping."; \ fi From 55c2dd07126e72eb4cac02f68b74759838aafda7 Mon Sep 17 00:00:00 2001 From: Fabrizio Waldner Date: Thu, 16 Jul 2026 14:42:22 +0200 Subject: [PATCH 3/3] Make it general --- .github/workflows/one_job.yml | 8 ++++---- Makefile | 33 ++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/.github/workflows/one_job.yml b/.github/workflows/one_job.yml index 5557c050d..d6062c552 100644 --- a/.github/workflows/one_job.yml +++ b/.github/workflows/one_job.yml @@ -204,7 +204,7 @@ jobs: fi go build "${packages[@]}" - test-slurm-scripts: + test-python: needs: [changes, authorize] if: needs.changes.outputs.should_build == 'true' runs-on: ubuntu-24.04 @@ -215,8 +215,8 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - - name: Test Slurm scripts - run: make test-slurm-scripts + - name: Test Python + run: make test-python build-soperator-images: needs: @@ -860,7 +860,7 @@ jobs: - pre-build - lint - build-e2e - - test-slurm-scripts + - test-python - build-slurm-images - build-soperator-images - manifest-populate-jail diff --git a/Makefile b/Makefile index 06e176d12..900079306 100644 --- a/Makefile +++ b/Makefile @@ -119,21 +119,28 @@ vet: ## Run go vet against code. test: manifests generate fmt vet envtest ## Run tests. go test ./... -.PHONY: test-slurm-scripts -test-slurm-scripts: ## Run Python unit tests for Slurm scripts. +.PHONY: test-python +test-python: ## Run all Python unit tests. @found=false; \ - for test_dir in helm/slurm-cluster/slurm_scripts images/worker; do \ - if find "$$test_dir" -type f -name '*_test.py' -print -quit | grep -q .; then \ - found=true; \ - echo "Running Python unit tests in $$test_dir"; \ - python3 -m unittest discover \ - -s "$$test_dir" \ - -p '*_test.py' \ - -v || exit $$?; \ - fi; \ - done; \ + while IFS= read -r -d '' test_file; do \ + found=true; \ + test_dir=$$(dirname "$$test_file"); \ + test_pattern=$$(basename "$$test_file"); \ + echo "Running Python unit tests in $$test_file"; \ + PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover \ + -s "$$test_dir" \ + -p "$$test_pattern" \ + -v; \ + done < <(find . \ + -type d \( \ + -name .git -o \ + -name .venv -o \ + -name venv -o \ + -name __pycache__ \ + \) -prune -o \ + -type f \( -name '*_test.py' -o -name 'test_*.py' \) -print0); \ if [ "$$found" = false ]; then \ - echo "No Slurm script unit tests found; skipping."; \ + echo "No Python unit tests found; skipping."; \ fi .PHONY: test-coverage