]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tests/ceph-disk: Creating missing working dir
authorErwan Velu <erwan@redhat.com>
Tue, 23 Feb 2016 10:36:51 +0000 (11:36 +0100)
committerErwan Velu <erwan@redhat.com>
Wed, 24 Feb 2016 08:55:46 +0000 (09:55 +0100)
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 <erwan@redhat.com>
src/ceph-disk/ceph_disk/main.py

index b36112ddf512af1539a9205bfcea51125a9132b6..1817f59e4daaf9adbf5530e2d4dd0b244ce3d5d5 100755 (executable)
@@ -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)