File 03_dev_or_dir.patch of Package ceph-deploy

diff --git a/ceph_deploy/osd.py b/ceph_deploy/osd.py
index a8f2ddf..d243e2a 100644
--- a/ceph_deploy/osd.py
+++ b/ceph_deploy/osd.py
@@ -186,11 +186,32 @@ def catch_osd_errors(conn, logger, args):
     if nearfull:
         logger.warning('OSDs are near full!')
 
+def detect_disk_dir(
+        disk):
+    path_norm = os.path.normpath(disk)
+    path_test = os.path.commonprefix([path_norm, '/dev/'])
+    if path_test == '/dev/':
+        return False
+    return True
+
+def prepare_disk_dir(
+        conn,
+        disk):
+    if conn.remote_module.path_exists(disk):
+        return
+    return remoto.process.run(
+        conn,
+        [
+            'mkdir',
+            disk
+        ],
+    )
 
 def prepare_disk(
         conn,
         cluster,
         disk,
+        disk_is_dir,
         journal,
         activate_prepared_disk,
         zap,
@@ -217,9 +238,13 @@ def prepare_disk(
         if dmcrypt_dir is not None:
             args.append('--dmcrypt-key-dir')
             args.append(dmcrypt_dir)
+    data_validation = '--data-dev'
+    if disk_is_dir:
+        data_validation = '--data-dir'
     args.extend([
         '--cluster',
         cluster,
+        data_validation,
         '--',
         disk,
     ])
@@ -260,6 +285,7 @@ def prepare(args, cfg, activate_prepared_disk):
             if disk is None:
                 raise exc.NeedDiskError(hostname)
 
+            disk_is_dir = detect_disk_dir(disk)
             distro = hosts.get(hostname, username=args.username)
             LOG.info(
                 'Distro info: %s %s %s',
@@ -285,10 +311,16 @@ def prepare(args, cfg, activate_prepared_disk):
             LOG.debug('Preparing host %s disk %s journal %s activate %s',
                       hostname, disk, journal, activate_prepared_disk)
 
+            if disk_is_dir:
+                prepare_disk_dir(
+                    distro.conn,
+                    disk=disk
+                )
             prepare_disk(
                 distro.conn,
                 cluster=args.cluster,
                 disk=disk,
+                disk_is_dir=disk_is_dir,
                 journal=journal,
                 activate_prepared_disk=activate_prepared_disk,
                 zap=args.zap_disk,
diff --git a/ceph_deploy/tests/test_osd.py b/ceph_deploy/tests/test_osd.py
new file mode 100644
index 0000000..6faa713
--- /dev/null
+++ b/ceph_deploy/tests/test_osd.py
@@ -0,0 +1,19 @@
+from ceph_deploy import osd
+
+
+class TestDetectDiskDir(object):
+    def test_detect_disk_dir_negative(self):
+        assert False == osd.detect_disk_dir('/dev/sda')
+        assert False == osd.detect_disk_dir('/dev/vda')
+        assert False == osd.detect_disk_dir('/dev/hda')
+        assert False == osd.detect_disk_dir('/dev/hdz')
+        assert False == osd.detect_disk_dir('/dev/sdz')
+        assert False == osd.detect_disk_dir('///dev/sda')
+        # Note : following test fails due to os.path.normpath behavior.
+        # assert False == osd.detect_disk_dir('//dev/sda')
+
+    def test_detect_disk_dir_positive(self):
+        assert True == osd.detect_disk_dir('/mnt/foo')
+        assert True == osd.detect_disk_dir('/srv/foo')
+        assert True == osd.detect_disk_dir('/srv/foo/bar')
+        assert True == osd.detect_disk_dir('/server/foo/')
openSUSE Build Service is sponsored by