Fix pep8 violations in csit/libraries/Topologynew.py
authorThanh Ha <thanh.ha@linuxfoundation.org>
Sun, 15 Mar 2015 21:09:55 +0000 (17:09 -0400)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Mon, 16 Mar 2015 01:04:06 +0000 (21:04 -0400)
Change-Id: I375388db8399f06bf9d377e13c6434c4fad7c91e
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
test/csit/libraries/Topologynew.py

index 8d1ee18c6e47444e1518ebe356c0aab12a7babb9..1ab31f3593f9b4df4044508bc8f21969b3ddd0cb 100644 (file)
@@ -3,32 +3,35 @@ Library for the robot based system test tool of the OpenDaylight project.
 Authors: Baohua Yang@IBM, Denghui Huang@IBM
 Updated: 2013-11-10
 """
-import string
-import robot
 import re
 from robot.libraries.BuiltIn import BuiltIn
-import Common 
+import Common
+
 
 class Topologynew(object):
     '''
     Topology class provide topology database and provide many method to get property of topology.
-    
+
     node_boilerplate = {u'type': u'MD_SAL', u'id': u'openflow:%d'}
     '''
-    topo_nodes_db=[[],
-            [{u'type': u'MD_SAL', u'id': u'openflow:1'}],
-            [{u'type': u'MD_SAL', u'id': u'openflow:1'},{u'type': u'MD_SAL', u'id': u'openflow:2'},{u'type': u'MD_SAL', u'id': u'openflow:3'}]]
-    
+    topo_nodes_db = [
+        [],
+        [{u'type': u'MD_SAL', u'id': u'openflow:1'}],
+        [{u'type': u'MD_SAL', u'id': u'openflow:1'},
+         {u'type': u'MD_SAL', u'id': u'openflow:2'},
+         {u'type': u'MD_SAL', u'id': u'openflow:3'}]
+        ]
+
     def __init__(self):
         self.builtin = BuiltIn()
 
-    def get_nodes_from_topology(self,topo_level):
+    def get_nodes_from_topology(self, topo_level):
         '''
         get nodes from topology database by topology tree level
         '''
         if isinstance(topo_level, str) or isinstance(topo_level, unicode):
             if topo_level.isdigit():
-                topo_level=int(topo_level)
+                topo_level = int(topo_level)
                 if topo_level <= 0:
                     return None
                 return self.topo_nodes_db[topo_level]
@@ -40,7 +43,7 @@ class Topologynew(object):
             return self.topo_nodes_db[topo_level]
         else:
             return None
-    
+
     def get_nodes_from_tree_topo(self, topo, exceptroot="0"):
         '''
         This function generates a dictionary that contains type and id of each node.
@@ -50,27 +53,27 @@ class Topologynew(object):
                          stands for depth and fanout respectively)
         @return array of dicitonary objects that contains info about each node
         '''
-        depth=0
-        fanout=2
+        depth = 0
+        fanout = 2
         if isinstance(topo, str) or isinstance(topo, unicode):
             t = tuple(int(v) for v in re.findall("[0-9]+", topo))
             if len(t) == 1:
-                depth = t[0]        
+                depth = t[0]
             elif len(t) == 2:
                 depth = t[0]
                 fanout = t[1]
             else:
-                return None                 #topology consists of two parameters: depth and fanout
+                return None                 # topology consists of two parameters: depth and fanout
         elif isinstance(topo, int):
             depth = topo
         else:
-            return  None                    #topo parameter is not given in a desired way
+            return None                     # topo parameter is not given in a desired way
 
         num_nodes = Common.num_of_nodes(depth, fanout)
         nodelist = []
         for i in xrange(1, num_nodes+1):
-            temp = { "id": "00:00:00:00:00:00:00:%s" % format(i, '02x'), "type": "OF" }
-            nodelist.append(temp)      
+            temp = {"id": "00:00:00:00:00:00:00:%s" % format(i, '02x'), "type": "OF"}
+            nodelist.append(temp)
         if int(exceptroot):
             del nodelist[0]
         return nodelist
@@ -88,17 +91,17 @@ class Topologynew(object):
         return leafnodes
 
     def _enumerate_nodes(self, currentdepth, nodeid, currentbranch, fanout, depth, leafnodes):
-        if currentdepth==depth:
+        if currentdepth == depth:
             leafnodes.append("00:00:00:00:00:00:00:%s" % format(nodeid, '02x'))
             return 1
         nodes = 1
         for i in xrange(1,  fanout+1):
             nodes += self._enumerate_nodes(currentdepth+1, nodeid+nodes, i, fanout, depth, leafnodes)
-        return nodes 
+        return nodes
 
 if __name__ == '__main__':
     topologynew = Topologynew()
-    #print topologynew.get_nodes_from_tree_topo(2)
-    #print topologynew.get_nodes_from_tree_topo('2')
+    # print topologynew.get_nodes_from_tree_topo(2)
+    # print topologynew.get_nodes_from_tree_topo('2')
     print topologynew.get_nodes_from_tree_topo('(2,3)')
-    #print topologynew.get_ids_of_leaf_nodes(2,2 )#, depth)
+    # print topologynew.get_ids_of_leaf_nodes(2,2 )#, depth)