X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=utils%2Ftest%2Fresult_collection_api%2Fopnfv_testapi%2Fresources%2Fresult_models.py;h=f73f5c6126f1b5be1fb3de9bd26b43c41f5fa508;hb=ebd48fb22672ba26b05ee638a4aac7cd0b456f8d;hp=fb6a80961c05f99b6fa9d51c4556192a082a065b;hpb=42e8032b74ef4489a8c77a9dc9e5e7a7cc02b997;p=releng.git diff --git a/utils/test/result_collection_api/opnfv_testapi/resources/result_models.py b/utils/test/result_collection_api/opnfv_testapi/resources/result_models.py index fb6a80961..f73f5c612 100644 --- a/utils/test/result_collection_api/opnfv_testapi/resources/result_models.py +++ b/utils/test/result_collection_api/opnfv_testapi/resources/result_models.py @@ -9,8 +9,69 @@ from opnfv_testapi.tornado_swagger import swagger +@swagger.model() +class TIHistory(object): + """ + @ptype step: L{float} + """ + def __init__(self, date=None, step=0): + self.date = date + self.step = step + + def format(self): + return { + "date": self.date, + "step": self.step + } + + @staticmethod + def from_dict(a_dict): + if a_dict is None: + return None + + return TIHistory(a_dict.get('date'), a_dict.get('step')) + + +@swagger.model() +class TI(object): + """ + @property histories: trust_indicator update histories + @ptype histories: C{list} of L{TIHistory} + @ptype current: L{float} + """ + def __init__(self, current=0): + self.current = current + self.histories = list() + + def format(self): + hs = [] + for h in self.histories: + hs.append(h.format()) + + return { + "current": self.current, + "histories": hs + } + + @staticmethod + def from_dict(a_dict): + t = TI() + if a_dict: + t.current = a_dict.get('current') + if 'histories' in a_dict.keys(): + for history in a_dict.get('histories', None): + t.histories.append(TIHistory.from_dict(history)) + else: + t.histories = [] + return t + + @swagger.model() class ResultCreateRequest(object): + """ + @property trust_indicator: + @ptype trust_indicator: L{TI} + """ def __init__(self, pod_name=None, project_name=None, @@ -35,7 +96,7 @@ class ResultCreateRequest(object): self.build_tag = build_tag self.scenario = scenario self.criteria = criteria - self.trust_indicator = trust_indicator + self.trust_indicator = trust_indicator if trust_indicator else TI(0) def format(self): return { @@ -50,15 +111,30 @@ class ResultCreateRequest(object): "build_tag": self.build_tag, "scenario": self.scenario, "criteria": self.criteria, - "trust_indicator": self.trust_indicator + "trust_indicator": self.trust_indicator.format() + } + + +@swagger.model() +class ResultUpdateRequest(object): + """ + @property trust_indicator: + @ptype trust_indicator: L{TI} + """ + def __init__(self, trust_indicator=None): + self.trust_indicator = trust_indicator + + def format(self): + return { + "trust_indicator": self.trust_indicator.format(), } @swagger.model() class TestResult(object): """ - @property trust_indicator: must be int/long/float - @ptype trust_indicator: L{float} + @property trust_indicator: used for long duration test case + @ptype trust_indicator: L{TI} """ def __init__(self, _id=None, case_name=None, project_name=None, pod_name=None, installer=None, version=None, @@ -90,7 +166,6 @@ class TestResult(object): t.case_name = a_dict.get('case_name') t.pod_name = a_dict.get('pod_name') t.project_name = a_dict.get('project_name') - t.description = a_dict.get('description') t.start_date = str(a_dict.get('start_date')) t.stop_date = str(a_dict.get('stop_date')) t.details = a_dict.get('details') @@ -99,19 +174,7 @@ class TestResult(object): t.build_tag = a_dict.get('build_tag') t.scenario = a_dict.get('scenario') t.criteria = a_dict.get('criteria') - # 0 < trust indicator < 1 - # if bad value => set this indicator to 0 - t.trust_indicator = a_dict.get('trust_indicator') - if t.trust_indicator is not None: - if isinstance(t.trust_indicator, (int, long, float)): - if t.trust_indicator < 0: - t.trust_indicator = 0 - elif t.trust_indicator > 1: - t.trust_indicator = 1 - else: - t.trust_indicator = 0 - else: - t.trust_indicator = 0 + t.trust_indicator = TI.from_dict(a_dict.get('trust_indicator')) return t def format(self): @@ -119,7 +182,6 @@ class TestResult(object): "case_name": self.case_name, "project_name": self.project_name, "pod_name": self.pod_name, - "description": self.description, "start_date": str(self.start_date), "stop_date": str(self.stop_date), "version": self.version, @@ -128,7 +190,7 @@ class TestResult(object): "build_tag": self.build_tag, "scenario": self.scenario, "criteria": self.criteria, - "trust_indicator": self.trust_indicator + "trust_indicator": self.trust_indicator.format() } def format_http(self): @@ -137,7 +199,6 @@ class TestResult(object): "case_name": self.case_name, "project_name": self.project_name, "pod_name": self.pod_name, - "description": self.description, "start_date": str(self.start_date), "stop_date": str(self.stop_date), "version": self.version, @@ -146,7 +207,7 @@ class TestResult(object): "build_tag": self.build_tag, "scenario": self.scenario, "criteria": self.criteria, - "trust_indicator": self.trust_indicator + "trust_indicator": self.trust_indicator.format() }