From: Erwan Velu Date: Tue, 23 Feb 2016 10:36:51 +0000 (+0100) Subject: tests/ceph-disk: Creating missing working dir X-Git-Tag: v10.1.0~317^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ba05b7e700c67af172f3a7d79a1df5eccb01d515;p=ceph.git tests/ceph-disk: Creating missing working dir When running run-tox.sh in a very simple env, the test will fail if '/var/lib/ceph/tmp' doesn't exist. This patch adds a check to create this directory if required as mkdtemp doesn't do it for you. Prior this patch, the following behavior was seen : tests/test_main.py:342: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ceph_disk/main.py:3753: in list_devices fstype=fs_type, options='') ceph_disk/main.py:1217: in mount dir=STATEDIR + '/tmp', _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ suffix = '', prefix = 'mnt.', dir = '/var/lib/ceph/tmp' def mkdtemp(suffix="", prefix=template, dir=None): """User-callable function to create and return a unique temporary directory. The return value is the pathname of the directory. Arguments are as for mkstemp, except that the 'text' argument is not accepted. The directory is readable, writable, and searchable only by the creating user. Caller is responsible for deleting the directory when done with it. """ if dir is None: dir = gettempdir() names = _get_candidate_names() for seq in xrange(TMP_MAX): name = names.next() file = _os.path.join(dir, prefix + name + suffix) try: > _os.mkdir(file, 0700) E OSError: [Errno 2] No such file or directory: '/var/lib/ceph/tmp/mnt.KoAV85' /usr/lib64/python2.7/tempfile.py:333: OSError Signed-off-by: Erwan Velu --- diff --git a/src/ceph-disk/ceph_disk/main.py b/src/ceph-disk/ceph_disk/main.py index b36112ddf512..1817f59e4daa 100755 --- a/src/ceph-disk/ceph_disk/main.py +++ b/src/ceph-disk/ceph_disk/main.py @@ -1211,10 +1211,16 @@ def mount( if options is None: options = MOUNT_OPTIONS.get(fstype, '') + myTemp = STATEDIR + '/tmp' + # mkdtemp expect 'dir' to be existing on the system + # Let's be sure it's always the case + if not os.path.exists(myTemp): + os.makedirs(myTemp) + # mount path = tempfile.mkdtemp( prefix='mnt.', - dir=STATEDIR + '/tmp', + dir=myTemp, ) try: LOG.debug('Mounting %s on %s with options %s', dev, path, options)