Update tests for aether pods

- Update test for QA-POD
- SRStaging for testing connecting to Staging pod
- Add some functions for a kubernetes deployed cluster
- Connect to ONOS nodes with kubernetes
- Add option to connect to components through jump hosts
- Fixes for installing ONOS in custom locations
- Invoke python2 instead of python
- If using an ssh agent, also use that for pexpect ssh sessions,
  E.G. Jenkins initiated tests

Change-Id: I1fc345c8eab60a5b00c17e6ed677a63489a74a19
diff --git a/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py b/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
index 699370c..5ed1784 100644
--- a/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
+++ b/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
@@ -365,7 +365,7 @@
         network.discoverHosts()
 
     @staticmethod
-    def connectToPhysicalNetwork( main ):
+    def connectToPhysicalNetwork( main, hostDiscovery=True ):
         main.step( "Connecting to physical netowrk" )
         main.physicalNet = True
         topoResult = main.NetworkBench.connectToNet()
@@ -414,7 +414,8 @@
                                  actual=stepResult,
                                  onpass="Successfully connected inband hosts",
                                  onfail="Failed to connect inband hosts" )
-        Testcaselib.discoverHosts( main )
+        if hostDiscovery:
+            Testcaselib.discoverHosts( main )
 
     @staticmethod
     def saveOnosDiagnostics( main ):
@@ -540,11 +541,13 @@
             main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
                                         "flows",
                                         main.logdir,
-                                        tag + "_FlowsBefore" )
+                                        tag + "_FlowsBefore",
+                                        cliPort=main.Cluster.active(0).CLI.karafPort )
             main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
                                         "groups",
                                         main.logdir,
-                                        tag + "_GroupsBefore" )
+                                        tag + "_GroupsBefore",
+                                        cliPort=main.Cluster.active(0).CLI.karafPort )
 
     @staticmethod
     def checkDevices( main, switches, tag="", sleep=10 ):
@@ -630,7 +633,7 @@
 
     @staticmethod
     def pingAll( main, tag="", dumpflows=True, acceptableFailed=0, basedOnIp=False,
-                 sleep=10, retryAttempts=1, skipOnFail=False ):
+                 sleep=10, retryAttempts=1, skipOnFail=False, useScapy=True ):
         '''
         Verify connectivity between hosts according to the ping chart
         acceptableFailed: max number of acceptable failed pings.
@@ -697,7 +700,7 @@
                                                  onpass="IPv6 connectivity successfully tested",
                                                  onfail="IPv6 connectivity failed" )
                 elif main.physicalNet:
-                    pa = main.Network.pingallHosts( hosts, ipv6=True, useScapy=True )
+                    pa = main.Network.pingallHosts( hosts, ipv6=True, useScapy=useScapy )
                     utilities.assert_equals( expect=expect, actual=pa,
                                              onpass="IP connectivity successfully tested",
                                              onfail="IP connectivity failed" )
@@ -716,11 +719,13 @@
             main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
                                         "flows",
                                         main.logdir,
-                                        tag + "_FlowsOn" )
+                                        tag + "_FlowsOn",
+                                        cliPort=main.Cluster.active(0).CLI.karafPort )
             main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
                                         "groups",
                                         main.logdir,
-                                        tag + "_GroupsOn" )
+                                        tag + "_GroupsOn",
+                                        cliPort=main.Cluster.active(0).CLI.karafPort )
 
     @staticmethod
     def killLink( main, end1, end2, switches, links, sleep=None ):
@@ -1053,6 +1058,8 @@
         if not main.persistentSetup:
             for ctrl in main.Cluster.active():
                 main.ONOSbench.onosStop( ctrl.ipAddress )
+        else:
+            Testcaselib.resetOnosLogLevels( main )
         Testcaselib.mnDockerTeardown( main )
 
     @staticmethod
@@ -1758,6 +1765,10 @@
         Read and Set onos log levels from the params file
         """
         main.step( 'Set logging levels' )
+        # Get original values incase we want to reset them
+        ctrl = main.Cluster.active(0)
+        ctrl.CLI.logList()
+
         logging = True
         try:
             logs = main.params.get( 'ONOS_Logging', False )
@@ -1770,3 +1781,32 @@
         utilities.assert_equals( expect=True, actual=logging,
                                  onpass="Set log levels",
                                  onfail="Failed to set log levels" )
+
+    @staticmethod
+    def resetOnosLogLevels( main ):
+        """
+        Read and reset onos log levels to a previously read set of values
+        """
+        main.step( 'Reset logging levels' )
+        # Get original values incase we want to reset them
+        ctrl = main.Cluster.active(0)
+        currentLevels = ctrl.CLI.logList( saveValues=False )
+        origLevels = ctrl.CLI.logLevels
+        toBeSet = {}
+        for logger, level in currentLevels.iteritems():
+            if logger not in origLevels:
+                toBeSet[ logger ] = origLevels[ 'ROOT' ]
+            else:
+                oldLevel = origLevels[ logger ]
+                if level != oldLevel:
+                    toBeSet[ logger ] = oldLevel
+        logging = True
+        try:
+            for logger, level in toBeSet.iteritems():
+                for ctrl in main.Cluster.active():
+                    ctrl.CLI.logSet( level, logger )
+        except AttributeError:
+            logging = False
+        utilities.assert_equals( expect=True, actual=logging,
+                                 onpass="Reset log levels",
+                                 onfail="Failed to reset log levels" )
diff --git a/TestON/tests/USECASE/SegmentRouting/dependencies/cfgtranslator.py b/TestON/tests/USECASE/SegmentRouting/dependencies/cfgtranslator.py
index b978b73..6b538a9 100644
--- a/TestON/tests/USECASE/SegmentRouting/dependencies/cfgtranslator.py
+++ b/TestON/tests/USECASE/SegmentRouting/dependencies/cfgtranslator.py
@@ -100,6 +100,10 @@
 # Translate configuration JSON file from OFDPA-OVS driver to BMv2 driver.
 def ofdpaToBmv2( main, switchPrefix="bmv2", cfgFile="", roleMap={r'0*[1-9]([0-9]){2}': 'spine', r'0{15}[1-9]': "leaf"} ):
     didRE = r"of:0*(?P<swNum>[1-9][0-9]*)(/(?P<portNum>[0-9]+))?"
+    if switchPrefix is None:
+        switchPrefix = ''
+    else:
+        switchPrefix += ':'
     if not cfgFile:
         cfgFile = "%s%s.json" % ( main.configPath + main.forJson,
                                   main.cfgName )
@@ -117,7 +121,7 @@
                     if roleMatch:
                         role = roleValue
                         break
-                new_port = 'device:' + switchPrefix + ':' + role + searchObj.group( 'swNum' ) + '/' + searchObj.group( 'portNum' )
+                new_port = 'device:' + switchPrefix + role + searchObj.group( 'swNum' ) + '/' + searchObj.group( 'portNum' )
                 netcfg[ 'ports' ][ new_port ] = netcfg[ 'ports' ].pop( port )
 
     if 'hosts' in netcfg.keys():
@@ -134,7 +138,7 @@
                             if roleMatch:
                                 role = roleValue
                                 break
-                        new_locations.append( 'device:' + switchPrefix + ':' + role + searchObj.group( 'swNum' ) + '/' + searchObj.group( 'portNum' ) )
+                        new_locations.append( 'device:' + switchPrefix + role + searchObj.group( 'swNum' ) + '/' + searchObj.group( 'portNum' ) )
                     else:
                         new_locations.append( location )
                 netcfg[ 'hosts' ][ host ][ 'basic' ][ 'locations' ] = new_locations
@@ -149,7 +153,7 @@
                         if roleMatch:
                             role = roleValue
                             break
-                    new_location = 'device:' + switchPrefix + ':' + role + searchObj.group( 'swNum' ) + '/' + searchObj.group( 'portNum' )
+                    new_location = 'device:' + switchPrefix + role + searchObj.group( 'swNum' ) + '/' + searchObj.group( 'portNum' )
                     netcfg[ 'hosts' ][ host ][ 'basic' ][ 'locations' ] = new_location
 
     if 'devices' in netcfg.keys():
@@ -160,9 +164,9 @@
                 #TODO This or roleMap? maybe use this to populate role Map?
                 isLeaf = netcfg[ 'devices' ][ device ][ SR_APP ][ 'isEdgeRouter' ]
                 if isLeaf is True:
-                    new_device = 'device:' + switchPrefix + ':leaf' + searchObj.group( 'swNum' )
+                    new_device = 'device:' + switchPrefix + 'leaf' + searchObj.group( 'swNum' )
                 else:
-                    new_device = 'device:' + switchPrefix + ':spine' + searchObj.group( 'swNum' )
+                    new_device = 'device:' + switchPrefix + 'spine' + searchObj.group( 'swNum' )
                 netcfg[ 'devices' ][ new_device ] = netcfg[ 'devices' ].pop( device )
             if 'pairDeviceId' in netcfg[ 'devices' ][ new_device ][ SR_APP ].keys():
                 searchObj = re.search( didRE,
@@ -175,7 +179,7 @@
                         if roleMatch:
                             role = roleValue
                             break
-                    netcfg[ 'devices' ][ new_device ][ SR_APP ][ 'pairDeviceId' ] = 'device:' + switchPrefix + ':' + role + \
+                    netcfg[ 'devices' ][ new_device ][ SR_APP ][ 'pairDeviceId' ] = 'device:' + switchPrefix + role + \
                                                                                     searchObj.group( 'swNum' )
             if 'basic' in netcfg[ 'devices' ][ new_device ].keys():
                 if 'driver' in netcfg[ 'devices' ][ new_device ][ 'basic' ].keys():
@@ -196,7 +200,7 @@
                                 role = roleValue
                                 break
                         netcfg[ 'apps' ][ DHCP_APP_ID ][ 'default' ][ i ][ 'dhcpServerConnectPoint' ] = \
-                            'device:' + switchPrefix + ':' + role + searchObj.group( 'swNum' ) + '/' + searchObj.group( 'portNum' )
+                            'device:' + switchPrefix + role + searchObj.group( 'swNum' ) + '/' + searchObj.group( 'portNum' )
 
     if 'xconnects' in netcfg.keys():
         new_xconnects = []
@@ -210,7 +214,7 @@
                     if roleMatch:
                         role = roleValue
                         break
-                new_device = 'device:' + switchPrefix + ':' + role + searchObj.group( 'swNum' )
+                new_device = 'device:' + switchPrefix + role + searchObj.group( 'swNum' )
                 xconnect[ 'deviceId' ] = new_device
             new_xconnects.append( xconnect )
         netcfg[ 'xconnects' ] = new_xconnects