Fix some logic errors

Change-Id: I59524575daf2664ceb7ccbbdd48d51c20376b33c
diff --git a/TestON/tests/HAstopNodes/HAstopNodes.py b/TestON/tests/HAstopNodes/HAstopNodes.py
index a3e4d69..28bfedd 100644
--- a/TestON/tests/HAstopNodes/HAstopNodes.py
+++ b/TestON/tests/HAstopNodes/HAstopNodes.py
@@ -2854,36 +2854,29 @@
             onfail="Something went wrong with installing Leadership election" )
 
         main.step( "Run for election on each node" )
-        leaderResult = main.TRUE
-        leaders = []
         for i in main.activeNodes:
             main.CLIs[i].electionTestRun()
-        for i in main.activeNodes:
-            cli = main.CLIs[i]
-            leader = cli.electionTestLeader()
-            if leader is None or leader == main.FALSE:
-                main.log.error( cli.name + ": Leader for the election app " +
-                                 "should be an ONOS node, instead got '" +
-                                 str( leader ) + "'" )
-                leaderResult = main.FALSE
-            leaders.append( leader )
+        time.sleep(5)
+        activeCLIs = [ main.CLIs[i] for i in main.activeNodes ]
+        sameResult, leaders = main.HA.consistentLeaderboards( activeCLIs )
         utilities.assert_equals(
-            expect=main.TRUE,
-            actual=leaderResult,
-            onpass="Successfully ran for leadership",
-            onfail="Failed to run for leadership" )
+            expect=True,
+            actual=sameResult,
+            onpass="All nodes see the same leaderboards",
+            onfail="Inconsistent leaderboards" )
 
-        main.step( "Check that each node shows the same leader" )
-        sameLeader = main.TRUE
-        if len( set( leaders ) ) != 1:
-            sameLeader = main.FALSE
-            main.log.error( "Results of electionTestLeader is order of main.CLIs:" +
-                            str( leaders ) )
-        utilities.assert_equals(
-            expect=main.TRUE,
-            actual=sameLeader,
-            onpass="Leadership is consistent for the election topic",
-            onfail="Nodes have different leaders" )
+        if sameResult:
+            leader = leaders[ 0 ][ 0 ]
+            if main.nodes[main.activeNodes[0]].ip_address in leader:
+                correctLeader = True
+            else:
+                correctLeader = False
+            main.step( "First node was elected leader" )
+            utilities.assert_equals(
+                expect=True,
+                actual=correctLeader,
+                onpass="Correct leader was elected",
+                onfail="Incorrect leader" )
 
     def CASE15( self, main ):
         """
@@ -2983,8 +2976,7 @@
                 main.log.error( "No leader was elected on at least 1 node" )
                 if not expectNoLeader:
                     newLeaderResult = False
-            else:
-                newLeader = newLeaders[ 0 ][ 0 ]
+            newLeader = newLeaders[ 0 ][ 0 ]
 
         # Check that the new leader is not the older leader, which was withdrawn
         if newLeader == oldLeader: