diff options
author | lanqinglong <lanqinglong@huawei.com> | 2016-01-15 10:28:42 +0800 |
---|---|---|
committer | Morgan Richomme <morgan.richomme@orange.com> | 2016-01-15 08:30:01 +0000 |
commit | b241534d5a37ac93368aec79727238e3aed75d43 (patch) | |
tree | 1526e9d3ca3abf8580d9582f4ea3d9317cfefb31 /testcases | |
parent | 822e22975778006780728e2759640fae8d4c1c02 (diff) |
Modify ONOS test for CI running
Change-Id: I2ce678c1239920071f9eeb6fe251a92cb3737e6a
Signed-off-by: lanqinglong <lanqinglong@huawei.com>
(cherry picked from commit be4d2778d535272a3683cb8e518c85065af6a582)
Diffstat (limited to 'testcases')
7 files changed, 112 insertions, 32 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()) diff --git a/testcases/config_functest.yaml b/testcases/config_functest.yaml index be7687ac4..10637159a 100644 --- a/testcases/config_functest.yaml +++ b/testcases/config_functest.yaml @@ -139,12 +139,15 @@ ONOS: 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 |