From 61d6a1cef4635ca87ae8c8dc4ce1124a71ed02a5 Mon Sep 17 00:00:00 2001 From: Claudio Pisa Date: Thu, 4 Sep 2014 17:26:04 +0000 Subject: [PATCH] read_topology_hna: be more resistant to errors in topology files --- nodeshot/scripts/read_topology_hna.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/nodeshot/scripts/read_topology_hna.py b/nodeshot/scripts/read_topology_hna.py index 8c127248..afadf288 100755 --- a/nodeshot/scripts/read_topology_hna.py +++ b/nodeshot/scripts/read_topology_hna.py @@ -104,11 +104,15 @@ def parse(self): ipaddr1, ipaddr2, hyst, lq, nlq, etx = line.split() print("Link: %s <--[%s]--> %s" % (ipaddr1, etx, ipaddr2)) self.linklist.append((ipaddr1, ipaddr2, float(etx))) + self.linklist.append((ipaddr2, ipaddr1, float(etx))) except ValueError: print ("wrong line or INFINITE ETX: %s" % line) pass i+=1 - line = self.topologylines[i] + if i < len(self.topologylines): + line = self.topologylines[i] + else: + return topologytablefound = True while line.find('Table: Topology') == -1: @@ -130,11 +134,15 @@ def parse(self): ipaddr1, ipaddr2, lq, nlq, etx = line.split() print("Link: %s --[%s]--> %s" % (ipaddr1, etx, ipaddr2)) self.linklist.append((ipaddr1, ipaddr2, float(etx))) + self.linklist.append((ipaddr2, ipaddr1, float(etx))) except ValueError: print ("wrong line or INFINITE ETX: %s" % line) pass i+=1 - line = self.topologylines[i] + if i < len(self.topologylines): + line = self.topologylines[i] + else: + return j = i + 1 # parse HNA info @@ -154,7 +162,10 @@ def parse(self): except ValueError: pass i+=1 - line = self.topologylines[i] + if i < len(self.topologylines): + line = self.topologylines[i] + else: + return else: i = j @@ -179,7 +190,10 @@ def parse(self): except ValueError: pass i+=1 - line = self.topologylines[i] + if i < len(self.topologylines): + line = self.topologylines[i] + else: + return #debug #print self.linklist