Пример #1
0
def test_valid_config_schemas():

    valid_schema_dir = os.path.join(pytest_root, "examples", "config_schemas",
                                    "valid")
    schema_config = load_schema(DEFAULT_SETTINGS_SCHEMA)
    for schema in walk_tree(valid_schema_dir, ".yml"):
        example = load_recipe(os.path.abspath(schema))
        custom_validator(recipe=example, schema=schema_config)
Пример #2
0
def func_config_view(args=None):
    """View buildtest configuration file. This implements ``buildtest config view``"""

    settings_file = resolve_settings_file()
    print(f"Settings File: {settings_file}")
    print("{:_<80}".format(""))
    content = load_recipe(settings_file)

    print(yaml.dump(content, default_flow_style=False, sort_keys=False))
Пример #3
0
def check_valid_recipes(recipes, valids, loaded):
    """This method validates all recipes found in tests/valid/global with global schema: global/global.schema.json"""

    for recipe in recipes:
        assert recipe
        assert re.search("(yml|yaml)$", recipe)
        recipe_path = os.path.join(valids, recipe)
        content = load_recipe(recipe_path)

        custom_validator(recipe=content, schema=loaded)
        print("Recipe File: %s should be valid" % recipe_path)
Пример #4
0
def load_settings(settings_path=None):
    """Load the default settings file if no argument is specified.

    :param settings_path: Path to buildtest settings file
    :type settings_path: str, optional
    """

    if not settings_path:
        settings_path = resolve_settings_file()

    # load the settings file into a schema object
    return load_recipe(settings_path)
Пример #5
0
def check_invalid_recipes(recipes, invalids, loaded):
    """This method validates all recipes found in tests/invalid/global with global schema: global/global.schema.json"""

    for recipe in recipes:
        assert recipe
        assert re.search("(yml|yaml)$", recipe)

        recipe_path = os.path.join(invalids, recipe)
        content = load_recipe(recipe_path)

        with pytest.raises(ValidationError) as excinfo:
            custom_validator(recipe=content, schema=loaded)
        print(excinfo.type, excinfo.value)
        print("Recipe File: %s  should be invalid" % recipe_path)
Пример #6
0
def check_valid_recipes(recipes, valids, loaded, version):
    for recipe in recipes:
        assert recipe
        assert re.search("(yml|yaml)$", recipe)
        recipe_path = os.path.join(valids, recipe)
        content = load_recipe(recipe_path)

        # Ensure version is correct in header
        assert content["version"] == version
        del content["version"]

        # For each section, assume folder type and validate
        for name in content["buildspecs"].keys():
            custom_validator(recipe=content["buildspecs"][name], schema=loaded)
            print("Testing %s from recipe %s should be valid" % (name, recipe))
Пример #7
0
    def __init__(self, settings_file):
        self.file = settings_file
        self.config = load_recipe(settings_file)
        self.systems = self.config["system"].keys()

        # self.target_config stores value for target system. The configuration may define multiple system,
        # but only one system can be active depending on which host buildtest is run
        self.target_config = None
        self._validate()

        self.localexecutors = None
        self.slurmexecutors = None
        self.lsfexecutors = None
        self.cobaltexecutors = None
        self.pbsexecutors = None

        self.get_current_system()
Пример #8
0
def func_config_executors(args=None):
    """Display executors from buildtest configuration. This implements ``buildtest config executors`` command.
    If no option is specified we display output in JSON format
    """

    settings_file = resolve_settings_file()
    content = load_recipe(settings_file)

    d = {"executors": content["executors"]}

    # display output in JSON format
    if args.json:
        print(json.dumps(d, indent=2))
        return

    # display output in YAML format
    print(yaml.dump(d, default_flow_style=False))
Пример #9
0
    def __init__(self, buildspec, buildexecutor):
        """The init method will run some checks against buildspec before loading
        buildspec. We retrieve available schemas via method
        ``get_schemas_available`` and check if ``type`` in buildspec
        match available schema. We validate the entire buildspec with
        global.schema.json and validate each test section with the designated
        type schema. If there is any error during the init method, an
        exception will be raised.

        :param buildspec: the pull path to the Buildspec file, must exist.
        :type buildspec: str, required
        :param buildexecutor: an instance of BuildExecutor class defines Executors from configuration file
        :type buildexecutor: BuildExecutor, required
        """

        self.logger = logging.getLogger(__name__)

        if not isinstance(buildexecutor, BuildExecutor):
            raise BuildTestError(
                "Invalid type argument for 'buildexecutor', must be of type BuildExecutor"
            )

        self.buildexecutors = buildexecutor.list_executors()

        # if invalid input for buildspec
        if not buildspec:
            raise BuildTestError(
                "Invalid input type for Buildspec, must be of type 'string'.")

        self.buildspec = resolve_path(buildspec)

        if not self.buildspec:
            raise BuildTestError("There is no file named: %s " % buildspec)

        if is_dir(self.buildspec):
            raise BuildTestError(
                f"Detected {self.buildspec} is a directory, please provide a file path (not a directory path) to BuildspecParser."
            )

        self.recipe = load_recipe(self.buildspec)
        # ensure self.recipe exists after loading recipe
        assert self.recipe

        # validate each schema defined in the recipes
        self._validate()
Пример #10
0
def test_settings_examples():

    # load schema and ensure type is a dict
    recipe = load_schema(settings_schema)

    valid = os.path.join(settings_schema_examples, "valid")
    assert valid

    valid_recipes = os.listdir(valid)
    assert valid_recipes
    # check all valid recipes
    for example in valid_recipes:

        filepath = os.path.join(valid, example)
        print(f"Loading Recipe File: {filepath}")
        example_recipe = load_recipe(filepath)
        assert example_recipe

        print(f"Expecting Recipe File: {filepath} to be valid")
        custom_validator(recipe=example_recipe, schema=recipe)
Пример #11
0
def test_build_executor(tmp_path):

    settings_schema = load_schema(DEFAULT_SETTINGS_SCHEMA)
    example = load_recipe(DEFAULT_SETTINGS_FILE)
    custom_validator(recipe=example, schema=settings_schema)

    # Load BuildExecutor
    be = BuildExecutor(example)
    # We should have a total of 5 executors (local.bash, local.sh, local.csh, local.zsh, local.python)
    assert len(be.executors) == 5
    assert list(be.executors.keys()) == [
        "local.bash",
        "local.sh",
        "local.csh",
        "local.zsh",
        "local.python",
    ]

    # Each should have
    for name, executor in be.executors.items():
        assert hasattr(executor, "_settings")

    examples_dir = os.path.join(pytest_root, "examples", "buildspecs")
    for buildspec in os.listdir(examples_dir):
        buildspec = os.path.join(examples_dir, buildspec)
        try:
            bp = BuildspecParser(buildspec)
        except (SystemExit, ValidationError):
            continue

        bp_filters = {"tags": None}
        builders = Builder(bp=bp, filters=bp_filters, testdir=tmp_path)
        valid_builders = builders.get_builders()

        # build each test and then run it
        for builder in valid_builders:
            builder.build()
            be.run(builder)
            assert builder.metadata["result"]