testutils: add openflow_ports()
This function replaces the common boilerplate code that gets a list of port
numbers from the config dictionary and checks that enough ports are available
for the test.
I changed the OF 1.3 tests to use this function.
diff --git a/src/python/oftest/testutils.py b/src/python/oftest/testutils.py
index bf2b24a..e87b7a0 100644
--- a/src/python/oftest/testutils.py
+++ b/src/python/oftest/testutils.py
@@ -1598,4 +1598,17 @@
test.assertTrue(msg == None, "Did not expect a packet-in message on port %d" % in_port)
+def openflow_ports(num=None):
+ """
+ Return a list of 'num' OpenFlow port numbers
+
+ If 'num' is None, return all available ports. Otherwise, limit the length
+ of the result to 'num' and raise an exception if not enough ports are
+ available.
+ """
+ ports = sorted(oftest.config["port_map"].keys())
+ if num != None and len(ports) < num:
+ raise Exception("test requires %d ports but only %d are available" % (num, len(ports)))
+ return ports[:num]
+
__all__ = list(set(locals()) - _import_blacklist)