Change in vdsm[master]: tests: Mark integration tests
by Nir Soffer
Nir Soffer has abandoned this change.
Change subject: tests: Mark integration tests
......................................................................
Abandoned
These tests pass now on travis in master, fixed by adding missing packages.
--
To view, visit https://gerrit.ovirt.org/55730
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: abandon
Gerrit-Change-Id: I056dc7534bde94a157e750f6699db4fe6a3aff27
Gerrit-PatchSet: 6
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>
Gerrit-Reviewer: Adam Litke <alitke(a)redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken(a)redhat.com>
Gerrit-Reviewer: Edward Haas <edwardh(a)redhat.com>
Gerrit-Reviewer: Francesco Romani <fromani(a)redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Jenkins CI RO
Gerrit-Reviewer: Nir Soffer <nsoffer(a)redhat.com>
Gerrit-Reviewer: Yaniv Bronhaim <ybronhei(a)redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation(a)ovirt.org>
7 years, 8 months
Change in vdsm[master]: tests: Make the run_tests*.sh scripts readable
by automation@ovirt.org
gerrit-hooks has posted comments on this change.
Change subject: tests: Make the run_tests*.sh scripts readable
......................................................................
Patch Set 2:
* Update tracker: IGNORE, no Bug-Url found
--
To view, visit https://gerrit.ovirt.org/55729
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: Iff09b1e71e2ca91ec3ef01490d019a893ff55b23
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken(a)redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Jenkins CI RO
Gerrit-Reviewer: Piotr Kliczewski <piotr.kliczewski(a)gmail.com>
Gerrit-Reviewer: Yaniv Bronhaim <ybronhei(a)redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation(a)ovirt.org>
Gerrit-HasComments: No
7 years, 8 months
Change in vdsm[master]: tests: Make the run_tests*.sh scripts readable
by Nir Soffer
Nir Soffer has abandoned this change.
Change subject: tests: Make the run_tests*.sh scripts readable
......................................................................
Abandoned
Similar change was already merged.
--
To view, visit https://gerrit.ovirt.org/55729
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: abandon
Gerrit-Change-Id: Iff09b1e71e2ca91ec3ef01490d019a893ff55b23
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken(a)redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Jenkins CI RO
Gerrit-Reviewer: Piotr Kliczewski <piotr.kliczewski(a)gmail.com>
Gerrit-Reviewer: Yaniv Bronhaim <ybronhei(a)redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation(a)ovirt.org>
7 years, 8 months
Change in vdsm[master]: qemuimg: Simplify and complete map tests
by Nir Soffer
Nir Soffer has uploaded a new change for review.
Change subject: qemuimg: Simplify and complete map tests
......................................................................
qemuimg: Simplify and complete map tests
Trying to understand map output:
- Use pprint to prety print the map
- Separte the single volume tests to make it easier to
understand the map
- Start to add assertions about the single volume cases.
To see the test output run with the -s flag:
./run_tests_local.sh qemuimg_test.py:TestMap -s
This should be squashed into the previous patch.
Change-Id: Ie765a13167ebd6f92c2125e6e634f227606854bb
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M lib/vdsm/qemuimg.py
M tests/qemuimg_test.py
2 files changed, 86 insertions(+), 16 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/51/65151/1
diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py
index a6e89d8..9692cca 100644
--- a/lib/vdsm/qemuimg.py
+++ b/lib/vdsm/qemuimg.py
@@ -211,16 +211,14 @@
def map(image):
cmd = [_qemuimg.cmd, "map", "--output", "json", image]
- # For simplicity, we always run commit in the image directory.
rc, out, err = commands.execCmd(cmd, raw=True)
if rc != 0:
raise QImgError(rc, out, err)
try:
- print "out: %s" % out
+ return json.loads(out)
except ValueError:
raise QImgError(rc, out, err, "Failed to process qemuimg map output")
-
class QemuImgOperation(object):
diff --git a/tests/qemuimg_test.py b/tests/qemuimg_test.py
index f00b830..56c3abb 100644
--- a/tests/qemuimg_test.py
+++ b/tests/qemuimg_test.py
@@ -20,6 +20,7 @@
import json
import os
+import pprint
from functools import partial
from monkeypatch import MonkeyPatch, MonkeyPatchScope
@@ -440,20 +441,87 @@
@expandPermutations
class TestMap(TestCaseBase):
- @permutations([
- # format, size
- (qemuimg.FORMAT.RAW, 0),
- (qemuimg.FORMAT.QCOW2, 0),
- (qemuimg.FORMAT.RAW, 1048576),
- (qemuimg.FORMAT.QCOW2, 1048576)
- ])
- def test_map_single_volume(self, format, size):
+ def test_raw_empty(self):
+ with namedTemporaryDir() as tmpdir:
+ size = 1048576
+ image = os.path.join(tmpdir, "base.img")
+ qemuimg.create(image, size=size, format=qemuimg.FORMAT.RAW)
+ img_map = qemuimg.map(image)
+ print
+ pprint.pprint(img_map, indent=4)
+
+ self.assertEqual(1, len(img_map))
+
+ # Empty run
+ run = img_map[0]
+ self.assertEqual(run["length"], size)
+ self.assertFalse(run["data"])
+ self.assertTrue(run["zero"])
+
+ def test_raw_one_block(self):
with namedTemporaryDir() as tmpdir:
image = os.path.join(tmpdir, "base.img")
- make_image(image, size, format, 0, "1.1")
- map = qemuimg.map(image)
+ qemuimg.create(image, size=1048576, format=qemuimg.FORMAT.RAW)
+ qemu_pattern_write(image, qemuimg.FORMAT.RAW, offset="64k",
+ len='4k', pattern=0xf0)
+ img_map = qemuimg.map(image)
+ print
+ pprint.pprint(img_map, indent=4)
- def test_map_chain(self):
+ self.assertEqual(3, len(img_map))
+
+ # Empty run
+ run = img_map[0]
+ self.assertEqual(run["length"], 64*1024)
+ self.assertFalse(run["data"])
+ self.assertTrue(run["zero"])
+
+ # Data run
+ run = img_map[1]
+ self.assertEqual(run["length"], 4*1024)
+ self.assertTrue(run["data"])
+ self.assertFalse(run["zero"])
+
+ # Empty run
+ run = img_map[2]
+ self.assertEqual(run["length"], (1024-68)*1024)
+ self.assertFalse(run["data"])
+ self.assertTrue(run["zero"])
+
+ @permutations([("0.10",), ("1.1",)])
+ def test_qcow2_empty(self, qcow2_compat):
+ with namedTemporaryDir() as tmpdir:
+ size = 1048576
+ image = os.path.join(tmpdir, "base.img")
+ qemuimg.create(image, size=size, format=qemuimg.FORMAT.QCOW2,
+ qcow2Compat=qcow2_compat)
+ img_map = qemuimg.map(image)
+ print
+ pprint.pprint(img_map, indent=4)
+
+ self.assertEqual(1, len(img_map))
+
+ # Empty run
+ run = img_map[0]
+ self.assertEqual(run["length"], size)
+ self.assertFalse(run["data"])
+ self.assertTrue(run["zero"])
+
+
+ @permutations([("0.10",), ("1.1",)])
+ def test_qcow2_one_block(self, qcow2_compat):
+ with namedTemporaryDir() as tmpdir:
+ image = os.path.join(tmpdir, "base.img")
+ qemuimg.create(image, size=1048576, format=qemuimg.FORMAT.QCOW2,
+ qcow2Compat=qcow2_compat)
+ qemu_pattern_write(image, qemuimg.FORMAT.RAW, offset="64k",
+ len='32k', pattern=0xf0)
+ img_map = qemuimg.map(image)
+ print
+ pprint.pprint(img_map, indent=4)
+
+ @permutations([("0.10",), ("1.1",)])
+ def test_chain(self, qcow2_compat):
with namedTemporaryDir() as tmpdir:
parent = None
chain = []
@@ -461,11 +529,15 @@
vol = os.path.join(tmpdir, "vol%d.img" % i)
format = (qemuimg.FORMAT.RAW if i == 0 else
qemuimg.FORMAT.QCOW2)
- make_image(vol, 1048576, format, i, "1.1", parent)
+ make_image(vol, 1048576, format, i, qcow2_compat, parent)
chain.append(vol)
parent = vol
- map = qemuimg.map(chain[0])
+ print
+ for vol in reversed(chain):
+ print os.path.basename(vol)
+ img_map = qemuimg.map(vol)
+ pprint.pprint(img_map, indent=4)
def make_image(path, size, format, index, qcow2_compat, backing=None):
--
To view, visit https://gerrit.ovirt.org/65151
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie765a13167ebd6f92c2125e6e634f227606854bb
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>
7 years, 8 months
Change in vdsm[master]: tests: Change offset and len arguments type
by ahino@redhat.com
Ala Hino has uploaded a new change for review.
Change subject: tests: Change offset and len arguments type
......................................................................
tests: Change offset and len arguments type
Change offset and len arguments type from string to integer.
Change-Id: I0118332c75db873c3fb8c54fc0bced208d9c50e9
Signed-off-by: Ala Hino <ahino(a)redhat.com>
---
M tests/qemuimg_test.py
M tests/storagetestlib.py
M tests/storagetestlib_test.py
3 files changed, 17 insertions(+), 16 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/74/65174/1
diff --git a/tests/qemuimg_test.py b/tests/qemuimg_test.py
index f6e8b35..238985f 100644
--- a/tests/qemuimg_test.py
+++ b/tests/qemuimg_test.py
@@ -408,14 +408,14 @@
op.wait_for_completion()
for i in range(base, top + 1):
- offset = "{}k".format(i)
+ offset = i * 1024
pattern = 0xf0 + i
# The base volume must have the data from all the volumes
# merged into it.
format = (qemuimg.FORMAT.RAW if i == 0 else
qemuimg.FORMAT.QCOW2)
qemu_pattern_verify(base_vol, format, offset=offset,
- len='1k', pattern=pattern)
+ len=1024, pattern=pattern)
if i > base:
# internal and top volumes should keep the data, we
# may want to wipe this data when deleting the volumes
@@ -440,5 +440,6 @@
def make_image(path, size, format, index, qcow2_compat, backing=None):
qemuimg.create(path, size=size, format=format, qcow2Compat=qcow2_compat,
backing=backing)
- qemu_pattern_write(path, format, offset="%dk" % index, len='1k',
+ offset = index * 1024
+ qemu_pattern_write(path, format, offset=offset, len=1024,
pattern=0xf0 + index)
diff --git a/tests/storagetestlib.py b/tests/storagetestlib.py
index 24cd27e..959a5fa 100644
--- a/tests/storagetestlib.py
+++ b/tests/storagetestlib.py
@@ -272,16 +272,16 @@
pass
-def qemu_pattern_write(path, format, offset='512', len='1k', pattern=5):
- write_cmd = 'write -P %d %s %s' % (pattern, offset, len)
+def qemu_pattern_write(path, format, offset=512, len=1024, pattern=5):
+ write_cmd = 'write -P %d %d %d' % (pattern, offset, len)
cmd = ['qemu-io', '-f', format, '-c', write_cmd, path]
rc, out, err = commands.execCmd(cmd, raw=True)
if rc != 0:
raise cmdutils.Error(cmd, rc, out, err)
-def qemu_pattern_verify(path, format, offset='512', len='1k', pattern=5):
- read_cmd = 'read -P %d -s 0 -l %s %s %s' % (pattern, len, offset, len)
+def qemu_pattern_verify(path, format, offset=512, len=1024, pattern=5):
+ read_cmd = 'read -P %d -s 0 -l %d %d %d' % (pattern, len, offset, len)
cmd = ['qemu-io', '-f', format, '-c', read_cmd, path]
rc, out, err = commands.execCmd(cmd, raw=True)
if rc != 0:
@@ -304,10 +304,10 @@
# This allows us to verify the integrity of the whole chain.
for i, vol in enumerate(vol_list):
vol_fmt = sc.fmt2str(vol.getFormat())
- offset = "{}k".format(i)
+ offset = i * 1024
pattern = 0xf0 + i
qemu_pattern_write(vol.volumePath, vol_fmt, offset=offset,
- len='1k', pattern=pattern)
+ len=1024, pattern=pattern)
def verify_qemu_chain(vol_list):
@@ -317,24 +317,24 @@
top_vol = vol_list[-1]
top_vol_fmt = sc.fmt2str(top_vol.getFormat())
for i, vol in enumerate(vol_list):
- offset = "{}k".format(i)
+ offset = i * 1024
pattern = 0xf0 + i
# Check that the correct pattern can be read through the top volume
qemu_pattern_verify(top_vol.volumePath, top_vol_fmt, offset=offset,
- len='1k', pattern=pattern)
+ len=1024, pattern=pattern)
# Check the volume where the pattern was originally written
vol_fmt = sc.fmt2str(vol.getFormat())
- qemu_pattern_verify(vol.volumePath, vol_fmt, offset=offset, len='1k',
+ qemu_pattern_verify(vol.volumePath, vol_fmt, offset=offset, len=1024,
pattern=pattern)
# Check that the next offset contains zeroes. If we know this layer
# has zeroes at next_offset we can be sure that data read at the same
# offset in the next layer belongs to that layer.
- next_offset = "{}K".format(i + 1)
+ next_offset = (i + 1) * 1024
qemu_pattern_verify(vol.volumePath, vol_fmt, offset=next_offset,
- len='1k', pattern=0)
+ len=1024, pattern=0)
def make_qemu_chain(env, size, base_vol_fmt, chain_len):
diff --git a/tests/storagetestlib_test.py b/tests/storagetestlib_test.py
index a7d6a2c..170082d 100644
--- a/tests/storagetestlib_test.py
+++ b/tests/storagetestlib_test.py
@@ -218,8 +218,8 @@
qemu_pattern_verify(path, img_format)
@permutations((
- ('0', '128'),
- ('10k', '5k')
+ (0, 128),
+ (10*1024, 5*1024)
))
def test_match_custom_offset_and_len(self, offset, len):
with namedTemporaryDir() as tmpdir:
--
To view, visit https://gerrit.ovirt.org/65174
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0118332c75db873c3fb8c54fc0bced208d9c50e9
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ala Hino <ahino(a)redhat.com>
7 years, 8 months
Change in vdsm[master]: tests: Rename storagetestlibTests.py to new Vdsm convention
by ahino@redhat.com
Ala Hino has uploaded a new change for review.
Change subject: tests: Rename storagetestlibTests.py to new Vdsm convention
......................................................................
tests: Rename storagetestlibTests.py to new Vdsm convention
Change-Id: Ida07628aba9ab9813489f75c2ddd77ef6ed437e7
Signed-off-by: Ala Hino <ahino(a)redhat.com>
---
M tests/Makefile.am
R tests/storagetestlib_test.py
2 files changed, 2 insertions(+), 2 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/73/65173/1
diff --git a/tests/Makefile.am b/tests/Makefile.am
index dcb36f8..1ee0b45 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -119,7 +119,7 @@
storagefakelibTests.py \
storageMailboxTests.py \
storageServerTests.py \
- storagetestlibTests.py \
+ storagetestlib_test.py \
storage_asyncevent_test.py \
storage_check_test.py \
storage_directio_test.py \
@@ -233,7 +233,7 @@
storage_volume_metadata_test.py \
storage_workarounds_test.py \
storagefakelibTests.py \
- storagetestlibTests.py \
+ storagetestlib_test.py \
toolBondingTests.py \
unicode_test.py \
utilsTests.py \
diff --git a/tests/storagetestlibTests.py b/tests/storagetestlib_test.py
similarity index 100%
rename from tests/storagetestlibTests.py
rename to tests/storagetestlib_test.py
--
To view, visit https://gerrit.ovirt.org/65173
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ida07628aba9ab9813489f75c2ddd77ef6ed437e7
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ala Hino <ahino(a)redhat.com>
7 years, 8 months
Change in vdsm[master]: procwatch: Port to python 3
by Nir Soffer
Nir Soffer has uploaded a new change for review.
Change subject: procwatch: Port to python 3
......................................................................
procwatch: Port to python 3
Fix test_recv and test_write to work with python 3.
Change-Id: I2761035a9a503ca283568e530c7b83ec53d104b6
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M tests/Makefile.am
M tests/procwatch_test.py
2 files changed, 5 insertions(+), 6 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/80/65080/1
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7135718..faa1df4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -208,7 +208,6 @@
outOfProcessTests.py \
periodicTests.py \
persistentDictTests.py \
- procwatch_test.py \
properties_test.py \
protocoldetectorTests.py \
qemuimg_test.py \
diff --git a/tests/procwatch_test.py b/tests/procwatch_test.py
index c97e920..6dad27a 100644
--- a/tests/procwatch_test.py
+++ b/tests/procwatch_test.py
@@ -38,7 +38,7 @@
(['sh', '-c', 'echo -n "%s" >&2'], False, True),
])
def test_receive(self, cmd, recv_out, recv_err):
- text = bytes('Hello World')
+ text = 'Hello World'
received = bytearray()
def recv_data(buffer):
@@ -60,14 +60,14 @@
retcode = process.wait()
self.assertEqual(retcode, 0)
- self.assertEqual(text, received)
+ self.assertEqual(text, received.decode('ascii'))
@permutations([
(['cat'], True, False),
(['sh', '-c', 'cat >&2'], False, True),
])
def test_write(self, cmd, recv_out, recv_err):
- text = bytes('Hello World')
+ data = b'Hello World'
received = bytearray()
def recv_data(buffer):
@@ -81,7 +81,7 @@
recv_data if recv_out else self.unexpected_data,
recv_data if recv_err else self.unexpected_data)
- process.stdin.write(text)
+ process.stdin.write(data)
process.stdin.flush()
process.stdin.close()
@@ -91,7 +91,7 @@
retcode = process.wait()
self.assertEqual(retcode, 0)
- self.assertEqual(text, str(received))
+ self.assertEqual(data, received)
def test_timeout(self):
process = self.start_process(["sleep", "5"])
--
To view, visit https://gerrit.ovirt.org/65080
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2761035a9a503ca283568e530c7b83ec53d104b6
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>
7 years, 8 months
Change in vdsm[master]: procwatch: Rename closed property to watching
by Nir Soffer
Nir Soffer has uploaded a new change for review.
Change subject: procwatch: Rename closed property to watching
......................................................................
procwatch: Rename closed property to watching
Closed is good term for a stream, but this class is not a stream. The
meaning of the "closed" state is that the watcher has nothing to watch,
so "watching" seems like a good name.
Change-Id: I6d6ec49a848af3ba95ebbcb70333e63b9a28b732
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M lib/vdsm/procwatch.py
M lib/vdsm/qemuimg.py
M tests/procwatch_test.py
3 files changed, 8 insertions(+), 7 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/79/65079/1
diff --git a/lib/vdsm/procwatch.py b/lib/vdsm/procwatch.py
index a75cbc7..3cc628b 100644
--- a/lib/vdsm/procwatch.py
+++ b/lib/vdsm/procwatch.py
@@ -63,8 +63,9 @@
self._poll_event(fileno)
@property
- def closed(self):
- return len(self._iocb) == 0
+ def watching(self):
+ return bool(self._iocb)
+
def receive(self, timeout=None):
"""
@@ -76,7 +77,7 @@
else:
endtime = utils.monotonic_time() + timeout
- while not self.closed:
+ while self.watching:
if timeout is not None:
poll_remaining = endtime - utils.monotonic_time()
if poll_remaining <= 0:
diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py
index 9133587..d5a10c9 100644
--- a/lib/vdsm/qemuimg.py
+++ b/lib/vdsm/qemuimg.py
@@ -249,7 +249,7 @@
def poll(self, timeout=None):
self._watcher.receive(timeout=timeout)
- if not self._watcher.closed:
+ if self._watcher.watching:
return
self._process.wait()
diff --git a/tests/procwatch_test.py b/tests/procwatch_test.py
index 53f2548..269142b 100644
--- a/tests/procwatch_test.py
+++ b/tests/procwatch_test.py
@@ -54,7 +54,7 @@
recv_data if recv_out else self.unexpected_data,
recv_data if recv_err else self.unexpected_data)
- while not watcher.closed:
+ while watcher.watching:
watcher.receive()
retcode = process.wait()
@@ -85,7 +85,7 @@
process.stdin.flush()
process.stdin.close()
- while not watcher.closed:
+ while watcher.watching:
watcher.receive()
retcode = process.wait()
@@ -101,7 +101,7 @@
with self.assertElapsed(2):
watcher.receive(2)
- self.assertEqual(watcher.closed, False)
+ self.assertEqual(watcher.watching, True)
process.terminate()
--
To view, visit https://gerrit.ovirt.org/65079
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6d6ec49a848af3ba95ebbcb70333e63b9a28b732
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>
7 years, 8 months
Change in vdsm[master]: procwatch: Specify stdout and stderr explicitly
by Nir Soffer
Nir Soffer has uploaded a new change for review.
Change subject: procwatch: Specify stdout and stderr explicitly
......................................................................
procwatch: Specify stdout and stderr explicitly
Unlike subprocess.Popen, cpopen.CPopen is always creating a pipe for
stdin, stdout and stderr. Specifying stdout and stderr allows replacing
cpopen.CPopen with subprocess.Popen, required for python 3 support.
Change-Id: I4a88d14f02763290116b167f83462edb28235ad2
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M tests/procwatch_test.py
1 file changed, 3 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/78/65078/1
diff --git a/tests/procwatch_test.py b/tests/procwatch_test.py
index 1995727..53f2548 100644
--- a/tests/procwatch_test.py
+++ b/tests/procwatch_test.py
@@ -21,6 +21,7 @@
from __future__ import absolute_import
import operator
import signal
+import subprocess
from testlib import VdsmTestCase
from testlib import expandPermutations, permutations
@@ -129,4 +130,5 @@
raise AssertionError("Unexpected data: %r" % data)
def start_process(self, cmd):
- return compat.CPopen(cmd)
+ return compat.CPopen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
--
To view, visit https://gerrit.ovirt.org/65078
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4a88d14f02763290116b167f83462edb28235ad2
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>
7 years, 8 months
Change in vdsm[master]: procwatch: Replace command with process
by Nir Soffer
Nir Soffer has uploaded a new change for review.
Change subject: procwatch: Replace command with process
......................................................................
procwatch: Replace command with process
ProcessWatcher is watching child process, not commands, which can be
confused with abstract things. Rename the argument and instance variable
in the class, the tests, and the user code.
Change-Id: I3a0265d7847d0fffd7cf0c60d1feb87621ee5ac5
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M lib/vdsm/procwatch.py
M lib/vdsm/qemuimg.py
M tests/procwatch_test.py
3 files changed, 33 insertions(+), 33 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/77/65077/1
diff --git a/lib/vdsm/procwatch.py b/lib/vdsm/procwatch.py
index fd4b543..a75cbc7 100644
--- a/lib/vdsm/procwatch.py
+++ b/lib/vdsm/procwatch.py
@@ -29,16 +29,16 @@
class ProcessWatcher(object):
- def __init__(self, command, stdoutcb, stderrcb):
- self._command = command
+ def __init__(self, process, stdoutcb, stderrcb):
+ self._process = process
self._poll = select.epoll()
self._iocb = {}
# In case both stderr and stdout are using the same fd the
# output is squashed to the stdout (given the order of the
# entries in the dictionary)
- self._iocb[self._command.stderr.fileno()] = stderrcb
- self._iocb[self._command.stdout.fileno()] = stdoutcb
+ self._iocb[self._process.stderr.fileno()] = stderrcb
+ self._iocb[self._process.stdout.fileno()] = stdoutcb
for fd in self._iocb:
self._poll.register(fd, select.EPOLLIN)
@@ -68,7 +68,7 @@
def receive(self, timeout=None):
"""
- Receiving data from the command can raise OSError
+ Receiving data from the process can raise OSError
exceptions as described in read(2).
"""
if timeout is None:
diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py
index 0527a15..9133587 100644
--- a/lib/vdsm/qemuimg.py
+++ b/lib/vdsm/qemuimg.py
@@ -202,9 +202,9 @@
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._process = CPopen(cmd, cwd=cwd, deathSignal=signal.SIGKILL)
self._watcher = procwatch.ProcessWatcher(
- self._command, self._recvstdout, self._recvstderr)
+ self._process, self._recvstdout, self._recvstderr)
def _recvstderr(self, buffer):
self._stderr += buffer
@@ -244,7 +244,7 @@
@property
def finished(self):
- return self._command.poll() is not None
+ return self._process.poll() is not None
def poll(self, timeout=None):
self._watcher.receive(timeout=timeout)
@@ -252,14 +252,14 @@
if not self._watcher.closed:
return
- self._command.wait()
+ self._process.wait()
if self._aborted:
raise exception.ActionStopped()
- cmdutils.retcode_log_line(self._command.returncode, self.error)
- if self._command.returncode != 0:
- raise QImgError(self._command.returncode, "", self.error)
+ cmdutils.retcode_log_line(self._process.returncode, self.error)
+ if self._process.returncode != 0:
+ raise QImgError(self._process.returncode, "", self.error)
def wait_for_completion(self):
timeout = config.getint("irs", "progress_interval")
@@ -268,9 +268,9 @@
_log.debug('qemu-img operation progress: %s%%', self.progress)
def abort(self):
- if self._command.poll() is None:
+ if self._process.poll() is None:
self._aborted = True
- self._command.terminate()
+ self._process.terminate()
def resize(image, newSize, format=None):
diff --git a/tests/procwatch_test.py b/tests/procwatch_test.py
index d66d3ff..0a5fe2d 100644
--- a/tests/procwatch_test.py
+++ b/tests/procwatch_test.py
@@ -47,16 +47,16 @@
cmd[-1] = cmd[-1] % text
- c = self.startCommand(cmd)
+ process = self.start_process(cmd)
watcher = procwatch.ProcessWatcher(
- c,
+ process,
recv_data if recv_out else self.unexpected_data,
recv_data if recv_err else self.unexpected_data)
while not watcher.closed:
watcher.receive()
- retcode = c.wait()
+ retcode = process.wait()
self.assertEqual(retcode, 0)
self.assertEqual(text, received)
@@ -74,59 +74,59 @@
# defined in the parent function.
operator.iadd(received, buffer)
- c = self.startCommand(cmd)
+ process = self.start_process(cmd)
watcher = procwatch.ProcessWatcher(
- c,
+ process,
recv_data if recv_out else self.unexpected_data,
recv_data if recv_err else self.unexpected_data)
- c.stdin.write(text)
- c.stdin.flush()
- c.stdin.close()
+ process.stdin.write(text)
+ process.stdin.flush()
+ process.stdin.close()
while not watcher.closed:
watcher.receive()
- retcode = c.wait()
+ retcode = process.wait()
self.assertEqual(retcode, 0)
self.assertEqual(text, str(received))
def test_timeout(self):
- c = self.startCommand(["sleep", "5"])
+ process = self.start_process(["sleep", "5"])
watcher = procwatch.ProcessWatcher(
- c, self.unexpected_data, self.unexpected_data)
+ process, self.unexpected_data, self.unexpected_data)
with self.assertElapsed(2):
watcher.receive(2)
self.assertEqual(watcher.closed, False)
- c.terminate()
+ process.terminate()
- self.assertEqual(c.wait(), -signal.SIGTERM)
+ self.assertEqual(process.wait(), -signal.SIGTERM)
@permutations((
('kill', -signal.SIGKILL),
('terminate', -signal.SIGTERM),
))
def test_signals(self, method, expected_retcode):
- c = self.startCommand(["sleep", "2"])
+ process = self.start_process(["sleep", "2"])
watcher = procwatch.ProcessWatcher(
- c, self.unexpected_data, self.unexpected_data)
+ process, self.unexpected_data, self.unexpected_data)
- getattr(c, method)()
+ getattr(process, method)()
try:
with self.assertElapsed(0):
watcher.receive(2)
finally:
- retcode = c.wait()
+ retcode = process.wait()
self.assertEqual(retcode, expected_retcode)
def unexpected_data(self, data):
raise AssertionError("Unexpected data: %r" % data)
- def startCommand(self, command):
- return compat.CPopen(command)
+ def start_process(self, cmd):
+ return compat.CPopen(cmd)
--
To view, visit https://gerrit.ovirt.org/65077
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3a0265d7847d0fffd7cf0c60d1feb87621ee5ac5
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>
7 years, 8 months