Change in vdsm[master]: utils: Fix terminating context manager
by automation@ovirt.org
gerrit-hooks has posted comments on this change.
Change subject: utils: Fix terminating context manager
......................................................................
Patch Set 2:
* Update tracker: IGNORE, no Bug-Url found
* Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url.
* Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 'ovirt-4.0'])
--
To view, visit https://gerrit.ovirt.org/65294
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I8674c9c3c2118041c74213cd8ce0d383086d6cbf
Gerrit-PatchSet: 2
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: Francesco Romani <fromani(a)redhat.com>
Gerrit-Reviewer: Nir Soffer <nsoffer(a)redhat.com>
Gerrit-Reviewer: Piotr Kliczewski <piotr.kliczewski(a)gmail.com>
Gerrit-Reviewer: gerrit-hooks <automation(a)ovirt.org>
Gerrit-HasComments: No
7 years, 8 months
Change in vdsm[master]: storage: Add inplace virt-sparsify support
by Nir Soffer
Nir Soffer has posted comments on this change.
Change subject: storage: Add inplace virt-sparsify support
......................................................................
Patch Set 13:
From the discussion with Richard and Kevin, we learned that we can use this only on the top volume in an image. We need to validate that the volume requested by the caller is the leaf volume, and fail the request if not.
We also must prevent usage of this verb on a template image used by any other image. Doing this check safely may be hard since it can be done only on the spm.
Finally we must protect the image during the operation using volume generation and mark the image as illegal, so another host cannot consume this image while we are sparsifying it. See the latest version of copy_data for the details how it is done.
--
To view, visit https://gerrit.ovirt.org/57347
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I6ac2bb1fbd2acbe0fc47694d17313c6ccd01a227
Gerrit-PatchSet: 13
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Shmuel Leib Melamud <smelamud(a)redhat.com>
Gerrit-Reviewer: Adam Litke <alitke(a)redhat.com>
Gerrit-Reviewer: Allon Mureinik <amureini(a)redhat.com>
Gerrit-Reviewer: Francesco Romani <fromani(a)redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Maor Lipchuk <mlipchuk(a)redhat.com>
Gerrit-Reviewer: Nir Soffer <nsoffer(a)redhat.com>
Gerrit-Reviewer: Piotr Kliczewski <piotr.kliczewski(a)gmail.com>
Gerrit-Reviewer: Shahar Havivi <shavivi(a)redhat.com>
Gerrit-Reviewer: Shmuel Leib Melamud <smelamud(a)redhat.com>
Gerrit-Reviewer: Shmuel Melamud <smelamud(a)redhat.com>
Gerrit-Reviewer: Yaniv Kaul <ykaul(a)redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation(a)ovirt.org>
Gerrit-HasComments: No
7 years, 8 months
Change in vdsm[master]: Revert "build tests: Require NOSE 1.3.7 and up for running t...
by edwardh@redhat.com
Edward Haas has uploaded a new change for review.
Change subject: Revert "build tests: Require NOSE 1.3.7 and up for running tests"
......................................................................
Revert "build tests: Require NOSE 1.3.7 and up for running tests"
NOSE is used during the VDSM build ('make rpm') where builders do not
use pip, just rpms provided by the standard repos.
Therefore, enforcing the nose version of 1.3.7 is not possible until it
is updated in the repos of centos7/rhel7.
This reverts commit 4e729ddd2b243d0953e2de5d31c42fc59859bf23.
Change-Id: I175c0752a5929d1b644cd41cf8d111bcce10f32d
Signed-off-by: Edward Haas <edwardh(a)redhat.com>
---
M Makefile.am
1 file changed, 1 insertion(+), 6 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/35/64035/1
diff --git a/Makefile.am b/Makefile.am
index 51fe2a5..aefd2b3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -132,12 +132,7 @@
.PHONY: tests
tests:
- @version=`nosetests --version | cut -d' ' -f3`; \
- if build-aux/vercmp $$version "1.3.7"; then \
- echo "Error: NOSE is too old, please install NOSE 1.3.7 or later"; \
- exit 1; \
- fi
- @$(MAKE) -C tests/ check
+ $(MAKE) -C tests/ check
all-local: \
vdsm.spec
--
To view, visit https://gerrit.ovirt.org/64035
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I175c0752a5929d1b644cd41cf8d111bcce10f32d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Edward Haas <edwardh(a)redhat.com>
7 years, 8 months
Change in vdsm[master]: travis: Separate Fedora and Centos builds
by Nir Soffer
Nir Soffer has uploaded a new change for review.
Change subject: travis: Separate Fedora and Centos builds
......................................................................
travis: Separate Fedora and Centos builds
Add build matrix, creating two sub-build for each build, one using the
Fedora image and the other the CentOS image.
Change-Id: I0fe524df5f4baf4f3c24f8da56c30d52ee22f8b1
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M .travis.yml
1 file changed, 7 insertions(+), 4 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/84/65284/1
diff --git a/.travis.yml b/.travis.yml
index f167e8d..c5d2ec3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,11 +7,14 @@
git:
depth: 9999999
+env:
+ matrix:
+ - DOCKER_IMAGE=nirs/vdsm-centos
+ - DOCKER_IMAGE=nirs/vdsm-fedora
+
before_install:
- docker --version
- - docker pull nirs/vdsm-centos
- - docker pull nirs/vdsm-fedora
+ - docker pull $DOCKER_IMAGE
script:
- - docker run --privileged --rm -it -v `pwd`:/vdsm:Z nirs/vdsm-centos bash -c "cd /vdsm && ./autogen.sh --system && make && make check"
- - docker run --privileged --rm -it -v `pwd`:/vdsm:Z nirs/vdsm-fedora bash -c "cd /vdsm && ./autogen.sh --system && make && make check"
+ - docker run --privileged --rm -it -v `pwd`:/vdsm:Z $DOCKER_IMAGE bash -c "cd /vdsm && ./autogen.sh --system && make && make check"
--
To view, visit https://gerrit.ovirt.org/65284
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0fe524df5f4baf4f3c24f8da56c30d52ee22f8b1
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>
Gerrit-Reviewer: Nir Soffer <nsoffer(a)redhat.com>
7 years, 8 months
Change in vdsm[master]: dokerfile: Rename Dockerfile to Dockerfile.centos
by Nir Soffer
Nir Soffer has uploaded a new change for review.
Change subject: dokerfile: Rename Dockerfile to Dockerfile.centos
......................................................................
dokerfile: Rename Dockerfile to Dockerfile.centos
We need another dockerfile for Fedora.
Change-Id: Ibd8245d5a5f7eabe01b8f33ab1e4210d3edf3777
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
R contrib/Dockerfile.centos
1 file changed, 0 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/69/65269/1
diff --git a/contrib/Dockerfile b/contrib/Dockerfile.centos
similarity index 100%
rename from contrib/Dockerfile
rename to contrib/Dockerfile.centos
--
To view, visit https://gerrit.ovirt.org/65269
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibd8245d5a5f7eabe01b8f33ab1e4210d3edf3777
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]: readme: Covert to markdown format
by Nir Soffer
Nir Soffer has uploaded a new change for review.
Change subject: readme: Covert to markdown format
......................................................................
readme: Covert to markdown format
Markdown is nicer to work with and render nicer in github.
Change-Id: I74ce4bcb8bb276e98fc6466ace7709733dd809c1
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M Makefile.am
R README.md
M vdsm.spec.in
3 files changed, 26 insertions(+), 25 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/60/65260/1
diff --git a/Makefile.am b/Makefile.am
index 64cd9a0..789221c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,6 +19,9 @@
#
TOX_MIN_VERSION = 2.1.1
+# We don't want the standard gnu file setup (README, INSTALL, etc.)
+AUTOMAKE_OPTIONS = foreign
+
SUBDIRS = \
client \
contrib \
@@ -42,6 +45,7 @@
EXTRA_DIST = \
.gitignore \
README.logging \
+ README.md \
autobuild.sh \
autogen.sh \
build-aux/pkg-version \
diff --git a/README b/README.md
similarity index 68%
rename from README
rename to README.md
index 955dfa9..9398827 100644
--- a/README
+++ b/README.md
@@ -1,5 +1,4 @@
- Vdsm: Virtual Desktop Server Manager
- ====================================
+# Vdsm: Virtual Desktop Server Manager
The Vdsm service exposes an API for managing virtualization
hosts running the KVM hypervisor technology. Vdsm manages and monitors
@@ -7,53 +6,53 @@
creation, other host administration tasks, statistics gathering, and
log collection.
-Installation
-============
+
+## Installation
The Vdsm service can be used by following the standard autotools
installation process, documented in the INSTALL file. As a quick
start you can do
- ./configure --prefix=/usr --sysconfdir=/etc \
+ ./configure --prefix=/usr --sysconfdir=/etc \
--localstatedir=/var --libdir=/usr/lib
- make
- sudo make install
+ make
+ sudo make install
In order to start vdsm at first try, please perform:
- vdsm-tool configure [--force]
+ vdsm-tool configure [--force]
- * --force flag will override old conf files with vdsm defaults and restart
- services that were configured (if were already running)
+--force flag will override old conf files with vdsm defaults and restart
+services that were configured (if were already running)
-Packaging
-=========
+
+## Packaging
The 'vdsm.spec' file demonstrates how to distribute Vdsm as an RPM
package.
-Getting Help
-============
+
+## Getting Help
There are two mailing lists for discussions:
- - For technical discussions about the project and its code base.
+- For technical discussions about the project and its code base.
- http://lists.ovirt.org/mailman/listinfo/devel
+ http://lists.ovirt.org/mailman/listinfo/devel
- - For questions by users, who do not want to be swamped by
- technicalities.
+- For questions by users, who do not want to be swamped by
+ technicalities.
- http://lists.ovirt.org/mailman/listinfo/users
+ http://lists.ovirt.org/mailman/listinfo/users
The developers also hang out on IRC at #vdsm hosted on freenode.net
The latest upstream code can be obtained from GIT:
- git clone https://gerrit.ovirt.org/vdsm
+ git clone https://gerrit.ovirt.org/vdsm
-Licensing
-=========
+
+## Licensing
Vdsm is provided under the terms of the GNU General Public License,
version 2 or later. Please see the COPYING file for complete GPLv2+
@@ -71,5 +70,3 @@
If you modify this program, you may extend this exception to your
version, but you are not obligated to do so. If you do not wish to do
so, delete this exception statement from your version.
-
--- End of readme
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 2842afa..b91ad3b 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -895,7 +895,7 @@
exit 0
%files
-%doc README
+%doc README.md
%doc lib/vdsm/vdsm.conf.sample
%doc README.logging
%license COPYING
--
To view, visit https://gerrit.ovirt.org/65260
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I74ce4bcb8bb276e98fc6466ace7709733dd809c1
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]: qemuimg: Add wrapper to execute command
by ahino@redhat.com
Ala Hino has uploaded a new change for review.
Change subject: qemuimg: Add wrapper to execute command
......................................................................
qemuimg: Add wrapper to execute command
Add wrapper to execute qemuimg command and raise QImgError if error
encountered.
Change-Id: I3483a202f9543098ad75e8be8bf4b398d26c8e4a
Signed-off-by: Ala Hino <ahino(a)redhat.com>
---
M lib/vdsm/qemuimg.py
1 file changed, 11 insertions(+), 16 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/78/65178/1
diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py
index ef98149..c9e72ec 100644
--- a/lib/vdsm/qemuimg.py
+++ b/lib/vdsm/qemuimg.py
@@ -71,9 +71,7 @@
cmd.extend(("-f", format))
cmd.append(image)
- rc, out, err = commands.execCmd(cmd, raw=True)
- if rc != 0:
- raise QImgError(rc, out, err)
+ out = _run_cmd(cmd)
try:
qemu_info = _parse_qemuimg_json(out)
@@ -125,10 +123,7 @@
if size is not None:
cmd.append(str(size))
- rc, out, err = commands.execCmd(cmd, cwd=cwdPath)
-
- if rc != 0:
- raise QImgError(rc, out, err)
+ _run_cmd(cmd, cwd=cwdPath)
def check(image, format=None):
@@ -138,11 +133,7 @@
cmd.extend(("-f", format))
cmd.append(image)
- rc, out, err = commands.execCmd(cmd, raw=True)
-
- # FIXME: handle different error codes and raise errors accordingly
- if rc != 0:
- raise QImgError(rc, out, err)
+ out = _run_cmd(cmd)
try:
qemu_check = _parse_qemuimg_json(out)
@@ -300,10 +291,7 @@
cmd.extend(("-f", format))
cmd.extend((image, str(newSize)))
- rc, out, err = commands.execCmd(cmd)
-
- if rc != 0:
- raise QImgError(rc, out, err)
+ _run_cmd(cmd)
def rebase(image, backing, format=None, backingFormat=None, unsafe=False,
@@ -351,3 +339,10 @@
if value not in _QCOW2_COMPAT_SUPPORTED:
raise ValueError("Invalid compat version %r" % value)
return value
+
+
+def _run_cmd(cmd, cwd=None):
+ rc, out, err = commands.execCmd(cmd, raw=True, cwd=cwd)
+ if rc != 0:
+ raise QImgError(rc, out, err)
+ return out
--
To view, visit https://gerrit.ovirt.org/65178
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3483a202f9543098ad75e8be8bf4b398d26c8e4a
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]: qemuimg: Introduce InvalidOutput exception
by ahino@redhat.com
Ala Hino has uploaded a new change for review.
Change subject: qemuimg: Introduce InvalidOutput exception
......................................................................
qemuimg: Introduce InvalidOutput exception
Raised when the command output is not valid.
Change-Id: If3f801f05f130c2417e4946877e31030260269a1
Signed-off-by: Ala Hino <ahino(a)redhat.com>
---
M lib/vdsm/qemuimg.py
1 file changed, 20 insertions(+), 5 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/08/65208/1
diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py
index 28cddee..8f6dc35 100644
--- a/lib/vdsm/qemuimg.py
+++ b/lib/vdsm/qemuimg.py
@@ -65,6 +65,21 @@
self.cmd, self.ecode, self.stdout, self.stderr, self.message)
+class InvalidOutput(QImgError):
+ """
+ Raised when the command output is not valid.
+ """
+
+ def __init__(self, cmd, stdout, message):
+ self.cmd = cmd
+ self.stdout = stdout
+ self.message = message
+
+ def __str__(self):
+ return "cmd=%s, stdout=%s, message=%s" % (
+ self.cmd, self.stdout, self.message)
+
+
def info(image, format=None):
cmd = [_qemuimg.cmd, "info", "--output", "json"]
@@ -79,7 +94,7 @@
try:
qemu_info = _parse_qemuimg_json(out)
except ValueError:
- raise QImgError(cmd, rc, out, err, "Failed to process qemu-img output")
+ raise InvalidOutput(cmd, out, "Failed to process qemu-img output")
try:
info = {
@@ -87,7 +102,7 @@
'virtualsize': qemu_info['virtual-size'],
}
except KeyError as key:
- raise QImgError(cmd, rc, out, err, "Missing field: %r" % key)
+ raise InvalidOutput(cmd, out, "Missing field: %r" % key)
if 'cluster-size' in qemu_info:
info['clustersize'] = qemu_info['cluster-size']
@@ -97,7 +112,7 @@
try:
info['compat'] = qemu_info['format-specific']['data']['compat']
except KeyError:
- raise QImgError(cmd, rc, out, err, "'compat' expected but not found")
+ raise InvalidOutput(cmd, out, "'compat' expected but not found")
return info
@@ -148,11 +163,11 @@
try:
qemu_check = _parse_qemuimg_json(out)
except ValueError:
- raise QImgError(cmd, rc, out, err, "Failed to process qemu-img output")
+ raise InvalidOutput(cmd, out, "Failed to process qemu-img output")
try:
return {"offset": qemu_check["image-end-offset"]}
except KeyError:
- raise QImgError(cmd, rc, out, err, "unable to parse qemu-img check output")
+ raise InvalidOutput(cmd, out, "unable to parse qemu-img check output")
def convert(srcImage, dstImage, srcFormat=None, dstFormat=None,
--
To view, visit https://gerrit.ovirt.org/65208
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If3f801f05f130c2417e4946877e31030260269a1
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]: qemuimg: Add the command to QImgError
by ahino@redhat.com
Ala Hino has uploaded a new change for review.
Change subject: qemuimg: Add the command to QImgError
......................................................................
qemuimg: Add the command to QImgError
Change-Id: I226a54b29ae4afc3854056efea78767383b89619
Signed-off-by: Ala Hino <ahino(a)redhat.com>
---
M lib/vdsm/qemuimg.py
1 file changed, 5 insertions(+), 4 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/79/65179/1
diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py
index c9e72ec..26d0ec1 100644
--- a/lib/vdsm/qemuimg.py
+++ b/lib/vdsm/qemuimg.py
@@ -53,15 +53,16 @@
class QImgError(Exception):
- def __init__(self, ecode, stdout, stderr, message=None):
+ def __init__(self, cmd, ecode, stdout, stderr, message=None):
+ self.cmd = cmd
self.ecode = ecode
self.stdout = stdout
self.stderr = stderr
self.message = message
def __str__(self):
- return "ecode=%s, stdout=%s, stderr=%s, message=%s" % (
- self.ecode, self.stdout, self.stderr, self.message)
+ return "cmd=%s, ecode=%s, stdout=%s, stderr=%s, message=%s" % (
+ self.cmd, self.ecode, self.stdout, self.stderr, self.message)
def info(image, format=None):
@@ -344,5 +345,5 @@
def _run_cmd(cmd, cwd=None):
rc, out, err = commands.execCmd(cmd, raw=True, cwd=cwd)
if rc != 0:
- raise QImgError(rc, out, err)
+ raise QImgError(cmd, rc, out, err)
return out
--
To view, visit https://gerrit.ovirt.org/65179
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I226a54b29ae4afc3854056efea78767383b89619
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: Move CommandStream to new module
by Nir Soffer
Nir Soffer has uploaded a new change for review.
Change subject: procwatch: Move CommandStream to new module
......................................................................
procwatch: Move CommandStream to new module
Move CommandStream from the utils junkyard to the new procwatch module
and the tests to a new test module, with minimal changes to keep it
working.
Change-Id: I045569d350aad19049a33338a72b59e68ba91e5b
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
A lib/vdsm/procwatch.py
M lib/vdsm/qemuimg.py
M lib/vdsm/utils.py
M tests/Makefile.am
A tests/procwatch_test.py
M tests/utilsTests.py
M vdsm.spec.in
7 files changed, 221 insertions(+), 158 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/72/65072/1
diff --git a/lib/vdsm/procwatch.py b/lib/vdsm/procwatch.py
new file mode 100644
index 0000000..1ae168a
--- /dev/null
+++ b/lib/vdsm/procwatch.py
@@ -0,0 +1,85 @@
+#
+# Copyright 2014-2016 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+from __future__ import absolute_import
+
+import io
+import os
+import select
+
+from vdsm import utils
+
+
+class CommandStream(object):
+
+ def __init__(self, command, stdoutcb, stderrcb):
+ self._command = command
+ 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
+
+ for fd in self._iocb:
+ self._poll.register(fd, select.EPOLLIN)
+
+ def _poll_input(self, fileno):
+ self._iocb[fileno](os.read(fileno, io.DEFAULT_BUFFER_SIZE))
+
+ def _poll_event(self, fileno):
+ self._poll.unregister(fileno)
+ del self._iocb[fileno]
+
+ def _poll_timeout(self, timeout):
+ # TODO: Kill NoIntrPoll, stopping polling on EINTR and procesing events
+ # is good enough, we don't need to check timeout here, caller is
+ # checking if timeout has expired.
+ fdevents = utils.NoIntrPoll(self._poll.poll, timeout)
+
+ for fileno, event in fdevents:
+ if event & select.EPOLLIN:
+ self._poll_input(fileno)
+ elif event & (select.EPOLLHUP | select.EPOLLERR):
+ self._poll_event(fileno)
+
+ @property
+ def closed(self):
+ return len(self._iocb) == 0
+
+ def receive(self, timeout=None):
+ """
+ Receiving data from the command can raise OSError
+ exceptions as described in read(2).
+ """
+ if timeout is None:
+ poll_remaining = -1
+ else:
+ endtime = utils.monotonic_time() + timeout
+
+ while not self.closed:
+ if timeout is not None:
+ poll_remaining = endtime - utils.monotonic_time()
+ if poll_remaining <= 0:
+ break
+
+ self._poll_timeout(poll_remaining)
diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py
index 8eef8fa..8d60e4c 100644
--- a/lib/vdsm/qemuimg.py
+++ b/lib/vdsm/qemuimg.py
@@ -29,6 +29,7 @@
from . import utils
from . import cmdutils
from . import commands
+from . import procwatch
from .compat import CPopen
from . config import config
@@ -202,7 +203,7 @@
with_ioclass=utils.IOCLASS.IDLE)
_log.debug(cmdutils.command_log_line(cmd, cwd=cwd))
self._command = CPopen(cmd, cwd=cwd, deathSignal=signal.SIGKILL)
- self._stream = utils.CommandStream(
+ self._stream = procwatch.CommandStream(
self._command, self._recvstdout, self._recvstderr)
def _recvstderr(self, buffer):
diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py
index a428c8e..5d1d822 100644
--- a/lib/vdsm/utils.py
+++ b/lib/vdsm/utils.py
@@ -280,60 +280,6 @@
timeout = max(0, endtime - monotonic_time())
-class CommandStream(object):
- def __init__(self, command, stdoutcb, stderrcb):
- self._command = command
- 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
-
- for fd in self._iocb:
- self._poll.register(fd, select.EPOLLIN)
-
- def _poll_input(self, fileno):
- self._iocb[fileno](os.read(fileno, io.DEFAULT_BUFFER_SIZE))
-
- def _poll_event(self, fileno):
- self._poll.unregister(fileno)
- del self._iocb[fileno]
-
- def _poll_timeout(self, timeout):
- fdevents = NoIntrPoll(self._poll.poll, timeout)
-
- for fileno, event in fdevents:
- if event & select.EPOLLIN:
- self._poll_input(fileno)
- elif event & (select.EPOLLHUP | select.EPOLLERR):
- self._poll_event(fileno)
-
- @property
- def closed(self):
- return len(self._iocb) == 0
-
- def receive(self, timeout=None):
- """
- Receiving data from the command can raise OSError
- exceptions as described in read(2).
- """
- if timeout is None:
- poll_remaining = -1
- else:
- endtime = monotonic_time() + timeout
-
- while not self.closed:
- if timeout is not None:
- poll_remaining = endtime - monotonic_time()
- if poll_remaining <= 0:
- break
-
- self._poll_timeout(poll_remaining)
-
-
def stripNewLines(lines):
return [l[:-1] if l.endswith('\n') else l for l in lines]
diff --git a/tests/Makefile.am b/tests/Makefile.am
index dcb36f8..faa1df4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -95,6 +95,7 @@
periodicTests.py \
permutationTests.py \
persistentDictTests.py \
+ procwatch_test.py \
properties_test.py \
protocoldetectorTests.py \
pthreadTests.py \
diff --git a/tests/procwatch_test.py b/tests/procwatch_test.py
new file mode 100644
index 0000000..e6b9d7f
--- /dev/null
+++ b/tests/procwatch_test.py
@@ -0,0 +1,132 @@
+#
+# Copyright 2014-2016 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+from __future__ import absolute_import
+import signal
+import operator
+
+from testlib import VdsmTestCase
+from testlib import expandPermutations, permutations
+
+from vdsm import compat
+from vdsm import procwatch
+
+
+@expandPermutations
+class CommandStreamTests(VdsmTestCase):
+
+ def assertUnexpectedCall(self, data):
+ raise AssertionError("Unexpected data: %r" % data)
+
+ def _startCommand(self, command):
+ return compat.CPopen(command)
+
+ @permutations([
+ (['echo', '-n', '%s'], True, False),
+ (['sh', '-c', 'echo -n "%s" >&2'], False, True),
+ ])
+ def test_receive(self, cmd, recv_out, recv_err):
+ text = bytes('Hello World')
+ received = bytearray()
+
+ def recv_data(buffer):
+ # cannot use received += buffer with a variable
+ # defined in the parent function.
+ operator.iadd(received, buffer)
+
+ cmd[-1] = cmd[-1] % text
+
+ c = self._startCommand(cmd)
+ p = procwatch.CommandStream(
+ c,
+ recv_data if recv_out else self.assertUnexpectedCall,
+ recv_data if recv_err else self.assertUnexpectedCall)
+
+ while not p.closed:
+ p.receive()
+
+ retcode = c.wait()
+
+ self.assertEqual(retcode, 0)
+ self.assertEqual(text, received)
+
+ @permutations([
+ (['cat'], True, False),
+ (['sh', '-c', 'cat >&2'], False, True),
+ ])
+ def test_write(self, cmd, recv_out, recv_err):
+ text = bytes('Hello World')
+ received = bytearray()
+
+ def recv_data(buffer):
+ # cannot use received += buffer with a variable
+ # defined in the parent function.
+ operator.iadd(received, buffer)
+
+ c = self._startCommand(cmd)
+ p = procwatch.CommandStream(
+ c,
+ recv_data if recv_out else self.assertUnexpectedCall,
+ recv_data if recv_err else self.assertUnexpectedCall)
+
+ c.stdin.write(text)
+ c.stdin.flush()
+ c.stdin.close()
+
+ while not p.closed:
+ p.receive()
+
+ retcode = c.wait()
+
+ self.assertEqual(retcode, 0)
+ self.assertEqual(text, str(received))
+
+ def test_timeout(self):
+ c = self._startCommand(["sleep", "5"])
+ p = procwatch.CommandStream(c, self.assertUnexpectedCall,
+ self.assertUnexpectedCall)
+
+ with self.assertElapsed(2):
+ p.receive(2)
+
+ self.assertEqual(p.closed, False)
+
+ c.terminate()
+
+ self.assertEqual(c.wait(), -signal.SIGTERM)
+
+ @permutations((
+ ('kill', -signal.SIGKILL),
+ ('terminate', -signal.SIGTERM),
+ ))
+ def test_signals(self, method, expected_retcode):
+ c = self._startCommand(["sleep", "2"])
+ p = procwatch.CommandStream(c, self.assertUnexpectedCall,
+ self.assertUnexpectedCall)
+
+ getattr(c, method)()
+
+ try:
+ with self.assertElapsed(0):
+ p.receive(2)
+ finally:
+ retcode = c.wait()
+
+ self.assertEqual(retcode, expected_retcode)
diff --git a/tests/utilsTests.py b/tests/utilsTests.py
index cdbfd7b..5aa2c41 100644
--- a/tests/utilsTests.py
+++ b/tests/utilsTests.py
@@ -774,109 +774,6 @@
self.assertEqual(utils.round(n, size), result)
-@expandPermutations
-class CommandStreamTests(TestCaseBase):
-
- def assertUnexpectedCall(self, data):
- raise AssertionError("Unexpected data: %r" % data)
-
- def _startCommand(self, command):
- return cpopen.CPopen(command)
-
- @permutations([
- (['echo', '-n', '%s'], True, False),
- (['sh', '-c', 'echo -n "%s" >&2'], False, True),
- ])
- def test_receive(self, cmd, recv_out, recv_err):
- text = bytes('Hello World')
- received = bytearray()
-
- def recv_data(buffer):
- # cannot use received += buffer with a variable
- # defined in the parent function.
- operator.iadd(received, buffer)
-
- cmd[-1] = cmd[-1] % text
-
- c = self._startCommand(cmd)
- p = utils.CommandStream(
- c,
- recv_data if recv_out else self.assertUnexpectedCall,
- recv_data if recv_err else self.assertUnexpectedCall)
-
- while not p.closed:
- p.receive()
-
- retcode = c.wait()
-
- self.assertEqual(retcode, 0)
- self.assertEqual(text, received)
-
- @permutations([
- (['cat'], True, False),
- (['sh', '-c', 'cat >&2'], False, True),
- ])
- def test_write(self, cmd, recv_out, recv_err):
- text = bytes('Hello World')
- received = bytearray()
-
- def recv_data(buffer):
- # cannot use received += buffer with a variable
- # defined in the parent function.
- operator.iadd(received, buffer)
-
- c = self._startCommand(cmd)
- p = utils.CommandStream(
- c,
- recv_data if recv_out else self.assertUnexpectedCall,
- recv_data if recv_err else self.assertUnexpectedCall)
-
- c.stdin.write(text)
- c.stdin.flush()
- c.stdin.close()
-
- while not p.closed:
- p.receive()
-
- retcode = c.wait()
-
- self.assertEqual(retcode, 0)
- self.assertEqual(text, str(received))
-
- def test_timeout(self):
- c = self._startCommand(["sleep", "5"])
- p = utils.CommandStream(c, self.assertUnexpectedCall,
- self.assertUnexpectedCall)
-
- with self.assertElapsed(2):
- p.receive(2)
-
- self.assertEqual(p.closed, False)
-
- c.terminate()
-
- self.assertEqual(c.wait(), -signal.SIGTERM)
-
- @permutations((
- ('kill', -signal.SIGKILL),
- ('terminate', -signal.SIGTERM),
- ))
- def test_signals(self, method, expected_retcode):
- c = self._startCommand(["sleep", "2"])
- p = utils.CommandStream(c, self.assertUnexpectedCall,
- self.assertUnexpectedCall)
-
- getattr(c, method)()
-
- try:
- with self.assertElapsed(0):
- p.receive(2)
- finally:
- retcode = c.wait()
-
- self.assertEqual(retcode, expected_retcode)
-
-
class FakeLogger(object):
def __init__(self, level):
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 2842afa..5a54307 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -1262,6 +1262,7 @@
%{python_sitelib}/%{vdsm_name}/storage/threadlocal.py*
%{python_sitelib}/%{vdsm_name}/storage/volumemetadata.py*
%{python_sitelib}/%{vdsm_name}/storage/workarounds.py*
+%{python_sitelib}/%{vdsm_name}/procwatch.py*
%{python_sitelib}/%{vdsm_name}/properties.py*
%{python_sitelib}/%{vdsm_name}/protocoldetector.py*
%{python_sitelib}/%{vdsm_name}/pthread.py*
--
To view, visit https://gerrit.ovirt.org/65072
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I045569d350aad19049a33338a72b59e68ba91e5b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>
7 years, 8 months