コード例 #1
0
ファイル: _config.py プロジェクト: ilanuk/taskcat
 def __init__(self, sources: list, uid: uuid.UUID):
     self.config = BaseConfig.from_dict(DEFAULTS)
     self.config.set_source("TASKCAT_DEFAULT")
     self.uid = uid
     for source in sources:
         config_dict: dict = source["config"]
         source_name: str = source["source"]
         source_config = BaseConfig.from_dict(config_dict)
         source_config.set_source(source_name)
         self.config = BaseConfig.merge(self.config, source_config)
コード例 #2
0
def parse_legacy_config(project_root: Path):
    config_file = (project_root / "ci/taskcat.yml").expanduser().resolve()
    if not config_file.is_file():
        raise TaskCatException(f"No config_file at {config_file}")
    with open(str(config_file), "r") as file_handle:
        config_dict = yaml.safe_load(file_handle)
    # need to rename global key, as it's a python keyword
    config_dict["global_"] = config_dict.pop("global")
    legacy_config = LegacyConfig.from_dict(config_dict)
    tests = {}
    for test_name, test_data in legacy_config.tests.items():
        parameters = {}
        parameter_file = project_root / "ci/" / test_data.parameter_input
        parameter_file = parameter_file.expanduser().resolve()
        with open(str(parameter_file), "r") as file_handle:
            for param in yaml.safe_load(file_handle):
                parameters[param["ParameterKey"]] = param["ParameterValue"]
        tests[test_name] = {
            "template": "templates/" + test_data.template_file,
            "parameters": parameters,
            "regions": test_data.regions,
        }
        if not tests[test_name]["regions"]:
            del tests[test_name]["regions"]
    new_config_dict = {
        "project": {
            "name": legacy_config.global_.qsname,
            "owner": legacy_config.global_.owner,
            "s3_bucket": legacy_config.global_.s3bucket,
            "package_lambda": legacy_config.global_.lambda_build,
            "regions": legacy_config.global_.regions,
        },
        "tests": tests,
    }
    new_config = BaseConfig.from_dict(new_config_dict)
    LOG.warning(
        "config is in a legacy format, support for which will be dropped in a "
        "future version. a new format config (.taskcat.yml) will been placed "
        "in your project_root"
    )
    new_config_path = project_root / ".taskcat.yml"
    if new_config_path.exists():
        LOG.warning(
            f"skipping new config file creation, file already exits at "
            f"{new_config_path}"
        )
    else:
        with open(str(new_config_path), "w") as file_handle:
            config_dict = new_config.to_dict()
            config_dict.pop("general")
            yaml.dump(config_dict, file_handle, default_flow_style=False)
    return new_config