Adding more simultaneous failure cases to SRRouting

- Cases 601, 640, 641
- Some style fixes
- Refactoring out some common functionality from SR library functions
- Adding more support for configuring cluster size in SR tests
- Make sleeps in SR library functions configurable
- Increase some small timeout values that cause intermitent problems due
  to increased latencies

Change-Id: Ic66c637467d7d47e92224c9017df86162f320318
diff --git a/TestON/tests/USECASE/SegmentRouting/SRRouting/dependencies/SRRoutingTest.py b/TestON/tests/USECASE/SegmentRouting/SRRouting/dependencies/SRRoutingTest.py
index f4b5481..90e8129 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRRouting/dependencies/SRRoutingTest.py
+++ b/TestON/tests/USECASE/SegmentRouting/SRRouting/dependencies/SRRoutingTest.py
@@ -19,7 +19,8 @@
     along with TestON.  If not, see <http://www.gnu.org/licenses/>.
 """
 
-def setupTest( main, test_idx, onosNodes, ipv4=True, ipv6=True, external=True, static=False, countFlowsGroups=False ):
+def setupTest( main, test_idx, onosNodes=-1, ipv4=True, ipv6=True,
+               external=True, static=False, countFlowsGroups=False ):
     """
     SRRouting test setup
     """
@@ -31,6 +32,8 @@
     if not hasattr( main, 'apps' ):
         init = True
         lib.initTest( main )
+    if onosNodes < 0:
+        onosNodes = main.Cluster.numCtrls
     # Skip onos packaging if the cluster size stays the same
     if not init and onosNodes == main.Cluster.numCtrls:
         skipPackage = True
@@ -162,7 +165,8 @@
     if external:
         verifyPingExternal( main, ipv4, ipv6, disconnected )
 
-def verifyLinkFailure( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True, countFlowsGroups=False ):
+def verifyLinkFailure( main, ipv4=True, ipv6=True, disconnected=False,
+                       internal=True, external=True, countFlowsGroups=False ):
     """
     Kill and recover all links to spine101 and 102 sequencially and run verifications
     """
@@ -186,7 +190,8 @@
     lib.restoreLinkBatch( main, linksToRemove, 48, 10 )
     verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
 
-def verifySwitchFailure( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True, countFlowsGroups=False ):
+def verifySwitchFailure( main, ipv4=True, ipv6=True, disconnected=False,
+                         internal=True, external=True, countFlowsGroups=False ):
     """
     Kill and recover spine101 and 102 sequencially and run verifications
     """
@@ -197,7 +202,8 @@
         lib.recoverSwitch( main, switchToKill, 10, 48 )
         verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
 
-def verifyOnosFailure( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True, countFlowsGroups=False ):
+def verifyOnosFailure( main, ipv4=True, ipv6=True, disconnected=False,
+                       internal=True, external=True, countFlowsGroups=False ):
     """
     Kill and recover onos nodes sequencially and run verifications
     """
@@ -208,16 +214,17 @@
     numCtrls = len( main.Cluster.runningNodes )
     links = len( json.loads( main.Cluster.next().links() ) )
     switches = len( json.loads( main.Cluster.next().devices() ) )
+    mastershipSleep = float( main.params[ 'timers' ][ 'balanceMasterSleep' ] )
     for ctrl in xrange( numCtrls ):
         # Kill node
         lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
         main.Cluster.active(0).CLI.balanceMasters()
-        time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
+        time.sleep( mastershipSleep )
         verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
         # Recover node
         lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
         main.Cluster.active(0).CLI.balanceMasters()
-        time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
+        time.sleep( mastershipSleep )
         verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
 
 def verify( main, ipv4=True, ipv6=True, disconnected=True, internal=True, external=True, countFlowsGroups=False ):
@@ -230,6 +237,6 @@
     lib.verifyNetworkHostIp( main )
     # check flows / groups numbers
     if countFlowsGroups:
-        run.checkFlowsGroupsFromFile( main )
+        lib.checkFlowsGroupsFromFile( main )
     # ping hosts
     verifyPing( main, ipv4, ipv6, disconnected, internal, external )