aboutsummaryrefslogtreecommitdiffstats
path: root/testcases/Controllers/ONOS
diff options
context:
space:
mode:
Diffstat (limited to 'testcases/Controllers/ONOS')
-rw-r--r--testcases/Controllers/ONOS/Teston/CI/adapters/client.py13
-rw-r--r--testcases/Controllers/ONOS/Teston/CI/adapters/connection.py3
-rw-r--r--testcases/Controllers/ONOS/Teston/CI/adapters/environment.py68
-rw-r--r--testcases/Controllers/ONOS/Teston/CI/adapters/foundation.py40
-rw-r--r--testcases/Controllers/ONOS/Teston/CI/log/gitignore0
-rw-r--r--testcases/Controllers/ONOS/Teston/CI/onosfunctest.py5
6 files changed, 103 insertions, 26 deletions
diff --git a/testcases/Controllers/ONOS/Teston/CI/adapters/client.py b/testcases/Controllers/ONOS/Teston/CI/adapters/client.py
index 32e3749f0..535b71f85 100644
--- a/testcases/Controllers/ONOS/Teston/CI/adapters/client.py
+++ b/testcases/Controllers/ONOS/Teston/CI/adapters/client.py
@@ -8,6 +8,8 @@ import os
import time
import pexpect
import re
+import requests
+import json
class client( environment ):
@@ -35,7 +37,7 @@ class client( environment ):
Result = runhandle.expect(["PEXPECT]#", pexpect.EOF, pexpect.TIMEOUT])
curshowscreeninfo = runhandle.before
if (len(lastshowscreeninfo) != len(curshowscreeninfo)):
- print str(curshowscreeninfo)[len(lastshowscreeninfo)::]
+ self.loginfo.log(str(curshowscreeninfo)[len(lastshowscreeninfo)::])
lastshowscreeninfo = curshowscreeninfo
if Result == 0:
print "Done!"
@@ -61,9 +63,14 @@ class client( environment ):
self.loginfo.log('Release onos handle Successful')
def push_results_to_db( self, payload, pushornot = 1):
+ if pushornot != 1:
+ return 1
url = self.Result_DB + "/results"
params = {"project_name": "functest", "case_name": "ONOS-" + self.testcase,
"pod_name": 'huawei-build-2', "details": payload}
headers = {'Content-Type': 'application/json'}
- r = requests.post(url, data=json.dumps(params), headers=headers)
- self.loginfo.log('Pushing result via Northbound, info:' + r )
+ try:
+ r = requests.post(url, data=json.dumps(params), headers=headers)
+ self.loginfo.log(r)
+ except:
+ self.loginfo.log('Error pushing results into Database')
diff --git a/testcases/Controllers/ONOS/Teston/CI/adapters/connection.py b/testcases/Controllers/ONOS/Teston/CI/adapters/connection.py
index f7f283ed0..c0eb464af 100644
--- a/testcases/Controllers/ONOS/Teston/CI/adapters/connection.py
+++ b/testcases/Controllers/ONOS/Teston/CI/adapters/connection.py
@@ -160,7 +160,7 @@ class connection( foundation ):
onospath: path of onos root
"""
print "Now Changing ONOS Root Path"
- filepath = onospath + '/onos/tools/dev/bash_profile'
+ filepath = onospath + 'onos/tools/dev/bash_profile'
line = open(filepath, 'r').readlines()
lenall = len(line) - 1
for i in range(lenall):
@@ -179,7 +179,6 @@ class connection( foundation ):
filepath = '/root/'
else :
filepath = '/home/' + self.masterusername + '/'
- self.OnosRootPathChange( filepath )
filepath = os.path.join( filepath, "onos/tools/dev/bash_profile" )
self.AddEnvIntoBashrc("source " + filepath + "\n")
self.AddEnvIntoBashrc("export OCT=" + self.OCT)
diff --git a/testcases/Controllers/ONOS/Teston/CI/adapters/environment.py b/testcases/Controllers/ONOS/Teston/CI/adapters/environment.py
index bdd0e122e..f0bafd760 100644
--- a/testcases/Controllers/ONOS/Teston/CI/adapters/environment.py
+++ b/testcases/Controllers/ONOS/Teston/CI/adapters/environment.py
@@ -32,35 +32,38 @@ class environment( connection ):
codeurl: clone code url
"""
print "Now loading test codes! Please wait in patient..."
- originalfolder = self.home
+ originalfolder = sys.path[0]
+ print originalfolder
gitclone = handle
gitclone.sendline( "git clone " + codeurl )
index = 0
+ increment = 0
while index != 1 or index != 4:
- index = gitclone.expect ( ['already exists', 'resolving deltas: 100%', \
- 'Receiving objects', 'Already up-to-date', \
- pexpect.EOF] )
+ index = gitclone.expect ( ['already exists', 'esolving deltas: 100%', \
+ 'eceiving objects', 'Already up-to-date', \
+ 'npacking objects: 100%', pexpect.EOF] )
- filefolder = originalfolder + '/' + codeurl.split('/')[-1].split('.')[0]
+ filefolder = self.home + '/' + codeurl.split('/')[-1].split('.')[0]
if index == 0 :
os.chdir( filefolder )
os.system( 'git pull' )
os.chdir( originalfolder )
self.loginfo.log( 'Download code success!' )
break
- elif index == 1 :
+ elif index == 1 or index == 4:
self.loginfo.log( 'Download code success!' )
+ gitclone.sendline( "mkdir onos" )
+ gitclone.prompt( )
+ gitclone.sendline( "cp -rf " + filefolder+ "/tools onos/" )
+ gitclone.prompt( )
break
elif index == 2 :
- increment += 1
- if increment == 20:
- print '\n'
- print '.'
+ os.write(1, gitclone.before)
+ sys.stdout.flush()
else :
self.loginfo.log( 'Download code failed!' )
self.loginfo.log( 'Information before' + gitclone.before )
break
- time.sleep(5)
gitclone.prompt( )
def InstallDefaultSoftware( self, handle ):
@@ -119,6 +122,12 @@ class environment( connection ):
agentpass: onos cluster&compute node password
"""
print "Now Setting test environment"
+ for host in self.hosts:
+ print "try to connect " + str(host)
+ result = self.CheckSshNoPasswd(host)
+ if not result:
+ print "ssh lgin failed,try to copy master publickey to agent " + str(host)
+ self.CopyPublicKey(host)
self.OnosPushKeys( handle, "onos-push-keys " + self.OCT, masterpass)
self.OnosPushKeys( handle, "onos-push-keys " + self.OC1, agentpass)
self.OnosPushKeys( handle, "onos-push-keys " + self.OC2, agentpass)
@@ -126,6 +135,24 @@ class environment( connection ):
self.OnosPushKeys( handle, "onos-push-keys " + self.OCN, agentpass)
self.OnosPushKeys( handle, "onos-push-keys " + self.OCN2, agentpass)
+ def CheckSshNoPasswd( self, host):
+ """
+ Check master can connect agent with no password
+ """
+ login = pexpect.spawn( "ssh " + str(host))
+ index = 4
+ while index == 4:
+ index = login.expect(['(yes/no)','>|#|\$', \
+ pexpect.EOF, pexpect.TIMEOUT] )
+ if index == 0:
+ login.sendline( "yes" )
+ index = 4
+ if index == 1:
+ self.loginfo.log("ssh connect to " + str(host) + " success,no need to copy ssh public key" )
+ return True
+ login.interact()
+ return False
+
def ChangeOnosName( self, user, password):
"""
Change onos name in envDefault file
@@ -204,11 +231,21 @@ class environment( connection ):
handle.logout()
def CopyOnostoTestbin( self ):
- sourcefile = os.curdir + '/dependencies/onos'
+ sourcefile = self.cipath + '/dependencies/onos'
destifile = self.home + '/onos/tools/test/bin/'
+ os.system( 'pwd' )
runcommand = 'cp ' + sourcefile + ' ' + destifile
os.system( runcommand )
+ def CopyPublicKey( self, host ):
+ output = os.popen( 'cat /root/.ssh/id_rsa.pub' )
+ publickey = output.read().strip('\n')
+ tmphandle = self.SSHlogin( self.installer_master, self.installer_master_username, self.installer_master_password )
+ tmphandle.sendline("ssh "+ host + " -T \'echo " + str(publickey) + ">>/root/.ssh/authorized_keys\'" )
+ tmphandle.prompt()
+ self.SSHRelease(tmphandle)
+ print "Add OCT PublicKey to " + host + " success"
+
def OnosEnvSetup( self, handle ):
"""
Onos Environment Setup function
@@ -219,7 +256,12 @@ class environment( connection ):
self.AddKnownHost( handle, self.OC2, "karaf", "karaf" )
self.AddKnownHost( handle, self.OC3, "karaf", "karaf" )
self.DownLoadCode( handle, 'https://github.com/sunyulin/OnosSystemTest.git' )
- self.DownLoadCode( handle, 'https://gerrit.onosproject.org/onos' )
+ #self.DownLoadCode( handle, 'https://gerrit.onosproject.org/onos' )
+ if self.masterusername == 'root':
+ filepath = '/root/'
+ else :
+ filepath = '/home/' + self.masterusername + '/'
+ self.OnosRootPathChange( filepath )
self.CopyOnostoTestbin()
self.ChangeOnosName(self.agentusername,self.agentpassword)
self.InstallDefaultSoftware( handle )
diff --git a/testcases/Controllers/ONOS/Teston/CI/adapters/foundation.py b/testcases/Controllers/ONOS/Teston/CI/adapters/foundation.py
index 9d0c63451..83cbcb242 100644
--- a/testcases/Controllers/ONOS/Teston/CI/adapters/foundation.py
+++ b/testcases/Controllers/ONOS/Teston/CI/adapters/foundation.py
@@ -8,15 +8,23 @@ import logging
import os
import time
import yaml
+import re
+import datetime
class foundation:
def __init__(self):
- currentpath = os.getcwd()
+ #currentpath = os.getcwd()
+ REPO_PATH = os.environ['repos_dir']+'/functest/'
+ currentpath = REPO_PATH + 'testcases/Controllers/ONOS/Teston/CI'
+ self.cipath = currentpath
self.logdir = os.path.join( currentpath, 'log' )
self.workhome = currentpath[0:currentpath.rfind('testcases')-1]
self.Result_DB = ''
+ filename = time.strftime( '%Y-%m-%d-%H-%M-%S' ) + '.log'
+ self.logfilepath = os.path.join( self.logdir, filename )
+ self.starttime = datetime.datetime.now()
def log (self, loginfo):
"""
@@ -24,14 +32,12 @@ class foundation:
parameters:
loginfo(input): record info
"""
- filename = time.strftime( '%Y-%m-%d-%H-%M-%S' ) + '.log'
- filepath = os.path.join( self.logdir, filename )
logging.basicConfig( level=logging.INFO,
format = '%(asctime)s %(filename)s:%(message)s',
datefmt = '%d %b %Y %H:%M:%S',
- filename = filepath,
+ filename = self.logfilepath,
filemode = 'w')
- filelog = logging.FileHandler( filepath )
+ filelog = logging.FileHandler( self.logfilepath )
logging.getLogger( 'Functest' ).addHandler( filelog )
print loginfo
logging.info(loginfo)
@@ -40,7 +46,7 @@ class foundation:
"""
Get Default Parameters value
"""
- with open("/home/opnfv/functest/conf/config_functest.yaml") as f:
+ with open(self.workhome + "/testcases/config_functest.yaml") as f:
functest_yaml = yaml.safe_load(f)
f.close()
@@ -60,5 +66,25 @@ class foundation:
self.OC3 = str(functest_yaml.get("ONOS").get("environment").get("OC3"))
self.OCN = str(functest_yaml.get("ONOS").get("environment").get("OCN"))
self.OCN2 = str(functest_yaml.get("ONOS").get("environment").get("OCN2"))
+ self.installer_master = str(functest_yaml.get("ONOS").get("environment").get("installer_master"))
+ self.installer_master_username = str(functest_yaml.get("ONOS").get("environment").get("installer_master_username"))
+ self.installer_master_password = str(functest_yaml.get("ONOS").get("environment").get("installer_master_password"))
+ self.hosts = [self.OC1, self.OCN, self.OCN2]
self.localhost = self.OCT
- return True \ No newline at end of file
+
+ def GetResult( self ):
+ cmd = "cat " + self.logfilepath + " | grep Fail"
+ Resultbuffer = os.popen(cmd).read()
+ duration = datetime.datetime.now() - self.starttime
+ time.sleep(2)
+
+ if re.search("[1-9]+", Resultbuffer):
+ self.log("Testcase Fails\n" + Resultbuffer)
+ Result = "POK"
+ else:
+ self.log("Testcases Pass")
+ Result = "OK"
+ payload={'timestart': str(self.starttime),
+ 'duration': str(duration),
+ 'status': Result}
+ return payload
diff --git a/testcases/Controllers/ONOS/Teston/CI/log/gitignore b/testcases/Controllers/ONOS/Teston/CI/log/gitignore
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/testcases/Controllers/ONOS/Teston/CI/log/gitignore
diff --git a/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py b/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py
index e8524430f..675b3fc68 100644
--- a/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py
+++ b/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py
@@ -17,5 +17,8 @@ if __name__=="__main__":
#scripts to run
runhandle = main.onosstart()
main.RunScript(runhandle, "FUNCvirNetNB")
- main.RunScript(runhandle, "FUNCovsdbtest")
+# main.RunScript(runhandle, "FUNCovsdbtest")
+ main.RunScript(runhandle, "FUNCvirNetNBL3")
+# main.RunScript(runhandle, "FUNCovsdbtestL3")
main.onosclean( runhandle )
+ main.push_results_to_db(main.GetResult())