From 108ef5856fb2d84efa48ea3f163d41d7a805e960 Mon Sep 17 00:00:00 2001 From: Andrei Chekun Date: Wed, 30 Oct 2024 10:45:28 +0100 Subject: [PATCH] test.py: Move get configured modes to common lib This will allow using this method inside the test module for pytest launching the boost and unit tests --- test.py | 17 ++--------------- test/pylib/util.py | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/test.py b/test.py index 177d5ed381..4c29ebd5aa 100755 --- a/test.py +++ b/test.py @@ -42,7 +42,7 @@ from test.pylib.pool import Pool from test.pylib.s3_proxy import S3ProxyServer from test.pylib.s3_server_mock import MockS3Server from test.pylib.resource_gather import setup_cgroup, run_resource_watcher, get_resource_gather -from test.pylib.util import LogPrefixAdapter +from test.pylib.util import LogPrefixAdapter, get_configured_modes, ninja from test.pylib.scylla_cluster import ScyllaServer, ScyllaCluster, get_cluster_manager, merge_cmdline_options from test.pylib.minio_server import MinioServer from typing import Dict, List, Callable, Any, Iterable, Optional, Awaitable, Union @@ -167,15 +167,6 @@ def path_to(mode, *components): return os.path.join(build_dir, mode, *components) -def ninja(target): - """Build specified target using ninja""" - build_dir = 'build' - args = ['ninja', target] - if os.path.exists(os.path.join(build_dir, 'build.ninja')): - args = ['ninja', '-C', build_dir, target] - return subprocess.Popen(args, stdout=subprocess.PIPE).communicate()[0].decode() - - class TestSuite(ABC): """A test suite is a folder with tests of the same type. E.g. it can be unit tests, boost tests, or CQL tests.""" @@ -1786,11 +1777,7 @@ def parse_cmd_line() -> argparse.Namespace: if not args.modes: try: - out = ninja('mode_list') - # [1/1] List configured modes - # debug release dev - args.modes = re.sub(r'.* List configured modes\n(.*)\n', r'\1', - out, count=1, flags=re.DOTALL).split("\n")[-1].split(' ') + args.modes = get_configured_modes() except Exception: print(palette.fail("Failed to read output of `ninja mode_list`: please run ./configure.py first")) raise diff --git a/test/pylib/util.py b/test/pylib/util.py index ae39f4395f..61191d1b3f 100644 --- a/test/pylib/util.py +++ b/test/pylib/util.py @@ -3,6 +3,8 @@ # # SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0 # +import re +import subprocess from collections.abc import Coroutine import threading import time @@ -10,7 +12,8 @@ import asyncio import logging import pathlib import os -import pytest +from functools import cache + import random import string @@ -255,3 +258,21 @@ async def wait_for_first_completed(coros: list[Coroutine]): t.cancel() for t in done: await t + + +def ninja(target): + """Build specified target using ninja""" + build_dir = 'build' + args = ['ninja', target] + if os.path.exists(os.path.join(build_dir, 'build.ninja')): + args = ['ninja', '-C', build_dir, target] + return subprocess.Popen(args, stdout=subprocess.PIPE).communicate()[0].decode() + + +@cache +def get_configured_modes(): + out = ninja('mode_list') + # [1/1] List configured modes + # debug release dev + return re.sub(r'.* List configured modes\n(.*)\n', r'\1', + out, count=1, flags=re.DOTALL).split('\n')[-1].split(' ')