Modify ONOS test for CI running 77/6777/4
authorlanqinglong <lanqinglong@huawei.com>
Fri, 15 Jan 2016 02:28:42 +0000 (10:28 +0800)
committerQinglong Lan <lanqinglong@huawei.com>
Fri, 15 Jan 2016 03:11:38 +0000 (03:11 +0000)
Change-Id: I2ce678c1239920071f9eeb6fe251a92cb3737e6a
Signed-off-by: lanqinglong <lanqinglong@huawei.com>
docker/run_tests.sh
testcases/Controllers/ONOS/Teston/CI/adapters/client.py
testcases/Controllers/ONOS/Teston/CI/adapters/connection.py
testcases/Controllers/ONOS/Teston/CI/adapters/environment.py
testcases/Controllers/ONOS/Teston/CI/adapters/foundation.py
testcases/Controllers/ONOS/Teston/CI/log/gitignore [new file with mode: 0644]
testcases/Controllers/ONOS/Teston/CI/onosfunctest.py
testcases/config_functest.yaml

index bbe0d9e..d6faff2 100755 (executable)
@@ -36,7 +36,7 @@ if [[ -n "$DEPLOY_SCENARIO" && "$DEPLOY_SCENARIO" != "none" ]]; then
      testcase=`cat /home/opnfv/functest/conf/testcase-list.txt`
      arr_test=("$testcase")
 else
      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(){
 fi
 
 function clean_openstack(){
index 32e3749..535b71f 100644 (file)
@@ -8,6 +8,8 @@ import os
 import time
 import pexpect
 import re
 import time
 import pexpect
 import re
+import requests
+import json
 
 class client( environment ):
 
 
 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)):
             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!"
                 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):
         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'}
         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')
index f7f283e..c0eb464 100644 (file)
@@ -160,7 +160,7 @@ class connection( foundation ):
         onospath: path of onos root
         """
         print "Now Changing ONOS Root Path"
         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):
         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 + '/'
             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)
         filepath = os.path.join( filepath, "onos/tools/dev/bash_profile" )
         self.AddEnvIntoBashrc("source " + filepath + "\n")
         self.AddEnvIntoBashrc("export OCT=" + self.OCT)
index bdd0e12..f0bafd7 100644 (file)
@@ -32,35 +32,38 @@ class environment( connection ):
         codeurl: clone code url
         """
         print "Now loading test codes! Please wait in patient..."
         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
         gitclone = handle
         gitclone.sendline( "git clone " + codeurl )
         index = 0
+        increment = 0
         while index != 1 or index != 4:
         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
             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!' )
                 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 :
                 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
             else :
                 self.loginfo.log( 'Download code failed!' )
                 self.loginfo.log( 'Information before' + gitclone.before )
                 break
-            time.sleep(5)
         gitclone.prompt( )
 
     def InstallDefaultSoftware( self, handle ):
         gitclone.prompt( )
 
     def InstallDefaultSoftware( self, handle ):
@@ -119,6 +122,12 @@ class environment( connection ):
         agentpass: onos cluster&compute node password
         """
         print "Now Setting test environment"
         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.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)
 
         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
     def ChangeOnosName( self, user, password):
         """
         Change onos name in envDefault file
@@ -204,11 +231,21 @@ class environment( connection ):
         handle.logout()
 
     def CopyOnostoTestbin( self ):
         handle.logout()
 
     def CopyOnostoTestbin( self ):
-        sourcefile = os.curdir + '/dependencies/onos'
+        sourcefile = self.cipath + '/dependencies/onos'
         destifile = self.home + '/onos/tools/test/bin/'
         destifile = self.home + '/onos/tools/test/bin/'
+        os.system( 'pwd' )
         runcommand = 'cp ' + sourcefile + ' ' + destifile
         os.system( runcommand )
 
         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
     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.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 )
         self.CopyOnostoTestbin()
         self.ChangeOnosName(self.agentusername,self.agentpassword)
         self.InstallDefaultSoftware( handle )
index 9d0c634..83cbcb2 100644 (file)
@@ -8,15 +8,23 @@ import logging
 import os
 import time
 import yaml
 import os
 import time
 import yaml
+import re
+import datetime
 
 class foundation:
 
     def __init__(self):
 
 
 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 = ''
         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):
         """
 
     def log (self, loginfo):
         """
@@ -24,14 +32,12 @@ class foundation:
         parameters:
         loginfo(input): record info
         """
         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',
         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')
                 filemode = 'w')
-        filelog = logging.FileHandler( filepath )
+        filelog = logging.FileHandler( self.logfilepath )
         logging.getLogger( 'Functest' ).addHandler( filelog )
         print loginfo
         logging.info(loginfo)
         logging.getLogger( 'Functest' ).addHandler( filelog )
         print loginfo
         logging.info(loginfo)
@@ -40,7 +46,7 @@ class foundation:
         """
         Get Default Parameters value
         """
         """
         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()
 
             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.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
         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 (file)
index 0000000..e69de29
index e852443..675b3fc 100644 (file)
@@ -17,5 +17,8 @@ if __name__=="__main__":
     #scripts to run
     runhandle = main.onosstart()
     main.RunScript(runhandle, "FUNCvirNetNB")
     #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.onosclean( runhandle )
+    main.push_results_to_db(main.GetResult())
index be7687a..1063715 100644 (file)
@@ -139,12 +139,15 @@ ONOS:
         onoscli_password: 'root'
         runtimeout: 300
     environment:
         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
 
 results:
     test_db_url: http://213.77.62.197