Change in vdsm[master]: compat: mock CPopen for Python 3 testing
danken at redhat.com
danken at redhat.com
Tue Mar 29 07:50:44 UTC 2016
Dan Kenigsberg has uploaded a new change for review.
Change subject: compat: mock CPopen for Python 3 testing
......................................................................
compat: mock CPopen for Python 3 testing
I would like to run Vdsm unit tests in Python 3, but many tests
ultimately attempt to import CPopen. The right thing to do is to remove
CPopen dependency from the code, but this task is lagging. Until then,
this patch drops CPopen dependecy for Python 3 only.
Change-Id: I3fb1310dc538ea92879ab1097d897fd7c4e2ef96
Signed-off-by: Dan Kenigsberg <danken at redhat.com>
---
M lib/vdsm/commands.py
M lib/vdsm/compat.py
M lib/vdsm/qemuimg.py
3 files changed, 27 insertions(+), 3 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/79/55379/1
diff --git a/lib/vdsm/commands.py b/lib/vdsm/commands.py
index 5c80902..5e86262 100644
--- a/lib/vdsm/commands.py
+++ b/lib/vdsm/commands.py
@@ -20,7 +20,6 @@
from __future__ import absolute_import
from StringIO import StringIO
-from cpopen import CPopen
from weakref import proxy
import errno
@@ -32,6 +31,7 @@
import threading
import time
from . import cmdutils
+from .compat import CPopen
from .exception import ActionStopped
from .utils import NoIntrPoll, stripNewLines
from vdsm import constants
diff --git a/lib/vdsm/compat.py b/lib/vdsm/compat.py
index 15e7ac6..c3cab79 100644
--- a/lib/vdsm/compat.py
+++ b/lib/vdsm/compat.py
@@ -38,3 +38,28 @@
# no big deal, fallback to standard library
import json
json # yep, this is needed twice.
+
+import sys
+if sys.version_info[0] == 2:
+ from cpopen import CPopen
+ CPopen # make pyflakes happy
+else:
+ from subprocess import Popen, PIPE
+
+ class CPopen(Popen):
+ """This is a mock for cpopen.CPopen which explodes in run-time when
+ initialized with the CPopen-only argunment deathSignal and childUmask.
+ It is intended to allow testing vdsm code on Python 3, and not for
+ runtime usages.
+ """
+ def __init__(self, args, close_fds=False, cwd=None, env=None,
+ deathSignal=0, childUmask=None,
+ stdin=PIPE, stdout=PIPE, stderr=PIPE,
+ restore_sigpipe=False):
+ if deathSignal != 0 or childUmask is not None:
+ raise AssertionError(
+ 'Popen called within deathSignal or childUmask')
+ Popen.__init__(self, args,
+ close_fds=close_fds, cwd=cwd, env=env,
+ stdin=stdin, stdout=stdout,
+ stderr=stderr)
diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py
index 4a75428..eeaee6d 100644
--- a/lib/vdsm/qemuimg.py
+++ b/lib/vdsm/qemuimg.py
@@ -24,12 +24,11 @@
import re
import signal
-from cpopen import CPopen
-
from . import exception
from . import utils
from . import cmdutils
from . import commands
+from .compat import CPopen
_qemuimg = utils.CommandPath("qemu-img",
"/usr/bin/qemu-img",) # Fedora, EL6
--
To view, visit https://gerrit.ovirt.org/55379
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3fb1310dc538ea92879ab1097d897fd7c4e2ef96
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dan Kenigsberg <danken at redhat.com>
More information about the vdsm-patches
mailing list