From: Ondrej Lichtner olichtne@redhat.com
The PerfRepo objects have the ability to be initialized from an XML Element tree, corresponding to an XML response from the REST API. This was implemented by checking the type of input using the isinstance method. However on Python 2.6 the API for ElementTree is different and Element is just a function instead of a class, so this method cannot be used.
Instead this patch replaces the isinstance call with the iselement() call that is provided by the ElementTree API in both Python versions.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com --- lnst/Controller/PerfRepo.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/lnst/Controller/PerfRepo.py b/lnst/Controller/PerfRepo.py index 3d2eed3..cc53f2e 100644 --- a/lnst/Controller/PerfRepo.py +++ b/lnst/Controller/PerfRepo.py @@ -19,7 +19,7 @@ import textwrap import pprint from types import StringType, NoneType from xml.etree import ElementTree -from xml.etree.ElementTree import Element +from xml.etree.ElementTree import Element, iselement from lnst.Common.Utils import recursive_dict_update from lnst.Common.Utils import dot_to_dict, dict_to_dot, indent
@@ -60,11 +60,12 @@ class PerfRepoTest(PerfRepoObject): self._description = None self._groupid = None self._metrics = [] - elif type(xml) is StringType or isinstance(xml, Element): + elif type(xml) is StringType or iselement(xml): if type(xml) is StringType: root = ElementTree.fromstring(xml) - else: + elif iselement(xml): root = xml + if root.tag != "test": raise PerfRepoException("Invalid xml.")
@@ -171,11 +172,12 @@ class PerfRepoTestExecution(PerfRepoObject): self._values = [] self._tags = [] self._parameters = [] - elif type(xml) is StringType or isinstance(xml, Element): + elif type(xml) is StringType or iselement(xml): if type(xml) is StringType: root = ElementTree.fromstring(xml) - else: + elif iselement(xml): root = xml + if root.tag != "testExecution": raise PerfRepoException("Invalid xml.")
@@ -340,11 +342,12 @@ class PerfRepoValue(PerfRepoObject): self._metricName = None self._result = None self._parameters = [] - elif type(xml) is StringType or isinstance(xml, Element): + elif type(xml) is StringType or iselement(xml): if type(xml) is StringType: root = ElementTree.fromstring(xml) - else: + elif iselement(xml): root = xml + if root.tag != "value": raise PerfRepoException("Invalid xml.")
@@ -420,11 +423,12 @@ class PerfRepoMetric(PerfRepoObject): self._name = None self._description = None self._comparator = None - elif type(xml) is StringType or isinstance(xml, Element): + elif type(xml) is StringType or iselement(xml): if type(xml) is StringType: root = ElementTree.fromstring(xml) - else: + elif iselement(xml): root = xml + if root.tag != "metric": raise PerfRepoException("Invalid xml.")
@@ -493,11 +497,12 @@ class PerfRepoReport(PerfRepoObject): self._name = None self._type = None self._properties = {} - elif type(xml) is StringType or isinstance(xml, Element): + elif type(xml) is StringType or iselement(xml): if type(xml) is StringType: root = ElementTree.fromstring(xml) - else: + elif iselement(xml): root = xml + if root.tag != "report": raise PerfRepoException("Invalid xml.")
From: Ondrej Lichtner olichtne@redhat.com
The log message contained an undefined variable because of a copy paste error. This patch fixes the problem.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com --- lnst/Controller/PerfRepo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lnst/Controller/PerfRepo.py b/lnst/Controller/PerfRepo.py index cc53f2e..c3a91d7 100644 --- a/lnst/Controller/PerfRepo.py +++ b/lnst/Controller/PerfRepo.py @@ -896,7 +896,7 @@ class PerfRepoRESTAPI(object): metric.set_id(new_id) if log: logging.debug("POST %s success" % post_url) - logging.info("Obj url: %s" % self.get_obj_url(test)) + logging.info("Obj url: %s" % self.get_obj_url(metric)) return metric
def test_delete(self, test_id, log=True):
Fri, Oct 30, 2015 at 03:33:35PM CET, olichtne@redhat.com wrote:
From: Ondrej Lichtner olichtne@redhat.com
The PerfRepo objects have the ability to be initialized from an XML Element tree, corresponding to an XML response from the REST API. This was implemented by checking the type of input using the isinstance method. However on Python 2.6 the API for ElementTree is different and Element is just a function instead of a class, so this method cannot be used.
Instead this patch replaces the isinstance call with the iselement() call that is provided by the ElementTree API in both Python versions.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com
lnst/Controller/PerfRepo.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/lnst/Controller/PerfRepo.py b/lnst/Controller/PerfRepo.py index 3d2eed3..cc53f2e 100644 --- a/lnst/Controller/PerfRepo.py +++ b/lnst/Controller/PerfRepo.py @@ -19,7 +19,7 @@ import textwrap import pprint from types import StringType, NoneType from xml.etree import ElementTree -from xml.etree.ElementTree import Element +from xml.etree.ElementTree import Element, iselement from lnst.Common.Utils import recursive_dict_update from lnst.Common.Utils import dot_to_dict, dict_to_dot, indent
@@ -60,11 +60,12 @@ class PerfRepoTest(PerfRepoObject): self._description = None self._groupid = None self._metrics = []
elif type(xml) is StringType or isinstance(xml, Element):
elif type(xml) is StringType or iselement(xml): if type(xml) is StringType: root = ElementTree.fromstring(xml)
else:
elif iselement(xml): root = xml
if root.tag != "test": raise PerfRepoException("Invalid xml.")
@@ -171,11 +172,12 @@ class PerfRepoTestExecution(PerfRepoObject): self._values = [] self._tags = [] self._parameters = []
elif type(xml) is StringType or isinstance(xml, Element):
elif type(xml) is StringType or iselement(xml): if type(xml) is StringType: root = ElementTree.fromstring(xml)
else:
elif iselement(xml): root = xml
if root.tag != "testExecution": raise PerfRepoException("Invalid xml.")
@@ -340,11 +342,12 @@ class PerfRepoValue(PerfRepoObject): self._metricName = None self._result = None self._parameters = []
elif type(xml) is StringType or isinstance(xml, Element):
elif type(xml) is StringType or iselement(xml): if type(xml) is StringType: root = ElementTree.fromstring(xml)
else:
elif iselement(xml): root = xml
if root.tag != "value": raise PerfRepoException("Invalid xml.")
@@ -420,11 +423,12 @@ class PerfRepoMetric(PerfRepoObject): self._name = None self._description = None self._comparator = None
elif type(xml) is StringType or isinstance(xml, Element):
elif type(xml) is StringType or iselement(xml): if type(xml) is StringType: root = ElementTree.fromstring(xml)
else:
elif iselement(xml): root = xml
if root.tag != "metric": raise PerfRepoException("Invalid xml.")
@@ -493,11 +497,12 @@ class PerfRepoReport(PerfRepoObject): self._name = None self._type = None self._properties = {}
elif type(xml) is StringType or isinstance(xml, Element):
elif type(xml) is StringType or iselement(xml): if type(xml) is StringType: root = ElementTree.fromstring(xml)
else:
elif iselement(xml): root = xml
if root.tag != "report": raise PerfRepoException("Invalid xml.")
-- 2.6.2
LNST-developers mailing list LNST-developers@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/lnst-developers
Ack to series
Acked-by: Jan Tluka jtluka@redhat.com
lnst-developers@lists.fedorahosted.org