From: Boris Ranto Date: Thu, 9 Feb 2017 18:17:12 +0000 (+0100) Subject: ceph-disk: Add unit test for fix command X-Git-Tag: v11.2.1~122^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=2db2fc81835ea8d0b35f563dd09691b030c920e9;p=ceph.git ceph-disk: Add unit test for fix command 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 (cherry picked from commit 1ec53dee9a690134936bdc3a09c9a02fecf13a9d) --- diff --git a/src/ceph-disk/tests/test_main.py b/src/ceph-disk/tests/test_main.py index d76a5d8b6040c..3f0e714e90bee 100644 --- a/src/ceph-disk/tests/test_main.py +++ b/src/ceph-disk/tests/test_main.py @@ -1292,6 +1292,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')