From cb1e0df497c24e6e31929b69353cada6bf0e0538 Mon Sep 17 00:00:00 2001 From: Mate Lakat Date: Wed, 4 Jun 2014 16:22:04 +0100 Subject: [PATCH] Fix XenError If the XML error description does not exist in the filesystem, XenError tried to call Exception.__init__(self, ''), which is invalid, as self is not inheriting from Exception. Github: fixes xapi-project/sm#158 Signed-off-by: Mate Lakat --- drivers/xs_errors.py | 3 +-- tests/test_xs_errors.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/test_xs_errors.py diff --git a/drivers/xs_errors.py b/drivers/xs_errors.py index 7caba3aaa..e1817a455 100755 --- a/drivers/xs_errors.py +++ b/drivers/xs_errors.py @@ -28,8 +28,7 @@ class XenError(object): def __init__(self, key, opterr=None): # Check the XML definition file exists if not os.path.exists(XML_DEFS): - print "No XML def file found" - raise Exception.__init__(self, '') + raise Exception("No XML def file found") # Read the definition list self._fromxml('SM-errorcodes') diff --git a/tests/test_xs_errors.py b/tests/test_xs_errors.py new file mode 100644 index 000000000..56a62956b --- /dev/null +++ b/tests/test_xs_errors.py @@ -0,0 +1,29 @@ +import unittest + +import testlib + +import xs_errors + + +class TestXenError(unittest.TestCase): + @testlib.with_context + def test_without_xml_defs(self, context): + raised_exception = None + try: + xs_errors.XenError('blah') + except Exception, e: + raised_exception = e + + self.assertTrue("No XML def file found" in str(e)) + + @testlib.with_context + def test_xml_defs(self, context): + context.setup_error_codes() + + raised_exception = None + try: + xs_errors.XenError('SRInUse') + except Exception, e: + raised_exception = e + + self.assertTrue("The SR device is currently in use" in str(e))