X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Ftools%2Fpresentation%2Fspecification_parser.py;h=2659c29ca59a4a9350fa87e604c969ff7c52f333;hp=ec663f99d9aa4ba69d358e6f1428163a2aa8b741;hb=efdcf6470f6e15dcc918c70e5a61d10e10653f1e;hpb=eecad36d7d2275fa47fbcab40dbcf56108ab0a51 diff --git a/resources/tools/presentation/specification_parser.py b/resources/tools/presentation/specification_parser.py index ec663f99d9..2659c29ca5 100644 --- a/resources/tools/presentation/specification_parser.py +++ b/resources/tools/presentation/specification_parser.py @@ -22,6 +22,7 @@ from yaml import load, YAMLError from pprint import pformat from errors import PresentationError +from utils import get_last_build_number class Specification(object): @@ -46,13 +47,15 @@ class Specification(object): self._cfg_yaml = None self._specification = {"environment": dict(), + "configuration": dict(), "debug": dict(), "static": dict(), "input": dict(), "output": dict(), "tables": list(), "plots": list(), - "files": list()} + "files": list(), + "cpta": dict()} @property def specification(self): @@ -72,6 +75,15 @@ class Specification(object): """ return self._specification["environment"] + @property + def configuration(self): + """Getter - configuration. + + :returns: Configuration of PAL. + :rtype: dict + """ + return self._specification["configuration"] + @property def static(self): """Getter - static content. @@ -163,6 +175,17 @@ class Specification(object): """ return self._specification["files"] + @property + def cpta(self): + """Getter - Continuous Performance Trending and Analysis to be + generated. + + :returns: List of specifications of Continuous Performance Trending and + Analysis to be generated. + :rtype: list + """ + return self._specification["cpta"] + def set_input_state(self, job, build_nr, state): """Set the state of input @@ -330,6 +353,47 @@ class Specification(object): logging.info("Done.") + def _parse_configuration(self): + """Parse configuration of PAL in the specification YAML file. + """ + + logging.info("Parsing specification file: configuration ...") + + idx = self._get_type_index("configuration") + if idx is None: + logging.warning("No configuration information in the specification " + "file.") + return None + + try: + self._specification["configuration"] = self._cfg_yaml[idx] + + except KeyError: + raise PresentationError("No configuration defined.") + + # Data sets: Replace ranges by lists + for set_name, data_set in self.configuration["data-sets"].items(): + for job, builds in data_set.items(): + if builds: + if isinstance(builds, dict): + # defined as a range + if builds.get("end", None) == "lastSuccessfulBuild": + # defined as a range + ret_code, build_nr, _ = get_last_build_number( + self.environment["urls"]["URL[JENKINS,CSIT]"], + job) + if ret_code != 0: + raise PresentationError( + "Not possible to get the number of the " + "last successful build.") + else: + # defined as a range + build_nr = builds.get("end", None) + builds = [x for x in range(1, int(build_nr)+1)] + self.configuration["data-sets"][set_name][job] = builds + + logging.info("Done.") + def _parse_debug(self): """Parse debug specification in the specification YAML file. """ @@ -383,8 +447,25 @@ class Specification(object): for key, value in self._cfg_yaml[idx]["general"].items(): self._specification["input"][key] = value self._specification["input"]["builds"] = dict() + for job, builds in self._cfg_yaml[idx]["builds"].items(): if builds: + if isinstance(builds, dict): + # defined as a range + if builds.get("end", None) == "lastSuccessfulBuild": + # defined as a range + ret_code, build_nr, _ = get_last_build_number( + self.environment["urls"]["URL[JENKINS,CSIT]"], + job) + if ret_code != 0: + raise PresentationError( + "Not possible to get the number of the " + "last successful build.") + else: + # defined as a range + build_nr = builds.get("end", None) + builds = [x for x in range(builds["start"], + int(build_nr) + 1)] self._specification["input"]["builds"][job] = list() for build in builds: self._specification["input"]["builds"][job].\ @@ -411,8 +492,8 @@ class Specification(object): raise PresentationError("No output defined.") try: - self._specification["output"] = self._cfg_yaml[idx]["format"] - except KeyError: + self._specification["output"] = self._cfg_yaml[idx] + except (KeyError, IndexError): raise PresentationError("No output defined.") logging.info("Done.") @@ -455,6 +536,17 @@ class Specification(object): self._specification["environment"]["paths"]) except KeyError: pass + + # add data sets to the elements: + if isinstance(element.get("data", None), str): + data_set = element["data"] + try: + element["data"] = self.configuration["data-sets"][data_set] + except KeyError: + raise PresentationError("Data set {0} is not defined in " + "the configuration section.". + format(data_set)) + if element["type"] == "table": logging.info(" {:3d} Processing a table ...".format(count)) try: @@ -465,10 +557,25 @@ class Specification(object): pass self._specification["tables"].append(element) count += 1 + elif element["type"] == "plot": logging.info(" {:3d} Processing a plot ...".format(count)) + + # Add layout to the plots: + layout = element["layout"].get("layout", None) + if layout is not None: + element["layout"].pop("layout") + try: + for key, val in (self.configuration["plot-layouts"] + [layout].items()): + element["layout"][key] = val + except KeyError: + raise PresentationError("Layout {0} is not defined in " + "the configuration section.". + format(layout)) self._specification["plots"].append(element) count += 1 + elif element["type"] == "file": logging.info(" {:3d} Processing a file ...".format(count)) try: @@ -480,6 +587,35 @@ class Specification(object): self._specification["files"].append(element) count += 1 + elif element["type"] == "cpta": + logging.info(" {:3d} Processing Continuous Performance " + "Trending and Analysis ...".format(count)) + + for plot in element["plots"]: + # Add layout to the plots: + layout = plot.get("layout", None) + if layout is not None: + try: + plot["layout"] = \ + self.configuration["plot-layouts"][layout] + except KeyError: + raise PresentationError( + "Layout {0} is not defined in the " + "configuration section.".format(layout)) + # Add data sets: + if isinstance(plot.get("data", None), str): + data_set = plot["data"] + try: + plot["data"] = \ + self.configuration["data-sets"][data_set] + except KeyError: + raise PresentationError( + "Data set {0} is not defined in " + "the configuration section.". + format(data_set)) + self._specification["cpta"] = element + count += 1 + logging.info("Done.") def read_specification(self): @@ -496,6 +632,7 @@ class Specification(object): details=str(err)) self._parse_env() + self._parse_configuration() self._parse_debug() if not self.debug: self._parse_input()