summaryrefslogtreecommitdiff
path: root/tests/topotests/example_test
diff options
context:
space:
mode:
authorChristian Hopps <chopps@labn.net>2021-07-29 09:38:55 +0000
committerChristian Hopps <chopps@labn.net>2021-09-04 09:04:46 -0400
commite82b531df94b9fd7bc456df8a1b7c58f2770eff9 (patch)
treec5b8812d719c905bec58db38a2f0800be675c0e5 /tests/topotests/example_test
parentd7d21c3a190f7754afe4d5b969501756a3739e48 (diff)
tests: remove legacy Topo class (fixes many pylint errors)
Signed-off-by: Christian Hopps <chopps@labn.net>
Diffstat (limited to 'tests/topotests/example_test')
-rw-r--r--tests/topotests/example_test/test_template.py59
1 files changed, 27 insertions, 32 deletions
diff --git a/tests/topotests/example_test/test_template.py b/tests/topotests/example_test/test_template.py
index 534dd998d9..7bd434d756 100644
--- a/tests/topotests/example_test/test_template.py
+++ b/tests/topotests/example_test/test_template.py
@@ -30,19 +30,10 @@ import os
import sys
import pytest
-# Save the Current Working Directory to find configuration files.
-CWD = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.join(CWD, "../"))
-
-# pylint: disable=C0413
# Import topogen and topotest helpers
-from lib import topotest
from lib.topogen import Topogen, TopoRouter, get_topogen
from lib.topolog import logger
-# Required to instantiate the topology builder class.
-from lib.micronet_compat import Topo
-
# TODO: select markers based on daemons used during test
# pytest module level markers
@@ -56,37 +47,40 @@ pytestmark = [
"""
-class TemplateTopo(Topo):
- "Test topology builder"
+def build_topo(tgen):
+ "Build function"
- def build(self, *_args, **_opts):
- "Build function"
- tgen = get_topogen(self)
+ # Create 2 routers
+ for routern in range(1, 3):
+ tgen.add_router("r{}".format(routern))
- # This function only purpose is to define allocation and relationship
- # between routers, switches and hosts.
- #
- # Example
- #
- # Create 2 routers
- for routern in range(1, 3):
- tgen.add_router("r{}".format(routern))
+ # Create a switch with just one router connected to it to simulate a
+ # empty network.
+ switch = tgen.add_switch("s1")
+ switch.add_link(tgen.gears["r1"])
- # Create a switch with just one router connected to it to simulate a
- # empty network.
- switch = tgen.add_switch("s1")
- switch.add_link(tgen.gears["r1"])
-
- # Create a connection between r1 and r2
- switch = tgen.add_switch("s2")
- switch.add_link(tgen.gears["r1"])
- switch.add_link(tgen.gears["r2"])
+ # Create a connection between r1 and r2
+ switch = tgen.add_switch("s2")
+ switch.add_link(tgen.gears["r1"])
+ switch.add_link(tgen.gears["r2"])
def setup_module(mod):
"Sets up the pytest environment"
+
+
# This function initiates the topology build with Topogen...
- tgen = Topogen(TemplateTopo, mod.__name__)
+ tgen = Topogen(build_topo, mod.__name__)
+
+ # The basic topology above could also have be more easily specified using a
+ # dictionary, remove the build_topo function and use the following instead:
+ #
+ # topodef = {
+ # "s1": "r1"
+ # "s2": ("r1", "r2")
+ # }
+ # tgen = Topogen(topodef, mod.__name__)
+
# ... and here it calls initialization functions.
tgen.start_topology()
@@ -94,6 +88,7 @@ def setup_module(mod):
router_list = tgen.routers()
# For all registred routers, load the zebra configuration file
+ # CWD = os.path.dirname(os.path.realpath(__file__))
for rname, router in router_list.items():
router.load_config(
TopoRouter.RD_ZEBRA,