From e2b4e4e1ac8e3d419f7431ec9dad644e0f0fb75a Mon Sep 17 00:00:00 2001 From: Kotresh HR Date: Fri, 28 Sep 2018 05:52:36 -0400 Subject: georep: python2 and python3 compat - bytes-str 1. Fix fdopen used for pid file 2. Fix sha256 checksum calculation Updates: #411 Change-Id: Ic173d104a73822c29aca260ba6de872cd8d23f86 Signed-off-by: Kotresh HR --- geo-replication/syncdaemon/syncdutils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/geo-replication/syncdaemon/syncdutils.py b/geo-replication/syncdaemon/syncdutils.py index 93e09756198..a17789995d8 100644 --- a/geo-replication/syncdaemon/syncdutils.py +++ b/geo-replication/syncdaemon/syncdutils.py @@ -160,7 +160,8 @@ def setup_ssh_ctl(ctld, remote_addr, resource_url): rconf.ssh_ctl_dir = ctld content = "SLAVE_HOST=%s\nSLAVE_RESOURCE_URL=%s" % (remote_addr, resource_url) - content_sha256 = sha256hex(content) + encoded_content = content.encode() + content_sha256 = sha256hex(encoded_content) """ The length of ctl_path for ssh connection should not be > 108. ssh fails with ctl_path too long if it is so. But when rsync @@ -172,7 +173,7 @@ def setup_ssh_ctl(ctld, remote_addr, resource_url): fname = os.path.join(rconf.ssh_ctl_dir, "%s.mft" % content_sha256) - create_manifest(fname, content) + create_manifest(fname, encoded_content) ssh_ctl_path = os.path.join(rconf.ssh_ctl_dir, "%s.sock" % content_sha256) rconf.ssh_ctl_args = ["-oControlMaster=auto", "-S", ssh_ctl_path] @@ -185,7 +186,7 @@ def grabfile(fname, content=None): """ # damn those messy open() mode codes fd = os.open(fname, os.O_CREAT | os.O_RDWR) - f = os.fdopen(fd, 'r+b', 0) + f = os.fdopen(fd, 'r+') try: fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB) except: @@ -199,6 +200,7 @@ def grabfile(fname, content=None): try: f.truncate() f.write(content) + f.flush() except: f.close() raise -- cgit