Пример #1
0
def execute_shell(cli,
                  project,
                  command,
                  *,
                  config=None,
                  mount=None,
                  element="base.bst",
                  isolate=False):
    # Ensure the element is built
    result = cli.run_project_config(project=project,
                                    project_config=config,
                                    args=["build", element])
    assert result.exit_code == 0

    args = ["shell"]
    if isolate:
        args += ["--isolate"]
    if mount is not None:
        host_path, target_path = mount
        args += ["--mount", host_path, target_path]
    args += [element, "--", *command]

    return cli.run_project_config(project=project,
                                  project_config=config,
                                  args=args)
Пример #2
0
def test_build_uid_in_project(cli, datafiles):
    project = str(datafiles)
    element_name = "build-uid/build-uid-1023.bst"

    project_config = {"name": "build-uid-test", "sandbox": {"build-uid": 1023, "build-gid": 3490}}

    result = cli.run_project_config(project=project, project_config=project_config, args=["build", element_name])
    assert result.exit_code == 0
Пример #3
0
def test_build_uid_overridden(cli, datafiles):
    project = str(datafiles)
    element_name = "build-uid/build-uid.bst"

    project_config = {"name": "build-uid-test", "sandbox": {"build-uid": 800, "build-gid": 900}}

    result = cli.run_project_config(project=project, project_config=project_config, args=["build", element_name])
    assert result.exit_code == 0
Пример #4
0
def test_preserve_environment(datafiles, cli):
    project = str(datafiles)
    checkout = os.path.join(cli.directory, "checkout")

    #
    # First build the target, this will create the echo-env-var.bst artifact
    # and cache an integration command which uses it's build environment
    # to create /etc/test.conf
    #
    result = cli.run(project=project, args=["build", "echo-target.bst"])
    result.assert_success()

    #
    # Now preserve the cache key of the toplevel
    #
    key = cli.get_element_key(project, "echo-target.bst")

    #
    # From here on out, we will augment the project.conf with a modified
    # environment, causing the definition of the element to change and
    # consequently the cache key.
    #
    project_config = {"environment": {"TEST_VAR": "horsy"}}

    #
    # This should changed the cache key such that a different artifact
    # would be produced, as the environment has changed.
    #
    result = cli.run_project_config(
        project=project,
        project_config=project_config,
        args=[
            "show", "--deps", "none", "--format", "%{full-key}",
            "echo-target.bst"
        ],
    )
    result.assert_success()
    assert result.output.strip() != key

    #
    # Now checkout the originally built artifact and request that it be integrated,
    # this will run integration commands encoded into the artifact.
    #
    checkout_args = [
        "artifact",
        "checkout",
        "--directory",
        checkout,
        "--deps",
        "build",
        "--integrate",
        "test/echo-target/" + key,
    ]
    result = cli.run_project_config(project=project,
                                    args=checkout_args,
                                    project_config=project_config)
    result.assert_success()

    #
    # Now observe the file generated by echo-env-var.bst's integration command.
    #
    # Here we assert that the actual environment from the artifact is being
    # used to run the integration command, and not the irrelevant project
    # data in the local project directory.
    #
    filename = os.path.join(checkout, "etc", "test.conf")
    assert os.path.exists(filename)
    with open(filename, "r") as f:
        data = f.read()
        data = data.strip()
        assert data == "pony"