From: Loic Dachary Date: Mon, 14 Sep 2015 11:25:02 +0000 (+0200) Subject: internal: move buildpackages before install task X-Git-Tag: 1.1.0~810^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=da1de303b5f9acd77c7c5dc5e9be9ffa92ebf67d;p=teuthology.git internal: move buildpackages before install task 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 --- diff --git a/teuthology/run.py b/teuthology/run.py index 430ed80d97..6b854d1bea 100644 --- a/teuthology/run.py +++ b/teuthology/run.py @@ -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}, ]) diff --git a/teuthology/task/internal.py b/teuthology/task/internal.py index 567621eea6..9879d23a7d 100644 --- a/teuthology/task/internal.py +++ b/teuthology/task/internal.py @@ -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 index 0000000000..2cb0bf12a2 --- /dev/null +++ b/teuthology/test/task/test_internal.py @@ -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': []} diff --git a/teuthology/test/test_run.py b/teuthology/test/test_run.py index f2c4e9099a..127a5bda33 100644 --- a/teuthology/test/test_run.py +++ b/teuthology/test/test_run.py @@ -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):