|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) Facebook, Inc. and its affiliates. |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# This source code is licensed under the BSD-style license found in the |
| 6 | +# LICENSE file in the root directory of this source tree. |
| 7 | + |
| 8 | +""" |
| 9 | +Kubernetes integration tests. |
| 10 | +""" |
| 11 | +import argparse |
| 12 | +import os |
| 13 | + |
| 14 | +# pyre-ignore-all-errors[21] # Cannot find module utils |
| 15 | +# pyre-ignore-all-errors[11] |
| 16 | + |
| 17 | +import example_app_defs as examples_app_defs_providers |
| 18 | +import torchx.components.integration_tests.component_provider as component_provider |
| 19 | +from integ_test_utils import ( |
| 20 | + MissingEnvError, |
| 21 | + build_images, |
| 22 | + push_images, |
| 23 | + BuildInfo, |
| 24 | +) |
| 25 | +from torchx.components.integration_tests.integ_tests import ( |
| 26 | + IntegComponentTest, |
| 27 | + SchedulerInfo, |
| 28 | +) |
| 29 | +from torchx.specs import RunConfig |
| 30 | + |
| 31 | + |
| 32 | +def build_and_push_image() -> BuildInfo: |
| 33 | + build = build_images() |
| 34 | + push_images(build) |
| 35 | + return build |
| 36 | + |
| 37 | + |
| 38 | +def get_k8s_sched_info(image: str) -> SchedulerInfo: |
| 39 | + cfg = RunConfig() |
| 40 | + cfg.set("namespace", "torchx-dev") |
| 41 | + cfg.set("queue", "default") |
| 42 | + return SchedulerInfo(name="kubernetes", image=image, runconfig=cfg) |
| 43 | + |
| 44 | + |
| 45 | +def get_local_cwd_sched_info(image: str) -> SchedulerInfo: |
| 46 | + return SchedulerInfo(name="local_cwd", image=image, runconfig=RunConfig()) |
| 47 | + |
| 48 | + |
| 49 | +def get_local_docker_sched_info(image: str) -> SchedulerInfo: |
| 50 | + return SchedulerInfo(name="local_docker", image=image, runconfig=RunConfig()) |
| 51 | + |
| 52 | + |
| 53 | +def main() -> None: |
| 54 | + parser = argparse.ArgumentParser(description="kubernetes integration test runner") |
| 55 | + parser.add_argument( |
| 56 | + "--dryrun", |
| 57 | + action="store_true", |
| 58 | + help="Does not actually submit the app," " just prints the scheduler request", |
| 59 | + ) |
| 60 | + args = parser.parse_args() |
| 61 | + print("Starting components integration tests") |
| 62 | + torchx_image = "dummy_image" |
| 63 | + examples_image = "dummy_image" |
| 64 | + try: |
| 65 | + build = build_and_push_image() |
| 66 | + torchx_image = build.torchx_image |
| 67 | + examples_image = build.examples_image |
| 68 | + except MissingEnvError: |
| 69 | + print("Skip runnig tests, executed only docker buid step") |
| 70 | + test_suite = IntegComponentTest(timeout=900) # 15 minutes |
| 71 | + test_suite.run_components( |
| 72 | + component_provider, |
| 73 | + scheduler_infos=[ |
| 74 | + get_local_cwd_sched_info(os.getcwd()), |
| 75 | + get_local_docker_sched_info(torchx_image), |
| 76 | + get_k8s_sched_info(torchx_image), |
| 77 | + ], |
| 78 | + dryrun=args.dryrun, |
| 79 | + ) |
| 80 | + |
| 81 | + test_suite.run_components( |
| 82 | + examples_app_defs_providers, |
| 83 | + scheduler_infos=[ |
| 84 | + get_local_docker_sched_info(examples_image), |
| 85 | + get_k8s_sched_info(examples_image), |
| 86 | + ], |
| 87 | + dryrun=args.dryrun, |
| 88 | + ) |
| 89 | + |
| 90 | + |
| 91 | +if __name__ == "__main__": |
| 92 | + main() |
0 commit comments