Exemple #1
0
def test_multiple_env():
    """Verifies that multiple environment variables can be successfully passed
    in."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    result = helpers.execute_command([
        "-v",
        "--env",
        "COMPOSE_PROJECT_NAME=test",
        "--env",
        "STARBURST_VER=354-e",
        "--env",
        "TRINO=is=awesome",
        "version",
    ])

    assert result.exit_code == 0
    assert all((
        '"COMPOSE_PROJECT_NAME": "test"' in result.output,
        '"STARBURST_VER": "354-e"' in result.output,
        '"TRINO": "is=awesome"' in result.output,
    ))

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
def main():
    helpers.log_status(__file__)
    test_invalid_module()
    test_valid_module()
    test_all_modules()
    test_json()
    test_running()
Exemple #3
0
def test_invalid_label():
    """Verifies that images with the Minitrino label applied to them are
    removed."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    helpers.execute_command(["provision", "--module", "test"])
    helpers.execute_command(["down", "--sig-kill"])
    result = helpers.execute_command(
        ["-v", "remove", "--images", "--label", "not-real-label=not-real"]
    )

    assert result.exit_code == 0
    assert "Image removed:" not in result.output

    assert_docker_resource_count(
        {
            "resource_type": docker_client.images,
            "label": "com.starburst.tests.module.test=catalog-test",
            "expected_count": 1,
        }
    )

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
    cleanup()
def test_bootstrap_script(result):
    """Ensures that bootstrap scripts properly execute in containers."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    assert all((
        "Successfully executed bootstrap script in container: 'trino'",
        "Successfully executed bootstrap script in container: 'test'",
    ))

    trino_bootstrap_check = subprocess.Popen(
        f"docker exec -i trino ls /etc/starburst/",
        shell=True,
        stdout=subprocess.PIPE,
        universal_newlines=True,
    )
    test_bootstrap_check = subprocess.Popen(
        f"docker exec -i test cat /root/test_bootstrap.txt",
        shell=True,
        stdout=subprocess.PIPE,
        universal_newlines=True,
    )

    trino_bootstrap_check, _ = trino_bootstrap_check.communicate()
    test_bootstrap_check, _ = test_bootstrap_check.communicate()

    assert "test_bootstrap.txt" in trino_bootstrap_check
    assert "hello world" in test_bootstrap_check

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
Exemple #5
0
def test_remove_dependent_resources_running():
    """Verifies that a dependent resources (tied to active containers) cannot be
    removed."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    helpers.execute_command(["provision", "--module", "test"])
    result = helpers.execute_command(
        ["-v", "remove", "--images", "--volumes"], command_input="y\n"
    )

    assert result.exit_code == 0
    assert all(
        (
            "Cannot remove volume:" in result.output,
            "Cannot remove image:" in result.output,
        )
    )

    assert_docker_resource_count(
        {
            "resource_type": docker_client.images,
            "label": "com.starburst.tests.module.test=catalog-test",
            "expected_count": 1,
        },
        {
            "resource_type": docker_client.volumes,
            "label": "com.starburst.tests.module.test=catalog-test",
            "expected_count": 1,
        },
    )

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
    cleanup()
Exemple #6
0
def test_specific_directory():
    """Tests that the snapshot file can be saved in a user-specified
    directory."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    cleanup()
    result = helpers.execute_command(
        [
            "-v",
            "snapshot",
            "--name",
            "test",
            "--module",
            "test",
            "--directory",
            "/tmp/",
        ],
        command_input="y\n",
    )

    run_assertions(result, True, check_path=os.path.join(os.sep, "tmp"))
    assert "Creating snapshot of specified modules" in result.output

    subprocess.call("rm -rf /tmp/test.tar.gz", shell=True)

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
Exemple #7
0
def test_all():
    """Verifies that all Minitrino resources are removed."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    helpers.execute_command(["provision", "--module", "test"])
    helpers.execute_command(["down", "--sig-kill"])
    result = helpers.execute_command(
        ["-v", "remove", "--images", "--volumes"], command_input="y\n"
    )

    assert result.exit_code == 0
    assert all(("Volume removed:" in result.output, "Image removed:" in result.output))

    assert_docker_resource_count(
        {
            "resource_type": docker_client.images,
            "label": RESOURCE_LABEL,
            "expected_count": 0,
        },
        {
            "resource_type": docker_client.volumes,
            "label": RESOURCE_LABEL,
            "expected_count": 0,
        },
    )

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
    cleanup()
Exemple #8
0
def test_label():
    """Verifies that only images with the given label are removed."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    helpers.execute_command(["provision", "--module", "test"])
    helpers.execute_command(["down", "--sig-kill"])
    result = helpers.execute_command(
        [
            "-v",
            "remove",
            "--images",
            "--label",
            "com.starburst.tests.module.test=catalog-test",
        ],
    )

    assert result.exit_code == 0
    assert "Image removed:" in result.output

    assert_docker_resource_count(
        {
            "resource_type": docker_client.images,
            "label": "com.starburst.tests.module.test=catalog-test",
            "expected_count": 0,
        },
        {
            "resource_type": docker_client.images,
            "label": "com.starburst.tests.module=trino",
            "expected_count": 1,
        },
    )

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
    cleanup()
def main():
    helpers.log_status(__file__)
    helpers.start_docker_daemon()
    cleanup()
    test_no_containers()
    test_running_containers()
    test_keep()
Exemple #10
0
def test_version():
    """Tests for correct version output."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    result = helpers.execute_command(["version"])
    assert pkg_resources.require("Minitrino")[0].version in result.output

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
def test_reset_with_directory():
    """Verifies that the configuration directory is only removed and restored
    with the user's approval. This is a valid test case for both 'yes' and 'no'
    responses."""

    import time

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    subprocess.call(
        f"mkdir {helpers.MINITRINO_USER_DIR}", shell=True, stdout=subprocess.DEVNULL
    )

    start_time = time.time()
    end_time = 2.0
    output = ""
    while time.time() - start_time <= end_time:
        process = subprocess.Popen(
            "minitrino -v config --reset",
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
            universal_newlines=True,
        )
        while True:
            output_line = process.stdout.readline()
            if output_line == "":
                break
        output, _ = process.communicate()  # Get full output (stdout + stderr)
        if time.time() >= end_time:
            process.terminate()
            break

    process = subprocess.Popen(
        "minitrino -v config --reset",
        stdout=subprocess.PIPE,
        stdin=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        shell=True,
        universal_newlines=True,
    )
    output = process.communicate(input="y\n", timeout=1)[0]
    process.terminate()

    assert process.returncode == 0
    assert all(
        (
            "Configuration directory exists" in output,
            "Created Minitrino configuration directory" in output,
            "Opening existing config file at path" in output,
        )
    )
    assert os.path.isdir(helpers.MINITRINO_USER_DIR)
    assert os.path.isfile(helpers.CONFIG_FILE)

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
def test_edit_valid_config():
    """Verifies that the user can edit an existing configuration file."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    subprocess.call(f"rm -rf {helpers.MINITRINO_USER_DIR}", shell=True)
    subprocess.call(f"mkdir {helpers.MINITRINO_USER_DIR}", shell=True)
    helpers.make_sample_config()
    return_code = subprocess.call(f"minitrino config", shell=True)
    assert return_code == 0
    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
Exemple #13
0
def test_env():
    """Verifies that an environment variable can be successfully passed in."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    result = helpers.execute_command(
        ["-v", "--env", "COMPOSE_PROJECT_NAME=test", "version"])

    assert result.exit_code == 0
    assert "COMPOSE_PROJECT_NAME" and "test" in result.output

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
def main():
    helpers.log_status(__file__)
    helpers.start_docker_daemon()
    cleanup()
    test_standalone()
    test_bad_sep_version()
    test_invalid_module()
    test_docker_native()
    test_valid_user_config()
    test_duplicate_config_props()
    test_incompatible_modules()
    test_provision_append()
def test_valid_module():
    """Ensures the `module` command works when providing a valid module name."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    result = helpers.execute_command(["-v", "modules", "--module", "test"])

    assert result.exit_code == 0
    assert all(("Module: test" in result.output, "Test module"
                in result.output))

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
def test_invalid_module():
    """Ensures Minitrino exists with a user error if an invalid module name is
    provided."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    result = helpers.execute_command(
        ["-v", "modules", "--module", "not-a-real-module"])

    assert result.exit_code == 2
    assert "Invalid module" in result.output

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
Exemple #17
0
def main():
    helpers.log_status(__file__)
    helpers.start_docker_daemon()
    cleanup()
    test_images()
    test_volumes()
    test_label()
    test_multiple_labels()
    test_invalid_label()
    test_all()
    test_remove_dependent_resources_running()
    test_remove_dependent_resources_stopped()
    test_remove_dependent_resources_force()
def test_edit_invalid_config():
    """Verifies that an error is not thrown if the config is 'invalid' (such as
    a missing section or value required to perform an action). This is because
    there is default behavior built in, and all major functions should still
    work without a valid configuration file."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    subprocess.call(f"rm -rf {helpers.MINITRINO_USER_DIR}", shell=True)
    subprocess.call(f"mkdir {helpers.MINITRINO_USER_DIR}", shell=True)
    subprocess.call(f"touch {helpers.CONFIG_FILE}", shell=True)
    return_code = subprocess.call(f"minitrino config", shell=True)
    assert return_code == 0
    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
def test_no_directory():
    """Verifies that a configuration directory and config file are created with
    config --reset."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    subprocess.call(f"rm -rf {helpers.MINITRINO_USER_DIR}", shell=True)
    return_code = subprocess.call("minitrino config", shell=True)

    assert return_code == 0
    assert os.path.isdir(helpers.MINITRINO_USER_DIR)
    assert os.path.isfile(helpers.CONFIG_FILE)

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
def test_install():
    """Verifies that the Minitrino library can be installed."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)
    cleanup()

    # Install 0.0.0 since it's always around as a test release
    result = helpers.execute_command(
        ["-v", "lib_install", "--version", "0.0.0"])

    assert result.exit_code == 0
    assert os.path.isdir(os.path.join(helpers.MINITRINO_USER_DIR, "lib"))

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
def test_json():
    """Ensures the `module` command can output module metadata in JSON
    format."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    result = helpers.execute_command(
        ["-v", "modules", "--module", "test", "--json"])

    assert result.exit_code == 0
    assert all(('"type": "catalog"' in result.output, '"test":'
                in result.output))

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
Exemple #22
0
def test_snapshot_standalone():
    """Verifies that a the standlone Trino module can be snapshotted."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    cleanup()
    result = helpers.execute_command(
        ["-v", "snapshot", "--name", "test"],
        command_input="y\n",
    )

    run_assertions(result, False)
    assert "Snapshotting Trino resources only" in result.output

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
Exemple #23
0
def main():
    helpers.log_status(__file__)
    helpers.start_docker_daemon()
    test_snapshot_no_directory()
    test_snapshot_standalone()
    test_snapshot_active_env()
    test_snapshot_inactive_env()
    test_valid_name()
    test_invalid_name()
    test_specific_directory()
    test_specific_directory_invalid()
    test_command_snapshot_file()
    test_force()
    test_scrub()
    test_no_scrub()
def test_bootstrap_re_execute():
    """Ensures that bootstrap scripts do not execute if they have already
    executed."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    result = helpers.execute_command(["-v", "provision", "--module", "test"])

    assert result.exit_code == 0
    assert all((
        "Bootstrap already executed in container 'trino'. Skipping.",
        "Bootstrap already executed in container 'test'. Skipping.",
    ))

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
def test_invalid_ver():
    """Verifies that an error is raised if an incorrect version is passed to the
    command."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    result = helpers.execute_command(
        ["-v", "lib_install", "--version", "YEE-TRINO"])

    assert result.exit_code == 1
    assert not os.path.isdir(os.path.join(helpers.MINITRINO_USER_DIR, "lib"))

    cleanup()

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
def test_install_overwrite():
    """Verifies that the Minitrino library can be installed over an existing
    library."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    result = helpers.execute_command(
        ["-v", "lib_install", "--version", "0.0.0"], command_input="y\n")

    assert result.exit_code == 0
    assert os.path.isdir(os.path.join(helpers.MINITRINO_USER_DIR, "lib"))
    assert "Removing existing library directory" in result.output

    cleanup()

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
def test_provision_append():
    """Verifies that modules can be appended to already-running environments."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    helpers.execute_command(["-v", "provision", "--module", "test"])
    result = helpers.execute_command(
        ["-v", "provision", "--module", "postgres"])
    containers = get_containers()

    assert result.exit_code == 0
    assert "Identified the following running modules" in result.output
    assert len(containers) == 3  # trino, test, and postgres

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
    cleanup()
Exemple #28
0
def test_invalid_name():
    """Tests that all valid characters can be present and succeed for a given
    snapshot name."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    cleanup()
    result = helpers.execute_command(
        ["-v", "snapshot", "--name", "##.my-test?", "--module", "test"],
        command_input="y\n",
    )

    assert result.exit_code == 2
    assert "Illegal character found in provided filename" in result.output

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
Exemple #29
0
def test_snapshot_inactive_env():
    """Verifies that a snapshot can be successfully created from an inactive
    environment."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    cleanup()
    result = helpers.execute_command(
        ["-v", "snapshot", "--name", "test", "--module", "test"],
        command_input="y\n",
    )

    run_assertions(result)
    assert "Creating snapshot of specified modules" in result.output

    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)
Exemple #30
0
def test_force():
    """Verifies that the user can override the check to see if the resulting
    tarball exists."""

    helpers.log_status(cast(FrameType, currentframe()).f_code.co_name)

    result = helpers.execute_command(
        ["-v", "snapshot", "--name", "test", "--module", "test", "--force"],
        command_input="y\n",
    )

    run_assertions(result)
    assert "Creating snapshot of specified modules" in result.output

    cleanup()
    helpers.log_success(cast(FrameType, currentframe()).f_code.co_name)