Martin Polednik has uploaded a new change for review. Change subject: udevadm: use udevadm module facilities for functions ......................................................................
udevadm: use udevadm module facilities for functions There is already an Error exception and _run_command function helper to handle running the udev commands. This patch makes sure that newly moved functions use these facilities to reach consistence in the module. Change-Id: Ic30db46bc578ce8c3acc30c0aaee1e2545ea4196 Signed-off-by: Martin Polednik <mpoled...@redhat.com> --- M lib/vdsm/constants.py.in M lib/vdsm/udevadm.py 2 files changed, 20 insertions(+), 16 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/09/44809/1 diff --git a/lib/vdsm/constants.py.in b/lib/vdsm/constants.py.in index 0c85b9f..cc4e317 100644 --- a/lib/vdsm/constants.py.in +++ b/lib/vdsm/constants.py.in @@ -138,8 +138,6 @@ EXT_TAR = '@TAR_PATH@' EXT_TUNE2FS = '@TUNE2FS_PATH@' -EXT_UDEVADM = '@UDEVADM_PATH@' - EXT_UMOUNT = '@UMOUNT_PATH@' EXT_SAFELEASE = '@SAFELEASE_PATH@' diff --git a/lib/vdsm/udevadm.py b/lib/vdsm/udevadm.py index 9c58075..c7dce78 100644 --- a/lib/vdsm/udevadm.py +++ b/lib/vdsm/udevadm.py @@ -23,8 +23,6 @@ import logging from . import utils -from vdsm.constants import EXT_UDEVADM - _UDEVADM = utils.CommandPath("udevadm", "/sbin/udevadm", "/usr/sbin/udevadm") _UDEV_WITH_RELOAD_VERSION = 181 @@ -67,7 +65,7 @@ def trigger(attr_matches=(), property_matches=()): _reload() - cmd = [EXT_UDEVADM, 'trigger', '--verbose', '--action', 'change'] + cmd = ['trigger', '--verbose', '--action', 'change'] for name, value in property_matches: cmd.append('--property-match={}={}'.format(name, value)) @@ -75,10 +73,11 @@ for name, value in attr_matches: cmd.append('--property-match={}={}'.format(name, value)) - rc, out, err = utils.execCmd(cmd) - if rc: + try: + _run_command(cmd) + except Error as e: raise OSError(errno.EINVAL, 'Could not trigger change ' - 'out %s\nerr %s' % (out, err)) + 'out %s\nerr %s' % (e.out, e.err)) def _reload(): @@ -86,22 +85,27 @@ reload = "--reload" else: reload = "--reload-rules" - cmd = [EXT_UDEVADM, 'control', reload] - rc, out, err = utils.execCmd(cmd) - if rc: + cmd = ['control', reload] + + try: + _run_command(cmd) + except Error as e: logging.error("Udevadm reload-rules command failed rc=%s, " - "out=\"%s\", err=\"%s\"", rc, out, err) + "out=\"%s\", err=\"%s\"", e.rc, e.out, e.err) raise OSError(errno.EINVAL, "Could not reload rules") @utils.memoized def _version(): - cmd = [EXT_UDEVADM, '--version'] - rc, out, err = utils.execCmd(cmd) - if rc: + cmd = ['--version'] + + try: + out = utils.execCmd(cmd) + except Error as e: logging.error("Udevadm version command failed rc=%s, " - "out=\"%s\", err=\"%s\"", rc, out, err) + "out=\"%s\", err=\"%s\"", e.rc, e.out, e.err) raise RuntimeError("Could not get udev version number") + return int(out[0]) @@ -115,3 +119,5 @@ rc, out, err = utils.execCmd(cmd, raw=True) if rc != 0: raise Error(rc, out, err) + + return out -- To view, visit https://gerrit.ovirt.org/44809 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic30db46bc578ce8c3acc30c0aaee1e2545ea4196 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Martin Polednik <mpoled...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches