Implement Secure SSH command and add ONOS_USE_SSH option
in the cell file
Change-Id: Id23a63fc5f0e09fe69540ede56393e4152a8f00e
diff --git a/TestON/drivers/common/cli/onosdriver.py b/TestON/drivers/common/cli/onosdriver.py
index d120951..dfb85fb 100755
--- a/TestON/drivers/common/cli/onosdriver.py
+++ b/TestON/drivers/common/cli/onosdriver.py
@@ -727,7 +727,7 @@
main.exit()
def createCellFile( self, benchIp, fileName, mnIpAddrs,
- appString, onosIpAddrs, onosUser="sdn" ):
+ appString, onosIpAddrs, onosUser="sdn", useSSH=False ):
"""
Creates a cell file based on arguments
Required:
@@ -762,6 +762,8 @@
appString = "export ONOS_APPS=" + appString
onosGroup = "export ONOS_GROUP=" + onosUser
onosUser = "export ONOS_USER=" + onosUser
+ if useSSH:
+ onosUseSSH = "export ONOS_USE_SSH=true"
mnString = "export OCN="
if mnIpAddrs == "":
mnString = ""
@@ -797,6 +799,8 @@
cellFile.write( appString + "\n" )
cellFile.write( onosGroup + "\n" )
cellFile.write( onosUser + "\n" )
+ if useSSH:
+ cellFile.write( onosUseSSH + "\n" )
cellFile.close()
# We use os.system to send the command to TestON cluster
@@ -978,6 +982,47 @@
main.cleanup()
main.exit()
+ def onosSecureSSH( self, userName="onos", userPWD="rocks", node=""):
+ """
+ Enables secure access to ONOS console
+ by removing default users & keys.
+
+ onos-secure-ssh -u onos -p rocks node
+
+ Returns: main.TRUE on success and main.FALSE on failure
+ """
+
+ try:
+ self.handle.sendline( " onos-secure-ssh -u " + userName + " -p " + userPWD + " " + node )
+
+ # NOTE: this timeout may need to change depending on the network
+ # and size of ONOS
+ # TODO: Handle the other possible error
+ i = self.handle.expect([ "Network\sis\sunreachable",
+ "\$",
+ pexpect.TIMEOUT ], timeout=180 )
+ if i == 0:
+ # can't reach ONOS node
+ main.log.warn( "Network is unreachable" )
+ self.handle.expect( "\$" )
+ return main.FALSE
+ elif i == 1:
+ # Process started
+ main.log.info(
+ "Secure SSH performed on " +
+ node)
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ except Exception:
+ main.log.exception( self.name + ": Uncaught exception!" )
+ main.cleanup()
+ main.exit()
+
+
def onosInstall( self, options="-f", node="" ):
"""
Installs ONOS bits on the designated cell machine.
diff --git a/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py b/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
index 4d4f568..7f189e5 100755
--- a/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
+++ b/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
@@ -97,7 +97,8 @@
main.Mininet1.ip_address,
apps,
tempOnosIp,
- onosUser )
+ onosUser,
+ useSSH=True )
cellResult = main.ONOSbench.setCell( "temp" )
verifyResult = main.ONOSbench.verifyCell( )
stepResult = cellResult and verifyResult
@@ -124,6 +125,15 @@
actual=stepResult,
onpass="Successfully installed ONOS package",
onfail="Failed to install ONOS package" )
+ for i in range( main.numCtrls ):
+ onosInstallResult = onosInstallResult and \
+ main.ONOSbench.onosSecureSSH(
+ node=main.ONOSip[ i ] )
+ stepResult = onosInstallResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=stepResult,
+ onpass="Successfully secure SSH",
+ onfail="Failed to secure SSH" )
main.step( "Starting ONOS service" )
stopResult, startResult, onosIsUp = main.TRUE, main.TRUE, main.TRUE,
for i in range( main.numCtrls ):