From 398c8b3a71c452e3dad616e12cf91b33db0a426e Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 30 Sep 2021 12:01:29 -0400 Subject: [PATCH] Improve syncfiles permission denied reporting When a non-readable file was encountered, confluent would cryptically report rsync failure. Check for the usual culprit, unreadable files if rsync fails. Cause this error to manifest with clearer text. --- confluent_server/confluent/syncfiles.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/confluent_server/confluent/syncfiles.py b/confluent_server/confluent/syncfiles.py index 0bb6aa51..67d72c96 100644 --- a/confluent_server/confluent/syncfiles.py +++ b/confluent_server/confluent/syncfiles.py @@ -90,6 +90,25 @@ def sync_list_to_node(sl, node, suffixes): sshutil.prep_ssh_key('/etc/confluent/ssh/automation') output = subprocess.check_output( ['rsync', '-rvL', targdir + '/', 'root@{}:/'.format(node)], timeout=86400) + except Exception as e: + if 'CalledProcessError' not in repr(e): + # https://github.com/eventlet/eventlet/issues/413 + # for some reason, can't catch the calledprocesserror normally + # for this exception, implement a hack workaround + raise + unreadablefiles = [] + for root, dirnames, filenames in os.walk(targdir): + for filename in filenames: + filename = os.path.join(root, filename) + try: + with open(filename, 'r') as _: + pass + except OSError as e: + unreadablefiles.append(filename.replace(targdir, '')) + if unreadablefiles: + raise Exception("Syncing failed due to unreadable files: " + ','.join(unreadablefiles)) + else: + raise finally: shutil.rmtree(targdir) return output