Fix startup for FUNCintentRest test and add REST authentication
- fix for mismatched cell and node definitions, use smaller number if
defined in topo
- Add basic rest authentication support
- Set up default rest login in the FUNCintentRest.topo file
Change-Id: I26e5308fd995c6e825fefe659695d172778796a7
diff --git a/TestON/drivers/common/api/controller/onosrestdriver.py b/TestON/drivers/common/api/controller/onosrestdriver.py
index 42b7680..66cd8b4 100644
--- a/TestON/drivers/common/api/controller/onosrestdriver.py
+++ b/TestON/drivers/common/api/controller/onosrestdriver.py
@@ -27,11 +27,11 @@
class OnosRestDriver( Controller ):
def __init__( self ):
+ self.pwd = None
+ self.user_name = "user"
super( Controller, self ).__init__()
self.ip_address = "localhost"
self.port = "8080"
- self.user_name = "user"
- self.password = "CHANGEME"
def connect( self, **connectargs ):
try:
@@ -56,7 +56,7 @@
return self.handle
def send( self, ip, port, url, base="/onos/v1", method="GET",
- query=None, data=None ):
+ query=None, data=None, debug=False ):
"""
Arguments:
str ip: ONOS IP Address
@@ -76,12 +76,19 @@
# ANSWER: Not yet, but potentially https with certificates
try:
path = "http://" + str( ip ) + ":" + str( port ) + base + url
+ if self.user_name and self.pwd:
+ auth = (self.user_name, self.pwd)
+ else:
+ auth=None
main.log.info( "Sending request " + path + " using " +
method.upper() + " method." )
response = requests.request( method.upper(),
path,
params=query,
- data=data )
+ data=data,
+ auth=auth )
+ if debug:
+ main.log.debug( response )
return ( response.status_code, response.text.encode( 'utf8' ) )
except requests.exceptions:
main.log.exception( "Error sending request." )
@@ -147,7 +154,7 @@
main.log.warn( "No ip given, reverting to ip from topo file" )
ip = self.ip_address
if port == "DEFAULT":
- main.log.warn( "No port given, reverting to port" +
+ main.log.warn( "No port given, reverting to port " +
"from topo file" )
port = self.port
# NOTE: REST url requires the intent id to be in decimal form
@@ -207,8 +214,8 @@
main.log.warn( "No ip given, reverting to ip from topo file" )
ip = self.ip_address
if port == "DEFAULT":
- main.log.warn( "No port given, reverting to port \
- from topo file" )
+ main.log.warn( "No port given, reverting to port " +
+ "from topo file" )
port = self.port
response = self.send( ip, port, url="/applications" )
if response:
@@ -244,7 +251,7 @@
main.log.warn( "No ip given, reverting to ip from topo file" )
ip = self.ip_address
if port == "DEFAULT":
- main.log.warn( "No port given, reverting to port" +
+ main.log.warn( "No port given, reverting to port " +
"from topo file" )
port = self.port
query = "/" + str( appName ) + "/active"
@@ -296,7 +303,7 @@
main.log.warn( "No ip given, reverting to ip from topo file" )
ip = self.ip_address
if port == "DEFAULT":
- main.log.warn( "No port given, reverting to port" +
+ main.log.warn( "No port given, reverting to port " +
"from topo file" )
port = self.port
query = "/" + str( appName ) + "/active"
@@ -346,7 +353,7 @@
main.log.warn( "No ip given, reverting to ip from topo file" )
ip = self.ip_address
if port == "DEFAULT":
- main.log.warn( "No port given, reverting to port" +
+ main.log.warn( "No port given, reverting to port " +
"from topo file" )
port = self.port
query = "/" + project + str( appName )
@@ -673,8 +680,8 @@
main.log.warn( "No ip given, reverting to ip from topo file" )
ip = self.ip_address
if port == "DEFAULT":
- main.log.warn( "No port given, reverting to port \
- from topo file" )
+ main.log.warn( "No port given, reverting to port " +
+ "from topo file" )
port = self.port
response = self.send( ip, port, url="/hosts" )
if response:
@@ -713,8 +720,8 @@
main.log.warn( "No ip given, reverting to ip from topo file" )
ip = self.ip_address
if port == "DEFAULT":
- main.log.warn( "No port given, reverting to port \
- from topo file" )
+ main.log.warn( "No port given, reverting to port " +
+ "from topo file" )
port = self.port
query = "/" + mac + "/" + vlan
response = self.send( ip, port, url="/hosts" + query )
@@ -749,8 +756,8 @@
main.log.warn( "No ip given, reverting to ip from topo file" )
ip = self.ip_address
if port == "DEFAULT":
- main.log.warn( "No port given, reverting to port \
- from topo file" )
+ main.log.warn( "No port given, reverting to port " +
+ "from topo file" )
port = self.port
response = self.send( ip, port, url="/topology" )
if response:
@@ -903,8 +910,8 @@
main.log.warn( "No ip given, reverting to ip from topo file" )
ip = self.ip_address
if port == "DEFAULT":
- main.log.warn( "No port given, reverting to port \
- from topo file" )
+ main.log.warn( "No port given, reverting to port " +
+ "from topo file" )
port = self.port
response = self.send( ip, port, url="/flows" )
if response:
@@ -937,8 +944,8 @@
main.log.warn( "No ip given, reverting to ip from topo file" )
ip = self.ip_address
if port == "DEFAULT":
- main.log.warn( "No port given, reverting to port \
- from topo file" )
+ main.log.warn( "No port given, reverting to port " +
+ "from topo file" )
port = self.port
url = "/flows/" + device
if flowId:
diff --git a/TestON/tests/FUNCintent/FUNCintent.py b/TestON/tests/FUNCintent/FUNCintent.py
index bf9edfd..797a91a 100644
--- a/TestON/tests/FUNCintent/FUNCintent.py
+++ b/TestON/tests/FUNCintent/FUNCintent.py
@@ -7,7 +7,6 @@
def CASE1( self, main ):
import time
- import os
import imp
import re
diff --git a/TestON/tests/FUNCintentRest/FUNCintentRest.py b/TestON/tests/FUNCintentRest/FUNCintentRest.py
index 0bc5c3c..e97bc9a 100644
--- a/TestON/tests/FUNCintentRest/FUNCintentRest.py
+++ b/TestON/tests/FUNCintentRest/FUNCintentRest.py
@@ -11,8 +11,8 @@
def CASE1( self, main ):
import time
- import os
import imp
+ import re
"""
- Construct tests variables
@@ -33,7 +33,7 @@
# Test variables
try:
- main.testOnDirectory = os.path.dirname( os.getcwd ( ) )
+ main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
main.apps = main.params[ 'ENV' ][ 'cellApps' ]
gitBranch = main.params[ 'GIT' ][ 'branch' ]
main.dependencyPath = main.testOnDirectory + \
@@ -64,8 +64,16 @@
main.ONOSip = main.ONOSbench.getOnosIps()
# Assigning ONOS cli handles to a list
- for i in range( 1, main.maxNodes + 1 ):
- main.CLIs.append( getattr( main, 'ONOSrest' + str( i ) ) )
+ try:
+ for i in range( 1, main.maxNodes + 1 ):
+ main.CLIs.append( getattr( main, 'ONOSrest' + str( i ) ) )
+ except AttributeError:
+ main.log.warn( "A " + str( main.maxNodes ) + " node cluster " +
+ "was defined in env variables, but only " +
+ str( len( main.CLIs ) ) +
+ " nodes were defined in the .topo file. " +
+ "Using " + str( len( main.CLIs ) ) +
+ " nodes for the test." )
# -- INIT SECTION, ONLY RUNS ONCE -- #
main.startUp = imp.load_source( wrapperFile1,
@@ -83,10 +91,11 @@
wrapperFile3 +
".py" )
- copyResult = main.ONOSbench.copyMininetFile( main.topology,
- main.dependencyPath,
- main.Mininet1.user_name,
- main.Mininet1.ip_address )
+ copyResult1 = main.ONOSbench.scp( main.Mininet1,
+ main.dependencyPath +
+ main.topology,
+ main.Mininet1.home,
+ direction="to" )
if main.CLIs:
stepResult = main.TRUE
else:
@@ -179,9 +188,9 @@
time.sleep( main.startUpSleep )
main.step( "Uninstalling ONOS package" )
onosUninstallResult = main.TRUE
- for i in range( main.numCtrls ):
+ for ip in main.ONOSip:
onosUninstallResult = onosUninstallResult and \
- main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] )
+ main.ONOSbench.onosUninstall( nodeIp=ip )
stepResult = onosUninstallResult
utilities.assert_equals( expect=main.TRUE,
actual=stepResult,
diff --git a/TestON/tests/FUNCintentRest/FUNCintentRest.topo b/TestON/tests/FUNCintentRest/FUNCintentRest.topo
index 647bdc6..efed3d6 100755
--- a/TestON/tests/FUNCintentRest/FUNCintentRest.topo
+++ b/TestON/tests/FUNCintentRest/FUNCintentRest.topo
@@ -14,8 +14,8 @@
<ONOSrest1>
<host>OC1</host>
<port>8181</port>
- <user>admin</user>
- <password>onos_test</password>
+ <user>onos</user>
+ <password>rocks</password>
<type>OnosRestDriver</type>
<connect_order>2</connect_order>
<COMPONENTS>
@@ -25,8 +25,8 @@
<ONOSrest2>
<host>OC2</host>
<port>8181</port>
- <user>admin</user>
- <password>onos_test</password>
+ <user>onos</user>
+ <password>rocks</password>
<type>OnosRestDriver</type>
<connect_order>3</connect_order>
<COMPONENTS>
@@ -36,8 +36,8 @@
<ONOSrest3>
<host>OC3</host>
<port>8181</port>
- <user>admin</user>
- <password>onos_test</password>
+ <user>onos</user>
+ <password>rocks</password>
<type>OnosRestDriver</type>
<connect_order>4</connect_order>
<COMPONENTS>