From 345374cfd88cc5bd1295d8e72c579edf3669ab1a Mon Sep 17 00:00:00 2001
From: Aravinda VK <avishwan@redhat.com>
Date: Wed, 6 Mar 2013 14:34:12 +0530
Subject: [PATCH 33/36] gluster: Handling Attribute error in Python 2.6
xml.etree.cElementTree in Python 2.6 doesn't have the attribute
ParseError(Introduced in Python 2.7). VDSM gluster/cli.py tries
to capture etree.ParseError when gluster cli returns incompatible
xml output.
Change-Id: I63c33b34ce11473636365ea094e267c5424c7255
Signed-off-by: Aravinda VK <avishwan@redhat.com>
(cherry picked from commit 5759c876e414b433b1a42e50e1817d5841ec2ef2)
Reviewed-on: http://gerrit.ovirt.org/12829
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
---
vdsm/gluster/cli.py | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/vdsm/gluster/cli.py b/vdsm/gluster/cli.py
index 7136281..d4f65ab 100644
--- a/vdsm/gluster/cli.py
+++ b/vdsm/gluster/cli.py
@@ -31,6 +31,12 @@ _glusterCommandPath = utils.CommandPath("gluster",
)
+if hasattr(etree, 'ParseError'):
+ _etreeExceptions = (etree.ParseError, AttributeError, ValueError)
+else:
+ _etreeExceptions = (SyntaxError, AttributeError, ValueError)
+
+
def _getGlusterVolCmd():
return [_glusterCommandPath.cmd, "--mode=script", "volume"]
@@ -85,7 +91,7 @@ def _execGlusterXml(cmd):
tree = etree.fromstring('\n'.join(out))
rv = int(tree.find('opRet').text)
msg = tree.find('opErrstr').text
- except (etree.ParseError, AttributeError, ValueError):
+ except _etreeExceptions:
raise ge.GlusterXmlErrorException(err=out)
if rv == 0:
return tree
@@ -303,7 +309,7 @@ def volumeStatus(volumeName, brick=None, option=None):
return _parseVolumeStatusMem(xmltree)
else:
return _parseVolumeStatus(xmltree)
- except (etree.ParseError, AttributeError, ValueError):
+ except _etreeExceptions:
raise ge.GlusterXmlErrorException(err=[etree.tostring(xmltree)])
@@ -427,7 +433,7 @@ def volumeInfo(volumeName=None):
raise ge.GlusterVolumesListFailedException(rc=e.rc, err=e.err)
try:
return _parseVolumeInfo(xmltree)
- except (etree.ParseError, AttributeError, ValueError):
+ except _etreeExceptions:
raise ge.GlusterXmlErrorException(err=[etree.tostring(xmltree)])
@@ -448,7 +454,7 @@ def volumeCreate(volumeName, brickList, replicaCount=0, stripeCount=0,
raise ge.GlusterVolumeCreateFailedException(rc=e.rc, err=e.err)
try:
return {'uuid': xmltree.find('volCreate/volume/id').text}
- except (etree.ParseError, AttributeError, ValueError):
+ except _etreeExceptions:
raise ge.GlusterXmlErrorException(err=[etree.tostring(xmltree)])
@@ -787,7 +793,7 @@ def peerStatus():
return _parsePeerStatus(xmltree,
_getLocalIpAddress() or _getGlusterHostName(),
_getGlusterUuid(), HostStatus.CONNECTED)
- except (etree.ParseError, AttributeError, ValueError):
+ except _etreeExceptions:
raise ge.GlusterXmlErrorException(err=[etree.tostring(xmltree)])
@@ -878,5 +884,5 @@ def volumeProfileInfo(volumeName, nfs=False):
raise ge.GlusterVolumeProfileInfoFailedException(rc=e.rc, err=e.err)
try:
return _parseVolumeProfileInfo(xmltree, nfs)
- except (etree.ParseError, AttributeError, ValueError):
+ except _etreeExceptions:
raise ge.GlusterXmlErrorException(err=[etree.tostring(xmltree)])
--
1.8.1.4