Exemple #1
0
def func_compiler_find(args=None):
    """This method implements ``buildtest config compilers find`` which detects
    new compilers based on module names defined in configuration. If system has
    Lmod we use Lmodule API to detect the compilers. For environment-modules we
    search for all modules in current ``$MODULEPATH``.
    """

    settings_file = resolve_settings_file()
    configuration = load_settings(settings_file)

    bc = BuildtestCompilers(debug=args.debug)
    bc.find_compilers()
    configuration["compilers"]["compiler"] = bc.compilers

    custom_validator(configuration,
                     schema_table["settings.schema.json"]["recipe"])

    print(f"Configuration File: {settings_file}")
    print("{:_<80}".format(""))
    print(
        yaml.safe_dump(configuration,
                       default_flow_style=False,
                       sort_keys=False))
    print("{:_<80}".format(""))
    print(f"Updating settings file:  {settings_file}")

    with open(settings_file, "w") as fd:
        yaml.safe_dump(configuration,
                       fd,
                       default_flow_style=False,
                       sort_keys=False)
Exemple #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))
Exemple #3
0
def func_config_validate(args=None):
    """This method implements ``buildtest config validate`` which attempts to
    validate buildtest settings with schema. If it not validate an exception
    an exception of type SystemError is raised. We invoke ``check_settings``
    method which will validate the configuration, if it fails we except an exception
    of type ValidationError which we catch and print message.
    """

    settings_file = resolve_settings_file()
    try:
        check_settings(settings_path=settings_file, executor_check=True)
    except (ValidationError, SystemExit) as err:
        print(err)
        raise sys.exit(f"{settings_file} is not valid")

    print(f"{settings_file} is valid")
Exemple #4
0
def func_config_compiler(args=None):
    """This method implements ``buildtest config compilers`` which shows compiler
    section from buildtest configuration.
    """

    settings_file = resolve_settings_file()
    configuration = load_settings(settings_file)

    bc = BuildtestCompilers(configuration)

    if args.json:
        bc.print_json()
    if args.yaml:
        bc.print_yaml()
    if args.list:
        bc.print_compilers()
Exemple #5
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))
Exemple #6
0
def func_config_summary(args=None):
    """This method implements ``buildtest config summary`` option. In this method
    we will display a summary of System Details, Buildtest settings, Schemas,
    Repository details, Buildspecs files and test names.
    """

    print("buildtest version: ", BUILDTEST_VERSION)
    print("buildtest Path:", shutil.which("buildtest"))

    print("\n")
    print("Machine Details")
    print("{:_<30}".format(""))
    print("Operating System: ", system.system["os"])
    print("Hostname: ", system.system["host"])
    print("Machine: ", system.system["machine"])
    print("Processor: ", system.system["processor"])
    print("Python Path", system.system["python"])
    print("Python Version:", system.system["pyver"])
    print("User:"******"\n")

    print("Buildtest Settings")
    print("{:_<80}".format(""))
    print(f"Buildtest Settings: {BUILDTEST_SETTINGS_FILE}")

    settings_file = resolve_settings_file()
    settings = load_settings(settings_file)

    executors = []
    for executor_type in settings.get("executors").keys():
        for name in settings["executors"][executor_type].keys():
            executors.append(f"{executor_type}.{name}")

    print("Executors: ", executors)

    print("Buildspec Cache File:", BUILDSPEC_CACHE_FILE)
    print("\n")

    print("Buildtest Schemas")
    print("{:_<80}".format(""))
    print("Available Schemas:", supported_schemas)
Exemple #7
0
def main():
    """Entry point to buildtest."""

    if not os.getenv("BUILDTEST_COLOR"):
        os.environ["BUILDTEST_COLOR"] = "True"

    # create a temporary file to store logfile and we don't delete file by setting 'delete=False'
    # by default tempfile will delete file upon exit.
    tf = tempfile.NamedTemporaryFile(prefix="buildtest_",
                                     delete=False,
                                     suffix=".log")
    dest_logfile = tf.name

    logger = init_logfile(dest_logfile)
    logger.info("Starting buildtest log")

    create_dir(BUILDTEST_USER_HOME)
    create_dir(var_root)

    # Create a build test system, and check requirements
    # BuildTestSystem()
    system.check()

    parser = BuildTestParser()
    args = parser.parse_options()

    if args.debug:
        streamlog(args.debug)

    if args.subcommands == "build":
        # settings_file = resolve_settings_file(args.config)
        # check_settings(args.config)
        cmd = BuildTest(
            config_file=args.config,
            buildspecs=args.buildspec,
            exclude_buildspecs=args.exclude,
            executors=args.executor,
            tags=args.tags,
            filter_tags=args.filter_tags,
            rebuild=args.rebuild,
            stage=args.stage,
            testdir=args.testdir,
        )
        cmd.build()

        logdir = buildtest_configuration.target_config.get("logdir")

        if not logdir:
            print(f"Writing Logfile to: {dest_logfile}")
            sys.exit(0)

        logdir = resolve_path(logdir, exist=False)
        if logdir:
            create_dir(logdir)
            fname = os.path.basename(dest_logfile)
            logpath = os.path.join(logdir, fname)
            shutil.copy2(dest_logfile, logpath)

            print(f"Writing Logfile to: {logpath}")
        else:
            print(f"Writing Logfile to: {dest_logfile}")

        # store copy of logfile at $BUILDTEST_ROOT/buildtest.log. A convenient location for user to
        # find logfile for last build, this will be overwritten for every subsequent build.
        shutil.copy2(
            dest_logfile,
            os.path.join(os.getenv("BUILDTEST_ROOT"), "buildtest.log"))
        return

    settings_file = resolve_settings_file()

    logger.info(f"Processing buildtest configuration file: {settings_file}")
    check_settings(settings_file)

    # implementation for 'buildtest buildspec find'
    if args.subcommands == "buildspec":
        buildspec_find(args=args, settings_file=settings_file)
        return

    if args.subcommands and args.func:
        args.func(args)
Exemple #8
0
def main():
    """Entry point to buildtest."""

    # create a temporary file to store logfile and we don't delete file by setting 'delete=False'
    # by default tempfile will delete file upon exit.
    tf = tempfile.NamedTemporaryFile(prefix="buildtest_",
                                     delete=False,
                                     suffix=".log")
    dest_logfile = tf.name

    logger = init_logfile(dest_logfile)
    logger.info("Starting buildtest log")

    create_dir(BUILDTEST_USER_HOME)
    create_dir(var_root)

    # Create a build test system, and check requirements
    # BuildTestSystem()
    system.check()

    parser = BuildTestParser()
    args = parser.parse_options()

    if args.debug:
        streamlog(args.debug)

    # invoking load_settings will attempt to initialize buildtest settings and
    # load the schema
    settings_file = resolve_settings_file()
    logger.info(f"Processing buildtest configuration file: {settings_file}")
    buildtest_configuration = check_settings(settings_file,
                                             retrieve_settings=True)

    if args.subcommands == "build":
        func_build_subcmd(args, buildtest_configuration)
    else:
        if args.subcommands and args.func:
            args.func(args)
        return

    logdir = buildtest_configuration.get("logdir")

    if not logdir:
        print(f"Writing Logfile to: {dest_logfile}")
        sys.exit(0)

    logdir = resolve_path(logdir, exist=False)
    if logdir:
        create_dir(logdir)
        fname = os.path.basename(dest_logfile)
        logpath = os.path.join(logdir, fname)
        shutil.copy2(dest_logfile, logpath)

        print(f"Writing Logfile to: {logpath}")
    else:
        print(f"Writing Logfile to: {dest_logfile}")

    # store copy of logfile at $BUILDTEST_ROOT/buildtest.log. A convenient location for user to
    # find logfile for last build, this will be overwritten for every subsequent build.
    shutil.copy2(dest_logfile,
                 os.path.join(os.getenv("BUILDTEST_ROOT"), "buildtest.log"))
Exemple #9
0
import os
import pytest
from buildtest.config import resolve_settings_file
from buildtest.defaults import BUILDTEST_ROOT
from buildtest.exceptions import BuildTestError
from buildtest.menu.buildspec import BuildspecCache

settings_file = resolve_settings_file()


@pytest.mark.cli
def test_func_buildspec_find():

    # buildtest buildspec find --rebuild
    cache = BuildspecCache(rebuild=True, settings_file=settings_file)

    cache.print_buildspecs()

    # buildtest buildspec find
    cache = BuildspecCache(settings_file=settings_file)
    cache.print_buildspecs()

    # implements buildtest buildspec find --tags
    cache.get_tags()

    # implements buildtest buildspec find --buildspec
    cache.get_buildspecfiles()

    # implements buildtest buildspec find --paths
    cache.print_paths()