From d6f8db249b3a7ab234b9bd676b92862b87df51e3 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Wed, 19 Oct 2011 18:05:22 +0100 Subject: [PATCH] Fix unittest failures with python 2.7 In python 2.7 the ovf unittests fail because OVFReader expects ElementTree.parse() of an erroneous document to throw an xml.parsers.expat.ExpatError while instead it throws an ElementTree.ParseError. The solution is to "except" for both errors, with the catch that ParseError didn't exist before, so we need to define it locally and get it from the module if it exists, while leaving it set to "None" (thus catching no exception) if it does not. Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Agata Murawska <agatamurawska@google.com> --- lib/ovf.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ovf.py b/lib/ovf.py index 7c5305b45..eabc71a8e 100644 --- a/lib/ovf.py +++ b/lib/ovf.py @@ -45,6 +45,11 @@ try: except ImportError: import elementtree.ElementTree as ET +try: + ParseError = ET.ParseError # pylint: disable=E1103 +except AttributeError: + ParseError = None + from ganeti import constants from ganeti import errors from ganeti import utils @@ -210,7 +215,7 @@ class OVFReader(object): self.tree = ET.ElementTree() try: self.tree.parse(input_path) - except xml.parsers.expat.ExpatError, err: + except (ParseError, xml.parsers.expat.ExpatError), err: raise errors.OpPrereqError("Error while reading %s file: %s" % (OVF_EXT, err)) -- GitLab