]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: tests: add tests for the system utility
authorAlfredo Deza <adeza@redhat.com>
Thu, 13 Jul 2017 13:49:55 +0000 (09:49 -0400)
committerAlfredo Deza <adeza@redhat.com>
Fri, 4 Aug 2017 14:25:58 +0000 (10:25 -0400)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
src/ceph-volume/ceph_volume/tests/util/test_system.py [new file with mode: 0644]

diff --git a/src/ceph-volume/ceph_volume/tests/util/test_system.py b/src/ceph-volume/ceph_volume/tests/util/test_system.py
new file mode 100644 (file)
index 0000000..fc3c0d4
--- /dev/null
@@ -0,0 +1,34 @@
+import os
+import pwd
+import getpass
+from ceph_volume.util import system
+
+
+class TestMkdirP(object):
+
+    def test_existing_dir_does_not_raise_w_chown(self, monkeypatch, tmpdir):
+        user = pwd.getpwnam(getpass.getuser())
+        uid, gid = user[2], user[3]
+        monkeypatch.setattr(system, 'get_ceph_user_ids', lambda: (uid, gid,))
+        path = str(tmpdir)
+        system.mkdir_p(path)
+        assert os.path.isdir(path)
+
+    def test_new_dir_w_chown(self, monkeypatch, tmpdir):
+        user = pwd.getpwnam(getpass.getuser())
+        uid, gid = user[2], user[3]
+        monkeypatch.setattr(system, 'get_ceph_user_ids', lambda: (uid, gid,))
+        path = os.path.join(str(tmpdir), 'new')
+        system.mkdir_p(path)
+        assert os.path.isdir(path)
+
+    def test_existing_dir_does_not_raise_no_chown(self, tmpdir):
+        path = str(tmpdir)
+        system.mkdir_p(path, chown=False)
+        assert os.path.isdir(path)
+
+    def test_new_dir_no_chown(self, tmpdir):
+        path = os.path.join(str(tmpdir), 'new')
+        system.mkdir_p(path, chown=False)
+        assert os.path.isdir(path)
+