From 1fca63c1e43243f3b4c27c193b74cb965e59bbe4 Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Thu, 15 Jun 2017 00:25:54 -0300 Subject: [PATCH] topogen: first code import Topogen (Topology Generator) is a helper that wraps around Topotest to simplify some of the boilerplate code. This abstraction will help the development of new tests and new APIs without breaking the existing ones. It also makes the relation of objects clearer, since we no longer touch the Mininet API directly, which in turn also makes us less vulnerable to external API changes. --- tests/topotests/conftest.py | 26 ++ tests/topotests/example-test/test_template.py | 107 +++++ tests/topotests/lib/topogen.py | 380 ++++++++++++++++++ tests/topotests/lib/topotest.py | 36 ++ 4 files changed, 549 insertions(+) create mode 100644 tests/topotests/conftest.py create mode 100644 tests/topotests/example-test/test_template.py create mode 100644 tests/topotests/lib/topogen.py diff --git a/tests/topotests/conftest.py b/tests/topotests/conftest.py new file mode 100644 index 0000000000..e042a3d13a --- /dev/null +++ b/tests/topotests/conftest.py @@ -0,0 +1,26 @@ +""" +Topotest conftest.py file. +""" + +from lib.topogen import get_topogen +import pytest + +def pytest_addoption(parser): + """ + Add topology-only option to the topology tester. This option makes pytest + only run the setup_module() to setup the topology without running any tests. + """ + parser.addoption('--topology-only', action='store_true', + help='Only set up this topology, don\'t run tests') + +def pytest_runtest_call(): + """ + This function must be run after setup_module(), it does standarized post + setup routines. It is only being used for the 'topology-only' option. + """ + # pylint: disable=E1101 + # Trust me, 'config' exists. + if pytest.config.getoption('--topology-only'): + # Allow user to play with the setup. + get_topogen().mininet_cli() + pytest.exit('the topology executed successfully') diff --git a/tests/topotests/example-test/test_template.py b/tests/topotests/example-test/test_template.py new file mode 100644 index 0000000000..53a4f444cc --- /dev/null +++ b/tests/topotests/example-test/test_template.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python + +# +#