From 72cbf1157acb31bef95d2161a1cbca66897d3cac Mon Sep 17 00:00:00 2001 From: Sam Lang Date: Thu, 11 Apr 2013 09:23:10 -0500 Subject: [PATCH] misc: Use job id and make short path for testdir Nightlies run on teuthology currently use a testdir of /home/ubuntu/cephtest, but this causes stale job errors occasionally from the previous tests not getting properly cleaned up, which prevents the nightlies from running successfully. The misc.py get_testdir() function can specify a testdir that is specific to the job, but previously the path was too long and would cause separate job failures. This patch does two things to resolve that. First, it uses the job id from the teuthology run if one exists. This should be a relatively short number that will identify the job run effectively. Second, if the job id isn't available, it creates a shortened form of the job's name, for example the job name: teuthology-2013-04-09_23:51:49-rgw-next-testing-basic becomes: te1304092351rntb Signed-off-by: Sam Lang --- teuthology/misc.py | 47 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/teuthology/misc.py b/teuthology/misc.py index 1fdeadf4aa5aa..aca1b3c638b36 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -13,12 +13,15 @@ import yaml import json from teuthology import safepath +from teuthology import lock from .orchestra import run log = logging.getLogger(__name__) import datetime -stamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S") +stamp = datetime.datetime.now().strftime("%y%m%d%H%M") +global_jobid = None +checked_jobid = False def get_testdir(ctx): if 'test_path' in ctx.teuthology_config: @@ -26,17 +29,51 @@ def get_testdir(ctx): basedir = ctx.teuthology_config.get('base_test_dir', '/tmp/cephtest') - if hasattr(ctx, 'name') and ctx.name: + global global_jobid + global checked_jobid + + # check if a jobid exists in the machine status for all our targets + # and if its the same jobid, use that as the subdir for the test + if not checked_jobid: + jobids = {} + for machine in ctx.config['targets'].iterkeys(): + status = lock.get_status(ctx, machine) + jid = status['description'].split('/')[-1] + jobids[jid] = 1 + if len(jobids) > 1: + break + if len(jobids) == 1: + # same job id on all machines, use that as the test subdir + (jobid,) = jobids.iterkeys() + global_jobid = jobid + checked_jobid = True + + # the subdir is chosen using the priority: + # 1. jobid chosen by the teuthology beanstalk queue + # 2. run name specified by teuthology schedule + # 3. user@timestamp + if global_jobid: + log.debug('with jobid basedir: {b}'.format(b=str(global_jobid))) + return '{basedir}/{jobid}'.format( + basedir=basedir, + jobid=global_jobid, + ) + elif hasattr(ctx, 'name') and ctx.name: log.debug('with name basedir: {b}'.format(b=basedir)) + # we need a short string to keep the path short + import re + m = re.match(r"(.*)-(.*)-(.*)-(.*)_(.*)-(.*)-(.*)-(.*)-(.*)", ctx.name) + (u, y, m, d, hms, s, c, k, f) = m.groups() + short = u[0:2] + y[2:3] + m[0:2] + d[0:2] + hms[0:2] + hms[3:5] + s[0] + c[0] + k[0] + f[0] return '{basedir}/{rundir}'.format( basedir=basedir, - rundir=ctx.name.replace(':','-'), # : breaks the $PATH list + rundir=short, ) else: log.debug('basedir: {b}'.format(b=basedir)) - return '{basedir}/{user}-{stamp}'.format( + return '{basedir}/{user}{stamp}'.format( basedir=basedir, - user=get_user(), + user=get_user()[0:2], stamp=stamp) def get_testdir_base(ctx): -- 2.39.5