Commit d6f8db24 authored by Guido Trotter's avatar Guido Trotter
Browse files

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: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarAgata Murawska  <agatamurawska@google.com>
parent 8b8f54dd
......@@ -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))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment