]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: Add unit test for fix command
authorBoris Ranto <branto@redhat.com>
Thu, 9 Feb 2017 18:17:12 +0000 (19:17 +0100)
committerBoris Ranto <branto@redhat.com>
Mon, 20 Mar 2017 08:57:18 +0000 (09:57 +0100)
This will simulate the command* functions to not actually run anything
thus excercising the python code directly. It also checks that the
proper (sub-strings) are in the output.

Signed-off-by: Boris Ranto <branto@redhat.com>
src/ceph-disk/tests/test_main.py

index c2123ebbac6fa747e2944e127a6f80f456f549f1..9bc9d1fa1d3e2b55accd7094a323da54aba012e2 100644 (file)
@@ -1302,6 +1302,27 @@ class TestCephDiskDeactivateAndDestroy(unittest.TestCase):
             self.assertRaises(Exception, main._deallocate_osd_id,
                               cluster, osd_id)
 
+    def test_main_fix(self):
+        args = main.parse_args(['fix', '--all', '--selinux', '--permissions'])
+        commands = []
+
+        def _command(x):
+            commands.append(" ".join(x))
+            return ("", "", None)
+
+        with patch.multiple(
+            main,
+            command=_command,
+            command_init=lambda x: commands.append(x),
+            command_wait=lambda x: None,
+        ):
+            main.main_fix(args)
+            commands = " ".join(commands)
+            assert '/var/lib/ceph' in commands
+            assert 'restorecon' in commands
+            assert 'chown' in commands
+            assert 'find' in commands
+
 
 def raise_command_error(*args):
     e = subprocess.CalledProcessError('aaa', 'bbb', 'ccc')