]> git.puffer.fish Git - mirror/frr.git/commitdiff
topotest: log sleep function
authorRafael Zalamena <rzalamena@gmail.com>
Mon, 24 Jul 2017 14:53:19 +0000 (11:53 -0300)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 28 Nov 2018 01:22:12 +0000 (20:22 -0500)
Added a wrapper for the sleep function that should be used to register
in the log files the amount of time spent sleeping.

tests/topotests/lib/topotest.py

index 1b5f7eed497b04efd9640b3e9facf84c4cde38b7..61f46097e177416d731abc3eae1897e1ecb9f8ab 100644 (file)
@@ -32,6 +32,7 @@ import subprocess
 import tempfile
 import platform
 import difflib
+import time
 
 from lib.topolog import logger
 
@@ -42,8 +43,6 @@ from mininet.log import setLogLevel, info
 from mininet.cli import CLI
 from mininet.link import Intf
 
-from time import sleep
-
 class json_cmp_result(object):
     "json_cmp result class for better assertion messages"
 
@@ -159,7 +158,7 @@ def run_and_expect(func, what, count=20, wait=3):
     while count > 0:
         result = func()
         if result != what:
-            sleep(wait)
+            time.sleep(wait)
             count -= 1
             continue
         return (True, result)
@@ -364,6 +363,17 @@ def ip6_route(node):
 
     return result
 
+def sleep(amount, reason=None):
+    """
+    Sleep wrapper that registers in the log the amount of sleep
+    """
+    if reason is None:
+        logger.info('Sleeping for {} seconds'.format(amount))
+    else:
+        logger.info(reason + ' ({} seconds)'.format(amount))
+
+    time.sleep(amount)
+
 def checkAddressSanitizerError(output, router, component):
     "Checks for AddressSanitizer in output. If found, then logs it and returns true, false otherwise"
 
@@ -576,7 +586,7 @@ class Router(Node):
             ))
             self.waitOutput()
             logger.debug('{}: {} zebra started'.format(self, self.routertype))
-            sleep(1)
+            time.sleep(1)
         # Fix Link-Local Addresses
         # Somehow (on Mininet only), Zebra removes the IPv6 Link-Local addresses on start. Fix this
         self.cmd('for i in `ls /sys/class/net/` ; do mac=`cat /sys/class/net/$i/address`; IFS=\':\'; set $mac; unset IFS; ip address add dev $i scope link fe80::$(printf %02x $((0x$1 ^ 2)))$2:${3}ff:fe$4:$5$6/64; done')