From 1c1d3d1ddc21ae28deabef9f5f6e310d46fdf0ef Mon Sep 17 00:00:00 2001 From: dongwenjuan Date: Mon, 28 Aug 2017 17:14:03 +0800 Subject: add running profiler in python For support bash and python both, I don't refactor the profiler_poc file, just call the func in python main. JIRA: DOCTOR-117 Change-Id: I5f06ecbd673c6a21acc94cc359a3f2b749b77b13 Signed-off-by: dongwenjuan --- tests/main.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests/main.py') diff --git a/tests/main.py b/tests/main.py index 7e7c3bc2..df7e95f3 100644 --- a/tests/main.py +++ b/tests/main.py @@ -14,6 +14,7 @@ import time from alarm import Alarm from common.constants import Host +from common.utils import match_rep_in_file import config from consumer import get_consumer from identity_auth import get_identity_auth @@ -26,6 +27,7 @@ import logger as doctor_log from network import Network from monitor import get_monitor from os_clients import nova_client +from profiler_poc import main as profiler_main from scenario.common import calculate_notification_time from scenario.network_failure import NetworkFault from user import User @@ -110,6 +112,11 @@ class DoctorTest(object): else: LOG.error('doctor test failed, notification_time=%s' % notification_time) sys.exit(1) + + if self.conf.profiler_type: + LOG.info('doctor test begin to run profile.......') + self.collect_logs() + self.run_profiler() except Exception as e: LOG.error('doctor test failed, Exception=%s' % e) sys.exit(1) @@ -145,6 +152,39 @@ class DoctorTest(object): time.sleep(2) self.check_host_status(self.down_host.name, 'up') + def collect_logs(self): + self.fault.get_disable_network_log() + + def run_profiler(self): + + log_file = '{0}/{1}'.format(sys.path[0], 'disable_network.log') + reg = '(?<=doctor set link down at )\d+.\d+' + linkdown = float(match_rep_in_file(reg, log_file).group(0)) + + log_file = '{0}/{1}'.format(sys.path[0], 'doctor.log') + reg = '(.* doctor mark vm.* error at )(\d+.\d+)' + vmdown = float(match_rep_in_file(reg, log_file).group(2)) + + reg = '(?<=doctor mark host.* down at )\d+.\d+' + hostdown = float(match_rep_in_file(reg, log_file).group(2)) + + reg = '(?<=doctor monitor detected at )\d+.\d+' + detected = float(match_rep_in_file(reg, log_file).group(0)) + + reg = '(?<=doctor consumer notified at )\d+.\d+' + notified = float(match_rep_in_file(reg, log_file).group(0)) + + # TODO(yujunz) check the actual delay to verify time sync status + # expected ~1s delay from $trigger to $linkdown + relative_start = linkdown + os.environ['DOCTOR_PROFILER_T00'] = str(int((linkdown - relative_start)*1000)) + os.environ['DOCTOR_PROFILER_T01'] = str(int((detected - relative_start) * 1000)) + os.environ['DOCTOR_PROFILER_T03'] = str(int((vmdown - relative_start) * 1000)) + os.environ['DOCTOR_PROFILER_T04'] = str(int((hostdown - relative_start) * 1000)) + os.environ['DOCTOR_PROFILER_T09'] = str(int((notified - relative_start) * 1000)) + + profiler_main(log=LOG) + def cleanup(self): self.unset_forced_down_hosts() self.inspector.stop() -- cgit 1.2.3-korg