Пример #1
0
def wait_for_dcos_ee(
    cluster: Cluster,
    superuser_username: str,
    superuser_password: str,
    request: SubRequest,
    log_dir: Path,
) -> None:
    """
    Helper for ``wait_for_dcos_ee`` that automatically dumps the journal of
    every cluster node if a ``DCOSTimeoutError`` is hit.
    """
    try:
        cluster.wait_for_dcos_ee(
            superuser_username=superuser_username,
            superuser_password=superuser_password,
        )
    except DCOSTimeoutError:
        # Dumping the logs on timeout only works if DC/OS has already started
        # the systemd units that the logs are retrieved from.
        # This does currently not pose a problem since the ``wait_for_dcos_ee``
        # timeout is set to one hour. We expect the systemd units to have
        # started by then.
        dump_cluster_journals(
            cluster=cluster,
            target_dir=log_dir / artifact_dir_format(request.node.name),
        )
        raise
Пример #2
0
def wait_for_dcos(
    cluster: Cluster,
    superuser_username: str,
    superuser_password: str,
    http_checks: bool,
    doctor_command_name: str,
    enable_spinner: bool,
) -> None:
    """
    Wait for DC/OS to start.

    Args:
        cluster: The cluster to wait for.
        superuser_username: If the cluster is a DC/OS Enterprise cluster, use
            this username to wait for DC/OS.
        superuser_password: If the cluster is a DC/OS Enterprise cluster, use
            this password to wait for DC/OS.
        http_checks: Whether or not to wait for checks which require an HTTP
            connection to the cluster.
        doctor_command_name: A ``doctor`` command to advise a user to use.
        enable_spinner: Whether to enable the spinner animation.
    """
    message = (
        'A cluster may take some time to be ready.\n'
        'The amount of time it takes to start a cluster depends on a variety '
        'of factors.\n'
        'If you are concerned that this is hanging, try '
        '"{doctor_command_name}" to diagnose common issues.').format(
            doctor_command_name=doctor_command_name)
    click.echo(message)

    no_login_message = ('If you cancel this command while it is running, '
                        'you may not be able to log in. '
                        'To resolve that, run this command again.')

    spinner = Halo(enabled=enable_spinner)
    spinner.start(text='Waiting for DC/OS variant')
    _wait_for_variant(cluster=cluster)
    dcos_variant = get_cluster_variant(cluster=cluster)
    spinner.succeed()
    if dcos_variant == DCOSVariant.OSS:
        click.echo(no_login_message)
    spinner.start(text='Waiting for DC/OS to start')
    try:
        if dcos_variant == DCOSVariant.ENTERPRISE:
            cluster.wait_for_dcos_ee(
                superuser_username=superuser_username,
                superuser_password=superuser_password,
                http_checks=http_checks,
            )
        else:
            cluster.wait_for_dcos_oss(http_checks=http_checks)
    except DCOSTimeoutError:
        spinner.fail(text='Waiting for DC/OS to start timed out.')
        sys.exit(1)

    spinner.succeed()
Пример #3
0
    extra_config['license_key_contents'] = test_license

dcos_config = {**cluster.base_config, **extra_config}

cluster.install_dcos_from_url(
    dcos_installer=sys.argv[1],
    dcos_config=dcos_config,
    ip_detect_path=cluster_backend.ip_detect_path,
    output=Output.LOG_AND_CAPTURE,
)

if dcos_variant == 'open':
    cluster.wait_for_dcos_oss()
else:
    cluster.wait_for_dcos_ee(
        superuser_username=username,
        superuser_password=password,
    )

master_node = next(iter(cluster.masters))
master_ip = master_node.public_ip_address.exploded

# In order to create a user with a password on DC/OS Open, we login with the well-known key
# from the default user to get an ACS token and then hit the IAM API directly.
# Hopefully in the future there will be a simpler way to do it.
if dcos_variant == 'open':
    response = requests.post(
        'http://' + master_ip + '/acs/api/v1/auth/login',
        headers={"Content-Type" : "application/json"},
        data=json.dumps({
            "token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik9UQkVOakZFTWtWQ09VRTRPRVpGTlRNMFJrWXlRa015Tnprd1JrSkVRemRCTWpBM1FqYzVOZyJ9.eyJlbWFpbCI6ImFsYmVydEBiZWtzdGlsLm5ldCIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJpc3MiOiJodHRwczovL2Rjb3MuYXV0aDAuY29tLyIsInN1YiI6Imdvb2dsZS1vYXV0aDJ8MTA5OTY0NDk5MDExMTA4OTA1MDUwIiwiYXVkIjoiM3lGNVRPU3pkbEk0NVExeHNweHplb0dCZTlmTnhtOW0iLCJleHAiOjIwOTA4ODQ5NzQsImlhdCI6MTQ2MDE2NDk3NH0.OxcoJJp06L1z2_41_p65FriEGkPzwFB_0pA9ULCvwvzJ8pJXw9hLbmsx-23aY2f-ydwJ7LSibL9i5NbQSR2riJWTcW4N7tLLCCMeFXKEK4hErN2hyxz71Fl765EjQSO5KD1A-HsOPr3ZZPoGTBjE0-EFtmXkSlHb1T2zd0Z8T5Z2-q96WkFoT6PiEdbrDA-e47LKtRmqsddnPZnp0xmMQdTr2MjpVgvqG7TlRvxDcYc-62rkwQXDNSWsW61FcKfQ-TRIZSf2GS9F9esDF4b5tRtrXcBNaorYa9ql0XAWH5W_ct4ylRNl3vwkYKWa4cmPvOqT5Wlj9Tf0af4lNO40PQ"
        }),
Пример #4
0
    'superuser_password_hash': sha512_crypt.hash(password),
    'fault_domain_enabled': False,
    'license_key_contents': test_license,
}

dcos_config = {**cluster.base_config, **extra_config}

cluster.install_dcos_from_url(
    build_artifact=sys.argv[1],
    dcos_config=dcos_config,
    log_output_live=True,
    ip_detect_path=cluster_backend.ip_detect_path,
)

cluster.wait_for_dcos_ee(
    superuser_username=username,
    superuser_password=password,
)

master_node = next(iter(cluster.masters))
master_ip = master_node.public_ip_address.exploded

out = '''
export DCOS_TEST_DEFAULT_CLUSTER_VARIANT=enterprise
export DCOS_TEST_DEFAULT_CLUSTER_USERNAME={}
export DCOS_TEST_DEFAULT_CLUSTER_PASSWORD={}
export DCOS_TEST_DEFAULT_CLUSTER_HOST={}
'''.format(username, password, master_ip)

with open('test_cluster.env.sh', 'w') as f:
    f.write(out)
Пример #5
0
def wait_for_dcos(
    dcos_variant: DCOSVariant,
    cluster: Cluster,
    superuser_username: str,
    superuser_password: str,
    http_checks: bool,
    sibling_ctx: click.core.Context,
    doctor_command: click.core.Command,
) -> None:
    """
    Wait for DC/OS to start.

    Args:
        dcos_variant: The DC/OS variant of the cluster.
        cluster: The cluster to wait for.
        superuser_username: If the cluster is a DC/OS Enterprise cluster, use
            this username to wait for DC/OS.
        superuser_password: If the cluster is a DC/OS Enterprise cluster, use
            this password to wait for DC/OS.
        http_checks: Whether or not to wait for checks which require an HTTP
            connection to the cluster.
        doctor_command: A ``doctor`` command to advise a user to use.
        sibling_ctx: A context associated with a call to a sibling of
            ``doctor_command``.
    """
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
    doctor_command_name = command_path(
        sibling_ctx=sibling_ctx,
        command=doctor_command,
    )
    message = (
        'A cluster may take some time to be ready.\n'
        'The amount of time it takes to start a cluster depends on a variety '
        'of factors.\n'
        'If you are concerned that this is hanging, try '
        '"{doctor_command_name}" to diagnose common issues.'
    ).format(doctor_command_name=doctor_command_name)
    click.echo(message)

    no_login_message = (
        'If you cancel this command while it is running, '
        'you may not be able to log in. '
        'To resolve that, run this command again.'
    )

    if not dcos_variant == DCOSVariant.ENTERPRISE:
        click.echo(no_login_message)

    with click_spinner.spinner():
        try:
            if dcos_variant == DCOSVariant.ENTERPRISE:
                cluster.wait_for_dcos_ee(
                    superuser_username=superuser_username,
                    superuser_password=superuser_password,
                    http_checks=http_checks,
                )
                return

            cluster.wait_for_dcos_oss(http_checks=http_checks)
        except DCOSTimeoutError:
            click.echo('Waiting for DC/OS to start timed out.', err=True)
            sys.exit(1)