]>
git.proxmox.com Git - ovs.git/blob - tests/test-reconnect.py
1 # Copyright (c) 2009, 2010, 2012 Nicira, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from __future__
import print_function
34 def do_force_reconnect(_
):
35 r
.force_reconnect(now
)
38 def error_from_string(s
):
41 elif s
== "ECONNREFUSED":
42 return errno
.ECONNREFUSED
44 return ovs
.reconnect
.EOF
46 sys
.stderr
.write("unknown error '%s'\n" % s
)
50 def do_disconnected(arg
):
51 r
.disconnected(now
, error_from_string(arg
))
58 def do_connect_failed(arg
):
59 r
.connect_failed(now
, error_from_string(arg
))
78 elif action
== ovs
.reconnect
.CONNECT
:
79 print(" should connect")
80 elif action
== ovs
.reconnect
.DISCONNECT
:
81 print(" should disconnect")
82 elif action
== ovs
.reconnect
.PROBE
:
83 print(" should send probe")
95 timeout
= r
.timeout(now
)
96 if timeout
is not None and timeout
>= 0:
97 print(" advance %d ms" % timeout
)
103 def do_set_max_tries(arg
):
104 r
.set_max_tries(int(arg
))
107 def diff_stats(old
, new
, delta
):
108 if (old
.state
!= new
.state
or
109 old
.state_elapsed
!= new
.state_elapsed
or
110 old
.backoff
!= new
.backoff
):
111 print(" in %s for %d ms (%d ms backoff)"
112 % (new
.state
, new
.state_elapsed
, new
.backoff
))
114 if (old
.creation_time
!= new
.creation_time
or
115 old
.last_activity
!= new
.last_activity
or
116 old
.last_connected
!= new
.last_connected
):
117 print(" created %d, last activity %d, last connected %d"
118 % (new
.creation_time
, new
.last_activity
, new
.last_connected
))
120 if (old
.n_successful_connections
!= new
.n_successful_connections
or
121 old
.n_attempted_connections
!= new
.n_attempted_connections
or
122 old
.seqno
!= new
.seqno
):
123 print(" %d successful connections out of %d attempts, seqno %d"
124 % (new
.n_successful_connections
, new
.n_attempted_connections
,
127 if (old
.is_connected
!= new
.is_connected
):
132 print(" %sconnected" % negate
)
134 if (old
.last_connected
!= new
.last_connected
or
135 (new
.msec_since_connect
is not None and
136 old
.msec_since_connect
!= new
.msec_since_connect
- delta
) or
137 (old
.total_connected_duration
!= new
.total_connected_duration
- delta
138 and not (old
.total_connected_duration
== 0 and
139 new
.total_connected_duration
== 0))):
140 print(" last connected %d ms ago, connected %d ms total"
141 % (new
.msec_since_connect
, new
.total_connected_duration
))
143 if (old
.last_disconnected
!= new
.last_disconnected
or
144 (new
.msec_since_disconnect
is not None and
145 old
.msec_since_disconnect
!= new
.msec_since_disconnect
- delta
)):
146 print(" disconnected at %d ms (%d ms ago)"
147 % (new
.last_disconnected
, new
.msec_since_disconnect
))
150 def do_set_passive(_
):
151 r
.set_passive(True, now
)
158 def do_listen_error(arg
):
159 r
.listen_error(now
, int(arg
))
165 "disable": do_disable
,
166 "force-reconnect": do_force_reconnect
,
167 "disconnected": do_disconnected
,
168 "connecting": do_connecting
,
169 "connect-failed": do_connect_failed
,
170 "connected": do_connected
,
171 "activity": do_activity
,
173 "advance": do_advance
,
174 "timeout": do_timeout
,
175 "set-max-tries": do_set_max_tries
,
176 "passive": do_set_passive
,
177 "listening": do_listening
,
178 "listen-error": do_listen_error
185 r
= ovs
.reconnect
.Reconnect(now
)
187 prev
= r
.get_stats(now
)
188 print("### t=%d ###" % now
)
190 old_max_tries
= r
.get_max_tries()
192 line
= sys
.stdin
.readline()
209 commands
[command
](op
)
213 print("### t=%d ###" % now
)
215 cur
= r
.get_stats(now
)
216 diff_stats(prev
, cur
, now
- old_time
)
218 if r
.get_max_tries() != old_max_tries
:
219 old_max_tries
= r
.get_max_tries()
220 print(" %d tries left" % old_max_tries
)
225 if __name__
== '__main__':