From 866c96fac82b538e7eb27f66e0ab2f25f60de1bd Mon Sep 17 00:00:00 2001 From: fonsecamau Date: Tue, 27 Sep 2016 14:21:42 -0700 Subject: [PATCH] chg: dev: Collecting docker coredumps on teardown and adding checks for p4 simulator --- lib/topology_docker_openswitch/openswitch.py | 18 ++++++++++++++++++ .../plugin/plugin.py | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/topology_docker_openswitch/openswitch.py b/lib/topology_docker_openswitch/openswitch.py index e3cf84f..bb8c309 100644 --- a/lib/topology_docker_openswitch/openswitch.py +++ b/lib/topology_docker_openswitch/openswitch.py @@ -49,6 +49,7 @@ from subprocess import check_call, check_output, call, CalledProcessError from socket import AF_UNIX, SOCK_STREAM, socket, gethostname +import re import yaml config_timeout = 300 @@ -155,6 +156,17 @@ def create_interfaces(): .format(hwport=hwport))) check_call('{ns_exec} ip link set dev {hwport} up' .format(**locals()), shell=True) + for i in range(0, config_timeout): + link_state = check_output( + '{ns_exec} ip link show {hwport}' + .format(**locals()), shell=True) + if "UP" in link_state: + break; + else: + sleep(0.1) + else: + raise Exception('Emulns interface did not came up...') + out = check_output( '{ns_exec} echo port_add {hwport} ' ' {port} | {ns_exec} ' @@ -167,6 +179,12 @@ def create_interfaces(): ) logging.info('BM port creation...') logging.info(out) + re_str = r''''\s*Control utility for runtime P4 table \ +manipulation\s*\nRuntimeCmd:\s*\nRuntimeCmd:\s*$''' #noqa + + if re.findall(re_str, out, re.MULTILINE) is None: + raise Exception('Control utility for runtime P4 table ' + 'failed...') except Exception as error: raise Exception( 'Failed to map ports with port labels: {}'.format( diff --git a/lib/topology_docker_openswitch/plugin/plugin.py b/lib/topology_docker_openswitch/plugin/plugin.py index 66f50ec..4d3d59e 100644 --- a/lib/topology_docker_openswitch/plugin/plugin.py +++ b/lib/topology_docker_openswitch/plugin/plugin.py @@ -93,6 +93,24 @@ def pytest_runtest_teardown(item): ) ) + try: + core_files = join('/var/diagnostics/coredump', 'core.*') + files = node_obj.send_command('ls {}'.format(core_files), + shell='bash').splitlines() + + if len(files) > 0: + for file in files: + path = '/tmp' + node_obj.send_command('cp {file} {path}' + .format(**locals()), + shell='bash') + except: + warning( + 'Unable to get coredumps from node {}.'.format( + node_obj.identifier + ) + ) + try: copytree(shared_dir, join(path_name, basename(shared_dir))) rmtree(shared_dir)