]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
internal: move buildpackages before install task
authorLoic Dachary <ldachary@redhat.com>
Mon, 14 Sep 2015 11:25:02 +0000 (13:25 +0200)
committerLoic Dachary <ldachary@redhat.com>
Wed, 23 Sep 2015 20:41:49 +0000 (22:41 +0200)
If a buildpackages task is found, ensure it is always before the install
task because it is intended to produce the packages that will be used by
the install task.

http://tracker.ceph.com/issues/13031 Refs: #13031

Signed-off-by: Loic Dachary <loic@dachary.org>
teuthology/run.py
teuthology/task/internal.py
teuthology/test/task/test_internal.py [new file with mode: 0644]
teuthology/test/test_run.py

index 430ed80d977436737492bc057d0c3fbe7a628e45..6b854d1bea66e7727729842903d2efa877cf820c 100644 (file)
@@ -208,6 +208,7 @@ def get_initial_tasks(lock, config, machine_type):
         {'internal.sudo': None},
         {'internal.syslog': None},
         {'internal.timer': None},
+        {'internal.buildpackages_prep': None},
         {'selinux': None},
     ])
 
index 567621eea69214e009574647f07291d6d4653000..9879d23a7d0f1d7e09aa4b1c33be931d815ca63b 100644 (file)
@@ -342,6 +342,51 @@ def push_inventory(ctx, config):
     except Exception:
         log.exception("Error pushing inventory")
 
+BUILDPACKAGES_SWAPPED = 0
+BUILDPACKAGES_OK = 1
+BUILDPACKAGES_REMOVED = 2
+BUILDPACKAGES_NOTHING = 3
+
+def buildpackages_prep(ctx, config):
+    """
+    Make sure the 'buildpackages' task happens before
+    the 'install' task.
+
+    Return:
+
+    BUILDPACKAGES_NOTHING if there is no buildpackages task
+    BUILDPACKAGES_REMOVED if there is a buildpackages task but no install task
+    BUILDPACKAGES_SWAPPED if a buildpackages task was moved before an install task
+    BUILDPACKAGES_OK if a buildpackages task already is before the install task
+    """
+    index = 0
+    install_index = None
+    buildpackages_index = None
+    for task in ctx.config['tasks']:
+        if task.keys()[0] == 'install':
+            install_index = index
+        if task.keys()[0] == 'buildpackages':
+            buildpackages_index = index
+        index += 1
+    if buildpackages_index is not None and install_index is not None:
+        if buildpackages_index > install_index:
+            log.info('buildpackages moved before the install task')
+            buildpackages = ctx.config['tasks'].pop(buildpackages_index)
+            ctx.config['tasks'].insert(install_index, buildpackages)
+            return BUILDPACKAGES_SWAPPED
+        else:
+            log.info('buildpackages is before the install task')
+            return BUILDPACKAGES_OK
+    elif buildpackages_index is not None and install_index is None:
+        ctx.config['tasks'].pop(buildpackages_index)
+        all_tasks = [x.keys()[0] for x in ctx.config['tasks']]
+        log.info('buildpackages removed because no install task found in ' +
+                 str(all_tasks))
+        return BUILDPACKAGES_REMOVED
+    elif buildpackages_index is None:
+        log.info('no buildpackages task found')
+        return BUILDPACKAGES_NOTHING
+
 
 def serialize_remote_roles(ctx, config):
     """
diff --git a/teuthology/test/task/test_internal.py b/teuthology/test/task/test_internal.py
new file mode 100644 (file)
index 0000000..2cb0bf1
--- /dev/null
@@ -0,0 +1,53 @@
+from teuthology.config import FakeNamespace
+from teuthology.task import internal
+
+
+class TestInternal(object):
+    def setup(self):
+        self.ctx = FakeNamespace()
+        self.ctx.config = dict()
+
+    def test_buildpackages_prep(self):
+        #
+        # no buildpackages nor install tasks
+        #
+        self.ctx.config = { 'tasks': [] }
+        assert internal.buildpackages_prep(self.ctx,
+                                      self.ctx.config) == internal.BUILDPACKAGES_NOTHING
+        #
+        # move the buildpackages tasks before the install task
+        #
+        self.ctx.config = {
+            'tasks': [ { 'atask': None },
+                       { 'install': None },
+                       { 'buildpackages': None } ],
+        }
+        assert internal.buildpackages_prep(self.ctx,
+                                      self.ctx.config) == internal.BUILDPACKAGES_SWAPPED
+        assert self.ctx.config == {
+            'tasks': [ { 'atask': None },
+                       { 'buildpackages': None },
+                       { 'install': None } ],
+        }
+        #
+        # the buildpackages task already is before the install task
+        #
+        assert internal.buildpackages_prep(self.ctx,
+                                      self.ctx.config) == internal.BUILDPACKAGES_OK
+        #
+        # no buildpackages task
+        #
+        self.ctx.config = {
+            'tasks': [ { 'install': None } ],
+        }
+        assert internal.buildpackages_prep(self.ctx,
+                                      self.ctx.config) == internal.BUILDPACKAGES_NOTHING
+        #
+        # no install task: the buildpackages task must be removed
+        #
+        self.ctx.config = {
+            'tasks': [ { 'buildpackages': None } ],
+        }
+        assert internal.buildpackages_prep(self.ctx,
+                                      self.ctx.config) == internal.BUILDPACKAGES_REMOVED
+        assert self.ctx.config == {'tasks': []}
index f2c4e9099a04e505c4c9b626eb7b8b5e173ba324..127a5bda33c21ef6b6cf6a18491332cf348c2d38 100644 (file)
@@ -105,6 +105,7 @@ class TestRun(object):
         assert {"kernel": "the_kernel"} in result
         # added because use_existing_cluster == False
         assert {'internal.vm_setup': None} in result
+        assert {'internal.buildpackages_prep': None} in result
 
     @patch("teuthology.run.fetch_qa_suite")
     def test_fetch_tasks_if_needed(self, m_fetch_qa_suite):