Change in vdsm[master]: udevadm: Add udevadm wrapper

nsoffer at redhat.com nsoffer at redhat.com
Fri Mar 27 16:57:17 UTC 2015


Nir Soffer has uploaded a new change for review.

Change subject: udevadm: Add udevadm wrapper
......................................................................

udevadm: Add udevadm wrapper

Add udevadm wrapper for running udevadm tool. In the current version the
wrapper implement only the settle() command, which should be used to
wait for events after modifying scsi connections.

Change-Id: Ieb83b2ff4dd6aeffd20db0697a4983bc1e949232
Relates-To: https://bugzilla.redhat.com/1205877
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M debian/vdsm.install
M vdsm.spec.in
M vdsm/storage/Makefile.am
A vdsm/storage/udevadm.py
4 files changed, 67 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/87/39287/1

diff --git a/debian/vdsm.install b/debian/vdsm.install
index 16a17ed..bf72e89 100644
--- a/debian/vdsm.install
+++ b/debian/vdsm.install
@@ -138,6 +138,7 @@
 ./usr/share/vdsm/storage/taskManager.py
 ./usr/share/vdsm/storage/threadLocal.py
 ./usr/share/vdsm/storage/threadPool.py
+./usr/share/vdsm/storage/udevadm.py
 ./usr/share/vdsm/storage/volume.py
 ./usr/share/vdsm/supervdsm.py
 ./usr/share/vdsm/supervdsmServer
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 242062e..42456d5 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -1185,6 +1185,7 @@
 %{_datadir}/%{vdsm_name}/storage/task.py*
 %{_datadir}/%{vdsm_name}/storage/threadLocal.py*
 %{_datadir}/%{vdsm_name}/storage/threadPool.py*
+%{_datadir}/%{vdsm_name}/storage/udevadm.py*
 %{_datadir}/%{vdsm_name}/storage/volume.py*
 %{_datadir}/%{vdsm_name}/storage/imageRepository/__init__.py*
 %{_datadir}/%{vdsm_name}/storage/imageRepository/formatConverter.py*
diff --git a/vdsm/storage/Makefile.am b/vdsm/storage/Makefile.am
index 4ebe0a2..a342efb 100644
--- a/vdsm/storage/Makefile.am
+++ b/vdsm/storage/Makefile.am
@@ -69,6 +69,7 @@
 	task.py \
 	threadLocal.py \
 	threadPool.py \
+	udevadm.py \
 	volume.py
 
 dist_vdsmexec_SCRIPTS = \
diff --git a/vdsm/storage/udevadm.py b/vdsm/storage/udevadm.py
new file mode 100644
index 0000000..3c6817b
--- /dev/null
+++ b/vdsm/storage/udevadm.py
@@ -0,0 +1,64 @@
+#
+# Copyright 2015 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 vdsm import utils
+
+_UDEVADM = utils.CommandPath("udevadm", "/sbin/udevadm", "/usr/sbin/udevadm")
+
+
+class Error(Exception):
+
+    def __init__(self, rc, err):
+        self.rc = rc
+        self.err = err
+
+    def __str__(self):
+        return "Process failed with rc=%d err=%r" % (self.rc, self.err)
+
+
+def settle(timeout, exit_if_exists=None):
+    """
+    Watches the udev event queue, and wait until all current events are
+    handled.
+
+    Arguments:
+
+    timeout        Maximum number of seconds to wait for the event queue to
+                   become empty. A value of 0 will check if the queue is empty
+                   and always return immediately.
+
+    exit_if_exists Stop waiting if file exists.
+
+    Raise udevadm.Error if process failed.
+    """
+    args = ["settle", "--timeout=%s" % timeout]
+
+    if exit_if_exists:
+        args.append("--exit-if-exists=%s" % exit_if_exists)
+
+    _run_command(args)
+
+
+def _run_command(args):
+    cmd = [_UDEVADM.cmd]
+    cmd.extend(args)
+    rc, out, err = utils.execCmd(cmd)
+    if rc != 0:
+        raise Error(rc, err)


-- 
To view, visit https://gerrit.ovirt.org/39287
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieb83b2ff4dd6aeffd20db0697a4983bc1e949232
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list