From e5fd65aae93f24805bcb9f6ec8d7a913f11eeb1c Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 17 Jun 2018 00:09:36 +0800 Subject: [PATCH] teuthology-suite: add --seed option for repeatable random test currently --rerun does not match tests of 'supported-random-distro$/ubuntu_latest.yaml' with 'supported-random-distro$/centos_latest.yaml'. the former could be part of description of a failed test, the latter is a a part of job description generated by build_matrix(). because the '$' operator instructs theuthology to choose a random file under the directory ending with '$', and we expand the '$' to a randomly picked file *before* filtering the generated job list with the filter collected from the failed tests, there is good chance that the job descriptions of the failed jobs in self.args.filter_in cannot match with the randomly generated ones. so, we introduce an argument '--seed' for teuthology-suite for the repeatable random test. this argument allows user to specify a seed for tne RNG used by build_matrix(). Signed-off-by: Kefu Chai --- scripts/suite.py | 7 ++++++- teuthology/suite/__init__.py | 4 ++++ teuthology/suite/build_matrix.py | 5 ++++- teuthology/suite/run.py | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/scripts/suite.py b/scripts/suite.py index 89b1190204..60b70cf0e3 100644 --- a/scripts/suite.py +++ b/scripts/suite.py @@ -117,12 +117,17 @@ Scheduler arguments: the original run, the resulting one will only inherit the suite value. Any others must be passed as normal while scheduling with this - feature. + feature. For random tests involving facet whose + path ends with '$' operator, you might want to + use --seed argument to repeat them. -R, --rerun-statuses A comma-separated list of statuses to be used with --rerun. Supported statuses are: 'dead', 'fail', 'pass', 'queued', 'running', 'waiting' [default: fail,dead] + --seed SEED An random number mostly useful when used along + with --rerun argument. This number can be found + in the output of teuthology-suite command. """.format( default_machine_type=config.default_machine_type, diff --git a/teuthology/suite/__init__.py b/teuthology/suite/__init__.py index e89a4fc399..299f5e0747 100644 --- a/teuthology/suite/__init__.py +++ b/teuthology/suite/__init__.py @@ -4,6 +4,7 @@ import logging import os +import random import time import teuthology @@ -82,6 +83,9 @@ def main(args): return conf.filter_in.extend(rerun_filters['descriptions']) conf.suite = normalize_suite_name(rerun_filters['suite']) + if conf.seed is None: + conf.seed = random.randint(0, 9999) + log.info('Using random seed=%s', conf.seed) run = Run(conf) name = run.name diff --git a/teuthology/suite/build_matrix.py b/teuthology/suite/build_matrix.py index 196a31d4bd..e9692a8667 100644 --- a/teuthology/suite/build_matrix.py +++ b/teuthology/suite/build_matrix.py @@ -1,12 +1,13 @@ import logging import os +import random from . import matrix log = logging.getLogger(__name__) -def build_matrix(path, subset=None): +def build_matrix(path, subset=None, seed=None): """ Return a list of items descibed by path such that if the list of items is chunked into mincyclicity pieces, each piece is still a @@ -45,12 +46,14 @@ def build_matrix(path, subset=None): :param path: The path to search for yaml fragments :param subset: (index, outof) + :param seed: The seed for repeatable random test """ if subset: log.info( 'Subset=%s/%s' % (str(subset[0]), str(subset[1])) ) + random.seed(seed) mat, first, matlimit = _get_matrix(path, subset) return generate_combinations(path, mat, first, matlimit) diff --git a/teuthology/suite/run.py b/teuthology/suite/run.py index a56f43e8c1..1388fcbd26 100644 --- a/teuthology/suite/run.py +++ b/teuthology/suite/run.py @@ -470,7 +470,7 @@ class Run(object): log.debug('Suite %s in %s' % (suite_name, suite_path)) configs = [ (combine_path(suite_name, item[0]), item[1]) for item in - build_matrix(suite_path, subset=self.args.subset) + build_matrix(suite_path, subset=self.args.subset, seed=self.args.seed) ] log.info('Suite %s in %s generated %d jobs (not yet filtered)' % ( suite_name, suite_path, len(configs))) -- 2.39.5