Change in vdsm[master]: vdsm-tool: Change exception reporting
dkuznets at redhat.com
dkuznets at redhat.com
Tue Apr 8 14:09:29 UTC 2014
Dima Kuznetsov has uploaded a new change for review.
Change subject: vdsm-tool: Change exception reporting
......................................................................
vdsm-tool: Change exception reporting
Introduced VdsmToolRuntimeError as the root class for all the errors
that vdsm-tool expects to encounter and wants to present to the user.
Those errors are just printed to the screen preceded by "Error:" and do
not generate a stack trace.
Change-Id: I467d1e5ef7503312cde6e013aacb68dc2d46dd37
Signed-off-by: Dima Kuznetsov <dkuznets at redhat.com>
---
M lib/vdsm/tool/__init__.py
M lib/vdsm/tool/configurator.py
M lib/vdsm/tool/dummybr.py
M lib/vdsm/tool/load_needed_modules.py.in
M lib/vdsm/tool/passwd.py
M lib/vdsm/tool/restore_nets.py
M lib/vdsm/tool/service.py
M lib/vdsm/tool/vdsm-id.py
M vdsm-tool/vdsm-tool
9 files changed, 48 insertions(+), 25 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/65/26565/1
diff --git a/lib/vdsm/tool/__init__.py b/lib/vdsm/tool/__init__.py
index 49f3767..863ad51 100644
--- a/lib/vdsm/tool/__init__.py
+++ b/lib/vdsm/tool/__init__.py
@@ -25,3 +25,12 @@
def __call__(self, fun):
fun._vdsm_tool = {"name": self.name}
return fun
+
+
+class VdsmToolRuntimeError(Exception):
+ pass
+
+
+class VdsmToolNotRootError(VdsmToolRuntimeError):
+ def __init__(self):
+ VdsmToolRuntimeError.__init__(self, "Must run as root")
diff --git a/lib/vdsm/tool/configurator.py b/lib/vdsm/tool/configurator.py
index f0944f3..601288f 100644
--- a/lib/vdsm/tool/configurator.py
+++ b/lib/vdsm/tool/configurator.py
@@ -23,7 +23,7 @@
import argparse
from .. import utils
-from . import service, expose
+from . import service, expose, VdsmToolRuntimeError, VdsmToolNotRootError
from ..constants import P_VDSM_EXEC, QEMU_PROCESS_GROUP, \
SANLOCK_USER, VDSM_GROUP
@@ -70,7 +70,7 @@
Invoke libvirt_configure.sh script
"""
if os.getuid() != 0:
- raise UserWarning("Must run as root")
+ raise VdsmToolNotRootError()
env = os.environ.copy()
for k, v in self.env_override.items():
@@ -88,7 +88,7 @@
sys.stdout.write(out)
sys.stderr.write(err)
if rc != 0:
- raise RuntimeError("Failed to perform libvirt action.")
+ raise VdsmToolRuntimeError("Failed to perform libvirt action.")
def _get_libvirt_exec(self):
return (os.path.join(P_VDSM_EXEC, 'libvirt_configure.sh'), )
@@ -103,7 +103,7 @@
try:
self._exec_libvirt_configure("test_conflict_configurations")
return True
- except RuntimeError:
+ except VdsmToolRuntimeError:
return False
def isconfigured(self):
@@ -113,7 +113,7 @@
try:
self._exec_libvirt_configure("check_if_configured")
return True
- except RuntimeError:
+ except VdsmToolRuntimeError:
return False
@@ -135,7 +135,7 @@
Configure sanlock process groups
"""
if os.getuid() != 0:
- raise UserWarning("Must run as root")
+ raise VdsmToolNotRootError()
rc, out, err = utils.execCmd(
(
@@ -150,7 +150,7 @@
sys.stdout.write(out)
sys.stderr.write(err)
if rc != 0:
- raise RuntimeError("Failed to perform sanlock config.")
+ raise VdsmToolRuntimeError("Failed to perform sanlock config.")
def isconfigured(self):
"""
@@ -171,7 +171,9 @@
strip().split(" ")]
break
else:
- raise RuntimeError("Unable to find sanlock service groups")
+ raise VdsmToolRuntimeError(
+ "Unable to find sanlock service groups"
+ )
is_sanlock_groups_set = True
for g in self.SANLOCK_GROUPS:
@@ -219,7 +221,7 @@
if c.getName() in args.modules:
override = args.force and c.reconfigureOnForce()
if not override and not c.validate():
- raise RuntimeError(
+ raise VdsmToolRuntimeError(
"Configuration of %s is invalid" % c.getName()
)
if override or not c.isconfigured():
@@ -230,7 +232,7 @@
for s in c.getServices():
if service.service_status(s, False) == 0:
if not args.force:
- raise RuntimeError(
+ raise VdsmToolRuntimeError(
"\n\nCannot configure while service '%s' is "
"running.\n Stop the service manually or use the "
"--force flag.\n" % s
@@ -281,7 +283,7 @@
(The force flag will stop the module's service and start it
afterwards automatically to load the new configuration.)
"""
- raise RuntimeError(msg)
+ raise VdsmToolRuntimeError(msg)
@expose("validate-config")
@@ -304,7 +306,7 @@
ret = False
if not ret:
- raise RuntimeError("Config is not valid. Check conf files")
+ raise VdsmToolRuntimeError("Config is not valid. Check conf files")
def _parse_args(action):
diff --git a/lib/vdsm/tool/dummybr.py b/lib/vdsm/tool/dummybr.py
index d5825f2..59a43d2 100644
--- a/lib/vdsm/tool/dummybr.py
+++ b/lib/vdsm/tool/dummybr.py
@@ -23,14 +23,15 @@
from ..netinfo import DUMMY_BRIDGE
from .. import libvirtconnection, utils, constants
-from . import expose
+from . import expose, VdsmToolRuntimeError
def createEphemeralBridge(bridgeName):
rc, out, err = utils.execCmd([constants.EXT_BRCTL, 'addbr', bridgeName])
if rc != 0:
- raise Exception('Failed to create ephemeral dummy bridge. Err: %s' %
- err)
+ raise VdsmToolRuntimeError(
+ 'Failed to create ephemeral dummy bridge. Err: %s' % err
+ )
def addBridgeToLibvirt(bridgeName):
diff --git a/lib/vdsm/tool/load_needed_modules.py.in b/lib/vdsm/tool/load_needed_modules.py.in
index 1be9448..8ebb1be 100644
--- a/lib/vdsm/tool/load_needed_modules.py.in
+++ b/lib/vdsm/tool/load_needed_modules.py.in
@@ -21,7 +21,7 @@
import os.path
from .. import netinfo
-from . import expose
+from . import expose, VdsmToolRuntimeError
from ..utils import execCmd
@@ -34,7 +34,9 @@
"""
rc, out, err = execCmd(argv, raw=True)
if rc != 0:
- raise Exception("Execute command %s failed: %s" % (argv, err))
+ raise VdsmToolRuntimeError(
+ "Execute command %s failed: %s" % (argv, err)
+ )
def _enable_bond_dev():
diff --git a/lib/vdsm/tool/passwd.py b/lib/vdsm/tool/passwd.py
index 71e6c1c..654d81d 100644
--- a/lib/vdsm/tool/passwd.py
+++ b/lib/vdsm/tool/passwd.py
@@ -20,7 +20,7 @@
import errno
import subprocess
from .. import constants
-from . import expose
+from . import expose, VdsmToolRuntimeError
@expose("set-saslpasswd")
@@ -43,4 +43,4 @@
stderr=subprocess.PIPE, close_fds=True)
output, err = p.communicate()
if p.returncode != 0:
- raise RuntimeError("Set password failed: %s" % (err,))
+ raise VdsmToolRuntimeError("Set password failed: %s" % (err,))
diff --git a/lib/vdsm/tool/restore_nets.py b/lib/vdsm/tool/restore_nets.py
index c2a0dcc..8ffe5d7 100644
--- a/lib/vdsm/tool/restore_nets.py
+++ b/lib/vdsm/tool/restore_nets.py
@@ -21,7 +21,7 @@
import sys
from .. import utils
-from . import expose
+from . import expose, VdsmToolRuntimeError
from ..constants import P_VDSM
@@ -35,4 +35,6 @@
sys.stdout.write(out)
sys.stderr.write(err)
if rc != 0:
- raise Exception('Failed to restore the persisted networks')
+ raise VdsmToolRuntimeError(
+ 'Failed to restore the persisted networks'
+ )
diff --git a/lib/vdsm/tool/service.py b/lib/vdsm/tool/service.py
index 444ef80..9c6f19c 100644
--- a/lib/vdsm/tool/service.py
+++ b/lib/vdsm/tool/service.py
@@ -27,7 +27,7 @@
import sys
from collections import defaultdict
-from . import expose
+from . import expose, VdsmToolRuntimeError
from ..utils import CommandPath
from ..utils import execCmd as _execCmd
@@ -75,7 +75,7 @@
_srvIsManagedAlts = []
-class ServiceError(RuntimeError):
+class ServiceError(VdsmToolRuntimeError):
def __init__(self, message, out=None, err=None):
self.out = out
self.err = err
diff --git a/lib/vdsm/tool/vdsm-id.py b/lib/vdsm/tool/vdsm-id.py
index ac5faae..2113621 100644
--- a/lib/vdsm/tool/vdsm-id.py
+++ b/lib/vdsm/tool/vdsm-id.py
@@ -18,7 +18,7 @@
#
from ..utils import getHostUUID
-from . import expose
+from . import expose, VdsmToolRuntimeError
import sys
@@ -29,6 +29,6 @@
"""
hostUUID = getHostUUID(False)
if hostUUID is None:
- raise RuntimeError('Cannot retrieve host UUID')
+ raise VdsmToolRuntimeError('Cannot retrieve host UUID')
sys.stdout.write(hostUUID)
return 0
diff --git a/vdsm-tool/vdsm-tool b/vdsm-tool/vdsm-tool
index 8bdf1bc..8eb4e52 100755
--- a/vdsm-tool/vdsm-tool
+++ b/vdsm-tool/vdsm-tool
@@ -149,9 +149,16 @@
try:
return tool_command[cmd]["command"](*args[1:])
+ except vdsm.tool.VdsmToolRuntimeError as e:
+ print >> sys.stderr, 'Error:', e
except Exception:
traceback.print_exc(file=sys.stderr)
return 1
+ except KeyboardInterrupt:
+ print "Interrupted"
+ return 1
+ except SystemExit:
+ return 1
if __name__ == "__main__":
sys.exit(main())
--
To view, visit http://gerrit.ovirt.org/26565
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I467d1e5ef7503312cde6e013aacb68dc2d46dd37
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dima Kuznetsov <dkuznets at redhat.com>
More information about the vdsm-patches
mailing list