def handle_test_report(item: pytest.Item, result): # _pytest.runner.TestReport '''Collects information from the cluster following a failed test. This should be called in a hookimpl fixture. See also handle_test_setup() which must be called in a pytest_runtest_setup() hook.''' if not result.failed: return # passed, nothing to do # Fetch all state from all currently-installed services. # We do this retrieval first in order to be closer to the actual test failure. # Services may still be installed when e.g. we're still in the middle of a test suite. service_names = list( filter( lambda name: name != sdk_package_registry. PACKAGE_REGISTRY_SERVICE_NAME, sdk_install.get_installed_service_names())) if len(service_names) > 0: log.info( 'Fetching plans for {} services that are currently installed: {}'. format(len(service_names), ', '.join(service_names))) for service_name in service_names: try: _dump_scheduler(item, service_name) except Exception: log.exception('Plan collection from service {} failed!'.format( service_name)) # Fetch all logs from tasks created since the last failure, or since the start of the suite. global _testlogs_ignored_task_ids new_task_ids = [ task.id for task in sdk_tasks.get_summary(with_completed=True) if task.id not in _testlogs_ignored_task_ids ] _testlogs_ignored_task_ids = _testlogs_ignored_task_ids.union(new_task_ids) # Enforce limit on how many tasks we will fetch logs from, to avoid unbounded log fetching. if len(new_task_ids) > _testlogs_task_id_limit: log.warning( 'Truncating list of {} new tasks to size {} to avoid fetching logs forever: {}' .format(len(new_task_ids), _testlogs_task_id_limit, new_task_ids)) del new_task_ids[_testlogs_task_id_limit:] try: log.info( 'Fetching logs for {} tasks launched in this suite since last failure: {}' .format(len(new_task_ids), ', '.join(new_task_ids))) _dump_task_logs(item, new_task_ids) except Exception: log.exception('Task log collection failed!') try: log.info('Fetching mesos state:') _dump_mesos_state(item) except Exception: log.exception('Mesos state collection failed!') try: log.info('Creating/fetching cluster diagnostics bundle:') _dump_diagnostics_bundle(item) except Exception: log.exception('Diagnostics bundle creation failed') log.info('Post-failure collection complete')
def handle_test_report(item: pytest.Item, result): # _pytest.runner.TestReport '''Collects information from the cluster following a failed test. This should be called in a hookimpl fixture. See also handle_test_setup() which must be called in a pytest_runtest_setup() hook.''' if not result.failed: return # passed, nothing to do # Fetch all plans from all currently-installed services. # We do this retrieval first in order to be closer to the actual test failure. # Services may still be installed when e.g. we're still in the middle of a test suite. service_names = sdk_install.get_installed_service_names() if len(service_names) > 0: log.info('Fetching plans for {} services that are currently installed: {}'.format( len(service_names), ', '.join(service_names))) for service_name in service_names: try: _dump_plans(item, service_name) except: log.exception('Plan collection from service {} failed!'.format(service_name)) # Fetch all logs from tasks created since the last failure, or since the start of the suite. global _testlogs_ignored_task_ids new_task_ids = [task.id for task in sdk_tasks.get_summary(with_completed=True) if task.id not in _testlogs_ignored_task_ids] _testlogs_ignored_task_ids = _testlogs_ignored_task_ids.union(new_task_ids) # Enforce limit on how many tasks we will fetch logs from, to avoid unbounded log fetching. if len(new_task_ids) > _testlogs_task_id_limit: log.warning('Truncating list of {} new tasks to size {} to avoid fetching logs forever: {}'.format( len(new_task_ids), _testlogs_task_id_limit, new_task_ids)) del new_task_ids[_testlogs_task_id_limit:] try: log.info('Fetching logs for {} tasks launched in this suite since last failure: {}'.format( len(new_task_ids), ', '.join(new_task_ids))) _dump_task_logs(item, new_task_ids) except: log.exception('Task log collection failed!') try: log.info('Fetching mesos state:') _dump_mesos_state(item) except: log.exception('Mesos state collection failed!') try: log.info('Creating/fetching cluster diagnostics bundle:') _dump_diagnostics_bundle(item) except: log.exception('Diagnostics bundle creation failed') log.info('Post-failure collection complete')
def handle_test_report(item: pytest.Item, result: runner.TestReport) -> None: """Collects information from the cluster following a failed test. This should be called in a hookimpl fixture. See also handle_test_setup() which must be called in a pytest_runtest_setup() hook.""" if not result.failed or os.environ.get('DISABLE_DIAG'): return # passed, nothing to do, or diagnostics collection disabled # Fetch all state from all currently-installed services. # We do this retrieval first in order to be closer to the actual test failure. # Services may still be installed when e.g. we're still in the middle of a test suite. service_names = list( filter( lambda name: name != sdk_package_registry.PACKAGE_REGISTRY_SERVICE_NAME, sdk_install.get_installed_service_names().union(_whitelisted_service_names(item)), ) ) if len(service_names) > 0: log.info( "Fetching plans for {} services that are currently installed: {}".format( len(service_names), ", ".join(service_names) ) ) for service_name in service_names: try: # Skip thread retrieval if plan retrieval fails: _dump_plans(item, service_name) _dump_threads(item, service_name) except Exception: log.exception("Plan/thread collection from service {} failed!".format(service_name)) # Fetch all logs from tasks created since the last failure, or since the start of the suite. global _testlogs_ignored_task_ids new_task_ids = [ task.id for task in sdk_tasks.get_summary(with_completed=True) if task.id not in _testlogs_ignored_task_ids ] _testlogs_ignored_task_ids = _testlogs_ignored_task_ids.union(new_task_ids) # Enforce limit on how many tasks we will fetch logs from, to avoid unbounded log fetching. if len(new_task_ids) > _testlogs_task_id_limit: log.warning( "Truncating list of {} new tasks to size {} to avoid fetching logs forever: {}".format( len(new_task_ids), _testlogs_task_id_limit, new_task_ids ) ) del new_task_ids[_testlogs_task_id_limit:] try: log.info( "Fetching logs for {} tasks launched in this suite since last failure: {}".format( len(new_task_ids), ", ".join(new_task_ids) ) ) _dump_task_logs(item, new_task_ids) except Exception: log.exception("Task log collection failed!") try: log.info("Fetching mesos state:") _dump_mesos_state(item) except Exception: log.exception("Mesos state collection failed!") try: log.info("Creating/fetching cluster diagnostics bundle:") _dump_diagnostics_bundle(item) except Exception: log.exception("Diagnostics bundle creation failed") log.info("Post-failure collection complete")