]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Use both $ and directory$ for random files.
authorWarren Usui <wusui@redhat.com>
Tue, 10 Apr 2018 21:33:23 +0000 (21:33 +0000)
committerWarren Usui <wusui@redhat.com>
Tue, 10 Apr 2018 21:33:23 +0000 (21:33 +0000)
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 <wusui@redhat.com>
teuthology/suite/build_matrix.py
teuthology/suite/test/test_build_matrix.py

index 7010fb6cbd8cb4e4e22a7ec4f2eef856119ce5eb..196a31d4bd58512c767244485eea7c28dd2e88bf 100644 (file)
@@ -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 = []
index 28728a984e927685eb716926e8c6eb69ea6010ec..97784fcc3d1ca08db787311c52daa79738977672 100644 (file)
@@ -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 = {