Пример #1
0
def test_get_package_version_pip(current_python_process: Process):
    # GIVEN a Process with the current python
    # WHEN fetching the pip version
    version = fetch_package_version(python_process=current_python_process,
                                    package_name="pip")
    # THEN assert that a version was returned
    assert version
Пример #2
0
def test_get_package_version_non_existing(current_python_process: Process):
    # GIVEN a Process with the current python
    # WHEN fetching the version of a non existing package
    version = fetch_package_version(python_process=current_python_process,
                                    package_name="non_existing")
    # THEN assert that a empty version was returned
    assert version == ""
Пример #3
0
def check_cmd(context):
    """Run a check if deployment would be possible"""
    LOG.info("Running shipping check")

    host_config: HostConfig = context.obj["host_config"]
    app_config: AppConfig = context.obj["app_config"]
    env_name: str = context.obj["env_name"]

    LOG.info(
        "%s wants to deploy %s on host %s in environment %s",
        context.obj["current_user"],
        app_config.tool,
        context.obj["current_host"],
        env_name,
    )
    if not check_if_deploy_possible(conda_env_name=env_name):
        LOG.info(
            "Please use 'shipping provision' to create valid conda environment"
        )
        return

    python_process = Process(str(get_python_path(env_name)))
    current_version = fetch_package_version(python_process, app_config.tool)

    click.echo(
        get_log_line(
            time_zone=host_config.tz_object,
            user=context.obj["current_user"],
            tool=app_config.tool,
            current_version=current_version,
        ))
Пример #4
0
def deploy_cmd(context):
    """Deploy a tool into an existing container system"""
    LOG.info("Running shipping deploy")

    app_config: AppConfig = context.obj["app_config"]
    host_config: HostConfig = context.obj["host_config"]
    env_name: str = context.obj["env_name"]
    python_process: Process = Process(str(get_python_path(env_name)))
    current_version: str = fetch_package_version(python_process,
                                                 app_config.tool)

    LOG.info(
        "%s wants to deploy %s on host %s in environment %s",
        context.obj["current_user"],
        app_config.tool,
        context.obj["current_host"],
        env_name,
    )
    result: bool = deploy_conda(tool_name=app_config.tool,
                                conda_env_name=env_name)
    if result is False:
        raise click.Abort

    LOG.info("Tool was successfully deployed")

    updated_version: str = fetch_package_version(python_process,
                                                 app_config.tool)
    log_line = get_log_line(
        time_zone=host_config.tz_object,
        user=context.obj["current_user"],
        tool=app_config.tool,
        current_version=current_version,
        updated_version=updated_version,
    )

    log_path = host_config.log_path
    if not log_path:
        click.echo(log_line)
        return

    if not log_path.exists():
        log_path.touch()
    log_deploy(log_line=log_line, log_file=log_path)
Пример #5
0
def test_get_package_version_other_env(other_python_process: Process,
                                       other_env: str, tool_name: str):
    # GIVEN a Process with the python binary from another environment
    other_python = other_python_process.binary
    # GIVEN a current environment with python and a process
    current_python = environment.get_python_path()
    current_python_process = Process(str(current_python))

    assert current_python != other_python
    # GIVEN a package that exists in other environment but not in the current environment
    deploy_conda(tool_name=tool_name, conda_env_name=other_env)
    current_env_version = fetch_package_version(
        python_process=current_python_process, package_name=tool_name)
    assert current_env_version == ""

    # WHEN fetching the version from the other env
    version = fetch_package_version(python_process=other_python_process,
                                    package_name=tool_name)
    # THEN assert that a version was returned
    assert version != ""
Пример #6
0
def test_check_cmd_environment_exists(
    populated_env: str, context: dict, tool_name: str, other_python_process: Process, caplog
):
    """Test to run the check command when the environment does exist"""
    caplog.set_level(logging.DEBUG)
    env_name = populated_env
    # GIVEN a environment that does exist
    assert conda_env_exists(env_name) is True
    # GIVEN that the tool is already installed in the environment
    version = fetch_package_version(python_process=other_python_process, package_name=tool_name)
    assert version

    # GIVEN a cli runner
    runner = CliRunner()
    # GIVEN a context with basic information

    # WHEN running the command to check if deployment is possible
    result = runner.invoke(check_cmd, [], obj=context)

    # THEN assert that the tool name is in the log line that was produced
    assert tool_name in result.output
    # THEN assert that the tool version is in the log line that was produced
    assert version in result.output