Exemplo n.º 1
0
def _dump_diagnostics(request, dcos_api_session):
    """Download the zipped diagnostics bundle report from each master in the cluster to the home directory. This should
    be run last. The _ prefix makes sure that pytest calls this first out of the autouse session scope fixtures, which
    means that its post-yield code will be executed last.

    * There is no official way to ensure fixtures are called in a certain order
    https://github.com/pytest-dev/pytest/issues/1216
    * However it seems that fixtures at the same scope are called alphabetically
    https://stackoverflow.com/a/28593102/1436300
    """
    yield

    make_diagnostics_report = os.environ.get(
        'DIAGNOSTICS_DIRECTORY') is not None
    if make_diagnostics_report:
        log.info('Create diagnostics report for all nodes')
        check_json(
            dcos_api_session.health.post('report/diagnostics/create',
                                         json={"nodes": ["all"]}))

        last_datapoint = {'time': None, 'value': 0}

        log.info('\nWait for diagnostics job to complete')
        wait_for_diagnostics_job(dcos_api_session, last_datapoint)

        log.info('\nWait for diagnostics report to become available')
        wait_for_diagnostics_list(dcos_api_session)

        log.info('\nDownload zipped diagnostics reports')
        bundles = _get_bundle_list(dcos_api_session)
        for bundle in bundles:
            for master_node in dcos_api_session.masters:
                r = dcos_api_session.health.get(os.path.join(
                    'report/diagnostics/serve', bundle),
                                                stream=True,
                                                node=master_node)
                bundle_path = os.path.join(os.path.expanduser('~'), bundle)
                with open(bundle_path, 'wb') as f:
                    for chunk in r.iter_content(1024):
                        f.write(chunk)
    else:
        log.info('\nNot downloading diagnostics bundle for this session.')
Exemplo n.º 2
0
def _dump_diagnostics(request, dcos_api_session):
    """Download the zipped diagnostics bundle report from each master in the cluster to the home directory. This should
    be run last. The _ prefix makes sure that pytest calls this first out of the autouse session scope fixtures, which
    means that its post-yield code will be executed last.

    * There is no official way to ensure fixtures are called in a certain order
    https://github.com/pytest-dev/pytest/issues/1216
    * However it seems that fixtures at the same scope are called alphabetically
    https://stackoverflow.com/a/28593102/1436300
    """
    yield

    make_diagnostics_report = os.environ.get('DIAGNOSTICS_DIRECTORY') is not None
    if make_diagnostics_report:
        log.info('Create diagnostics report for all nodes')
        check_json(dcos_api_session.health.post('/report/diagnostics/create', json={"nodes": ["all"]}))

        last_datapoint = {
            'time': None,
            'value': 0
        }

        log.info('\nWait for diagnostics job to complete')
        wait_for_diagnostics_job(dcos_api_session, last_datapoint)

        log.info('\nWait for diagnostics report to become available')
        wait_for_diagnostics_list(dcos_api_session)

        log.info('\nDownload zipped diagnostics reports')
        bundles = _get_bundle_list(dcos_api_session)
        for bundle in bundles:
            for master_node in dcos_api_session.masters:
                r = dcos_api_session.health.get(os.path.join('/report/diagnostics/serve', bundle), stream=True,
                                                node=master_node)
                bundle_path = os.path.join(os.path.expanduser('~'), bundle)
                with open(bundle_path, 'wb') as f:
                    for chunk in r.iter_content(1024):
                        f.write(chunk)
    else:
        log.info('\nNot downloading diagnostics bundle for this session.')