fix the path of log file
[doctor.git] / doctor_tests / scenario / common.py
1 ##############################################################################
2 # Copyright (c) 2017 ZTE Corporation and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 import os
10
11 from doctor_tests.common.utils import match_rep_in_file
12
13
14 def calculate_notification_time():
15     scenario_dir = os.path.split(os.path.realpath(__file__))[0]
16     doctor_tests_dir = os.path.dirname(scenario_dir)
17     log_file = '{0}/{1}'.format(doctor_tests_dir, 'doctor.log')
18
19     reg = '(?<=doctor monitor detected at )\d+.\d+'
20     result = match_rep_in_file(reg, log_file)
21     if not result:
22         raise Exception('Can not match detected time')
23     detected = result.group(0)
24
25     reg = '(?<=doctor consumer notified at )\d+.\d+'
26     result = match_rep_in_file(reg, log_file)
27     if not result:
28         raise Exception('Can not match notified time')
29     notified = result.group(0)
30
31     return float(notified) - float(detected)