Run codestyle script on HA test suite

Change-Id: Ib59ce54b5f5596a1d33845f05b86a117d42a4d32
diff --git a/TestON/tests/HA/HAkillNodes/HAkillNodes.py b/TestON/tests/HA/HAkillNodes/HAkillNodes.py
index 560cb71..e3feb50 100644
--- a/TestON/tests/HA/HAkillNodes/HAkillNodes.py
+++ b/TestON/tests/HA/HAkillNodes/HAkillNodes.py
@@ -23,8 +23,6 @@
 CASE16: Install Distributed Primitives app
 CASE17: Check for basic functionality with distributed primitives
 """
-
-
 class HAkillNodes:
 
     def __init__( self ):
@@ -149,7 +147,7 @@
                             filePath + topoName,
                             main.Mininet1.home,
                             direction="to" )
-        mnResult = main.Mininet1.startNet( )
+        mnResult = main.Mininet1.startNet()
         utilities.assert_equals( expect=main.TRUE, actual=mnResult,
                                  onpass="Mininet Started",
                                  onfail="Error starting Mininet" )
@@ -201,7 +199,7 @@
                   'seamless="seamless"></iframe>\n'
         graphs += ']]></ac:plain-text-body>\n'
         graphs += '</ac:structured-macro>\n'
-        main.log.wiki(graphs)
+        main.log.wiki( graphs )
 
         main.step( "Creating ONOS package" )
         # copy gen-partions file to ONOS
@@ -268,9 +266,9 @@
         cliResults = main.TRUE
         threads = []
         for i in range( main.numCtrls ):
-            t = main.Thread( target=main.CLIs[i].startOnosCli,
+            t = main.Thread( target=main.CLIs[ i ].startOnosCli,
                              name="startOnosCli-" + str( i ),
-                             args=[main.nodes[i].ip_address] )
+                             args=[ main.nodes[ i ].ip_address ] )
             threads.append( t )
             t.start()
 
@@ -300,7 +298,7 @@
         main.step( "Checking ONOS nodes" )
         nodeResults = utilities.retry( main.HA.nodesCheck,
                                        False,
-                                       args=[main.activeNodes],
+                                       args=[ main.activeNodes ],
                                        attempts=5 )
 
         utilities.assert_equals( expect=True, actual=nodeResults,
@@ -309,7 +307,7 @@
 
         if not nodeResults:
             for i in main.activeNodes:
-                cli = main.CLIs[i]
+                cli = main.CLIs[ i ]
                 main.log.debug( "{} components not ACTIVE: \n{}".format(
                     cli.name,
                     cli.sendline( "scr:list | grep -v ACTIVE" ) ) )
@@ -321,7 +319,7 @@
         # get data from the params
         apps = main.params.get( 'apps' )
         if apps:
-            apps = apps.split(',')
+            apps = apps.split( ',' )
             main.log.warn( apps )
             activateResult = True
             for app in apps:
@@ -348,8 +346,8 @@
             main.log.debug( config )
             checkResult = main.TRUE
             for component in config:
-                for setting in config[component]:
-                    value = config[component][setting]
+                for setting in config[ component ]:
+                    value = config[ component ][ setting ]
                     check = main.CLIs[ 0 ].setCfg( component, setting, value )
                     main.log.info( "Value was changed? {}".format( main.TRUE == check ) )
                     checkResult = check and checkResult
@@ -364,7 +362,7 @@
         appCheck = main.TRUE
         threads = []
         for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].appToIDCheck,
+            t = main.Thread( target=main.CLIs[ i ].appToIDCheck,
                              name="appToIDCheck-" + str( i ),
                              args=[] )
             threads.append( t )
@@ -374,9 +372,9 @@
             t.join()
             appCheck = appCheck and t.result
         if appCheck != main.TRUE:
-            node = main.activeNodes[0]
-            main.log.warn( main.CLIs[node].apps() )
-            main.log.warn( main.CLIs[node].appIDs() )
+            node = main.activeNodes[ 0 ]
+            main.log.warn( main.CLIs[ node ].apps() )
+            main.log.warn( main.CLIs[ node ].appIDs() )
         utilities.assert_equals( expect=main.TRUE, actual=appCheck,
                                  onpass="App Ids seem to be correct",
                                  onfail="Something is wrong with app Ids" )
@@ -461,9 +459,9 @@
         # Manually assign mastership to the controller we want
         roleCall = main.TRUE
 
-        ipList = [ ]
+        ipList = []
         deviceList = []
-        onosCli = main.CLIs[ main.activeNodes[0] ]
+        onosCli = main.CLIs[ main.activeNodes[ 0 ] ]
         try:
             # Assign mastership to specific controllers. This assignment was
             # determined for a 7 node cluser, but will work with any sized
@@ -537,8 +535,8 @@
         #       atomic and is actually a multi step process
         time.sleep( 5 )
         for i in range( len( ipList ) ):
-            ip = ipList[i]
-            deviceId = deviceList[i]
+            ip = ipList[ i ]
+            deviceId = deviceList[ i ]
             # Check assignment
             master = onosCli.getRole( deviceId ).get( 'master' )
             if ip in master:
@@ -586,7 +584,7 @@
 
         # install onos-app-fwd
         main.step( "Install reactive forwarding app" )
-        onosCli = main.CLIs[ main.activeNodes[0] ]
+        onosCli = main.CLIs[ main.activeNodes[ 0 ] ]
         installResults = onosCli.activateApp( "org.onosproject.fwd" )
         utilities.assert_equals( expect=main.TRUE, actual=installResults,
                                  onpass="Install fwd successful",
@@ -596,7 +594,7 @@
         appCheck = main.TRUE
         threads = []
         for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].appToIDCheck,
+            t = main.Thread( target=main.CLIs[ i ].appToIDCheck,
                              name="appToIDCheck-" + str( i ),
                              args=[] )
             threads.append( t )
@@ -621,13 +619,13 @@
         pingResult = main.Mininet1.pingall()
         time2 = time.time()
         if not pingResult:
-            main.log.warn("First pingall failed. Trying again...")
+            main.log.warn( "First pingall failed. Trying again..." )
             pingResult = main.Mininet1.pingall()
             passMsg += " on the second try"
         utilities.assert_equals(
             expect=main.TRUE,
             actual=pingResult,
-            onpass= passMsg,
+            onpass=passMsg,
             onfail="Reactive Pingall failed, " +
                    "one or more ping pairs failed" )
         main.log.info( "Time for pingall: %2f seconds" %
@@ -636,8 +634,8 @@
         time.sleep( 11 )
         # uninstall onos-app-fwd
         main.step( "Uninstall reactive forwarding app" )
-        node = main.activeNodes[0]
-        uninstallResult = main.CLIs[node].deactivateApp( "org.onosproject.fwd" )
+        node = main.activeNodes[ 0 ]
+        uninstallResult = main.CLIs[ node ].deactivateApp( "org.onosproject.fwd" )
         utilities.assert_equals( expect=main.TRUE, actual=uninstallResult,
                                  onpass="Uninstall fwd successful",
                                  onfail="Uninstall fwd failed" )
@@ -646,7 +644,7 @@
         threads = []
         appCheck2 = main.TRUE
         for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].appToIDCheck,
+            t = main.Thread( target=main.CLIs[ i ].appToIDCheck,
                              name="appToIDCheck-" + str( i ),
                              args=[] )
             threads.append( t )
@@ -656,9 +654,9 @@
             t.join()
             appCheck2 = appCheck2 and t.result
         if appCheck2 != main.TRUE:
-            node = main.activeNodes[0]
-            main.log.warn( main.CLIs[node].apps() )
-            main.log.warn( main.CLIs[node].appIDs() )
+            node = main.activeNodes[ 0 ]
+            main.log.warn( main.CLIs[ node ].apps() )
+            main.log.warn( main.CLIs[ node ].appIDs() )
         utilities.assert_equals( expect=main.TRUE, actual=appCheck2,
                                  onpass="App Ids seem to be correct",
                                  onfail="Something is wrong with app Ids" )
@@ -686,8 +684,8 @@
                 host2Id = host2Dict.get( 'id', None )
             if host1Id and host2Id:
                 nodeNum = ( i % len( main.activeNodes ) )
-                node = main.activeNodes[nodeNum]
-                tmpId = main.CLIs[node].addHostIntent( host1Id, host2Id )
+                node = main.activeNodes[ nodeNum ]
+                tmpId = main.CLIs[ node ].addHostIntent( host1Id, host2Id )
                 if tmpId:
                     main.log.info( "Added intent with id: " + tmpId )
                     intentIds.append( tmpId )
@@ -697,8 +695,8 @@
             else:
                 main.log.error( "Error, getHost() failed for h" + str( i ) +
                                 " and/or h" + str( i + 10 ) )
-                node = main.activeNodes[0]
-                hosts = main.CLIs[node].hosts()
+                node = main.activeNodes[ 0 ]
+                hosts = main.CLIs[ node ].hosts()
                 main.log.warn( "Hosts output: " )
                 try:
                     main.log.warn( json.dumps( json.loads( hosts ),
@@ -766,7 +764,7 @@
                 for i in range( 14 ):
                     topics.append( "work-partition-" + str( i ) )
                 main.log.debug( topics )
-                ONOStopics = [ j['topic'] for j in parsedLeaders ]
+                ONOStopics = [ j[ 'topic' ] for j in parsedLeaders ]
                 for topic in topics:
                     if topic not in ONOStopics:
                         main.log.error( "Error: " + topic +
@@ -780,13 +778,13 @@
         # Check all nodes
         if missing:
             for i in main.activeNodes:
-                response = main.CLIs[i].leaders( jsonFormat=False)
-                main.log.warn( str( main.CLIs[i].name ) + " leaders output: \n" +
+                response = main.CLIs[ i ].leaders( jsonFormat=False )
+                main.log.warn( str( main.CLIs[ i ].name ) + " leaders output: \n" +
                                str( response ) )
 
         partitions = onosCli.partitions()
         try:
-            if partitions :
+            if partitions:
                 parsedPartitions = json.loads( partitions )
                 main.log.warn( json.dumps( parsedPartitions,
                                            sort_keys=True,
@@ -801,7 +799,7 @@
             main.log.error( repr( partitions ) )
         pendingMap = onosCli.pendingMap()
         try:
-            if pendingMap :
+            if pendingMap:
                 parsedPending = json.loads( pendingMap )
                 main.log.warn( json.dumps( parsedPending,
                                            sort_keys=True,
@@ -820,21 +818,21 @@
             main.log.error( "Error in pushing host intents to ONOS" )
 
         main.step( "Intent Anti-Entropy dispersion" )
-        for j in range(100):
+        for j in range( 100 ):
             correct = True
             main.log.info( "Submitted intents: " + str( sorted( intentIds ) ) )
             for i in main.activeNodes:
                 onosIds = []
-                ids = main.CLIs[i].getAllIntentsId()
+                ids = main.CLIs[ i ].getAllIntentsId()
                 onosIds.append( ids )
-                main.log.debug( "Intents in " + main.CLIs[i].name + ": " +
+                main.log.debug( "Intents in " + main.CLIs[ i ].name + ": " +
                                 str( sorted( onosIds ) ) )
                 if sorted( ids ) != sorted( intentIds ):
                     main.log.warn( "Set of intent IDs doesn't match" )
                     correct = False
                     break
                 else:
-                    intents = json.loads( main.CLIs[i].intents() )
+                    intents = json.loads( main.CLIs[ i ].intents() )
                     for intent in intents:
                         if intent[ 'state' ] != "INSTALLED":
                             main.log.warn( "Intent " + intent[ 'id' ] +
@@ -844,14 +842,14 @@
             if correct:
                 break
             else:
-                time.sleep(1)
+                time.sleep( 1 )
         if not intentStop:
             intentStop = time.time()
         global gossipTime
         gossipTime = intentStop - intentStart
         main.log.info( "It took about " + str( gossipTime ) +
                         " seconds for all intents to appear in each node" )
-        gossipPeriod = int( main.params['timers']['gossip'] )
+        gossipPeriod = int( main.params[ 'timers' ][ 'gossip' ] )
         maxGossipTime = gossipPeriod * len( main.activeNodes )
         utilities.assert_greater_equals(
                 expect=maxGossipTime, actual=gossipTime,
@@ -913,7 +911,7 @@
                     # FIXME: this should only be after we start the app
                     topics.append( "org.onosproject.election" )
                     main.log.debug( topics )
-                    ONOStopics = [ j['topic'] for j in parsedLeaders ]
+                    ONOStopics = [ j[ 'topic' ] for j in parsedLeaders ]
                     for topic in topics:
                         if topic not in ONOStopics:
                             main.log.error( "Error: " + topic +
@@ -927,14 +925,14 @@
             # Check all nodes
             if missing:
                 for i in main.activeNodes:
-                    node = main.CLIs[i]
-                    response = node.leaders( jsonFormat=False)
+                    node = main.CLIs[ i ]
+                    response = node.leaders( jsonFormat=False )
                     main.log.warn( str( node.name ) + " leaders output: \n" +
                                    str( response ) )
 
             partitions = onosCli.partitions()
             try:
-                if partitions :
+                if partitions:
                     parsedPartitions = json.loads( partitions )
                     main.log.warn( json.dumps( parsedPartitions,
                                                sort_keys=True,
@@ -949,7 +947,7 @@
                 main.log.error( repr( partitions ) )
             pendingMap = onosCli.pendingMap()
             try:
-                if pendingMap :
+                if pendingMap:
                     parsedPending = json.loads( pendingMap )
                     main.log.warn( json.dumps( parsedPending,
                                                sort_keys=True,
@@ -978,7 +976,7 @@
                                 "functionality and check the state of " +\
                                 "the intent"
 
-        onosCli = main.CLIs[ main.activeNodes[0] ]
+        onosCli = main.CLIs[ main.activeNodes[ 0 ] ]
         main.step( "Check Intent state" )
         installedCheck = False
         loopCount = 0
@@ -1064,7 +1062,7 @@
                 # FIXME: topics.append( "org.onosproject.election" )
                 # Print leaders output
                 main.log.debug( topics )
-                ONOStopics = [ j['topic'] for j in parsedLeaders ]
+                ONOStopics = [ j[ 'topic' ] for j in parsedLeaders ]
                 for topic in topics:
                     if topic not in ONOStopics:
                         main.log.error( "Error: " + topic +
@@ -1081,8 +1079,8 @@
         # Check all nodes
         if topicCheck:
             for i in main.activeNodes:
-                node = main.CLIs[i]
-                response = node.leaders( jsonFormat=False)
+                node = main.CLIs[ i ]
+                response = node.leaders( jsonFormat=False )
                 main.log.warn( str( node.name ) + " leaders output: \n" +
                                str( response ) )
 
@@ -1092,7 +1090,7 @@
         # Print partitions
         partitions = onosCli.partitions()
         try:
-            if partitions :
+            if partitions:
                 parsedPartitions = json.loads( partitions )
                 main.log.warn( json.dumps( parsedPartitions,
                                            sort_keys=True,
@@ -1108,7 +1106,7 @@
         # Print Pending Map
         pendingMap = onosCli.pendingMap()
         try:
-            if pendingMap :
+            if pendingMap:
                 parsedPending = json.loads( pendingMap )
                 main.log.warn( json.dumps( parsedPending,
                                            sort_keys=True,
@@ -1162,7 +1160,7 @@
                     # FIXME: this should only be after we start the app
                     topics.append( "org.onosproject.election" )
                     main.log.debug( topics )
-                    ONOStopics = [ j['topic'] for j in parsedLeaders ]
+                    ONOStopics = [ j[ 'topic' ] for j in parsedLeaders ]
                     for topic in topics:
                         if topic not in ONOStopics:
                             main.log.error( "Error: " + topic +
@@ -1175,14 +1173,14 @@
                 main.log.error( repr( leaders ) )
             if missing:
                 for i in main.activeNodes:
-                    node = main.CLIs[i]
-                    response = node.leaders( jsonFormat=False)
+                    node = main.CLIs[ i ]
+                    response = node.leaders( jsonFormat=False )
                     main.log.warn( str( node.name ) + " leaders output: \n" +
                                    str( response ) )
 
             partitions = onosCli.partitions()
             try:
-                if partitions :
+                if partitions:
                     parsedPartitions = json.loads( partitions )
                     main.log.warn( json.dumps( parsedPartitions,
                                                sort_keys=True,
@@ -1197,7 +1195,7 @@
                 main.log.error( repr( partitions ) )
             pendingMap = onosCli.pendingMap()
             try:
-                if pendingMap :
+                if pendingMap:
                     parsedPending = json.loads( pendingMap )
                     main.log.warn( json.dumps( parsedPending,
                                                sort_keys=True,
@@ -1268,7 +1266,7 @@
         rolesNotNull = main.TRUE
         threads = []
         for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].rolesNotNull,
+            t = main.Thread( target=main.CLIs[ i ].rolesNotNull,
                              name="rolesNotNull-" + str( i ),
                              args=[] )
             threads.append( t )
@@ -1290,7 +1288,7 @@
         rolesResults = True
         threads = []
         for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].roles,
+            t = main.Thread( target=main.CLIs[ i ].roles,
                              name="roles-" + str( i ),
                              args=[] )
             threads.append( t )
@@ -1301,11 +1299,11 @@
             ONOSMastership.append( t.result )
 
         for i in range( len( ONOSMastership ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if not ONOSMastership[i] or "Error" in ONOSMastership[i]:
+            node = str( main.activeNodes[ i ] + 1 )
+            if not ONOSMastership[ i ] or "Error" in ONOSMastership[ i ]:
                 main.log.error( "Error in getting ONOS" + node + " roles" )
                 main.log.warn( "ONOS" + node + " mastership response: " +
-                               repr( ONOSMastership[i] ) )
+                               repr( ONOSMastership[ i ] ) )
                 rolesResults = False
         utilities.assert_equals(
             expect=True,
@@ -1314,7 +1312,7 @@
             onfail="Error in reading roles from ONOS" )
 
         main.step( "Check for consistency in roles from each controller" )
-        if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ):
+        if all( [ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ):
             main.log.info(
                 "Switch roles are consistent across all ONOS nodes" )
         else:
@@ -1327,7 +1325,7 @@
 
         if rolesResults and not consistentMastership:
             for i in range( len( main.activeNodes ) ):
-                node = str( main.activeNodes[i] + 1 )
+                node = str( main.activeNodes[ i ] + 1 )
                 try:
                     main.log.warn(
                         "ONOS" + node + " roles: ",
@@ -1351,7 +1349,7 @@
         intentsResults = True
         threads = []
         for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].intents,
+            t = main.Thread( target=main.CLIs[ i ].intents,
                              name="intents-" + str( i ),
                              args=[],
                              kwargs={ 'jsonFormat': True } )
@@ -1363,7 +1361,7 @@
             ONOSIntents.append( t.result )
 
         for i in range( len( ONOSIntents ) ):
-            node = str( main.activeNodes[i] + 1 )
+            node = str( main.activeNodes[ i ] + 1 )
             if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]:
                 main.log.error( "Error in getting ONOS" + node + " intents" )
                 main.log.warn( "ONOS" + node + " intents response: " +
@@ -1376,7 +1374,7 @@
             onfail="Error in reading intents from ONOS" )
 
         main.step( "Check for consistency in Intents from each controller" )
-        if all([ sorted( i ) == sorted( ONOSIntents[ 0 ] ) for i in ONOSIntents ] ):
+        if all( [ sorted( i ) == sorted( ONOSIntents[ 0 ] ) for i in ONOSIntents ] ):
             main.log.info( "Intents are consistent across all ONOS " +
                              "nodes" )
         else:
@@ -1424,17 +1422,17 @@
 
         if intentsResults and not consistentIntents:
             # print the json objects
-            n = str( main.activeNodes[-1] + 1 )
+            n = str( main.activeNodes[ -1 ] + 1 )
             main.log.debug( "ONOS" + n + " intents: " )
             main.log.debug( json.dumps( json.loads( ONOSIntents[ -1 ] ),
                                         sort_keys=True,
                                         indent=4,
                                         separators=( ',', ': ' ) ) )
             for i in range( len( ONOSIntents ) ):
-                node = str( main.activeNodes[i] + 1 )
+                node = str( main.activeNodes[ i ] + 1 )
                 if ONOSIntents[ i ] != ONOSIntents[ -1 ]:
                     main.log.debug( "ONOS" + node + " intents: " )
-                    main.log.debug( json.dumps( json.loads( ONOSIntents[i] ),
+                    main.log.debug( json.dumps( json.loads( ONOSIntents[ i ] ),
                                                 sort_keys=True,
                                                 indent=4,
                                                 separators=( ',', ': ' ) ) )
@@ -1455,7 +1453,7 @@
         flowsResults = True
         threads = []
         for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].flows,
+            t = main.Thread( target=main.CLIs[ i ].flows,
                              name="flows-" + str( i ),
                              args=[],
                              kwargs={ 'jsonFormat': True } )
@@ -1463,14 +1461,14 @@
             t.start()
 
         # NOTE: Flows command can take some time to run
-        time.sleep(30)
+        time.sleep( 30 )
         for t in threads:
             t.join()
             result = t.result
             ONOSFlows.append( result )
 
         for i in range( len( ONOSFlows ) ):
-            num = str( main.activeNodes[i] + 1 )
+            num = str( main.activeNodes[ i ] + 1 )
             if not ONOSFlows[ i ] or "Error" in ONOSFlows[ i ]:
                 main.log.error( "Error in getting ONOS" + num + " flows" )
                 main.log.warn( "ONOS" + num + " flows response: " +
@@ -1507,11 +1505,11 @@
 
         if flowsResults and not consistentFlows:
             for i in range( len( ONOSFlows ) ):
-                node = str( main.activeNodes[i] + 1 )
+                node = str( main.activeNodes[ i ] + 1 )
                 try:
                     main.log.warn(
                         "ONOS" + node + " flows: " +
-                        json.dumps( json.loads( ONOSFlows[i] ), sort_keys=True,
+                        json.dumps( json.loads( ONOSFlows[ i ] ), sort_keys=True,
                                     indent=4, separators=( ',', ': ' ) ) )
                 except ( ValueError, TypeError ):
                     main.log.warn( "ONOS" + node + " flows: " +
@@ -1576,9 +1574,9 @@
         devices = []
         threads = []
         for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].devices,
+            t = main.Thread( target=main.CLIs[ i ].devices,
                              name="devices-" + str( i ),
-                             args=[ ] )
+                             args=[] )
             threads.append( t )
             t.start()
 
@@ -1588,9 +1586,9 @@
         hosts = []
         threads = []
         for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].hosts,
+            t = main.Thread( target=main.CLIs[ i ].hosts,
                              name="hosts-" + str( i ),
-                             args=[ ] )
+                             args=[] )
             threads.append( t )
             t.start()
 
@@ -1608,9 +1606,9 @@
         ports = []
         threads = []
         for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].ports,
+            t = main.Thread( target=main.CLIs[ i ].ports,
                              name="ports-" + str( i ),
-                             args=[ ] )
+                             args=[] )
             threads.append( t )
             t.start()
 
@@ -1620,9 +1618,9 @@
         links = []
         threads = []
         for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].links,
+            t = main.Thread( target=main.CLIs[ i ].links,
                              name="links-" + str( i ),
-                             args=[ ] )
+                             args=[] )
             threads.append( t )
             t.start()
 
@@ -1632,9 +1630,9 @@
         clusters = []
         threads = []
         for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].clusters,
+            t = main.Thread( target=main.CLIs[ i ].clusters,
                              name="clusters-" + str( i ),
-                             args=[ ] )
+                             args=[] )
             threads.append( t )
             t.start()
 
@@ -1647,7 +1645,7 @@
         main.step( "Host view is consistent across ONOS nodes" )
         consistentHostsResult = main.TRUE
         for controller in range( len( hosts ) ):
-            controllerStr = str( main.activeNodes[controller] + 1 )
+            controllerStr = str( main.activeNodes[ controller ] + 1 )
             if hosts[ controller ] and "Error" not in hosts[ controller ]:
                 if hosts[ controller ] == hosts[ 0 ]:
                     continue
@@ -1674,10 +1672,10 @@
         main.step( "Each host has an IP address" )
         ipResult = main.TRUE
         for controller in range( 0, len( hosts ) ):
-            controllerStr = str( main.activeNodes[controller] + 1 )
+            controllerStr = str( main.activeNodes[ controller ] + 1 )
             if hosts[ controller ]:
                 for host in hosts[ controller ]:
-                    if not host.get( 'ipAddresses', [ ] ):
+                    if not host.get( 'ipAddresses', [] ):
                         main.log.error( "Error with host ips on controller" +
                                         controllerStr + ": " + str( host ) )
                         ipResult = main.FALSE
@@ -1691,7 +1689,7 @@
         main.step( "Cluster view is consistent across ONOS nodes" )
         consistentClustersResult = main.TRUE
         for controller in range( len( clusters ) ):
-            controllerStr = str( main.activeNodes[controller] + 1 )
+            controllerStr = str( main.activeNodes[ controller ] + 1 )
             if "Error" not in clusters[ controller ]:
                 if clusters[ controller ] == clusters[ 0 ]:
                     continue
@@ -1740,14 +1738,14 @@
         mnLinks = main.Mininet1.getLinks()
         mnHosts = main.Mininet1.getHosts()
         for controller in main.activeNodes:
-            controllerStr = str( main.activeNodes[controller] + 1 )
+            controllerStr = str( main.activeNodes[ controller ] + 1 )
             if devices[ controller ] and ports[ controller ] and\
-                "Error" not in devices[ controller ] and\
-                "Error" not in ports[ controller ]:
-                    currentDevicesResult = main.Mininet1.compareSwitches(
-                            mnSwitches,
-                            json.loads( devices[ controller ] ),
-                            json.loads( ports[ controller ] ) )
+                    "Error" not in devices[ controller ] and\
+                    "Error" not in ports[ controller ]:
+                currentDevicesResult = main.Mininet1.compareSwitches(
+                        mnSwitches,
+                        json.loads( devices[ controller ] ),
+                        json.loads( ports[ controller ] ) )
             else:
                 currentDevicesResult = main.FALSE
             utilities.assert_equals( expect=main.TRUE,
@@ -1834,7 +1832,7 @@
         killResults = main.TRUE
         for i in main.kill:
             killResults = killResults and\
-                          main.ONOSbench.onosKill( main.nodes[i].ip_address )
+                          main.ONOSbench.onosKill( main.nodes[ i ].ip_address )
             main.activeNodes.remove( i )
         utilities.assert_equals( expect=main.TRUE, actual=killResults,
                                  onpass="ONOS nodes killed successfully",
@@ -1843,7 +1841,7 @@
         main.step( "Checking ONOS nodes" )
         nodeResults = utilities.retry( main.HA.nodesCheck,
                                        False,
-                                       args=[main.activeNodes],
+                                       args=[ main.activeNodes ],
                                        sleep=15,
                                        attempts=5 )
 
@@ -1853,7 +1851,7 @@
 
         if not nodeResults:
             for i in main.activeNodes:
-                cli = main.CLIs[i]
+                cli = main.CLIs[ i ]
                 main.log.debug( "{} components not ACTIVE: \n{}".format(
                     cli.name,
                     cli.sendline( "scr:list | grep -v ACTIVE" ) ) )
@@ -1879,7 +1877,7 @@
         restartTime = time.time()
         for i in main.kill:
             startResults = startResults and\
-                           main.ONOSbench.onosStart( main.nodes[i].ip_address )
+                           main.ONOSbench.onosStart( main.nodes[ i ].ip_address )
         utilities.assert_equals( expect=main.TRUE, actual=startResults,
                                  onpass="ONOS nodes started successfully",
                                  onfail="ONOS nodes NOT successfully started" )
@@ -1891,7 +1889,7 @@
             onosIsupResult = main.TRUE
             for i in main.kill:
                 onosIsupResult = onosIsupResult and\
-                                 main.ONOSbench.isup( main.nodes[i].ip_address )
+                                 main.ONOSbench.isup( main.nodes[ i ].ip_address )
             count = count + 1
         utilities.assert_equals( expect=main.TRUE, actual=onosIsupResult,
                                  onpass="ONOS restarted successfully",
@@ -1901,7 +1899,7 @@
         cliResults = main.TRUE
         for i in main.kill:
             cliResults = cliResults and\
-                         main.CLIs[i].startOnosCli( main.nodes[i].ip_address )
+                         main.CLIs[ i ].startOnosCli( main.nodes[ i ].ip_address )
             main.activeNodes.append( i )
         utilities.assert_equals( expect=main.TRUE, actual=cliResults,
                                  onpass="ONOS cli restarted",
@@ -1923,7 +1921,7 @@
         main.step( "Checking ONOS nodes" )
         nodeResults = utilities.retry( main.HA.nodesCheck,
                                        False,
-                                       args=[main.activeNodes],
+                                       args=[ main.activeNodes ],
                                        sleep=15,
                                        attempts=5 )
 
@@ -1933,7 +1931,7 @@
 
         if not nodeResults:
             for i in main.activeNodes:
-                cli = main.CLIs[i]
+                cli = main.CLIs[ i ]
                 main.log.debug( "{} components not ACTIVE: \n{}".format(
                     cli.name,
                     cli.sendline( "scr:list | grep -v ACTIVE" ) ) )
@@ -1941,16 +1939,16 @@
             main.cleanup()
             main.exit()
 
-        node = main.activeNodes[0]
-        main.log.debug( main.CLIs[node].nodes( jsonFormat=False ) )
-        main.log.debug( main.CLIs[node].leaders( jsonFormat=False ) )
-        main.log.debug( main.CLIs[node].partitions( jsonFormat=False ) )
+        node = main.activeNodes[ 0 ]
+        main.log.debug( main.CLIs[ node ].nodes( jsonFormat=False ) )
+        main.log.debug( main.CLIs[ node ].leaders( jsonFormat=False ) )
+        main.log.debug( main.CLIs[ node ].partitions( jsonFormat=False ) )
 
         main.step( "Rerun for election on the node(s) that were killed" )
         runResults = main.TRUE
         for i in main.kill:
             runResults = runResults and\
-                         main.CLIs[i].electionTestRun()
+                         main.CLIs[ i ].electionTestRun()
         utilities.assert_equals( expect=main.TRUE, actual=runResults,
                                  onpass="ONOS nodes reran for election topic",
                                  onfail="Errror rerunning for election" )
@@ -1977,9 +1975,9 @@
         rolesNotNull = main.TRUE
         threads = []
         for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].rolesNotNull,
+            t = main.Thread( target=main.CLIs[ i ].rolesNotNull,
                              name="rolesNotNull-" + str( i ),
-                             args=[ ] )
+                             args=[] )
             threads.append( t )
             t.start()
 
@@ -1999,7 +1997,7 @@
         rolesResults = True
         threads = []
         for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].roles,
+            t = main.Thread( target=main.CLIs[ i ].roles,
                              name="roles-" + str( i ),
                              args=[] )
             threads.append( t )
@@ -2010,11 +2008,11 @@
             ONOSMastership.append( t.result )
 
         for i in range( len( ONOSMastership ) ):
-            node = str( main.activeNodes[i] + 1 )
-            if not ONOSMastership[i] or "Error" in ONOSMastership[i]:
+            node = str( main.activeNodes[ i ] + 1 )
+            if not ONOSMastership[ i ] or "Error" in ONOSMastership[ i ]:
                 main.log.error( "Error in getting ONOS" + node + " roles" )
                 main.log.warn( "ONOS" + node + " mastership response: " +
-                               repr( ONOSMastership[i] ) )
+                               repr( ONOSMastership[ i ] ) )
                 rolesResults = False
         utilities.assert_equals(
             expect=True,
@@ -2023,7 +2021,7 @@
             onfail="Error in reading roles from ONOS" )
 
         main.step( "Check for consistency in roles from each controller" )
-        if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ):
+        if all( [ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ):
             main.log.info(
                 "Switch roles are consistent across all ONOS nodes" )
         else:
@@ -2036,7 +2034,7 @@
 
         if rolesResults and not consistentMastership:
             for i in range( len( ONOSMastership ) ):
-                node = str( main.activeNodes[i] + 1 )
+                node = str( main.activeNodes[ i ] + 1 )
                 main.log.warn( "ONOS" + node + " roles: ",
                                json.dumps( json.loads( ONOSMastership[ i ] ),
                                            sort_keys=True,
@@ -2054,7 +2052,7 @@
         intentsResults = True
         threads = []
         for i in main.activeNodes:
-            t = main.Thread( target=main.CLIs[i].intents,
+            t = main.Thread( target=main.CLIs[ i ].intents,
                              name="intents-" + str( i ),
                              args=[],
                              kwargs={ 'jsonFormat': True } )
@@ -2065,8 +2063,8 @@
             t.join()
             ONOSIntents.append( t.result )
 
-        for i in range( len( ONOSIntents) ):
-            node = str( main.activeNodes[i] + 1 )
+        for i in range( len( ONOSIntents ) ):
+            node = str( main.activeNodes[ i ] + 1 )
             if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]:
                 main.log.error( "Error in getting ONOS" + node + " intents" )
                 main.log.warn( "ONOS" + node + " intents response: " +
@@ -2079,7 +2077,7 @@
             onfail="Error in reading intents from ONOS" )
 
         main.step( "Check for consistency in Intents from each controller" )
-        if all([ sorted( i ) == sorted( ONOSIntents[ 0 ] ) for i in ONOSIntents ] ):
+        if all( [ sorted( i ) == sorted( ONOSIntents[ 0 ] ) for i in ONOSIntents ] ):
             main.log.info( "Intents are consistent across all ONOS " +
                              "nodes" )
         else:
@@ -2128,12 +2126,12 @@
                 main.log.exception( "Error in parsing intents" )
                 main.log.error( repr( node ) )
             intentStates.append( nodeStates )
-            out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
+            out = [ ( i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
             main.log.info( dict( out ) )
 
         if intentsResults and not consistentIntents:
             for i in range( len( main.activeNodes ) ):
-                node = str( main.activeNodes[i] + 1 )
+                node = str( main.activeNodes[ i ] + 1 )
                 main.log.warn( "ONOS" + node + " intents: " )
                 main.log.warn( json.dumps(
                     json.loads( ONOSIntents[ i ] ),
@@ -2172,7 +2170,7 @@
                             main.log.debug( json.dumps( intent ) )
                 except ( ValueError, TypeError ):
                     main.log.exception( "Exception printing intents" )
-                    main.log.debug( repr( ONOSIntents[0] ) )
+                    main.log.debug( repr( ONOSIntents[ 0 ] ) )
                     main.log.debug( repr( intentState ) )
             if sameIntents == main.FALSE:
                 try:
@@ -2186,7 +2184,7 @@
                                                 separators=( ',', ': ' ) ) )
                 except ( ValueError, TypeError ):
                     main.log.exception( "Exception printing intents" )
-                    main.log.debug( repr( ONOSIntents[0] ) )
+                    main.log.debug( repr( ONOSIntents[ 0 ] ) )
                     main.log.debug( repr( intentState ) )
             utilities.assert_equals(
                 expect=main.TRUE,
@@ -2201,7 +2199,7 @@
         for i in range( 28 ):
             main.log.info( "Checking flow table on s" + str( i + 1 ) )
             tmpFlows = main.Mininet1.getFlowTable( "s" + str( i + 1 ), version="1.3", debug=False )
-            curSwitch = main.Mininet1.flowTableComp( flows[i], tmpFlows )
+            curSwitch = main.Mininet1.flowTableComp( flows[ i ], tmpFlows )
             FlowTables = FlowTables and curSwitch
             if curSwitch == main.FALSE:
                 main.log.warn( "Differences in flow table for switch: s{}".format( i + 1 ) )
@@ -2212,7 +2210,7 @@
             onfail="Changes were found in the flow tables" )
 
         main.Mininet2.pingLongKill()
-        '''
+        """
         main.step( "Check the continuous pings to ensure that no packets " +
                    "were dropped during component failure" )
         main.Mininet2.pingKill( main.params[ 'TESTONUSER' ],
@@ -2238,19 +2236,18 @@
             actual=LossInPings,
             onpass="No Loss of connectivity",
             onfail="Loss of dataplane connectivity detected" )
-        '''
-
+        """
         main.step( "Leadership Election is still functional" )
         # Test of LeadershipElection
         leaderList = []
 
         restarted = []
         for i in main.kill:
-            restarted.append( main.nodes[i].ip_address )
+            restarted.append( main.nodes[ i ].ip_address )
         leaderResult = main.TRUE
 
         for i in main.activeNodes:
-            cli = main.CLIs[i]
+            cli = main.CLIs[ i ]
             leaderN = cli.electionTestLeader()
             leaderList.append( leaderN )
             if leaderN == main.FALSE:
@@ -2314,8 +2311,8 @@
             for i in main.activeNodes:
                 t = main.Thread( target=utilities.retry,
                                  name="devices-" + str( i ),
-                                 args=[ main.CLIs[i].devices, [ None ] ],
-                                 kwargs= { 'sleep': 5, 'attempts': 5,
+                                 args=[ main.CLIs[ i ].devices, [ None ] ],
+                                 kwargs={ 'sleep': 5, 'attempts': 5,
                                            'randomTime': True } )
                 threads.append( t )
                 t.start()
@@ -2329,8 +2326,8 @@
             for i in main.activeNodes:
                 t = main.Thread( target=utilities.retry,
                                  name="hosts-" + str( i ),
-                                 args=[ main.CLIs[i].hosts, [ None ] ],
-                                 kwargs= { 'sleep': 5, 'attempts': 5,
+                                 args=[ main.CLIs[ i ].hosts, [ None ] ],
+                                 kwargs={ 'sleep': 5, 'attempts': 5,
                                            'randomTime': True } )
                 threads.append( t )
                 t.start()
@@ -2344,7 +2341,7 @@
                     main.log.error( repr( t.result ) )
                     hosts.append( None )
             for controller in range( 0, len( hosts ) ):
-                controllerStr = str( main.activeNodes[controller] + 1 )
+                controllerStr = str( main.activeNodes[ controller ] + 1 )
                 if hosts[ controller ]:
                     for host in hosts[ controller ]:
                         if host is None or host.get( 'ipAddresses', [] ) == []:
@@ -2357,8 +2354,8 @@
             for i in main.activeNodes:
                 t = main.Thread( target=utilities.retry,
                                  name="ports-" + str( i ),
-                                 args=[ main.CLIs[i].ports, [ None ] ],
-                                 kwargs= { 'sleep': 5, 'attempts': 5,
+                                 args=[ main.CLIs[ i ].ports, [ None ] ],
+                                 kwargs={ 'sleep': 5, 'attempts': 5,
                                            'randomTime': True } )
                 threads.append( t )
                 t.start()
@@ -2371,8 +2368,8 @@
             for i in main.activeNodes:
                 t = main.Thread( target=utilities.retry,
                                  name="links-" + str( i ),
-                                 args=[ main.CLIs[i].links, [ None ] ],
-                                 kwargs= { 'sleep': 5, 'attempts': 5,
+                                 args=[ main.CLIs[ i ].links, [ None ] ],
+                                 kwargs={ 'sleep': 5, 'attempts': 5,
                                            'randomTime': True } )
                 threads.append( t )
                 t.start()
@@ -2385,8 +2382,8 @@
             for i in main.activeNodes:
                 t = main.Thread( target=utilities.retry,
                                  name="clusters-" + str( i ),
-                                 args=[ main.CLIs[i].clusters, [ None ] ],
-                                 kwargs= { 'sleep': 5, 'attempts': 5,
+                                 args=[ main.CLIs[ i ].clusters, [ None ] ],
+                                 kwargs={ 'sleep': 5, 'attempts': 5,
                                            'randomTime': True } )
                 threads.append( t )
                 t.start()
@@ -2405,18 +2402,18 @@
                all( e is None for e in ports ) and\
                all( e is None for e in links ) and\
                all( e is None for e in clusters ):
-                   topoFailMsg = "Could not get topology from ONOS"
-                   main.log.error( topoFailMsg )
-                   continue  # Try again, No use trying to compare
+                topoFailMsg = "Could not get topology from ONOS"
+                main.log.error( topoFailMsg )
+                continue  # Try again, No use trying to compare
 
             mnSwitches = main.Mininet1.getSwitches()
             mnLinks = main.Mininet1.getLinks()
             mnHosts = main.Mininet1.getHosts()
             for controller in range( len( main.activeNodes ) ):
-                controllerStr = str( main.activeNodes[controller] + 1 )
+                controllerStr = str( main.activeNodes[ controller ] + 1 )
                 if devices[ controller ] and ports[ controller ] and\
-                    "Error" not in devices[ controller ] and\
-                    "Error" not in ports[ controller ]:
+                        "Error" not in devices[ controller ] and\
+                        "Error" not in ports[ controller ]:
 
                     try:
                         currentDevicesResult = main.Mininet1.compareSwitches(
@@ -2469,29 +2466,29 @@
                 mappings = {}
                 for i in range( 1, 29 ):  # hosts 1 through 28
                     # set up correct variables:
-                    macId = "00:" * 5 + hex( i ).split( "0x" )[1].upper().zfill(2)
+                    macId = "00:" * 5 + hex( i ).split( "0x" )[ 1 ].upper().zfill( 2 )
                     if i == 1:
-                        deviceId = "1000".zfill(16)
+                        deviceId = "1000".zfill( 16 )
                     elif i == 2:
-                        deviceId = "2000".zfill(16)
+                        deviceId = "2000".zfill( 16 )
                     elif i == 3:
-                        deviceId = "3000".zfill(16)
+                        deviceId = "3000".zfill( 16 )
                     elif i == 4:
-                        deviceId = "3004".zfill(16)
+                        deviceId = "3004".zfill( 16 )
                     elif i == 5:
-                        deviceId = "5000".zfill(16)
+                        deviceId = "5000".zfill( 16 )
                     elif i == 6:
-                        deviceId = "6000".zfill(16)
+                        deviceId = "6000".zfill( 16 )
                     elif i == 7:
-                        deviceId = "6007".zfill(16)
+                        deviceId = "6007".zfill( 16 )
                     elif i >= 8 and i <= 17:
                         dpid = '3' + str( i ).zfill( 3 )
-                        deviceId = dpid.zfill(16)
+                        deviceId = dpid.zfill( 16 )
                     elif i >= 18 and i <= 27:
                         dpid = '6' + str( i ).zfill( 3 )
-                        deviceId = dpid.zfill(16)
+                        deviceId = dpid.zfill( 16 )
                     elif i == 28:
-                        deviceId = "2800".zfill(16)
+                        deviceId = "2800".zfill( 16 )
                     mappings[ macId ] = deviceId
                 if hosts[ controller ] is not None and "Error" not in hosts[ controller ]:
                     if hosts[ controller ] == []:
@@ -2511,7 +2508,7 @@
                                 assert location, "location field could not be found for this host object"
 
                                 # Trim the protocol identifier off deviceId
-                                device = str( location.get( 'elementId' ) ).split(':')[1]
+                                device = str( location.get( 'elementId' ) ).split( ':' )[ 1 ]
                                 assert device, "elementId field could not be found for this host location object"
 
                                 port = location.get( 'port' )
@@ -2522,7 +2519,7 @@
                                     if str( port ) != "1":
                                         main.log.error( "The attachment port is incorrect for " +
                                                         "host " + str( mac ) +
-                                                        ". Expected: 1 Actual: " + str( port) )
+                                                        ". Expected: 1 Actual: " + str( port ) )
                                         hostAttachment = False
                                     if device != mappings[ str( mac ) ]:
                                         main.log.error( "The attachment device is incorrect for " +
@@ -2564,7 +2561,7 @@
         main.step( "Hosts view is consistent across all ONOS nodes" )
         consistentHostsResult = main.TRUE
         for controller in range( len( hosts ) ):
-            controllerStr = str( main.activeNodes[controller] + 1 )
+            controllerStr = str( main.activeNodes[ controller ] + 1 )
             if hosts[ controller ] is not None and "Error" not in hosts[ controller ]:
                 if hosts[ controller ] == hosts[ 0 ]:
                     continue
@@ -2606,7 +2603,7 @@
         main.step( "Clusters view is consistent across all ONOS nodes" )
         consistentClustersResult = main.TRUE
         for controller in range( len( clusters ) ):
-            controllerStr = str( main.activeNodes[controller] + 1 )
+            controllerStr = str( main.activeNodes[ controller ] + 1 )
             if "Error" not in clusters[ controller ]:
                 if clusters[ controller ] == clusters[ 0 ]:
                     continue
@@ -2636,7 +2633,7 @@
             numClusters = len( json.loads( clusters[ 0 ] ) )
         except ( ValueError, TypeError ):
             main.log.exception( "Error parsing clusters[0]: " +
-                                repr( clusters[0] ) )
+                                repr( clusters[ 0 ] ) )
             numClusters = "ERROR"
         clusterResults = main.FALSE
         if numClusters == 1:
@@ -2686,7 +2683,7 @@
         main.step( "Checking ONOS nodes" )
         nodeResults = utilities.retry( main.HA.nodesCheck,
                                        False,
-                                       args=[main.activeNodes],
+                                       args=[ main.activeNodes ],
                                        attempts=5 )
 
         utilities.assert_equals( expect=True, actual=nodeResults,
@@ -2695,8 +2692,8 @@
         if not nodeResults:
             for i in main.activeNodes:
                 main.log.debug( "{} components not ACTIVE: \n{}".format(
-                    main.CLIs[i].name,
-                    main.CLIs[i].sendline( "scr:list | grep -v ACTIVE" ) ) )
+                    main.CLIs[ i ].name,
+                    main.CLIs[ i ].sendline( "scr:list | grep -v ACTIVE" ) ) )
 
         if not topoResult:
             main.cleanup()
@@ -2773,7 +2770,7 @@
         switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
 
         description = "Killing a switch to ensure it is discovered correctly"
-        onosCli = main.CLIs[ main.activeNodes[0] ]
+        onosCli = main.CLIs[ main.activeNodes[ 0 ] ]
         main.case( description )
         switch = main.params[ 'kill' ][ 'switch' ]
         switchDPID = main.params[ 'kill' ][ 'dpid' ]
@@ -2818,7 +2815,7 @@
         switch = main.params[ 'kill' ][ 'switch' ]
         switchDPID = main.params[ 'kill' ][ 'dpid' ]
         links = main.params[ 'kill' ][ 'links' ].split()
-        onosCli = main.CLIs[ main.activeNodes[0] ]
+        onosCli = main.CLIs[ main.activeNodes[ 0 ] ]
         description = "Adding a switch to ensure it is discovered correctly"
         main.case( description )
 
@@ -2905,14 +2902,14 @@
             main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
 
         try:
-            timerLog = open( main.logdir + "/Timers.csv", 'w')
+            timerLog = open( main.logdir + "/Timers.csv", 'w' )
             # Overwrite with empty line and close
             labels = "Gossip Intents, Restart"
             data = str( gossipTime ) + ", " + str( main.restartTime )
             timerLog.write( labels + "\n" + data )
             timerLog.close()
-        except NameError, e:
-            main.log.exception(e)
+        except NameError as e:
+            main.log.exception( e )
 
     def CASE14( self, main ):
         """
@@ -2924,9 +2921,9 @@
         assert main.CLIs, "main.CLIs not defined"
         assert main.nodes, "main.nodes not defined"
 
-        main.case("Start Leadership Election app")
+        main.case( "Start Leadership Election app" )
         main.step( "Install leadership election app" )
-        onosCli = main.CLIs[ main.activeNodes[0] ]
+        onosCli = main.CLIs[ main.activeNodes[ 0 ] ]
         appResult = onosCli.activateApp( "org.onosproject.election" )
         utilities.assert_equals(
             expect=main.TRUE,
@@ -2936,9 +2933,9 @@
 
         main.step( "Run for election on each node" )
         for i in main.activeNodes:
-            main.CLIs[i].electionTestRun()
-        time.sleep(5)
-        activeCLIs = [ main.CLIs[i] for i in main.activeNodes ]
+            main.CLIs[ i ].electionTestRun()
+        time.sleep( 5 )
+        activeCLIs = [ main.CLIs[ i ] for i in main.activeNodes ]
         sameResult, leaders = main.HA.consistentLeaderboards( activeCLIs )
         utilities.assert_equals(
             expect=True,
@@ -2948,7 +2945,7 @@
 
         if sameResult:
             leader = leaders[ 0 ][ 0 ]
-            if main.nodes[main.activeNodes[0]].ip_address in leader:
+            if main.nodes[ main.activeNodes[ 0 ] ].ip_address in leader:
                 correctLeader = True
             else:
                 correctLeader = False
@@ -2998,7 +2995,7 @@
         electionResult = main.TRUE
 
         for i in main.activeNodes:  # run test election on each node
-            if main.CLIs[i].electionTestRun() == main.FALSE:
+            if main.CLIs[ i ].electionTestRun() == main.FALSE:
                 electionResult = main.FALSE
         utilities.assert_equals(
             expect=main.TRUE,
@@ -3013,7 +3010,7 @@
 
         main.step( "Check that each node shows the same leader and candidates" )
         failMessage = "Nodes have different leaderboards"
-        activeCLIs = [ main.CLIs[i] for i in main.activeNodes ]
+        activeCLIs = [ main.CLIs[ i ] for i in main.activeNodes ]
         sameResult, oldLeaders = main.HA.consistentLeaderboards( activeCLIs )
         if sameResult:
             oldLeader = oldLeaders[ 0 ][ 0 ]
@@ -3063,7 +3060,7 @@
         if newLeader == oldLeader:
             newLeaderResult = False
             main.log.error( "All nodes still see old leader: " + str( oldLeader ) +
-                " as the current leader" )
+                            " as the current leader" )
         utilities.assert_equals(
             expect=True,
             actual=newLeaderResult,
@@ -3080,7 +3077,7 @@
             else:
                 main.log.info( "Expected no leader, got: " + str( newLeader ) )
                 correctCandidateResult = main.FALSE
-        elif len( oldLeaders[0] ) >= 3:
+        elif len( oldLeaders[ 0 ] ) >= 3:
             if newLeader == oldLeaders[ 0 ][ 2 ]:
                 # correct leader was elected
                 correctCandidateResult = main.TRUE
@@ -3120,10 +3117,10 @@
         positionResult, reRunLeaders = main.HA.consistentLeaderboards( activeCLIs )
 
         # Check that the re-elected node is last on the candidate List
-        if not reRunLeaders[0]:
+        if not reRunLeaders[ 0 ]:
             positionResult = main.FALSE
         elif oldLeader != reRunLeaders[ 0 ][ -1 ]:
-            main.log.error( "Old Leader ({}) not in the proper position: {} ".format( str( oldLeader),
+            main.log.error( "Old Leader ({}) not in the proper position: {} ".format( str( oldLeader ),
                                                                                       str( reRunLeaders[ 0 ] ) ) )
             positionResult = main.FALSE
         utilities.assert_equals(
@@ -3147,15 +3144,15 @@
         # Variables for the distributed primitives tests
         main.pCounterName = "TestON-Partitions"
         main.pCounterValue = 0
-        main.onosSet = set([])
+        main.onosSet = set( [] )
         main.onosSetName = "TestON-set"
 
         description = "Install Primitives app"
         main.case( description )
         main.step( "Install Primitives app" )
         appName = "org.onosproject.distributedprimitives"
-        node = main.activeNodes[0]
-        appResults = main.CLIs[node].activateApp( appName )
+        node = main.activeNodes[ 0 ]
+        appResults = main.CLIs[ node ].activateApp( appName )
         utilities.assert_equals( expect=main.TRUE,
                                  actual=appResults,
                                  onpass="Primitives app activated",