From: Ondrej Lichtner olichtne@redhat.com
Since PerfRepo support is now dependent on an external library it should be an optional dependency so that it doesn't crash LNST if the user is not using PerfRepo.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com --- lnst/Controller/Task.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py index 19499da..3903746 100644 --- a/lnst/Controller/Task.py +++ b/lnst/Controller/Task.py @@ -13,9 +13,6 @@ rpazdera@redhat.com (Radek Pazdera) import hashlib import re import logging -from perfrepo import PerfRepoRESTAPI -from perfrepo import PerfRepoTestExecution -from perfrepo import PerfRepoValue from lnst.Common.Utils import dict_to_dot, list_to_dot, deprecated from lnst.Common.Config import lnst_config from lnst.Controller.XmlTemplates import XmlTemplateError @@ -23,6 +20,15 @@ from lnst.Common.Path import Path from lnst.Controller.PerfRepoMapping import PerfRepoMapping from lnst.Common.Utils import Noop
+try: + from perfrepo import PerfRepoRESTAPI + from perfrepo import PerfRepoTestExecution + from perfrepo import PerfRepoValue +except: + PerfRepoRESTAPI = None + PerfRepoTestExecution = None + PerfRepoValue = None + # The handle to be imported from each task ctl = None
@@ -544,7 +550,12 @@ class PerfRepoAPI(object): return False
def connect(self, url, username, password): - self._rest_api = PerfRepoRESTAPI(url, username, password) + if PerfRepoRESTAPI is not None: + self._rest_api = PerfRepoRESTAPI(url, username, password) + if not self._rest_api.connected(): + self._rest_api = None + else: + self._rest_api = None
def new_result(self, mapping_key, name, hash_ignore=[]): if not self.connected():
From: Ondrej Lichtner olichtne@redhat.com
This makes sure that all methods that use the PerfRepoRESTAPI check whether or not it is connected to a PerfRepo instance.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com --- lnst/Controller/Task.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py index 3903746..ebe32c1 100644 --- a/lnst/Controller/Task.py +++ b/lnst/Controller/Task.py @@ -544,7 +544,8 @@ class PerfRepoAPI(object): return self._mapping
def connected(self): - if self._rest_api is not None and self._mapping is not None: + if self._rest_api is not None and self._rest_api.connected() and\ + self._mapping is not None: return True else: return False @@ -586,10 +587,10 @@ class PerfRepoAPI(object): return result
def save_result(self, result): - if self._rest_api is None: - raise TaskError("Not connected to PerfRepo.") - elif isinstance(result, Noop): + if isinstance(result, Noop): return + elif not self.connected(): + raise TaskError("Not connected to PerfRepo.") elif isinstance(result, PerfRepoResult): if len(result.get_testExecution().get_values()) < 1: logging.debug("PerfRepoResult with no result data, skipping "\ @@ -627,7 +628,7 @@ class PerfRepoAPI(object): "of PerfRepoResult")
def get_baseline(self, report_id): - if report_id is None: + if report_id is None or not self.connected(): return Noop()
report = self._rest_api.report_get_by_id(report_id, log=False) @@ -653,7 +654,7 @@ class PerfRepoAPI(object): return PerfRepoBaseline(baseline_testExec)
def get_baseline_of_result(self, result): - if not isinstance(result, PerfRepoResult): + if not isinstance(result, PerfRepoResult) or not self.connected(): return Noop()
res_hash = result.generate_hash() @@ -674,6 +675,8 @@ class PerfRepoAPI(object): return baseline
def compare_to_baseline(self, result, report_id, metric_name): + if not self.connected(): + return False baseline_testExec = self.get_baseline(report_id) result_testExec = result.get_testExecution()
lnst-developers@lists.fedorahosted.org