Exemplo n.º 1
0
def install(
        package_name,
        running_task_count,
        service_name=None,
        additional_options={},
        package_version=None,
        check_suppression=True):
    if not service_name:
        service_name = package_name
    start = time.time()
    merged_options = get_package_options(additional_options)

    sdk_utils.out('Installing {} with options={} version={}'.format(
        package_name, merged_options, package_version))

    # install_package_and_wait silently waits for all marathon deployments to clear.
    # to give some visibility, install in the following order:
    # 1. install package
    shakedown.install_package(
        package_name,
        package_version=package_version,
        options_json=merged_options)

    # 2. wait for expected tasks to come up
    sdk_utils.out("Waiting for expected tasks to come up...")
    sdk_tasks.check_running(service_name, running_task_count)
    sdk_plan.wait_for_completed_deployment(service_name)

    # 3. check service health
    marathon_client = dcos.marathon.create_client()
    def is_deployment_finished():
        # TODO(nickbp): upstream fix to shakedown, which currently checks for ANY deployments rather
        #               than the one we care about
        deploying_apps = set([])
        sdk_utils.out("Getting deployments")
        deployments = marathon_client.get_deployments()
        sdk_utils.out("Found {} deployments".format(len(deployments)))
        for deployment in deployments:
            sdk_utils.out("Deployment: {}".format(deployment))
            for app in deployment.get('affectedApps', []):
                sdk_utils.out("Adding {}".format(app))
                deploying_apps.add(app)
        sdk_utils.out('Checking that deployment of {} has ended:\n- Deploying apps: {}'.format(service_name, deploying_apps))
        return not '/{}'.format(service_name) in deploying_apps
    sdk_utils.out("Waiting for marathon deployment to finish...")
    sdk_spin.time_wait_noisy(is_deployment_finished)

    # 4. Ensure the framework is suppressed.
    #
    # This is only configurable in order to support installs from
    # Universe during the upgrade_downgrade tests, because currently
    # the suppression endpoint isn't supported by all frameworks in
    # Universe.  It can be removed once all frameworks rely on
    # dcos-commons >= 0.13.
    if check_suppression:
        sdk_utils.out("Waiting for framework to be suppressed...")
        sdk_spin.time_wait_noisy(
            lambda: sdk_api.is_suppressed(service_name))

    sdk_utils.out('Install done after {}'.format(sdk_spin.pretty_time(time.time() - start)))
Exemplo n.º 2
0
def _upgrade_or_downgrade(package_name, to_package_version, service_name,
                          running_task_count, additional_options,
                          timeout_seconds, wait_for_deployment):
    task_ids = sdk_tasks.get_task_ids(service_name, '')
    if shakedown.dcos_version_less_than(
            "1.10") or shakedown.ee_version() is None:
        log.info('Using marathon upgrade flow to upgrade {} {}'.format(
            package_name, to_package_version))
        sdk_marathon.destroy_app(service_name)
        sdk_install.install(package_name,
                            service_name,
                            running_task_count,
                            additional_options=additional_options,
                            package_version=to_package_version,
                            timeout_seconds=timeout_seconds,
                            wait_for_deployment=wait_for_deployment)
    else:
        log.info('Using CLI upgrade flow to upgrade {} {}'.format(
            package_name, to_package_version))
        if additional_options:
            with tempfile.NamedTemporaryFile() as opts_f:
                opts_f.write(json.dumps(additional_options).encode('utf-8'))
                opts_f.flush(
                )  # ensure json content is available for the CLI to read below
                sdk_cmd.svc_cli(
                    package_name, service_name,
                    'update start --package-version={} --options={}'.format(
                        to_package_version, opts_f.name))
        else:
            sdk_cmd.svc_cli(
                package_name, service_name,
                'update start --package-version={}'.format(to_package_version))

    if wait_for_deployment:
        log.info('Checking that all tasks have restarted')
        sdk_tasks.check_tasks_updated(service_name, '', task_ids)

        # this can take a while, default is 15 minutes. for example with HDFS, we can hit the expected
        # total task count via FINISHED tasks, without actually completing deployment
        log.info("Waiting for {}/{} to finish deployment plan...".format(
            package_name, service_name))
        sdk_plan.wait_for_completed_deployment(service_name, timeout_seconds)

        # given the above wait for plan completion, here we just wait up to 5 minutes
        if shakedown.dcos_version_less_than("1.9"):
            log.info(
                "Skipping `is_suppressed` check for %s/%s as this is only suppored starting in version 1.9",
                package_name, service_name)
        else:
            log.info("Waiting for %s/%s to be suppressed...", package_name,
                     service_name)
            shakedown.wait_for(lambda: sdk_api.is_suppressed(service_name),
                               noisy=True,
                               timeout_seconds=5 * 60)
Exemplo n.º 3
0
def _upgrade_or_downgrade(
        package_name,
        to_package_version,
        service_name,
        running_task_count,
        additional_options,
        timeout_seconds,
        wait_for_deployment):
    task_ids = sdk_tasks.get_task_ids(service_name, '')
    if shakedown.dcos_version_less_than("1.10") or shakedown.ee_version() is None:
        log.info('Using marathon upgrade flow to upgrade {} {}'.format(package_name, to_package_version))
        sdk_marathon.destroy_app(service_name)
        sdk_install.install(
            package_name,
            service_name,
            running_task_count,
            additional_options=additional_options,
            package_version=to_package_version,
            timeout_seconds=timeout_seconds,
            wait_for_deployment=wait_for_deployment)
    else:
        log.info('Using CLI upgrade flow to upgrade {} {}'.format(package_name, to_package_version))
        if additional_options:
            with tempfile.NamedTemporaryFile() as opts_f:
                opts_f.write(json.dumps(additional_options).encode('utf-8'))
                opts_f.flush() # ensure json content is available for the CLI to read below
                sdk_cmd.svc_cli(
                    package_name, service_name,
                    'update start --package-version={} --options={}'.format(to_package_version, opts_f.name))
        else:
            sdk_cmd.svc_cli(
                package_name, service_name,
                'update start --package-version={}'.format(to_package_version))

    if wait_for_deployment:
        log.info('Checking that all tasks have restarted')
        sdk_tasks.check_tasks_updated(service_name, '', task_ids)

        # this can take a while, default is 15 minutes. for example with HDFS, we can hit the expected
        # total task count via FINISHED tasks, without actually completing deployment
        log.info("Waiting for {}/{} to finish deployment plan...".format(
            package_name, service_name))
        sdk_plan.wait_for_completed_deployment(service_name, timeout_seconds)

        # given the above wait for plan completion, here we just wait up to 5 minutes
        if shakedown.dcos_version_less_than("1.9"):
            log.info("Skipping `is_suppressed` check for %s/%s as this is only suppored starting in version 1.9",
                     package_name, service_name)
        else:
            log.info("Waiting for %s/%s to be suppressed...", package_name, service_name)
            shakedown.wait_for(
                lambda: sdk_api.is_suppressed(service_name),
                noisy=True,
                timeout_seconds=5 * 60)
Exemplo n.º 4
0
def install(
        package_name,
        expected_running_tasks,
        service_name=None,
        additional_options={},
        package_version=None,
        timeout_seconds=TIMEOUT_SECONDS,
        wait_for_deployment=True):
    if not service_name:
        service_name = package_name
    start = time.time()
    merged_options = get_package_options(additional_options)

    log.info('Installing {}/{} with options={} version={}'.format(
        package_name, service_name, merged_options, package_version))

    # 1. Install package, wait for tasks, wait for marathon deployment
    retried_shakedown_install(
        package_name,
        package_version,
        service_name,
        merged_options,
        timeout_seconds,
        expected_running_tasks)

    # 2. Wait for the scheduler to be idle (as implied by deploy plan completion and suppressed bit)
    # This should be skipped ONLY when it's known that the scheduler will be stuck in an incomplete state.
    if wait_for_deployment:
        # this can take a while, default is 15 minutes. for example with HDFS, we can hit the expected
        # total task count via FINISHED tasks, without actually completing deployment
        log.info("Waiting for {}/{} to finish deployment plan...".format(
            package_name, service_name))
        sdk_plan.wait_for_completed_deployment(service_name, timeout_seconds)

        # given the above wait for plan completion, here we just wait up to 5 minutes
        if shakedown.dcos_version_less_than("1.9"):
            log.info("Skipping `is_suppressed` check for %s/%s as this is only suppored starting in version 1.9",
                     package_name, service_name)
        else:
            log.info("Waiting for %s/%s to be suppressed...", package_name, service_name)
            shakedown.wait_for(
                lambda: sdk_api.is_suppressed(service_name),
                noisy=True,
                timeout_seconds=5 * 60)

    log.info('Installed {}/{} after {}'.format(
        package_name, service_name, shakedown.pretty_duration(time.time() - start)))
Exemplo n.º 5
0
def install(
        package_name,
        service_name,
        expected_running_tasks,
        additional_options={},
        package_version=None,
        timeout_seconds=TIMEOUT_SECONDS,
        wait_for_deployment=True):
    start = time.time()
    merged_options = get_package_options(additional_options)

    log.info('Installing {}/{} with options={} version={}'.format(
        package_name, service_name, merged_options, package_version))

    # 1. Install package, wait for tasks, wait for marathon deployment
    retried_shakedown_install(
        package_name,
        service_name,
        package_version,
        merged_options,
        timeout_seconds,
        expected_running_tasks)

    # 2. Wait for the scheduler to be idle (as implied by deploy plan completion and suppressed bit)
    # This should be skipped ONLY when it's known that the scheduler will be stuck in an incomplete state.
    if wait_for_deployment:
        # this can take a while, default is 15 minutes. for example with HDFS, we can hit the expected
        # total task count via FINISHED tasks, without actually completing deployment
        log.info("Waiting for {}/{} to finish deployment plan...".format(
            package_name, service_name))
        sdk_plan.wait_for_completed_deployment(service_name, timeout_seconds)

        # given the above wait for plan completion, here we just wait up to 5 minutes
        if shakedown.dcos_version_less_than("1.9"):
            log.info("Skipping `is_suppressed` check for %s/%s as this is only suppored starting in version 1.9",
                     package_name, service_name)
        else:
            log.info("Waiting for %s/%s to be suppressed...", package_name, service_name)
            shakedown.wait_for(
                lambda: sdk_api.is_suppressed(service_name),
                noisy=True,
                timeout_seconds=5 * 60)

    log.info('Installed {}/{} after {}'.format(
        package_name, service_name, shakedown.pretty_duration(time.time() - start)))
Exemplo n.º 6
0
def install(package_name,
            running_task_count,
            service_name=None,
            additional_options={},
            package_version=None,
            check_suppression=True,
            timeout_seconds=15 * 60):
    if not service_name:
        service_name = package_name
    start = time.time()
    merged_options = get_package_options(additional_options)

    sdk_utils.out('Installing {} with options={} version={}'.format(
        package_name, merged_options, package_version))

    # 1. Install package, wait for tasks, wait for marathon deployment
    shakedown.install_package(package_name,
                              package_version=package_version,
                              service_name=service_name,
                              options_json=merged_options,
                              wait_for_completion=True,
                              timeout_sec=timeout_seconds,
                              expected_running_tasks=running_task_count)

    # 2. Ensure the framework is suppressed.
    #
    # This is only configurable in order to support installs from
    # Universe during the upgrade_downgrade tests, because currently
    # the suppression endpoint isn't supported by all frameworks in
    # Universe.  It can be removed once all frameworks rely on
    # dcos-commons >= 0.13.
    if check_suppression:
        sdk_utils.out("Waiting for framework to be suppressed...")
        shakedown.wait_for(lambda: sdk_api.is_suppressed(service_name),
                           noisy=True,
                           timeout_seconds=5 * 60)

    sdk_utils.out('Install done after {}'.format(
        shakedown.pretty_duration(time.time() - start)))