]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/tasks/workunit: factor out overrides and refspec logic
authorIlya Dryomov <idryomov@gmail.com>
Thu, 6 Sep 2018 14:53:25 +0000 (16:53 +0200)
committerJason Dillaman <dillaman@redhat.com>
Tue, 16 Oct 2018 17:45:09 +0000 (13:45 -0400)
Allow for reuse in the cram task.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit e1c89b51c80407fadbfee82d5d396cfcbd791aae)

qa/tasks/util/workunit.py [new file with mode: 0644]
qa/tasks/workunit.py

diff --git a/qa/tasks/util/workunit.py b/qa/tasks/util/workunit.py
new file mode 100644 (file)
index 0000000..16d0721
--- /dev/null
@@ -0,0 +1,77 @@
+import copy
+
+from teuthology import misc
+from teuthology.orchestra import run
+
+class Refspec:
+    def __init__(self, refspec):
+        self.refspec = refspec
+
+    def __str__(self):
+        return self.refspec
+
+    def _clone(self, git_url, clonedir, opts=None):
+        if opts is None:
+            opts = []
+        return (['rm', '-rf', clonedir] +
+                [run.Raw('&&')] +
+                ['git', 'clone'] + opts +
+                [git_url, clonedir])
+
+    def _cd(self, clonedir):
+        return ['cd', clonedir]
+
+    def _checkout(self):
+        return ['git', 'checkout', self.refspec]
+
+    def clone(self, git_url, clonedir):
+        return (self._clone(git_url, clonedir) +
+                [run.Raw('&&')] +
+                self._cd(clonedir) +
+                [run.Raw('&&')] +
+                self._checkout())
+
+
+class Branch(Refspec):
+    def __init__(self, tag):
+        Refspec.__init__(self, tag)
+
+    def clone(self, git_url, clonedir):
+        opts = ['--depth', '1',
+                '--branch', self.refspec]
+        return (self._clone(git_url, clonedir, opts) +
+                [run.Raw('&&')] +
+                self._cd(clonedir))
+
+
+class Head(Refspec):
+    def __init__(self):
+        Refspec.__init__(self, 'HEAD')
+
+    def clone(self, git_url, clonedir):
+        opts = ['--depth', '1']
+        return (self._clone(git_url, clonedir, opts) +
+                [run.Raw('&&')] +
+                self._cd(clonedir))
+
+
+def get_refspec_after_overrides(config, overrides):
+    # mimic the behavior of the "install" task, where the "overrides" are
+    # actually the defaults of that task. in other words, if none of "sha1",
+    # "tag", or "branch" is specified by a "workunit" tasks, we will update
+    # it with the information in the "workunit" sub-task nested in "overrides".
+    overrides = copy.deepcopy(overrides.get('workunit', {}))
+    refspecs = {'branch': Branch, 'tag': Refspec, 'sha1': Refspec}
+    if any(map(lambda i: i in config, refspecs.iterkeys())):
+        for i in refspecs.iterkeys():
+            overrides.pop(i, None)
+    misc.deep_merge(config, overrides)
+
+    for spec, cls in refspecs.iteritems():
+        refspec = config.get(spec)
+        if refspec:
+            refspec = cls(refspec)
+            break
+    if refspec is None:
+        refspec = Head()
+    return refspec
index c792ca606be647be65c3f7550098e358b8cdc13d..0a46ade76ab3e503b61330973f44a2152fc8bc66 100644 (file)
@@ -6,8 +6,8 @@ import pipes
 import os
 import re
 
-from copy import deepcopy
 from util import get_remote_for_role
+from util.workunit import get_refspec_after_overrides
 
 from teuthology import misc
 from teuthology.config import config as teuth_config
@@ -17,59 +17,6 @@ from teuthology.orchestra import run
 
 log = logging.getLogger(__name__)
 
-
-class Refspec:
-    def __init__(self, refspec):
-        self.refspec = refspec
-
-    def __str__(self):
-        return self.refspec
-
-    def _clone(self, git_url, clonedir, opts=None):
-        if opts is None:
-            opts = []
-        return (['rm', '-rf', clonedir] +
-                [run.Raw('&&')] +
-                ['git', 'clone'] + opts +
-                [git_url, clonedir])
-
-    def _cd(self, clonedir):
-        return ['cd', clonedir]
-
-    def _checkout(self):
-        return ['git', 'checkout', self.refspec]
-
-    def clone(self, git_url, clonedir):
-        return (self._clone(git_url, clonedir) +
-                [run.Raw('&&')] +
-                self._cd(clonedir) +
-                [run.Raw('&&')] +
-                self._checkout())
-
-
-class Branch(Refspec):
-    def __init__(self, tag):
-        Refspec.__init__(self, tag)
-
-    def clone(self, git_url, clonedir):
-        opts = ['--depth', '1',
-                '--branch', self.refspec]
-        return (self._clone(git_url, clonedir, opts) +
-                [run.Raw('&&')] +
-                self._cd(clonedir))
-
-
-class Head(Refspec):
-    def __init__(self):
-        Refspec.__init__(self, 'HEAD')
-
-    def clone(self, git_url, clonedir):
-        opts = ['--depth', '1']
-        return (self._clone(git_url, clonedir, opts) +
-                [run.Raw('&&')] +
-                self._cd(clonedir))
-
-
 def task(ctx, config):
     """
     Run ceph on all workunits found under the specified path.
@@ -140,25 +87,8 @@ def task(ctx, config):
     assert isinstance(config.get('clients'), dict), \
         'configuration must contain a dictionary of clients'
 
-    # mimic the behavior of the "install" task, where the "overrides" are
-    # actually the defaults of that task. in other words, if none of "sha1",
-    # "tag", or "branch" is specified by a "workunit" tasks, we will update
-    # it with the information in the "workunit" sub-task nested in "overrides".
-    overrides = deepcopy(ctx.config.get('overrides', {}).get('workunit', {}))
-    refspecs = {'branch': Branch, 'tag': Refspec, 'sha1': Refspec}
-    if any(map(lambda i: i in config, refspecs.iterkeys())):
-        for i in refspecs.iterkeys():
-            overrides.pop(i, None)
-    misc.deep_merge(config, overrides)
-
-    for spec, cls in refspecs.iteritems():
-        refspec = config.get(spec)
-        if refspec:
-            refspec = cls(refspec)
-            break
-    if refspec is None:
-        refspec = Head()
-
+    overrides = ctx.config.get('overrides', {})
+    refspec = get_refspec_after_overrides(config, overrides)
     timeout = config.get('timeout', '3h')
     cleanup = config.get('cleanup', True)