Esempio n. 1
0
def test_find_standard_component_name():
    """Tests for find_standard_component_name()."""
    from reana.reana_dev.utils import find_standard_component_name

    for (input_value, output_expected) in (
        ("reana", "reana"),
        ("r-server", "reana-server"),
        ("r-j-controller", "reana-job-controller"),
        ("reana-ui", "reana-ui"),
    ):
        output_obtained = find_standard_component_name(input_value)
        assert output_obtained == output_expected
Esempio n. 2
0
def cluster_deploy(
    namespace,
    job_mounts,
    mode,
    values,
    exclude_components,
    admin_email,
    admin_password,
    instance_name,
):  # noqa: D301
    """Deploy REANA cluster.

    \b
    Example:
       $ reana-dev cluster-deploy --mode debug
                                  --exclude-components=r-ui
                                  --admin-email [email protected]
                                  --admin-password mysecretpassword
    """
    def job_mounts_to_config(job_mounts):
        job_mount_list = []
        for mount in job_mounts:
            job_mount_list.append({
                "name":
                mount["containerPath"].replace("/", "-")[1:],
                "hostPath":
                mount["hostPath"],
                "mountPath":
                mount["containerPath"],
            })

        job_mount_config = ""
        if job_mount_list:
            job_mount_config = json.dumps(job_mount_list)
        else:
            job_mount_config = ""

        return job_mount_config

    if mode in (
            "releasehelm") and values == "helm/configurations/values-dev.yaml":
        values = "helm/reana/values.yaml"

    values_dict = {}
    with open(os.path.join(get_srcdir("reana"), values)) as f:
        values_dict = yaml.safe_load(f.read())

    job_mount_config = job_mounts_to_config(job_mounts)
    if job_mount_config:
        values_dict.setdefault("components", {}).setdefault(
            "reana_workflow_controller",
            {}).setdefault("environment",
                           {})["REANA_JOB_HOSTPATH_MOUNTS"] = job_mount_config

    if mode in ("debug"):
        values_dict.setdefault("debug", {})["enabled"] = True

    if exclude_components:
        standard_named_exclude_components = [
            find_standard_component_name(c)
            for c in exclude_components.split(",")
        ]
        if "reana-ui" in standard_named_exclude_components:
            values_dict["components"]["reana_ui"]["enabled"] = False

    helm_install = "cat <<EOF | helm install reana helm/reana -n {namespace} --create-namespace --wait -f -\n{values}\nEOF".format(
        namespace=namespace,
        values=values_dict and yaml.dump(values_dict) or "",
    )
    cmds = []
    if mode in ("debug"):
        cmds.append("reana-dev python-install-eggs")
        cmds.append("reana-dev git-submodule --update")
    cmds.extend([
        "helm dep update helm/reana",
        helm_install,
        "kubectl config set-context --current --namespace={}".format(
            namespace),
        os.path.join(
            get_srcdir("reana"),
            f"scripts/create-admin-user.sh {namespace} {instance_name} {admin_email} {admin_password}",
        ),
    ])
    for cmd in cmds:
        run_command(cmd, "reana")