From 38db951e51af0f6f80a481dd597ebb3a4d2bc209 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 10 Sep 2013 10:53:41 -0700 Subject: [PATCH] remove basedir/testdir distinction We should never run with a conflicting testdir in the basedir, and the code to do this is confusing and buggy. Go back to a single testdir and simple checks. Signed-off-by: Sage Weil (cherry picked from commit 5acc57f5ad6ed14b3e1c89166d2571cf302a467c) Conflicts: README.rst teuthology/misc.py --- README.rst | 21 ++++------- teuthology/misc.py | 72 +++++++------------------------------ teuthology/nuke.py | 4 +-- teuthology/task/internal.py | 50 +++----------------------- 4 files changed, 26 insertions(+), 121 deletions(-) diff --git a/README.rst b/README.rst index 91bbb55c81..f2d6e3cbcf 100644 --- a/README.rst +++ b/README.rst @@ -303,24 +303,15 @@ this issue. Test Sandbox Directory ====================== -Teuthology currently places most test files and mount points in a sandbox -directory, defaulting to ``/tmp/cephtest/{rundir}``. The ``{rundir}`` is the -name of the run (as given by ``--name``) or if no name is specified, -``user@host-timestamp`` is used. To change the location of the sandbox -directory, the following options can be specified in -``$HOME/.teuthology.yaml``:: - - base_test_dir: - -The ``base_test_dir`` option will set the base directory to use for the individual -run directories. If not specified, this defaults to: ``/tmp/cephtest``. +Teuthology currently places most test files and mount points in a +sandbox directory, defaulting to ``/home/$USER/cephtest``. To change +the location of the sandbox directory, the following option can be +specified in ``$HOME/.teuthology.yaml``:: test_path: -The ``test_path`` option will set the complete path to use for the test directory. -This allows for the old behavior, where ``/tmp/cephtest`` was used as the sandbox -directory. - +======= +>>>>>>> 5acc57f... remove basedir/testdir distinction VIRTUAL MACHINE SUPPORT ======================= diff --git a/teuthology/misc.py b/teuthology/misc.py index 1a0eee7e4c..cf531e6a5e 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -21,8 +21,6 @@ log = logging.getLogger(__name__) import datetime stamp = datetime.datetime.now().strftime("%y%m%d%H%M") -global_jobid = None -checked_jobid = False is_vm = lambda x: x.startswith('vpm') or x.startswith('ubuntu@vpm') is_arm = lambda x: x.startswith('tala') or x.startswith('ubuntu@tala') or x.startswith('saya') or x.startswith('ubuntu@saya') @@ -30,66 +28,22 @@ is_arm = lambda x: x.startswith('tala') or x.startswith('ubuntu@tala') or x.star def get_testdir(ctx): if 'test_path' in ctx.teuthology_config: return ctx.teuthology_config['test_path'] + test_user = get_test_user(ctx) + # FIXME this ideally should use os.path.expanduser() in the future, in case + # $HOME isn't /home/$USER - e.g. on a Mac. However, since we're executing + # this on the server side, it won't work properly. + return ctx.teuthology_config.get('test_path', '/home/%s/cephtest' % test_user) - basedir = ctx.teuthology_config.get('base_test_dir', '/home/ubuntu/cephtest') - - global global_jobid - global checked_jobid +def get_test_user(ctx): + """ + :returns: str -- the user to run tests as on remote hosts + """ + return ctx.teuthology_config.get('test_user', 'ubuntu') - # 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 and ctx.config.get('check-locks') != False: - jobids = {} - for machine in ctx.config['targets'].iterkeys(): - status = lockstatus.get_status(ctx, machine) - if status is None or 'description' not in status or status['description'] is None: - continue - jid = status['description'].split('/')[-1] - if jid is None or jid == 'None': - continue - 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() - if jobid is not None: - global_jobid = jobid - log.debug('setting my jobid to {jid}'.format(jid=global_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 is not None: - log.debug('with jobid basedir: {b}'.format(b=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:4] + 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=short, - ) - else: - log.debug('basedir: {b}'.format(b=basedir)) - return '{basedir}/{user}{stamp}'.format( - basedir=basedir, - user=get_user()[0:2], - stamp=stamp) -def get_testdir_base(ctx): - if 'test_path' in ctx.teuthology_config: - return ctx.teuthology_config['test_path'] - return ctx.teuthology_config.get('base_test_dir', '/home/ubuntu/cephtest') +def get_archive_dir(ctx): + test_dir = get_testdir(ctx) + return os.path.normpath(os.path.join(test_dir, 'archive')) def get_ceph_binary_url(package=None, branch=None, tag=None, sha1=None, dist=None, diff --git a/teuthology/nuke.py b/teuthology/nuke.py index 82389f99d5..0dfffb84a9 100644 --- a/teuthology/nuke.py +++ b/teuthology/nuke.py @@ -263,13 +263,13 @@ def remove_installed_packages(ctx, log): install_task.purge_data(ctx) def remove_testing_tree(ctx, log): - from teuthology.misc import get_testdir_base + from teuthology.misc import get_testdir from .orchestra import run nodes = {} for remote in ctx.cluster.remotes.iterkeys(): proc = remote.run( args=[ - 'sudo', 'rm', '-rf', get_testdir_base(ctx), + 'sudo', 'rm', '-rf', get_testdir(ctx), # just for old time's sake run.Raw('&&'), 'sudo', 'rm', '-rf', '/tmp/cephtest', diff --git a/teuthology/task/internal.py b/teuthology/task/internal.py index 755af8f526..c7dff23eec 100644 --- a/teuthology/task/internal.py +++ b/teuthology/task/internal.py @@ -18,31 +18,17 @@ log = logging.getLogger(__name__) @contextlib.contextmanager def base(ctx, config): - log.info('Creating base directory...') - test_basedir = teuthology.get_testdir_base(ctx) + log.info('Creating test directory...') testdir = teuthology.get_testdir(ctx) - # make base dir if it doesn't exist run.wait( ctx.cluster.run( args=[ - 'mkdir', '-m0755', '-p', '--', - test_basedir, - ], - wait=False, - ) - ) - # only create testdir if its not set to basedir - if test_basedir != testdir: - run.wait( - ctx.cluster.run( - args=[ - 'mkdir', '-m0755', '--', - testdir, + 'mkdir', '-m0755', '--', + testdir, ], - wait=False, - ) + wait=False, ) - + ) try: yield finally: @@ -235,32 +221,6 @@ def check_ceph_data(ctx, config): def check_conflict(ctx, config): log.info('Checking for old test directory...') - test_basedir = teuthology.get_testdir_base(ctx) - processes = ctx.cluster.run( - args=[ - 'test', '!', '-e', test_basedir, - ], - wait=False, - ) - for proc in processes: - assert isinstance(proc.exitstatus, gevent.event.AsyncResult) - try: - proc.exitstatus.get() - except run.CommandFailedError: - # base dir exists - r = proc.remote.run( - args=[ - 'ls', test_basedir, run.Raw('|'), 'wc', '-l' - ], - stdout=StringIO(), - ) - - if int(r.stdout.getvalue()) > 0: - log.error('WARNING: Host %s has stale test directories, these need to be investigated and cleaned up!', - proc.remote.shortname) - - # testdir might be the same as base dir (if test_path is set) - # need to bail out in that case if the testdir exists testdir = teuthology.get_testdir(ctx) processes = ctx.cluster.run( args=[ -- 2.39.5