testcase=`cat /home/opnfv/functest/conf/testcase-list.txt`
arr_test=("$testcase")
else
- arr_test=(vping odl tempest vims rally)
+ arr_test=(vping odl tempest vims rally onos)
fi
function clean_openstack(){
import time
import pexpect
import re
+import requests
+import json
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!"
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')
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):
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)
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 ):
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)
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
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
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 )
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):
"""
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)
"""
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()
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
#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())
onoscli_password: 'root'
runtimeout: 300
environment:
- OCT: '189.42.8.99'
- OC1: '189.42.8.101'
- OC2: '189.42.8.102'
- OC3: '189.42.8.103'
- OCN: '189.42.8.104'
- OCN2: '189.42.8.105'
+ OCT: '10.20.0.1'
+ OC1: '10.20.0.7'
+ OC2: '10.20.0.7'
+ OC3: '10.20.0.7'
+ OCN: '10.20.0.4'
+ OCN2: '10.20.0.5'
+ installer_master: '10.20.0.2'
+ installer_master_username: 'root'
+ installer_master_password: 'r00tme'
results:
test_db_url: http://213.77.62.197