|
| 1 | +""" |
| 2 | +Utility for re-running python tests under flux. |
| 3 | +
|
| 4 | +Copied from flux-core. |
| 5 | +""" |
| 6 | + |
| 7 | +############################################################### |
| 8 | +# Copyright 2014 Lawrence Livermore National Security, LLC |
| 9 | +# (c.f. AUTHORS, NOTICE.LLNS, COPYING) |
| 10 | +# |
| 11 | +# This file is part of the Flux resource manager framework. |
| 12 | +# For details, see https://github.com/flux-framework. |
| 13 | +# |
| 14 | +# SPDX-License-Identifier: LGPL-3.0 |
| 15 | +############################################################### |
| 16 | + |
| 17 | +import argparse |
| 18 | +import os |
| 19 | +import subprocess |
| 20 | +import sys |
| 21 | +import shutil |
| 22 | + |
| 23 | + |
| 24 | +# Ignore -v, --verbose and --root options so that python test scripts |
| 25 | +# can absorb the same options as sharness tests. Later, something could |
| 26 | +# be done with these options, but for now they are dropped silently. |
| 27 | +parser = argparse.ArgumentParser() |
| 28 | +parser.add_argument("--debug", "-d", action="store_true") |
| 29 | +parser.add_argument("--root", metavar="PATH", type=str) |
| 30 | +args, remainder = parser.parse_known_args() |
| 31 | + |
| 32 | +sys.argv[1:] = remainder |
| 33 | + |
| 34 | + |
| 35 | +def rerun_under_flux(size=1): |
| 36 | + try: |
| 37 | + if os.environ["IN_SUBFLUX"] == "1": |
| 38 | + return True |
| 39 | + except KeyError: |
| 40 | + pass |
| 41 | + |
| 42 | + child_env = dict(**os.environ) |
| 43 | + child_env["IN_SUBFLUX"] = "1" |
| 44 | + |
| 45 | + # ported from sharness.d/flux-sharness.sh |
| 46 | + command = [shutil.which("flux"), "start", "--test-size", str(size)] |
| 47 | + |
| 48 | + command.extend([sys.executable, sys.argv[0]]) |
| 49 | + |
| 50 | + p = subprocess.Popen( |
| 51 | + command, env=child_env, bufsize=-1, stdout=sys.stdout, stderr=sys.stderr |
| 52 | + ) |
| 53 | + p.wait() |
| 54 | + if p.returncode > 0: |
| 55 | + sys.exit(p.returncode) |
| 56 | + elif p.returncode < 0: |
| 57 | + sys.exit(128 + -p.returncode) |
| 58 | + return False |
0 commit comments