Protect against IndexErrors
Change-Id: I0fb5b8c081c9959bbfed8432a8f1fb3ebd5d34f1
diff --git a/TestON/tests/HAclusterRestart/HAclusterRestart.py b/TestON/tests/HAclusterRestart/HAclusterRestart.py
index 2e840a1..0ff0da3 100644
--- a/TestON/tests/HAclusterRestart/HAclusterRestart.py
+++ b/TestON/tests/HAclusterRestart/HAclusterRestart.py
@@ -2977,14 +2977,14 @@
failMessage = "Nodes have different leaders"
# Get new leaders and candidates
newLeaderResult, newLeaders = main.HA.consistentLeaderboards( activeCLIs )
- if newLeaders[ 0 ][ 0 ] == 'none':
- main.log.error( "No leader was elected on at least 1 node" )
- if not expectNoLeader:
- newLeaderResult = False
+ newLeader = None
if newLeaderResult:
- newLeader = newLeaders[ 0 ][ 0 ]
- else:
- newLeader = None
+ if newLeaders[ 0 ][ 0 ] == 'none':
+ main.log.error( "No leader was elected on at least 1 node" )
+ if not expectNoLeader:
+ newLeaderResult = False
+ else:
+ newLeader = newLeaders[ 0 ][ 0 ]
# Check that the new leader is not the older leader, which was withdrawn
if newLeader == oldLeader:
@@ -3047,11 +3047,12 @@
positionResult, reRunLeaders = main.HA.consistentLeaderboards( activeCLIs )
# Check that the re-elected node is last on the candidate List
- if oldLeader != reRunLeaders[ 0 ][ -1 ]:
+ 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),
str( reRunLeaders[ 0 ] ) ) )
positionResult = main.FALSE
-
utilities.assert_equals(
expect=True,
actual=positionResult,
diff --git a/TestON/tests/HAfullNetPartition/HAfullNetPartition.py b/TestON/tests/HAfullNetPartition/HAfullNetPartition.py
index 6ae0c7b..cebf43e 100644
--- a/TestON/tests/HAfullNetPartition/HAfullNetPartition.py
+++ b/TestON/tests/HAfullNetPartition/HAfullNetPartition.py
@@ -2965,14 +2965,14 @@
failMessage = "Nodes have different leaders"
# Get new leaders and candidates
newLeaderResult, newLeaders = main.HA.consistentLeaderboards( activeCLIs )
- if newLeaders[ 0 ][ 0 ] == 'none':
- main.log.error( "No leader was elected on at least 1 node" )
- if not expectNoLeader:
- newLeaderResult = False
+ newLeader = None
if newLeaderResult:
- newLeader = newLeaders[ 0 ][ 0 ]
- else:
- newLeader = None
+ if newLeaders[ 0 ][ 0 ] == 'none':
+ main.log.error( "No leader was elected on at least 1 node" )
+ if not expectNoLeader:
+ newLeaderResult = False
+ else:
+ newLeader = newLeaders[ 0 ][ 0 ]
# Check that the new leader is not the older leader, which was withdrawn
if newLeader == oldLeader:
@@ -3035,11 +3035,12 @@
positionResult, reRunLeaders = main.HA.consistentLeaderboards( activeCLIs )
# Check that the re-elected node is last on the candidate List
- if oldLeader != reRunLeaders[ 0 ][ -1 ]:
+ 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),
str( reRunLeaders[ 0 ] ) ) )
positionResult = main.FALSE
-
utilities.assert_equals(
expect=True,
actual=positionResult,
diff --git a/TestON/tests/HAkillNodes/HAkillNodes.py b/TestON/tests/HAkillNodes/HAkillNodes.py
index 4d75d8d..c542028 100644
--- a/TestON/tests/HAkillNodes/HAkillNodes.py
+++ b/TestON/tests/HAkillNodes/HAkillNodes.py
@@ -3000,14 +3000,14 @@
failMessage = "Nodes have different leaders"
# Get new leaders and candidates
newLeaderResult, newLeaders = main.HA.consistentLeaderboards( activeCLIs )
- if newLeaders[ 0 ][ 0 ] == 'none':
- main.log.error( "No leader was elected on at least 1 node" )
- if not expectNoLeader:
- newLeaderResult = False
+ newLeader = None
if newLeaderResult:
- newLeader = newLeaders[ 0 ][ 0 ]
- else:
- newLeader = None
+ if newLeaders[ 0 ][ 0 ] == 'none':
+ main.log.error( "No leader was elected on at least 1 node" )
+ if not expectNoLeader:
+ newLeaderResult = False
+ else:
+ newLeader = newLeaders[ 0 ][ 0 ]
# Check that the new leader is not the older leader, which was withdrawn
if newLeader == oldLeader:
@@ -3070,11 +3070,12 @@
positionResult, reRunLeaders = main.HA.consistentLeaderboards( activeCLIs )
# Check that the re-elected node is last on the candidate List
- if oldLeader != reRunLeaders[ 0 ][ -1 ]:
+ 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),
str( reRunLeaders[ 0 ] ) ) )
positionResult = main.FALSE
-
utilities.assert_equals(
expect=True,
actual=positionResult,
diff --git a/TestON/tests/HAsanity/HAsanity.py b/TestON/tests/HAsanity/HAsanity.py
index 499b23a..53aa906 100644
--- a/TestON/tests/HAsanity/HAsanity.py
+++ b/TestON/tests/HAsanity/HAsanity.py
@@ -2901,14 +2901,14 @@
failMessage = "Nodes have different leaders"
# Get new leaders and candidates
newLeaderResult, newLeaders = main.HA.consistentLeaderboards( activeCLIs )
- if newLeaders[ 0 ][ 0 ] == 'none':
- main.log.error( "No leader was elected on at least 1 node" )
- if not expectNoLeader:
- newLeaderResult = False
+ newLeader = None
if newLeaderResult:
- newLeader = newLeaders[ 0 ][ 0 ]
- else:
- newLeader = None
+ if newLeaders[ 0 ][ 0 ] == 'none':
+ main.log.error( "No leader was elected on at least 1 node" )
+ if not expectNoLeader:
+ newLeaderResult = False
+ else:
+ newLeader = newLeaders[ 0 ][ 0 ]
# Check that the new leader is not the older leader, which was withdrawn
if newLeader == oldLeader:
@@ -2971,11 +2971,12 @@
positionResult, reRunLeaders = main.HA.consistentLeaderboards( activeCLIs )
# Check that the re-elected node is last on the candidate List
- if oldLeader != reRunLeaders[ 0 ][ -1 ]:
+ 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),
str( reRunLeaders[ 0 ] ) ) )
positionResult = main.FALSE
-
utilities.assert_equals(
expect=True,
actual=positionResult,
diff --git a/TestON/tests/HAsingleInstanceRestart/HAsingleInstanceRestart.py b/TestON/tests/HAsingleInstanceRestart/HAsingleInstanceRestart.py
index de14bf9..ee24c97 100644
--- a/TestON/tests/HAsingleInstanceRestart/HAsingleInstanceRestart.py
+++ b/TestON/tests/HAsingleInstanceRestart/HAsingleInstanceRestart.py
@@ -2179,14 +2179,14 @@
failMessage = "Nodes have different leaders"
# Get new leaders and candidates
newLeaderResult, newLeaders = main.HA.consistentLeaderboards( activeCLIs )
- if newLeaders[ 0 ][ 0 ] == 'none':
- main.log.error( "No leader was elected on at least 1 node" )
- if not expectNoLeader:
- newLeaderResult = False
+ newLeader = None
if newLeaderResult:
- newLeader = newLeaders[ 0 ][ 0 ]
- else:
- newLeader = None
+ if newLeaders[ 0 ][ 0 ] == 'none':
+ main.log.error( "No leader was elected on at least 1 node" )
+ if not expectNoLeader:
+ newLeaderResult = False
+ else:
+ newLeader = newLeaders[ 0 ][ 0 ]
# Check that the new leader is not the older leader, which was withdrawn
if newLeader == oldLeader:
@@ -2249,11 +2249,12 @@
positionResult, reRunLeaders = main.HA.consistentLeaderboards( activeCLIs )
# Check that the re-elected node is last on the candidate List
- if oldLeader != reRunLeaders[ 0 ][ -1 ]:
+ 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),
str( reRunLeaders[ 0 ] ) ) )
positionResult = main.FALSE
-
utilities.assert_equals(
expect=True,
actual=positionResult,
diff --git a/TestON/tests/HAstopNodes/HAstopNodes.py b/TestON/tests/HAstopNodes/HAstopNodes.py
index 6a594b2..a3e4d69 100644
--- a/TestON/tests/HAstopNodes/HAstopNodes.py
+++ b/TestON/tests/HAstopNodes/HAstopNodes.py
@@ -2977,14 +2977,14 @@
failMessage = "Nodes have different leaders"
# Get new leaders and candidates
newLeaderResult, newLeaders = main.HA.consistentLeaderboards( activeCLIs )
- if newLeaders[ 0 ][ 0 ] == 'none':
- main.log.error( "No leader was elected on at least 1 node" )
- if not expectNoLeader:
- newLeaderResult = False
+ newLeader = None
if newLeaderResult:
- newLeader = newLeaders[ 0 ][ 0 ]
- else:
- newLeader = None
+ if newLeaders[ 0 ][ 0 ] == 'none':
+ main.log.error( "No leader was elected on at least 1 node" )
+ if not expectNoLeader:
+ newLeaderResult = False
+ else:
+ newLeader = newLeaders[ 0 ][ 0 ]
# Check that the new leader is not the older leader, which was withdrawn
if newLeader == oldLeader:
@@ -3047,11 +3047,12 @@
positionResult, reRunLeaders = main.HA.consistentLeaderboards( activeCLIs )
# Check that the re-elected node is last on the candidate List
- if oldLeader != reRunLeaders[ 0 ][ -1 ]:
+ 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),
str( reRunLeaders[ 0 ] ) ) )
positionResult = main.FALSE
-
utilities.assert_equals(
expect=True,
actual=positionResult,