diff options
| author | Rafael Zalamena <rzalamena@gmail.com> | 2017-06-22 17:51:32 -0300 |
|---|---|---|
| committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2018-11-27 20:22:11 -0500 |
| commit | 7326ea11c0da069e9a96a8857bd39a1951885e4c (patch) | |
| tree | 65a0657211b58e9bb3f7fce3e41a52f9a1e93e47 | |
| parent | 240e334fca888265af02d8e0930623b15d13c991 (diff) | |
topogen: implement __str__ for TopoGear objects
Print TopoGear name, links and type (currently TopoRouter and Switch
don't have any other useful attributes).
| -rw-r--r-- | tests/topotests/lib/topogen.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index e87b6bd0a7..19c36ed0d7 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -224,6 +224,16 @@ class TopoGear(object): self.links = {} self.linkn = 0 + def __str__(self): + links = '' + for myif, dest in self.links.iteritems(): + _, destif = dest + if links != '': + links += ',' + links += '"{}"<->"{}"'.format(myif, destif) + + return 'TopoGear<name="{}",links=[{}]>'.format(self.name, links) + def run(self, command): """ Runs the provided command string in the router and returns a string @@ -307,7 +317,7 @@ class TopoRouter(TopoGear): ] # Router Daemon enumeration definition. - RD_ZEBRA = 1, + RD_ZEBRA = 1 RD_RIP = 2 RD_RIPNG = 3 RD_OSPF = 4 @@ -346,6 +356,11 @@ class TopoRouter(TopoGear): params['privateDirs'] = self.PRIVATE_DIRS self.tgen.topo.addNode(self.name, cls=self.cls, **params) + def __str__(self): + gear = super(TopoRouter, self).__str__() + gear += ' TopoRouter<>' + return gear + def load_config(self, daemon, source=None): """ Loads daemon configuration from the specified source @@ -442,3 +457,8 @@ class TopoSwitch(TopoGear): self.name = name self.cls = cls self.tgen.topo.addSwitch(name, cls=self.cls) + + def __str__(self): + gear = super(TopoSwitch, self).__str__() + gear += ' TopoSwitch<>' + return gear |
