Exemple #1
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()
Exemple #2
0
 def test_wait_for_dcos_oss(self, cluster: Cluster) -> None:
     """
     Exercise ``wait_for_dcos_oss`` code.
     """
     # We exercise the "http_checks=False" code here but we do not test
     # its functionality. It is a temporary measure while we wait for
     # more thorough dcos-checks.
     cluster.wait_for_dcos_oss(http_checks=False)
     cluster.wait_for_dcos_oss(http_checks=True)
     # We check that no users are added by ``wait_for_dcos_oss``.
     # If a user is added, a user cannot log in via the web UI.
     get_users_args = ['curl', 'http://localhost:8101/acs/api/v1/users']
     (master, ) = cluster.masters
     result = master.run(args=get_users_args, output=Output.CAPTURE)
     users = json.loads(result.stdout.decode())['array']
     assert not users
    def test_wait_for_dcos_oss(
        self,
        cluster: Cluster,
        zk_client: KazooClient,
    ) -> None:
        """
        Exercise ``wait_for_dcos_oss`` code.
        """
        # We exercise the "http_checks=False" code here but we do not test
        # its functionality. It is a temporary measure while we wait for
        # more thorough dcos-checks.
        cluster.wait_for_dcos_oss(http_checks=False)

        cluster.wait_for_dcos_oss()
        email = '*****@*****.**'
        path = '/dcos/users/{email}'.format(email=email)
        assert not zk_client.exists(path=path)
Exemple #4
0
def wait_for_dcos_oss(
    cluster: Cluster,
    request: SubRequest,
    log_dir: Path,
) -> None:
    """
    Helper for ``wait_for_dcos_oss`` that automatically dumps the journal of
    every cluster node if a ``DCOSTimeoutError`` is hit.
    """
    try:
        cluster.wait_for_dcos_oss()
    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
Exemple #5
0
def wait_for_dcos_oss(
    cluster: Cluster,
    request: SubRequest,
    log_dir: Path,
) -> None:
    """
    Helper for ``wait_for_dcos_oss`` that automatically dumps the journal of
    every cluster node if a ``DCOSTimeoutError`` is hit.
    """
    try:
        cluster.wait_for_dcos_oss()
    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
Exemple #6
0
test_license = os.environ.get('DCOS_TEST_LICENSE')
if test_license:
    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',
Exemple #7
0
test_license = os.environ.get('DCOS_TEST_LICENSE')
if test_license:
    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',
Exemple #8
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)