예제 #1
0
def uninstall(
        package_name,
        service_name,
        role=None,
        service_account=None,
        zk=None):
    start = time.time()

    global _installed_service_names
    try:
        _installed_service_names.remove(service_name)
    except KeyError:
        pass  # allow tests to 'uninstall' up-front

    log.info('Uninstalling {}'.format(service_name))

    try:
        retried_uninstall_package_and_wait(package_name, service_name=service_name)
    except Exception:
        log.info('Got exception when uninstalling {}'.format(service_name))
        log.info(traceback.format_exc())
        raise
    finally:
        log.info('Reserved resources post uninstall:')
        sdk_utils.list_reserved_resources()

    cleanup_start = time.time()

    try:
        if sdk_utils.dcos_version_less_than('1.10'):
            log.info('Janitoring {}'.format(service_name))
            retried_run_janitor(service_name, role, service_account, zk)
        else:
            log.info('Waiting for Marathon app to be removed {}'.format(service_name))
            sdk_marathon.retried_wait_for_deployment_and_app_removal(
                sdk_marathon.get_app_id(service_name), timeout=TIMEOUT_SECONDS)
    except Exception:
        log.info('Got exception when cleaning up {}'.format(service_name))
        log.info(traceback.format_exc())
        raise
    finally:
        log.info('Reserved resources post cleanup:')
        sdk_utils.list_reserved_resources()

    finish = time.time()

    log.info(
        'Uninstalled {} after pkg({}) + cleanup({}) = total({})'.format(
            service_name,
            shakedown.pretty_duration(cleanup_start - start),
            shakedown.pretty_duration(finish - cleanup_start),
            shakedown.pretty_duration(finish - start)))
예제 #2
0
def uninstall(
        package_name,
        service_name,
        role=None,
        service_account=None,
        zk=None):
    start = time.time()

    global _installed_service_names
    try:
        _installed_service_names.remove(service_name)
    except KeyError:
        pass  # allow tests to 'uninstall' up-front

    log.info('Uninstalling {}'.format(service_name))

    try:
        retried_uninstall_package_and_wait(package_name, service_name=service_name)
    except Exception as e:
        log.info('Got exception when uninstalling {}'.format(service_name))
        log.info(traceback.format_exc())
        raise
    finally:
        log.info('Reserved resources post uninstall:')
        sdk_utils.list_reserved_resources()

    cleanup_start = time.time()

    try:
        if sdk_utils.dcos_version_less_than('1.10'):
            log.info('Janitoring {}'.format(service_name))
            retried_run_janitor(service_name, role, service_account, zk)
        else:
            log.info('Waiting for Marathon app to be removed {}'.format(service_name))
            sdk_marathon.retried_wait_for_deployment_and_app_removal(
                sdk_marathon.get_app_id(service_name), timeout=TIMEOUT_SECONDS)
    except Exception as e:
        log.info('Got exception when cleaning up {}'.format(service_name))
        log.info(traceback.format_exc())
        raise
    finally:
        log.info('Reserved resources post cleanup:')
        sdk_utils.list_reserved_resources()

    finish = time.time()

    log.info(
        'Uninstalled {} after pkg({}) + cleanup({}) = total({})'.format(
            service_name,
            shakedown.pretty_duration(cleanup_start - start),
            shakedown.pretty_duration(finish - cleanup_start),
            shakedown.pretty_duration(finish - start)))
예제 #3
0
def uninstall(package_name, service_name):
    '''Uninstalls the specified service from the cluster, and verifies that its resources and
    framework were correctly cleaned up after the uninstall has completed. Any agents which are
    expected to have orphaned resources (e.g. due to being shut down) should be passed to
    ignore_dead_agent() before triggering the uninstall.
    '''
    start = time.time()

    log.info('Uninstalling {}'.format(service_name))

    try:
        _retried_uninstall_package_and_wait(package_name, service_name=service_name)
    except Exception:
        log.exception('Got exception when uninstalling {}'.format(service_name))
        raise

    cleanup_start = time.time()

    try:
        if sdk_utils.dcos_version_less_than('1.10'):
            # 1.9 and earlier: Run janitor to unreserve resources
            log.info('Janitoring {}'.format(service_name))
            _retried_run_janitor(service_name)
        else:
            # 1.10 and later: Wait for uninstall scheduler to finish and be removed by Cosmos
            log.info('Waiting for Marathon app to be removed {}'.format(service_name))
            sdk_marathon.retried_wait_for_deployment_and_app_removal(
                sdk_marathon.get_app_id(service_name), timeout=TIMEOUT_SECONDS)
    except Exception:
        log.exception('Got exception when cleaning up {}'.format(service_name))
        raise

    finish = time.time()

    log.info(
        'Uninstalled {} after pkg({}) + cleanup({}) = total({})'.format(
            service_name,
            shakedown.pretty_duration(cleanup_start - start),
            shakedown.pretty_duration(finish - cleanup_start),
            shakedown.pretty_duration(finish - start)))

    # Sanity check: Verify that all resources and the framework have been successfully cleaned up,
    # and throw an exception if anything is left over (uninstall bug?)
    _verify_completed_uninstall(service_name)

    # Finally, remove the service from the installed list (used by sdk_diag)
    global _installed_service_names
    try:
        _installed_service_names.remove(service_name)
    except KeyError:
        pass  # Expected when tests preemptively uninstall at start of test