|
3 | 3 |
|
4 | 4 | import dataclasses
|
5 | 5 | import enum
|
| 6 | +import shlex |
6 | 7 | import shutil
|
7 |
| -import unittest |
| 8 | +import subprocess |
| 9 | +import sys |
| 10 | +import typing |
8 | 11 | from pathlib import Path
|
9 | 12 |
|
| 13 | +import pytest |
| 14 | + |
| 15 | +if typing.TYPE_CHECKING: |
| 16 | + from collections.abc import Generator, Iterable |
| 17 | + |
| 18 | +ROOT_DIR = Path(__file__).parent.parent |
| 19 | + |
10 | 20 | JUPYTER_MINIMAL_NOTEBOOK_ID = "minimal"
|
11 | 21 | JUPYTER_DATASCIENCE_NOTEBOOK_ID = "datascience"
|
12 | 22 | JUPYTER_TRUSTYAI_NOTEBOOK_ID = "trustyai"
|
@@ -192,7 +202,7 @@ def get_source_of_truth_filepath(
|
192 | 202 | return filepath
|
193 | 203 |
|
194 | 204 |
|
195 |
| -class SelfTests(unittest.TestCase): |
| 205 | +class TestManifests: |
196 | 206 | def test_rstudio_path(self):
|
197 | 207 | metadata = extract_metadata_from_path(Path("notebooks/rstudio/rhel9-python-3.11"))
|
198 | 208 | assert metadata == NotebookMetadata(
|
@@ -261,3 +271,96 @@ def test_source_of_truth_jupyter_tensorflow_rocm(self):
|
261 | 271 | metadata = extract_metadata_from_path(Path("notebooks/jupyter/rocm/tensorflow/ubi9-python-3.12"))
|
262 | 272 | path = get_source_of_truth_filepath(root_repo_directory=Path("notebooks"), metadata=metadata)
|
263 | 273 | assert path == Path("notebooks/manifests/base/jupyter-rocm-tensorflow-notebook-imagestream.yaml")
|
| 274 | + |
| 275 | + def run_shell_function( |
| 276 | + self, |
| 277 | + shell_script_path: Path, |
| 278 | + shell_function_name: str, |
| 279 | + args: Iterable[str] = (), |
| 280 | + env: dict[str, str] | None = None, |
| 281 | + ) -> str: |
| 282 | + env = env or {} |
| 283 | + shell_notebook_id = subprocess.run( |
| 284 | + f"""source {shell_script_path} && {shell_function_name} {" ".join(shlex.quote(arg) for arg in args)}""", |
| 285 | + shell=True, |
| 286 | + executable="/bin/bash", |
| 287 | + env=env, |
| 288 | + stdout=subprocess.PIPE, |
| 289 | + text=True, |
| 290 | + check=True, |
| 291 | + ) |
| 292 | + return shell_notebook_id.stdout.rstrip() |
| 293 | + |
| 294 | + @staticmethod |
| 295 | + def get_targets() -> Generator[tuple[str, Path], None, None]: |
| 296 | + # TODO(jdanek): should systematize import paths to avoid this hack |
| 297 | + sys.path.insert(0, str(ROOT_DIR / "ci/cached-builds")) |
| 298 | + from ci.cached_builds import gen_gha_matrix_jobs # noqa: PLC0415 |
| 299 | + |
| 300 | + python_311 = gen_gha_matrix_jobs.extract_image_targets(ROOT_DIR, env={"RELEASE_PYTHON_VERSION": "3.11"}) |
| 301 | + python_312 = gen_gha_matrix_jobs.extract_image_targets(ROOT_DIR, env={"RELEASE_PYTHON_VERSION": "3.12"}) |
| 302 | + targets = python_311 + python_312 |
| 303 | + expected_manifest_paths = { |
| 304 | + "jupyter-minimal-ubi9-python-3.12": ROOT_DIR / "manifests/base/jupyter-minimal-notebook-imagestream.yaml", |
| 305 | + "runtime-minimal-ubi9-python-3.12": ROOT_DIR / "manifests/base/jupyter-minimal-notebook-imagestream.yaml", |
| 306 | + # no -gpu-? |
| 307 | + "cuda-jupyter-minimal-ubi9-python-3.12": ROOT_DIR |
| 308 | + / "manifests/base/jupyter-minimal-notebook-imagestream.yaml", |
| 309 | + "rocm-jupyter-minimal-ubi9-python-3.12": ROOT_DIR |
| 310 | + / "manifests/base/jupyter-minimal-notebook-imagestream.yaml", |
| 311 | + "jupyter-datascience-ubi9-python-3.12": ROOT_DIR |
| 312 | + / "manifests/base/jupyter-datascience-notebook-imagestream.yaml", |
| 313 | + "runtime-datascience-ubi9-python-3.12": ROOT_DIR |
| 314 | + / "manifests/base/jupyter-datascience-notebook-imagestream.yaml", |
| 315 | + "cuda-jupyter-pytorch-ubi9-python-3.12": ROOT_DIR |
| 316 | + / "manifests/base/jupyter-pytorch-notebook-imagestream.yaml", |
| 317 | + "runtime-cuda-pytorch-ubi9-python-3.12": ROOT_DIR |
| 318 | + / "manifests/base/jupyter-pytorch-notebook-imagestream.yaml", |
| 319 | + "rocm-jupyter-pytorch-ubi9-python-3.12": ROOT_DIR |
| 320 | + / "manifests/base/jupyter-pytorch-notebook-imagestream.yaml", |
| 321 | + "rocm-runtime-pytorch-ubi9-python-3.12": ROOT_DIR |
| 322 | + / "manifests/base/jupyter-pytorch-notebook-imagestream.yaml", |
| 323 | + "cuda-jupyter-pytorch-llmcompressor-ubi9-python-3.12": ROOT_DIR |
| 324 | + / "manifests/base/jupyter-pytorch-notebook-imagestream.yaml", |
| 325 | + "runtime-cuda-pytorch-llmcompressor-ubi9-python-3.12": ROOT_DIR |
| 326 | + / "manifests/base/jupyter-pytorch-notebook-imagestream.yaml", |
| 327 | + "cuda-jupyter-tensorflow-ubi9-python-3.12": ROOT_DIR |
| 328 | + / "manifests/base/jupyter-tensorflow-notebook-imagestream.yaml", |
| 329 | + "runtime-cuda-tensorflow-ubi9-python-3.12": ROOT_DIR |
| 330 | + / "manifests/base/jupyter-tensorflow-notebook-imagestream.yaml", |
| 331 | + "rocm-jupyter-tensorflow-ubi9-python-3.12": ROOT_DIR |
| 332 | + / "manifests/base/jupyter-tensorflow-notebook-imagestream.yaml", |
| 333 | + "rocm-runtime-tensorflow-ubi9-python-3.12": ROOT_DIR |
| 334 | + / "manifests/base/jupyter-tensorflow-notebook-imagestream.yaml", |
| 335 | + "jupyter-trustyai-ubi9-python-3.12": ROOT_DIR / "manifests/base/jupyter-trustyai-notebook-imagestream.yaml", |
| 336 | + "codeserver-ubi9-python-3.12": ROOT_DIR / "manifests/base/code-server-notebook-imagestream.yaml", |
| 337 | + "rstudio-ubi9-python-3.11": ROOT_DIR / "manifests/base/rstudio-buildconfig.yaml", |
| 338 | + "rstudio-c9s-python-3.11": ROOT_DIR / "manifests/base/rstudio-buildconfig.yaml", |
| 339 | + "cuda-rstudio-c9s-python-3.11": ROOT_DIR / "manifests/base/cuda-rstudio-buildconfig.yaml", |
| 340 | + "rstudio-rhel9-python-3.11": ROOT_DIR / "manifests/base/rstudio-buildconfig.yaml", |
| 341 | + "cuda-rstudio-rhel9-python-3.11": ROOT_DIR / "manifests/base/cuda-rstudio-buildconfig.yaml", |
| 342 | + } |
| 343 | + for target in targets: |
| 344 | + if "codeserver" in target: |
| 345 | + continue |
| 346 | + if "rstudio" in target: |
| 347 | + continue |
| 348 | + yield target, expected_manifest_paths[target] |
| 349 | + |
| 350 | + @pytest.mark.parametrize("target,expected_manifest_path", get_targets()) |
| 351 | + def test_compare_with_shell_implementation(self, target: str, expected_manifest_path: Path): |
| 352 | + shell_script_path = ROOT_DIR / "scripts/test_jupyter_with_papermill.sh" |
| 353 | + |
| 354 | + notebook_id = self.run_shell_function( |
| 355 | + shell_script_path, |
| 356 | + "_get_notebook_id", |
| 357 | + env={"notebook_workload_name": target}, |
| 358 | + ) |
| 359 | + assert notebook_id |
| 360 | + |
| 361 | + source_of_truth_filepath = self.run_shell_function( |
| 362 | + shell_script_path, |
| 363 | + "_get_source_of_truth_filepath", |
| 364 | + [notebook_id], |
| 365 | + ) |
| 366 | + assert source_of_truth_filepath == str(expected_manifest_path) |
0 commit comments