From e77d436db95345b19b93e59dc6d68745d6c03f2b Mon Sep 17 00:00:00 2001 From: Warren Usui Date: Wed, 11 Apr 2018 00:48:55 +0000 Subject: [PATCH] Allow both $ and directory$ for random yamls. If either the diretory contains a magic $ file, or if the directory name ends with $, then the random selection of a yaml file will occur. Signed-off-by: Warren Usui --- teuthology/suite/build_matrix.py | 32 +++++---- teuthology/suite/test/test_build_matrix.py | 84 +++++++++++++++++++--- 2 files changed, 93 insertions(+), 23 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..742f33b54d 100644 --- a/teuthology/suite/test/test_build_matrix.py +++ b/teuthology/suite/test/test_build_matrix.py @@ -193,9 +193,30 @@ class TestBuildMatrix(object): }, }, } + 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, + }, + }, + } self.start_patchers(fake_fs) result = build_matrix.build_matrix('d0_0') assert len(result) == 1 + self.stop_patchers() + self.start_patchers(fake_fs1) + result = build_matrix.build_matrix('d0_0$') + assert len(result) == 1 def test_random_dollar_sign_with_concat(self): fake_fs = { @@ -217,15 +238,38 @@ 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] + if dval == 'd0_0': + self.stop_patchers() def test_random_dollar_sign_with_convolve(self): fake_fs = { @@ -250,6 +294,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, + }, + }, + } + self.stop_patchers() + self.start_patchers(fake_fs1) + result = build_matrix.build_matrix('d0_0') + assert len(result) == 4 def test_emulate_teuthology_noceph(self): fake_fs = { -- 2.39.5