]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Implement $ option to randomly choose yamls.
authorWarren Usui <wusui@redhat.com>
Tue, 20 Mar 2018 01:15:42 +0000 (01:15 +0000)
committerWarren Usui <wusui@redhat.com>
Tue, 20 Mar 2018 01:36:04 +0000 (01:36 +0000)
This implements tracker #23208

Signed-off-by: Warren Usui <wusui@redhat.com>
teuthology/suite/build_matrix.py
teuthology/suite/matrix.py

index a2fe2ba3812fbae791ac2c8e8a1834f1fa2c0a06..7010fb6cbd8cb4e4e22a7ec4f2eef856119ce5eb 100644 (file)
@@ -34,6 +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.
+
     The final description (after recursion) for each item will look
     like a relative path.  If there was a % product, that path
     component will appear as a file with braces listing the selection
@@ -112,6 +115,18 @@ 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 956425d6790d56a124892f9a0159a2011039650b..5141f995025849c880a5929711760c11b78c9fbc 100644 (file)
@@ -1,4 +1,5 @@
 import os
+import random
 import heapq
 from fractions import gcd
 
@@ -197,6 +198,30 @@ class Concat(Matrix):
         ret = '\t'*depth + "Concat({item}):\n".format(item=self.item)
         return ret + ''.join([i[1].tostr(depth+1) for i in self.submats])
 
+class PickRandom(Matrix):
+    """
+    Select a random item from the child matrices.
+    """
+    def __init__(self, item, submats):
+        self.submats = submats
+        self.item = item
+
+    def size(self):
+        return 1
+
+    def minscanlen(self):
+        return 1
+
+    def index(self, i):
+        indx = random.randint(0, len(self.submats) - 1)
+        submat = self.submats[indx]
+        out = frozenset([submat.index(indx)])
+        return (self.item, out)
+
+    def tostr(self, depth):
+        ret = '\t'*depth + "PickRandom({item}):\n".format(item=self.item)
+        return ret + ''.join([i[1].tostr(depth+1) for i in self.submats])
+
 class Sum(Matrix):
     """
     We want to mix the subsequences proportionately to their size.