From: Boris Ranto Date: Thu, 25 May 2017 12:36:13 +0000 (+0200) Subject: ceph-disk: Fix the file ownership, skip missing X-Git-Tag: v11.2.1~2^2~3 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=fa100ed57c3002b357d56398c3589f33cc651fcf;p=ceph.git ceph-disk: Fix the file ownership, skip missing This commit fixes the file ownership for the /usr/bin/ and /etc/ceph files and skips missing files as some of the files that we do specify now can be missing from the system (not installed, e.f. radosgw). Fixes: http://tracker.ceph.com/issues/20077 Signed-off-by: Boris Ranto (cherry picked from commit 077038b4393a28ccbd38ca4a90105dbd4c1ffcd5) --- diff --git a/src/ceph-disk/ceph_disk/main.py b/src/ceph-disk/ceph_disk/main.py index c783c46730fe7..6e09a449ea4b0 100755 --- a/src/ceph-disk/ceph_disk/main.py +++ b/src/ceph-disk/ceph_disk/main.py @@ -4686,11 +4686,11 @@ def main_trigger(args): def main_fix(args): # A hash table containing 'path': ('uid', 'gid', blocking, recursive) fix_table = [ - ('/usr/bin/ceph-mon', 'ceph', 'ceph', True, False), - ('/usr/bin/ceph-mds', 'ceph', 'ceph', True, False), - ('/usr/bin/ceph-osd', 'ceph', 'ceph', True, False), - ('/usr/bin/radosgw', 'ceph', 'ceph', True, False), - ('/etc/ceph', 'ceph', 'ceph', True, True), + ('/usr/bin/ceph-mon', 'root', 'root', True, False), + ('/usr/bin/ceph-mds', 'root', 'root', True, False), + ('/usr/bin/ceph-osd', 'root', 'root', True, False), + ('/usr/bin/radosgw', 'root', 'root', True, False), + ('/etc/ceph', 'root', 'root', True, True), ('/var/run/ceph', 'ceph', 'ceph', True, True), ('/var/log/ceph', 'ceph', 'ceph', True, True), ('/var/log/radosgw', 'ceph', 'ceph', True, True), @@ -4748,6 +4748,10 @@ def main_fix(args): # Use find to relabel + chown ~simultaenously if args.all: for directory, uid, gid, blocking, recursive in fix_table: + # Skip directories/files that are not installed + if not os.access(directory, os.F_OK): + continue + c = [ 'find', directory, @@ -4787,6 +4791,10 @@ def main_fix(args): # Fix permissions if args.permissions: for directory, uid, gid, blocking, recursive in fix_table: + # Skip directories/files that are not installed + if not os.access(directory, os.F_OK): + continue + if recursive: c = [ 'chown', @@ -4822,6 +4830,10 @@ def main_fix(args): # Fix SELinux labels if args.selinux: for directory, uid, gid, blocking, recursive in fix_table: + # Skip directories/files that are not installed + if not os.access(directory, os.F_OK): + continue + if recursive: c = [ 'restorecon', diff --git a/src/ceph-disk/tests/test_main.py b/src/ceph-disk/tests/test_main.py index 3f0e714e90bee..f6993362bcefb 100644 --- a/src/ceph-disk/tests/test_main.py +++ b/src/ceph-disk/tests/test_main.py @@ -1300,11 +1300,19 @@ class TestCephDiskDeactivateAndDestroy(unittest.TestCase): commands.append(" ".join(x)) return ("", "", None) + class Os(object): + F_OK = 0 + + @staticmethod + def access(x, y): + return True + with patch.multiple( main, command=_command, command_init=lambda x: commands.append(x), command_wait=lambda x: None, + os=Os, ): main.main_fix(args) commands = " ".join(commands)