summaryrefslogtreecommitdiffstats
path: root/testcases/Controllers/ONOS/Teston/CI/adapters/client.py
blob: c84f187fab098a1cb854bbdffbefa4c4e0445eda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
Description:
    This file is used to run testcase
    lanqinglong@huawei.com
"""
from environment import environment
import os
import time
import pexpect
import re

class client( environment ):

    def __init__( self ):
        environment.__init__( self )
        self.loginfo = environment()

    def RunScript( self, handle, testname, timeout=300 ):
        """
        Run ONOS Test Script
        Parameters:
        testname: ONOS Testcase Name
        masterusername: The server username of running ONOS
        masterpassword: The server password of running ONOS
        """
        self.ChangeTestCasePara( testname, self.masterusername, self.masterpassword )
        runhandle = handle
        runtest = self.home + "/OnosSystemTest/TestON/bin/cli.py run " + testname
        runhandle.sendline(runtest)
        circletime = 0
        lastshowscreeninfo = ''
        while True:
            Result = runhandle.expect(["PEXPECT]#", pexpect.EOF, pexpect.TIMEOUT])
            curshowscreeninfo = runhandle.before
            if (len(lastshowscreeninfo) != len(curshowscreeninfo)):
                print str(curshowscreeninfo)[len(lastshowscreeninfo)::]
                lastshowscreeninfo = curshowscreeninfo
            if Result == 0:
                print "Done!"
                return
            time.sleep(1)
            circletime += 1
            if circletime > timeout:
                break
        self.loginfo.log( "Timeout when running the test, please check!" )

    def onosstart( self ):
        #This is the compass run machine user&pass,you need to modify

        print "Test Begin....."
        self.OnosConnectionSet()
        masterhandle = self.SSHlogin(self.localhost, self.masterusername,
                                    self.masterpassword)
        self.OnosEnvSetup( masterhandle )
        return masterhandle

    def onosclean( self, handle ):
        self.SSHRelease( handle )