Ejemplo n.º 1
0
 def __call__(self, omap):
     """
     Merges the original map with our yaml config map
     :param omap:
     :return:
     """
     self.original_map = omap
     updated = omap.update(self.record)
     log.log(DEFAULT_LOG_LEVEL, "=================== {} ====================".format(self.__class__))
     dprint(updated)
     return updated
Ejemplo n.º 2
0
    def __call__(self, omap):
        self.original_map = omap
        log.log(DEFAULT_LOG_LEVEL, "------------------- BEFORE: {} -----------------------".format(self.__class__))
        dprint(omap)

        distro_record = self._make_distro_record()
        if self.args.distro:
            self.dict_args["distro"] = distro_record

        # Before we modify the map, let's see if an environment file was passed in
        art_path = "artifact/{}".format(self.args.artifact_archive)
        if self.args.environment_file is not None:
            if "result_path" in omap:
                artifact = omap["result_path"] + art_path
            else:
                artifact = ""
        else:
            artifact = self.dict_args["result_path"]
            if isinstance(artifact, str) and artifact.startswith("http"):
                if art_path not in artifact:
                    artifact += art_path
        self.dict_args["result_path"] = artifact

        # If requirement_prefix or testcase_prefix were not set, give defaults here.  We can't set them in the
        # argparse default=, otherwise, since CLIConfigurator will come last, it will override earlier Configurators
        prefixes = ["requirement_prefix", "testcase_prefix"]
        for p in prefixes:
            if p not in omap and getattr(self.args, p) is None:
                self.dict_args[p] = ""

        # Trim any args from self.dict_args that are None
        final_args = {k: v for k, v in self.dict_args.items() if v is not None}
        updated = omap.update(final_args)
        log.log(DEFAULT_LOG_LEVEL, "=================== {} ====================".format(self.__class__))
        dprint(updated)
        return updated
Ejemplo n.º 3
0
def kickstart(yaml_path=None, args=None):
    """
    Kicks everything off by creating the configuration function pipeline

    :return:
    """
    # Create the CLIConfigurator first, because it may override defaults (eg, it can override the
    # default location of pylarion_path or exporter_config, which are needed by PylarionConfigurator
    # and YAMLConfigurator)

    cli_cfg = CLIConfigurator()
    start_map = pyr.m()
    init_map = cli_cfg(start_map)
    pyl_path = init_map.get("pylarion_path")
    yaml_path = init_map.get("exporter_config")
    env_path = init_map.get("environment_file")

    pyl_cfg = PylarionConfigurator(path=pyl_path)
    env_cfg = OSEnvironmentConfigurator()
    yml_cfg = YAMLConfigurator(cfg_path=yaml_path)
    jnk_cfg = None
    if env_path:
        jnk_cfg = JenkinsConfigurator(env_path)
    cli_cfg = CLIConfigurator(args=args)

    if env_path:
        pipeline = compose(cli_cfg, jnk_cfg, yml_cfg, env_cfg, pyl_cfg)
    else:
        pipeline = compose(cli_cfg, yml_cfg, env_cfg, pyl_cfg)
    end_map = pipeline(start_map)

    log.log(DEFAULT_LOG_LEVEL, "================ end_map ===================")
    dprint(end_map)

    try:
        final = ConfigRecord(**end_map)
    except pyr._checked_types.InvariantException as ex:
        print ex
        if ex.missing_fields:
            log.error("Following fields not configured: " + str(ex.missing_fields))
        if False and  ex.invariant_errors:
            log.error("Invariants broken: " + str(ex.invariant_errors))
        log.error("Please correct the above and run again")
        sys.exit(1)
    log.log(logging.INFO, "================= final ====================")
    dprint(final, log_lvl=logging.INFO)
    log.log(logging.INFO, "============================================\n")

    result = {"pyl_cfg": pyl_cfg,
              "env_cfg": env_cfg,
              "yml_cfg": yml_cfg,
              "cli_cfg": cli_cfg,
              "config": final}
    return result
Ejemplo n.º 4
0
def dprint(m, log_lvl=DEFAULT_LOG_LEVEL):
    for k, v in m.items():
        kv = "{}={}".format(str(k), str(v))
        log.log(log_lvl, kv)
Ejemplo n.º 5
0
 def __call__(self, omap):
     self.original_map = omap
     updated = omap.update(self.pylarion_record)
     log.log(DEFAULT_LOG_LEVEL, "=================== {} ====================".format(self.__class__))
     dprint(updated)
     return updated
Ejemplo n.º 6
0
 def __call__(self, config_map):
     self.original_map = config_map
     updated = config_map.update(self._make_record())
     log.log(DEFAULT_LOG_LEVEL, "=================== {} ====================".format(self.__class__))
     dprint(updated)
     return updated