a7240c00b409ef54bfc0e628fe24c68e87c18675
[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 from doctor_tests.common.utils import match_rep_in_file
10
11
12 def calculate_notification_time(log_file):
13
14     reg = '(?<=doctor monitor detected at )\d+.\d+'
15     result = match_rep_in_file(reg, log_file)
16     if not result:
17         raise Exception('Can not match detected time')
18     detected = result.group(0)
19
20     reg = '(?<=doctor consumer notified at )\d+.\d+'
21     result = match_rep_in_file(reg, log_file)
22     if not result:
23         raise Exception('Can not match notified time')
24     notified = result.group(0)
25
26     return float(notified) - float(detected)