From 3fbb31cfdf8dd7bd324ca6a4a83ce72adb1d0e76 Mon Sep 17 00:00:00 2001 From: Warren Usui Date: Tue, 10 Apr 2018 21:33:23 +0000 Subject: [PATCH] Use both $ and directory$ for random files. The ability to select one random yaml from a directory can be accomplished by adding a $ file to the diretory or by ending the name of the directory or symlink with a $. Signed-off-by: Warren Usui --- teuthology/suite/build_matrix.py | 32 ++++---- teuthology/suite/test/test_build_matrix.py | 90 ++++++++++++++++++---- 2 files changed, 93 insertions(+), 29 deletions(-) diff --git a/teuthology/suite/build_matrix.py b/teuthology/suite/build_matrix.py index 7010fb6cbd..196a31d4bd 100644 --- a/teuthology/suite/build_matrix.py +++ b/teuthology/suite/build_matrix.py @@ -34,8 +34,9 @@ def build_matrix(path, subset=None): for each item in the directory, and then do a product to generate a result list with all combinations (A Product). - For a directory with a magic '$' file, we generate a list of all - items that we will randomly choose from. + For a directory with a magic '$' file, or for a directory whose name + ends in '$', we generate a list of all items that we will randomly + choose from. The final description (after recursion) for each item will look like a relative path. If there was a % product, that path @@ -98,6 +99,21 @@ def _build_matrix(path, mincyclicity=0, item=''): if submat is not None: submats.append(submat) return matrix.Concat(item, submats) + elif path.endswith('$') or '$' in files: + # pick a random item -- make sure we don't pick any magic files + if '$' in files: + files.remove('$') + if '%' in files: + files.remove('%') + submats = [] + for fn in sorted(files): + submat = _build_matrix( + os.path.join(path, fn), + mincyclicity, + fn) + if submat is not None: + submats.append(submat) + return matrix.PickRandom(item, submats) elif '%' in files: # convolve items files.remove('%') @@ -115,18 +131,6 @@ def _build_matrix(path, mincyclicity=0, item=''): (mincyclicity + mat.cyclicity() - 1) / mat.cyclicity(), mat ) return mat - elif '$' in files: - # pick a random item - files.remove('$') - submats = [] - for fn in sorted(files): - submat = _build_matrix( - os.path.join(path, fn), - mincyclicity, - fn) - if submat is not None: - submats.append(submat) - return matrix.PickRandom(item, submats) else: # list items submats = [] diff --git a/teuthology/suite/test/test_build_matrix.py b/teuthology/suite/test/test_build_matrix.py index 28728a984e..97784fcc3d 100644 --- a/teuthology/suite/test/test_build_matrix.py +++ b/teuthology/suite/test/test_build_matrix.py @@ -193,9 +193,29 @@ class TestBuildMatrix(object): }, }, } - self.start_patchers(fake_fs) - result = build_matrix.build_matrix('d0_0') - assert len(result) == 1 + fake_fs1 = { + 'd0_0$': { + 'd1_0': { + 'd1_0_0.yaml': None, + 'd1_0_1.yaml': None, + }, + 'd1_1': { + 'd1_1_0.yaml': None, + 'd1_1_1.yaml': None, + }, + 'd1_2': { + 'd1_2_0.yaml': None, + 'd1_2_1.yaml': None, + 'd1_2_2.yaml': None, + }, + }, + } + for info in [(fake_fs,'d0_0'), (fake_fs1,'d0_0$')]: + fsv = info[0] + dval = info[1] + self.start_patchers(fsv) + result = build_matrix.build_matrix(dval) + assert len(result) == 1 def test_random_dollar_sign_with_concat(self): fake_fs = { @@ -217,15 +237,36 @@ class TestBuildMatrix(object): }, }, } - self.start_patchers(fake_fs) - result = build_matrix.build_matrix('d0_0') - assert len(result) == 1 - if result[0][0][1:].startswith('d1_2'): - for i in result: - assert 'd0_0/d1_2/d1_2_0.yaml' in i[1] - assert 'd0_0/d1_2/d1_2_1.yaml' in i[1] - assert 'd0_0/d1_2/d1_2_2.yaml' in i[1] - assert 'd0_0/d1_2/d1_2_3.yaml' in i[1] + fake_fs1 = { + 'd0_0$': { + 'd1_0': { + 'd1_0_0.yaml': None, + }, + 'd1_1': { + 'd1_1_0.yaml': None, + 'd1_1_1.yaml': None, + }, + 'd1_2': { + '+': None, + 'd1_2_0.yaml': None, + 'd1_2_1.yaml': None, + 'd1_2_2.yaml': None, + 'd1_2_3.yaml': None, + }, + }, + } + for info in [(fake_fs,'d0_0'), (fake_fs1,'d0_0$')]: + fsv = info[0] + dval = info[1] + self.start_patchers(fsv) + result = build_matrix.build_matrix(dval) + assert len(result) == 1 + if result[0][0][1:].startswith('d1_2'): + for i in result: + assert 'd0_0/d1_2/d1_2_0.yaml' in i[1] + assert 'd0_0/d1_2/d1_2_1.yaml' in i[1] + assert 'd0_0/d1_2/d1_2_2.yaml' in i[1] + assert 'd0_0/d1_2/d1_2_3.yaml' in i[1] def test_random_dollar_sign_with_convolve(self): fake_fs = { @@ -247,9 +288,28 @@ class TestBuildMatrix(object): }, }, } - self.start_patchers(fake_fs) - result = build_matrix.build_matrix('d0_0') - assert len(result) == 4 + fake_fs1 = { + 'd0_0': { + '%': None, + 'd1_0': { + 'd1_0_0.yaml': None, + 'd1_0_1.yaml': None, + }, + 'd1_1': { + 'd1_1_0.yaml': None, + 'd1_1_1.yaml': None, + }, + 'd1_2$': { + 'd1_2_0.yaml': None, + 'd1_2_1.yaml': None, + 'd1_2_2.yaml': None, + }, + }, + } + for fsv in [fake_fs, fake_fs1]: + self.start_patchers(fsv) + result = build_matrix.build_matrix('d0_0') + assert len(result) == 4 def test_emulate_teuthology_noceph(self): fake_fs = { -- 2.39.5