Skip to content

Commit

Permalink
Fix XenError
Browse files Browse the repository at this point in the history
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 #158

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
  • Loading branch information
Mate Lakat authored and chandrikas committed Jun 4, 2014
1 parent 0c91e38 commit cb1e0df
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
3 changes: 1 addition & 2 deletions drivers/xs_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
29 changes: 29 additions & 0 deletions tests/test_xs_errors.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit cb1e0df

Please sign in to comment.