georep: python3 compatibility (Popen)

The file objects for python3 by default is opened
in binary mode where as in python2 it's opened
as text by default.

The geo-rep code parses the output of Popen assuming
it as text, hence used the 'universal_newlines' flag
which provides backward compatibility for the same.

Change-Id: I371a03b6348af9666164cb2e8b93d47475431ad9
Updates: #411
Signed-off-by: Kotresh HR <khiremat@redhat.com>
This commit is contained in:
Kotresh HR 2018-09-24 21:18:30 +05:30 committed by Amar Tumballi
parent 89636be4c7
commit 65aed1070c
3 changed files with 21 additions and 12 deletions

View File

@ -834,7 +834,8 @@ class Mounter(object):
def umount_l(self, d):
"""perform lazy umount"""
po = Popen(self.make_umount_argv(d), stderr=subprocess.PIPE)
po = Popen(self.make_umount_argv(d), stderr=subprocess.PIPE,
universal_newlines=True)
po.wait()
return po
@ -950,7 +951,7 @@ class DirectMounter(Mounter):
"""mounter backend which calls mount(8), umount(8) directly"""
mountkw = {'stderr': subprocess.PIPE}
mountkw = {'stderr': subprocess.PIPE, 'universal_newlines': True}
glusterprog = 'glusterfs'
@staticmethod
@ -973,7 +974,8 @@ class MountbrokerMounter(Mounter):
"""mounter backend using the mountbroker gluster service"""
mountkw = {'stderr': subprocess.PIPE, 'stdout': subprocess.PIPE}
mountkw = {'stderr': subprocess.PIPE, 'stdout': subprocess.PIPE,
'universal_newlines': True}
glusterprog = 'gluster'
@classmethod
@ -1475,9 +1477,10 @@ class SSH(object):
# Else rsync will write to stdout and nobody is their
# to consume. If PIPE is full rsync hangs.
po = Popen(argv, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stderr=subprocess.PIPE, universal_newlines=True)
else:
po = Popen(argv, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
po = Popen(argv, stdin=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True)
for f in files:
po.stdin.write(f)
@ -1526,8 +1529,10 @@ class SSH(object):
[host, "tar"] + \
["--overwrite", "-xf", "-", "-C", rdir]
p0 = Popen(tar_cmd, stdout=subprocess.PIPE,
stdin=subprocess.PIPE, stderr=subprocess.PIPE)
p1 = Popen(ssh_cmd, stdin=p0.stdout, stderr=subprocess.PIPE)
stdin=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True)
p1 = Popen(ssh_cmd, stdin=p0.stdout, stderr=subprocess.PIPE,
universal_newlines=True)
for f in files:
p0.stdin.write(f)
p0.stdin.write('\n')

View File

@ -112,7 +112,8 @@ def subcmd_voluuidget(args):
po = Popen(['gluster', '--xml', '--remote-host=' + args.host,
'volume', 'info', args.volname], bufsize=0,
stdin=None, stdout=PIPE, stderr=PIPE)
stdin=None, stdout=PIPE, stderr=PIPE,
universal_newlines=True)
vix, err = po.communicate()
if po.returncode != 0:

View File

@ -261,7 +261,8 @@ def finalize(*args, **kwargs):
umount_cmd = rconf.mbr_umount_cmd + [rconf.mount_point, 'lazy']
else:
umount_cmd = ['umount', '-l', rconf.mount_point]
p0 = subprocess.Popen(umount_cmd, stderr=subprocess.PIPE)
p0 = subprocess.Popen(umount_cmd, stderr=subprocess.PIPE,
universal_newlines=True)
_, errdata = p0.communicate()
if p0.returncode == 0:
try:
@ -636,7 +637,8 @@ def unshare_propagation_supported():
unshare_mnt_propagation = False
p = subprocess.Popen(["unshare", "--help"],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
stdout=subprocess.PIPE,
universal_newlines=True)
out, err = p.communicate()
if p.returncode == 0:
if "propagation" in out:
@ -653,7 +655,8 @@ def get_rsync_version(rsync_cmd):
rsync_version = "0"
p = subprocess.Popen([rsync_cmd, "--version"],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
stdout=subprocess.PIPE,
universal_newlines=True)
out, err = p.communicate()
if p.returncode == 0:
rsync_version = out.split(" ", 4)[3]
@ -856,7 +859,7 @@ class Volinfo(object):
def __init__(self, vol, host='localhost', prelude=[]):
po = Popen(prelude + ['gluster', '--xml', '--remote-host=' + host,
'volume', 'info', vol],
stdout=PIPE, stderr=PIPE)
stdout=PIPE, stderr=PIPE, universal_newlines=True)
vix = po.stdout.read()
po.wait()
po.terminate_geterr()