From b2f725c6dfdeede88b38530006b28d73cdcd6e5e Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Wed, 21 Nov 2012 17:35:52 +0900 Subject: contrib/ovs: TypeError: bad operand type for unary -: 'NoneType' This fixes the following exception: When Stream.__scs_connecting doesn't change self.state, Stream.connect() returns None as implicit return value. Thus, the following exception is raised. conf_switch_set_handler 00003247b5e63145 ovsdb_addr tcp:172.17.60.198:6634 _ovsdb_update 00003247b5e63145 tcp:172.17.60.198:6634 172.17.60.198 _add_tunnel_ports set([]) 172.17.60.198 - - [2012-11-21 15:01:00] "PUT /v1.0/conf/switches/00003247b5e63145/ovsdb_addr HTTP/1.1" 201 120 0.267351 remote tcp:172.17.60.198:6634 Traceback (most recent call last): File "/usr/lib/pymodules/python2.7/gevent/greenlet.py", line 390, in run result = self._run(*self.args, **self.kwargs) File "/home/yamahata/openvswitch/sp-lab/scarab/gre-tunnel/ryu-2/bin/ryu/app/tunnel_port_updater.py", line 289, in _serve_loop self._init() File "/home/yamahata/openvswitch/sp-lab/scarab/gre-tunnel/ryu-2/bin/ryu/app/tunnel_port_updater.py", line 125, in _init self.ovs_bridge.init() File "/home/yamahata/openvswitch/sp-lab/scarab/gre-tunnel/ryu-2/bin/ryu/lib/ovs/bridge.py", line 103, in init self.br_name = self._get_bridge_name() File "/home/yamahata/openvswitch/sp-lab/scarab/gre-tunnel/ryu-2/bin/ryu/lib/ovs/bridge.py", line 111, in _get_bridge_name self.run_command([command]) File "/home/yamahata/openvswitch/sp-lab/scarab/gre-tunnel/ryu-2/bin/ryu/lib/ovs/bridge.py", line 99, in run_command self.vsctl.run_command(commands, self.timeout, self.exception) File "/home/yamahata/openvswitch/sp-lab/scarab/gre-tunnel/ryu-2/bin/ryu/lib/ovs/vsctl.py", line 1006, in run_command self._run_command(commands) File "/home/yamahata/openvswitch/sp-lab/scarab/gre-tunnel/ryu-2/bin/ryu/lib/ovs/vsctl.py", line 999, in _run_command self._do_main(commands) File "/home/yamahata/openvswitch/sp-lab/scarab/gre-tunnel/ryu-2/bin/ryu/lib/ovs/vsctl.py", line 918, in _do_main self._init_schema_helper() File "/home/yamahata/openvswitch/sp-lab/scarab/gre-tunnel/ryu-2/bin/ryu/lib/ovs/vsctl.py", line 805, in _init_schema_helper vswitch_idl.OVSREC_DB_NAME) File "/home/yamahata/openvswitch/sp-lab/scarab/gre-tunnel/ryu-2/bin/ryu/lib/ovs/vsctl.py", line 793, in _rpc_get_schema_json error, reply = rpc.transact_block(request) File "/home/yamahata/openvswitch/sp-lab/scarab/gre-tunnel/ryu-2/bin/ryu/contrib/ovs/jsonrpc.py", line 306, in transact_block error = self.send(request) File "/home/yamahata/openvswitch/sp-lab/scarab/gre-tunnel/ryu-2/bin/ryu/contrib/ovs/jsonrpc.py", line 240, in send self.run() File "/home/yamahata/openvswitch/sp-lab/scarab/gre-tunnel/ryu-2/bin/ryu/contrib/ovs/jsonrpc.py", line 200, in run retval = self.stream.send(self.output) File "/home/yamahata/openvswitch/sp-lab/scarab/gre-tunnel/ryu-2/bin/ryu/contrib/ovs/stream.py", line 213, in send return -retval TypeError: bad operand type for unary -: 'NoneType' >> failed with TypeError Signed-off-by: Isaku Yamahata Signed-off-by: FUJITA Tomonori --- ryu/contrib/ovs/stream.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ryu/contrib/ovs/stream.py b/ryu/contrib/ovs/stream.py index c4d243d0..b4f5ba6f 100644 --- a/ryu/contrib/ovs/stream.py +++ b/ryu/contrib/ovs/stream.py @@ -152,9 +152,10 @@ class Stream(object): assert retval != errno.EINPROGRESS if retval == 0: self.state = Stream.__S_CONNECTED - elif retval != errno.EAGAIN: - self.state = Stream.__S_DISCONNECTED + else: self.error = retval + if retval != errno.EAGAIN: + self.state = Stream.__S_DISCONNECTED def connect(self): """Tries to complete the connection on this stream. If the connection @@ -166,6 +167,11 @@ class Stream(object): last_state = self.state if self.state == Stream.__S_CONNECTING: self.__scs_connecting() + if self.state == Stream.__S_CONNECTING: + # try again + assert self.error == errno.EAGAIN + last_state = -1 + assert self.state != last_state elif self.state == Stream.__S_CONNECTED: return 0 elif self.state == Stream.__S_DISCONNECTED: -- cgit v1.2.3