diff options
author | Morgan Richomme <morgan.richomme@orange.com> | 2015-10-01 11:03:09 +0200 |
---|---|---|
committer | Morgan Richomme <morgan.richomme@orange.com> | 2015-10-01 11:03:09 +0200 |
commit | 19c7d0ecfd453d5e631466401e454d4da3314f9b (patch) | |
tree | c1dac5451af1760f963d709772b5062ba2741983 /testcases/Controllers/ONOS | |
parent | 5901dd9a47b08c162acb631bf5acaeeb1b7ce745 (diff) | |
parent | 96bf9abe9b1b26a79dcc86900e8eb33d8544e773 (diff) |
Merge branch 'master' into stable/arnoarno.2015.2.0
Diffstat (limited to 'testcases/Controllers/ONOS')
-rw-r--r-- | testcases/Controllers/ONOS/Teston/CI/Readme.txt | 5 | ||||
-rw-r--r-- | testcases/Controllers/ONOS/Teston/CI/dependencies/onos | 23 | ||||
-rw-r--r-- | testcases/Controllers/ONOS/Teston/CI/onosfunctest.py | 203 |
3 files changed, 231 insertions, 0 deletions
diff --git a/testcases/Controllers/ONOS/Teston/CI/Readme.txt b/testcases/Controllers/ONOS/Teston/CI/Readme.txt new file mode 100644 index 000000000..7648b2a98 --- /dev/null +++ b/testcases/Controllers/ONOS/Teston/CI/Readme.txt @@ -0,0 +1,5 @@ +1.This is a basic test run about onos,we will make them better and better +2.This test include two suits: +(1)Test northbound(network/subnet/ports create/update/delete) +(2)Ovsdb test,default configuration,openflow connection,vm go onlines. +3.Later we will make a framework to do this test
\ No newline at end of file diff --git a/testcases/Controllers/ONOS/Teston/CI/dependencies/onos b/testcases/Controllers/ONOS/Teston/CI/dependencies/onos new file mode 100644 index 000000000..d4d59e0f7 --- /dev/null +++ b/testcases/Controllers/ONOS/Teston/CI/dependencies/onos @@ -0,0 +1,23 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# ONOS remote command-line client. +# ----------------------------------------------------------------------------- + +[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 +. /root/.bashrc +. $ONOS_ROOT/tools/build/envDefaults +. $ONOS_ROOT/tools/test/bin/find-node.sh + +[ "$1" = "-w" ] && shift && onos-wait-for-start $1 + +[ -n "$1" ] && OCI=$(find_node $1) && shift + +if which client 1>/dev/null 2>&1 && [ -z "$ONOS_USE_SSH" ]; then + # Use Karaf client only if we can and are allowed to + unset KARAF_HOME + client -h $OCI -u karaf "$@" 2>/dev/null +else + # Otherwise use raw ssh; strict checking is off for dev environments only + #ssh -p 8101 -o StrictHostKeyChecking=no $OCI "$@" + sshpass -p karaf ssh -l karaf -p 8101 $OCI "$@" +fi diff --git a/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py b/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py new file mode 100644 index 000000000..72fa4ae1f --- /dev/null +++ b/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py @@ -0,0 +1,203 @@ +""" +Description: This test is to run onos Teston VTN scripts + +List of test cases: +CASE1 - Northbound NBI test network/subnet/ports +CASE2 - Ovsdb test&Default configuration&Vm go online + +lanqinglong@huawei.com +""" +import os +import os.path +import time +import pexpect +import re +import sys + +def SSHlogin(ipaddr,username,password): + login = pexpect.spawn('ssh %s@%s'%(username,ipaddr)) + index = 0 + while index != 2: + index = login.expect(['assword:','yes/no','#|$',pexpect.EOF]) + if index == 0: + login.sendline(password) + login.interact() + if index == 1: + login.sendline('yes') + print "Login Success!" + +def AddKarafUser(ipaddr,username,password): + print '\033[1;31;40m' + print "Now Adding karaf user to OC1..." + print "\033[0m" + login = pexpect.spawn("ssh -l %s -p 8101 %s"%(username,ipaddr)) + index = 0 + while index != 2: + index = login.expect(['assword:','yes/no',pexpect.EOF]) + if index == 0: + login.sendline(password) + login.sendline("logout") + index = login.expect(["closed",pexpect.EOF]) + if index == 0: + print "Add SSH Known Host Success!" + else: + print "Add SSH Known Host Failed! Please Check!" + login.interact() + if index == 1: + login.sendline('yes') + +def DownLoadCode(): + print '\033[1;31;40m' + print "Now loading test codes!Please wait in patient..." + print "\033[0m" + os.system("git clone https://github.com/sunyulin/OnosSystemTest.git") + time.sleep(1) + os.system("git clone https://gerrit.onosproject.org/onos") + time.sleep(1) + print "Done!" + +def CleanEnv(): + print '\033[1;31;40m' + print "Now Cleaning test environment" + print "\033[0m" + os.system("sudo apt-get install -y mininet") + os.system("OnosSystemTest/TestON/bin/cleanup.sh") + time.sleep(5) + print "Done!" + +def OnosPushKeys(cmd,password): + print '\033[1;31;40m' + print "Now Pushing Onos Keys:"+cmd + print "\033[0m" + Pushkeys = pexpect.spawn(cmd) + Result = 0 + while Result != 2: + Result = Pushkeys.expect(["yes","password",pexpect.EOF,pexpect.TIMEOUT]) + if (Result == 0): + Pushkeys.sendline("yes") + if (Result == 1): + Pushkeys.sendline(password) + if (Result == 3): + print("Push keys Error!") + print "Done!" + +def AddEnvIntoBashrc(name): + print '\033[1;31;40m' + print "Now Adding bash environment" + print "\033[0m" + fileopen = open("/etc/profile",'r') + findContext = 1 + while findContext: + findContext = fileopen.readline() + result = findContext.find('dev/bash_profile') + if result != -1: + break + fileopen.close + if result == -1: + envAdd = open("/etc/profile",'a+') + envAdd.writelines("\nsource /root/onos/tools/dev/bash_profile") + envAdd.close() + +def SetEnvVar(masterpass,agentpass): + print '\033[1;31;40m' + print "Now Setting test environment" + print "\033[0m" + os.environ["OCT"] = "10.1.0.1" + os.environ["OC1"] = "10.1.0.50" + os.environ["OC2"] = "10.1.0.51" + os.environ["OC3"] = "10.1.0.52" + os.environ["OCN"] = "10.1.0.53" + os.environ["OCN2"] = "10.1.0.54" + os.environ["localhost"] = "10.1.0.1" + os.system("sudo pip install configobj") + os.system("sudo apt-get install -y sshpass") + OnosPushKeys("onos-push-keys 10.1.0.1",masterpass) + OnosPushKeys("onos-push-keys 10.1.0.50",agentpass) + OnosPushKeys("onos-push-keys 10.1.0.53",agentpass) + OnosPushKeys("onos-push-keys 10.1.0.54",agentpass) + +def Gensshkey(): + print '\033[1;31;40m' + print "Now Generating SSH keys..." + print "\033[0m" + os.system("rm -rf ~/.ssh/*") + keysub = pexpect.spawn("ssh-keygen -t rsa") + Result = 0 + while Result != 2: + Result = keysub.expect(["Overwrite","Enter",pexpect.EOF,pexpect.TIMEOUT]) + if Result == 0: + keysub.sendline("y") + if Result == 1: + keysub.sendline("\n") + if Result == 3: + printf("Generate SSH key failed.") + print "Done!" + +def ChangeOnosName(user,password): + print '\033[1;31;40m' + print "Now Changing ONOS name&password" + print "\033[0m" + line = open("onos/tools/build/envDefaults",'r').readlines() + lenall = len(line)-1 + for i in range(lenall): + if "ONOS_USER=" in line[i]: + line[i]=line[i].replace("sdn",user) + if "ONOS_GROUP" in line[i]: + line[i]=line[i].replace("sdn",user) + if "ONOS_PWD" in line[i]: + line[i]=line[i].replace("rocks",password) + NewFile = open("onos/tools/build/envDefaults",'w') + NewFile.writelines(line) + NewFile.close + print "Done!" + +def ChangeTestCasePara(testcase,user,password): + print '\033[1;31;40m' + print "Now Changing " + testcase + " name&password" + print "\033[0m" + filepath = "OnosSystemTest/TestON/tests/" + testcase + "/" + testcase + ".topo" + line = open(filepath,'r').readlines() + lenall = len(line)-1 + for i in range(lenall-2): + if ("localhost" in line[i]) or ("OCT" in line[i]): + line[i+1]=re.sub(">\w+",">"+user,line[i+1]) + line[i+2]=re.sub(">\w+",">"+password,line[i+2]) + if "OC1" in line [i] \ + or "OC2" in line [i] \ + or "OC3" in line [i] \ + or "OCN" in line [i] \ + or "OCN2" in line[i]: + line[i+1]=re.sub(">\w+",">root",line[i+1]) + line[i+2]=re.sub(">\w+",">root",line[i+2]) + NewFile = open(filepath,'w') + NewFile.writelines(line) + NewFile.close + print "Done!" + +def RunScript(testname,masterusername,masterpassword): + ChangeTestCasePara(testname,masterusername,masterpassword) + runtest = "OnosSystemTest/TestON/bin/cli.py run " + testname + os.system(runtest) + print "Done!" + +if __name__=="__main__": + + #This is the compass run machine user&pass,you need to modify + masterusername = "root" + masterpassword = "root" + + #The config below you don't need to care + agentusername = "root" + agentpassword = "root" + + print "Test Begin....." + Gensshkey() + AddKarafUser("10.1.0.50","karaf","karaf") + AddEnvIntoBashrc("source onos/tools/dev/bash_profile") + SSHlogin("10.1.0.1",masterusername,masterpassword) + ChangeOnosName(agentusername,agentpassword) + DownLoadCode() + CleanEnv() + SetEnvVar(masterpassword,agentpassword) + RunScript("FUNCvirNetNB",masterusername,masterpassword) + RunScript("FUNCovsdbtest",masterusername,masterpassword) |