Yaniv Bronhaim has uploaded a new change for review. Change subject: Moving cpopen import to compat to allow working with python 3 ......................................................................
Moving cpopen import to compat to allow working with python 3 Once python3-copen will be available we'll be able to use it. Till then this import trick will allow us to work with the python Popen Change-Id: I181cd2e52706bfe7b24073d0f0eb42fec15ac490 Signed-off-by: Yaniv Bronhaim <ybron...@redhat.com> --- M lib/vdsm/compat.py M lib/vdsm/infra/zombiereaper/tests.py M lib/vdsm/qemuimg.py M lib/vdsm/utils.py M vdsm/storage/remoteFileHandler.py 5 files changed, 13 insertions(+), 8 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/84/48384/1 diff --git a/lib/vdsm/compat.py b/lib/vdsm/compat.py index 8ac5201..5c785a9 100644 --- a/lib/vdsm/compat.py +++ b/lib/vdsm/compat.py @@ -38,3 +38,8 @@ # no big deal, fallback to standard libary import json json # yep, this is needed twice. + +try: + from cpopen import CPopen as Popen +except ImportError: + from subprocess import Popen diff --git a/lib/vdsm/infra/zombiereaper/tests.py b/lib/vdsm/infra/zombiereaper/tests.py index 681579f..9392758 100644 --- a/lib/vdsm/infra/zombiereaper/tests.py +++ b/lib/vdsm/infra/zombiereaper/tests.py @@ -22,7 +22,7 @@ import os from .. import zombiereaper -from cpopen import CPopen +from vdsm.compat import Popen from unittest import TestCase @@ -36,7 +36,7 @@ zombiereaper.unregisterSignalHandler() def testProcessDiesAfterBeingTracked(self): - p = CPopen(["sleep", "1"]) + p = Popen(["sleep", "1"]) zombiereaper.autoReapPID(p.pid) # wait for the grim reaper to arrive sleep(4) @@ -45,7 +45,7 @@ self.assertRaises(OSError, os.waitpid, p.pid, os.WNOHANG) def testProcessDiedBeforeBeingTracked(self): - p = CPopen(["sleep", "0"]) + p = Popen(["sleep", "0"]) # wait for the process to die sleep(1) diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py index bce9973..49ea43d 100644 --- a/lib/vdsm/qemuimg.py +++ b/lib/vdsm/qemuimg.py @@ -24,7 +24,7 @@ import re import signal -from cpopen import CPopen +from vdsm.compat import Popen from . import utils from . import cmdutils @@ -223,7 +223,7 @@ cmd = cmdutils.wrap_command(cmd, with_nice=utils.NICENESS.HIGH, with_ioclass=utils.IOCLASS.IDLE) _log.debug(cmdutils.command_log_line(cmd, cwd=cwd)) - self._command = CPopen(cmd, cwd=cwd, deathSignal=signal.SIGKILL) + self._command = Popen(cmd, cwd=cwd, deathSignal=signal.SIGKILL) self._stream = utils.CommandStream( self._command, self._recvstdout, self._recvstderr) diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py index 9ebef54..0b14e59 100644 --- a/lib/vdsm/utils.py +++ b/lib/vdsm/utils.py @@ -52,6 +52,7 @@ import string import threading import time +from vdsm.compat import Popen import vdsm.infra.zombiereaper as zombiereaper from cpopen import CPopen @@ -629,7 +630,6 @@ a temporary thread, spawn a sync=False sub-process, and have the thread finish, the new subprocess would die immediately. """ - command = cmdutils.wrap_command(command, with_ioclass=ioclass, ioclassdata=ioclassdata, with_nice=nice, with_setsid=setsid, with_sudo=sudo, diff --git a/vdsm/storage/remoteFileHandler.py b/vdsm/storage/remoteFileHandler.py index e69ae8c..2123777 100644 --- a/vdsm/storage/remoteFileHandler.py +++ b/vdsm/storage/remoteFileHandler.py @@ -33,7 +33,7 @@ if __name__ != "__main__": # The following modules are not used by the newly spawned child porcess. # Do not import them in the child to save memory. - from cpopen import CPopen + from vdsm.compat import Popen from vdsm import constants else: # We add the parent directory so that imports that import the storage @@ -231,7 +231,7 @@ env.get("PYTHONPATH", ""), constants.P_VDSM) env['PYTHONPATH'] = ":".join(map(os.path.abspath, env['PYTHONPATH'].split(":"))) - self.process = CPopen([constants.EXT_PYTHON, __file__, + self.process = Popen([constants.EXT_PYTHON, __file__, str(hisRead), str(hisWrite)], close_fds=False, env=env) -- To view, visit https://gerrit.ovirt.org/48384 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I181cd2e52706bfe7b24073d0f0eb42fec15ac490 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Yaniv Bronhaim <ybron...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches