{'internal.sudo': None},
{'internal.syslog': None},
{'internal.timer': None},
+ {'internal.buildpackages_prep': None},
{'selinux': None},
])
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):
"""
--- /dev/null
+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': []}
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):