throw AssertionError if controller.message_send fails
Unlike other types of exception an AssertionError will cause the test to "fail"
instead of "error". Using an exception instead of checking return values
removes a lot of boilerplate code that wasn't always present (or correct). It
may also help disabuse test writers of the dangerous notion that succeeding in
writing a message to the TCP socket means anything.
diff --git a/src/python/oftest/controller.py b/src/python/oftest/controller.py
index b60823a..fa346c3 100644
--- a/src/python/oftest/controller.py
+++ b/src/python/oftest/controller.py
@@ -258,8 +258,7 @@
rep = echo_reply()
rep.header.xid = hdr.xid
# Ignoring additional data
- if self.message_send(rep.pack(), zero_xid=True) < 0:
- self.logger.error("Error sending echo reply")
+ self.message_send(rep.pack(), zero_xid=True)
continue
# Now check for message handlers; preference is given to
@@ -613,10 +612,7 @@
self.xid = msg.header.xid
self.xid_response = None
- if self.message_send(msg.pack()) < 0:
- self.logger.error("Error sending pkt for transaction %d" %
- msg.header.xid)
- return (None, None)
+ self.message_send(msg.pack())
self.logger.debug("Waiting for transaction %d" % msg.header.xid)
timed_wait(self.xid_cv, lambda: self.xid_response, timeout=timeout)
@@ -641,9 +637,6 @@
the XID in the header is 0, then an XID will be generated
for the message. Set zero_xid to override this behavior (and keep an
existing 0 xid)
-
- @return 0 on success
-
"""
if not self.switch_socket:
@@ -663,9 +656,9 @@
ofp_type_map.get(msg_type, "unknown (%d)" % msg_type),
msg_len)
if self.switch_socket.sendall(outpkt) is not None:
- raise Exception("unknown error on sendall")
+ raise AssertionError("failed to send message to switch")
- return 0
+ return 0 # for backwards compatibility
def __str__(self):
string = "Controller:\n"
diff --git a/src/python/oftest/testutils.py b/src/python/oftest/testutils.py
index de7b52a..0fc6ce0 100644
--- a/src/python/oftest/testutils.py
+++ b/src/python/oftest/testutils.py
@@ -43,7 +43,8 @@
msg.out_port = ofp.OFPP_NONE
msg.command = ofp.OFPFC_DELETE
msg.buffer_id = 0xffffffff
- return ctrl.message_send(msg)
+ ctrl.message_send(msg)
+ return 0
def required_wildcards(parent):
w = test_param_get('required_wildcards', default='default')
@@ -349,8 +350,8 @@
mod.config = config
mod.mask = mask
mod.advertise = reply.ports[idx].advertised
- rv = controller.message_send(mod)
- return rv
+ controller.message_send(mod)
+ return 0
def receive_pkt_check(dp, pkt, yes_ports, no_ports, assert_if):
"""
@@ -574,8 +575,7 @@
parent.assertEqual(rc, 0, "Failed to delete all flows")
logging.debug("Insert flow")
- rv = parent.controller.message_send(request)
- parent.assertTrue(rv != -1, "Error installing flow mod")
+ parent.controller.message_send(request)
parent.assertEqual(do_barrier(parent.controller), 0, "Barrier failed")
@@ -642,8 +642,7 @@
msg.actions.add(act)
logging.debug(msg.show())
- rv = parent.controller.message_send(msg)
- parent.assertTrue(rv == 0, "Error sending out message")
+ parent.controller.message_send(msg)
if exp_pkt is None:
exp_pkt = pkt