dpif-netdev: Fix typo in comment.
[cascardo/ovs.git] / tests / test-reconnect.py
index 44b4723..8132fd9 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2009, 2010 Nicira, Inc.
+# Copyright (c) 2009, 2010, 2012 Nicira, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -12,6 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from __future__ import print_function
+
 import errno
 import sys
 
@@ -61,8 +63,8 @@ def do_connected(_):
     r.connected(now)
 
 
-def do_received(_):
-    r.received(now)
+def do_activity(_):
+    r.activity(now)
 
 
 def do_run(arg):
@@ -74,11 +76,11 @@ def do_run(arg):
     if action is None:
         pass
     elif action == ovs.reconnect.CONNECT:
-        print "  should connect"
+        print("  should connect")
     elif action == ovs.reconnect.DISCONNECT:
-        print "  should disconnect"
+        print("  should disconnect")
     elif action == ovs.reconnect.PROBE:
-        print "  should send probe"
+        print("  should send probe")
     else:
         assert False
 
@@ -91,11 +93,11 @@ def do_advance(arg):
 def do_timeout(_):
     global now
     timeout = r.timeout(now)
-    if timeout >= 0:
-        print "  advance %d ms" % timeout
+    if timeout is not None and timeout >= 0:
+        print("  advance %d ms" % timeout)
         now += timeout
     else:
-        print "  no timeout"
+        print("  no timeout")
 
 
 def do_set_max_tries(arg):
@@ -110,10 +112,10 @@ def diff_stats(old, new, delta):
               % (new.state, new.state_elapsed, new.backoff))
 
     if (old.creation_time != new.creation_time or
-        old.last_received != new.last_received or
+        old.last_activity != new.last_activity or
         old.last_connected != new.last_connected):
-        print("  created %d, last received %d, last connected %d"
-              % (new.creation_time, new.last_received, new.last_connected))
+        print("  created %d, last activity %d, last connected %d"
+              % (new.creation_time, new.last_activity, new.last_connected))
 
     if (old.n_successful_connections != new.n_successful_connections or
         old.n_attempted_connections != new.n_attempted_connections or
@@ -130,7 +132,7 @@ def diff_stats(old, new, delta):
         print("  %sconnected" % negate)
 
     if (old.last_connected != new.last_connected or
-        (new.msec_since_connect != None and
+        (new.msec_since_connect is not None and
          old.msec_since_connect != new.msec_since_connect - delta) or
         (old.total_connected_duration != new.total_connected_duration - delta
             and not (old.total_connected_duration == 0 and
@@ -139,7 +141,7 @@ def diff_stats(old, new, delta):
               % (new.msec_since_connect, new.total_connected_duration))
 
     if (old.last_disconnected != new.last_disconnected or
-        (new.msec_since_disconnect != None and
+        (new.msec_since_disconnect is not None and
          old.msec_since_disconnect != new.msec_since_disconnect - delta)):
         print("  disconnected at %d ms (%d ms ago)"
               % (new.last_disconnected, new.msec_since_disconnect))
@@ -166,7 +168,7 @@ def main():
         "connecting": do_connecting,
         "connect-failed": do_connect_failed,
         "connected": do_connected,
-        "received": do_received,
+        "activity": do_activity,
         "run": do_run,
         "advance": do_advance,
         "timeout": do_timeout,
@@ -183,7 +185,7 @@ def main():
     r = ovs.reconnect.Reconnect(now)
     r.set_name("remote")
     prev = r.get_stats(now)
-    print "### t=%d ###" % now
+    print("### t=%d ###" % now)
     old_time = now
     old_max_tries = r.get_max_tries()
     while True:
@@ -191,7 +193,7 @@ def main():
         if line == "":
             break
 
-        print line[:-1]
+        print(line[:-1])
         if line[0] == "#":
             continue
 
@@ -207,15 +209,15 @@ def main():
         commands[command](op)
 
         if old_time != now:
-            print
-            print "### t=%d ###" % now
+            print()
+            print("### t=%d ###" % now)
 
         cur = r.get_stats(now)
         diff_stats(prev, cur, now - old_time)
         prev = cur
         if r.get_max_tries() != old_max_tries:
             old_max_tries = r.get_max_tries()
-            print "  %d tries left" % old_max_tries
+            print("  %d tries left" % old_max_tries)
 
         old_time = now