summaryrefslogtreecommitdiffstats
path: root/testcases/Controllers/ONOS/Teston/CI/adapters/connection.py
diff options
context:
space:
mode:
Diffstat (limited to 'testcases/Controllers/ONOS/Teston/CI/adapters/connection.py')
-rw-r--r--testcases/Controllers/ONOS/Teston/CI/adapters/connection.py107
1 files changed, 53 insertions, 54 deletions
diff --git a/testcases/Controllers/ONOS/Teston/CI/adapters/connection.py b/testcases/Controllers/ONOS/Teston/CI/adapters/connection.py
index e2788b412..16f2ef32c 100644
--- a/testcases/Controllers/ONOS/Teston/CI/adapters/connection.py
+++ b/testcases/Controllers/ONOS/Teston/CI/adapters/connection.py
@@ -14,19 +14,18 @@ Description:
#
"""
import os
-import time
import pexpect
import re
-import sys
from foundation import foundation
-class connection( foundation ):
- def __init__( self ):
- foundation.__init__( self )
+class connection(foundation):
+
+ def __init__(self):
+ foundation.__init__(self)
self.loginfo = foundation()
- def AddKnownHost( self, handle, ipaddr, username, password ):
+ def AddKnownHost(self, handle, ipaddr, username, password):
"""
Add an user to known host,so that onos can login in with onos $ipaddr.
parameters:
@@ -34,29 +33,30 @@ class connection( foundation ):
username: login user name
password: login password
"""
- print( "Now Adding an user to known hosts " + ipaddr )
+ print("Now Adding an user to known hosts " + ipaddr)
login = handle
- login.sendline( "ssh -l %s -p 8101 %s"%( username, ipaddr ) )
+ login.sendline("ssh -l %s -p 8101 %s" % (username, ipaddr))
index = 0
while index != 2:
- index = login.expect( ['assword:', 'yes/no', pexpect.EOF, \
- pexpect.TIMEOUT] )
+ index = login.expect(['assword:', 'yes/no', pexpect.EOF,
+ pexpect.TIMEOUT])
if index == 0:
- login.sendline( password )
- login.sendline( "logout" )
- index = login.expect( ["closed", pexpect.EOF] )
+ login.sendline(password)
+ login.sendline("logout")
+ index = login.expect(["closed", pexpect.EOF])
if index == 0:
- self.loginfo.log( "Add SSH Known Host Success!" )
+ self.loginfo.log("Add SSH Known Host Success!")
break
else:
- self.loginfo.log( "Add SSH Known Host Failed! Please Check!" )
+ self.loginfo.log("Add SSH Known Host Failed! "
+ "Please Check!")
break
- login.prompt( )
+ login.prompt()
if index == 1:
login.sendline('yes')
- def GetEnvValue( self, handle, envname):
+ def GetEnvValue(self, handle, envname):
"""
os.getenv only returns current user value
GetEnvValue returns a environment value of
@@ -64,26 +64,26 @@ class connection( foundation ):
eg: GetEnvValue(handle,'HOME')
"""
envhandle = handle
- envhandle.sendline( 'echo $' + envname )
- envhandle.prompt( )
+ envhandle.sendline('echo $' + envname)
+ envhandle.prompt()
reg = envname + '\r\n(.*)\r'
- envaluereg = re.compile( reg )
- envalue = envaluereg.search( envhandle.before )
+ envaluereg = re.compile(reg)
+ envalue = envaluereg.search(envhandle.before)
if envalue:
return envalue.groups()[0]
else:
return None
- def Gensshkey( self, handle ):
+ def Gensshkey(self, handle):
"""
Generate ssh keys, used for some server have no sshkey.
"""
print "Now Generating SSH keys..."
- #Here file name may be id_rsa or id_ecdsa or others
- #So here will have a judgement
+ # Here file name may be id_rsa or id_ecdsa or others
+ # So here will have a judgement
keysub = handle
- filepath = self.GetEnvValue( keysub, 'HOME' ) + '/.ssh'
- filelist = os.listdir( filepath )
+ filepath = self.GetEnvValue(keysub, 'HOME') + '/.ssh'
+ filelist = os.listdir(filepath)
for item in filelist:
if 'id' in item:
self.loginfo.log("SSH keys are exsit in ssh directory.")
@@ -91,14 +91,14 @@ class connection( foundation ):
keysub.sendline("ssh-keygen -t rsa")
Result = 0
while Result != 2:
- Result = keysub.expect( ["Overwrite", "Enter", pexpect.EOF, \
- 'PEXPECT]#', pexpect.TIMEOUT])
+ Result = keysub.expect(["Overwrite", "Enter", pexpect.EOF,
+ 'PEXPECT]#', pexpect.TIMEOUT])
if Result == 0:
keysub.sendline("y")
if Result == 1 or Result == 2:
keysub.sendline("\n")
if Result == 3:
- self.loginfo.log( "Generate SSH key success." )
+ self.loginfo.log("Generate SSH key success.")
keysub.prompt()
break
if Result == 4:
@@ -106,33 +106,32 @@ class connection( foundation ):
keysub.prompt()
break
- def GetRootAuth( self, password ):
+ def GetRootAuth(self, password):
"""
Get root user
parameters:
password: root login password
"""
- print( "Now changing to user root" )
- login = pexpect.spawn( "su - root" )
+ print("Now changing to user root")
+ login = pexpect.spawn("su - root")
index = 0
while index != 2:
- index = login.expect( ['assword:', "failure", \
- pexpect.EOF, pexpect.TIMEOUT] )
+ index = login.expect(['assword:', "failure",
+ pexpect.EOF, pexpect.TIMEOUT])
if index == 0:
- login.sendline( password )
+ login.sendline(password)
if index == 1:
self.loginfo.log("Change user to root failed.")
login.interact()
- def ReleaseRootAuth( self ):
+ def ReleaseRootAuth(self):
"""
Exit root user.
"""
- print( "Now Release user root" )
- login = pexpect.spawn( "exit" )
- index = login.expect( ['logout', \
- pexpect.EOF, pexpect.TIMEOUT] )
+ print("Now Release user root")
+ login = pexpect.spawn("exit")
+ index = login.expect(['logout', pexpect.EOF, pexpect.TIMEOUT])
if index == 0:
self.loginfo.log("Release root user success.")
if index == 1:
@@ -140,28 +139,28 @@ class connection( foundation ):
login.interact()
- def AddEnvIntoBashrc( self, envalue ):
+ def AddEnvIntoBashrc(self, envalue):
"""
Add Env var into /etc/profile.
parameters:
envalue: environment value to add
"""
print "Now Adding bash environment"
- fileopen = open( "/etc/profile", 'r' )
+ fileopen = open("/etc/profile", 'r')
findContext = 1
while findContext:
- findContext = fileopen.readline( )
- result = findContext.find( envalue )
+ findContext = fileopen.readline()
+ result = findContext.find(envalue)
if result != -1:
break
fileopen.close
if result == -1:
- envAdd = open( "/etc/profile", 'a+' )
- envAdd.writelines( "\n" + envalue )
- envAdd.close( )
- self.loginfo.log( "Add env to bashrc success!" )
+ envAdd = open("/etc/profile", 'a+')
+ envAdd.writelines("\n" + envalue)
+ envAdd.close()
+ self.loginfo.log("Add env to bashrc success!")
- def OnosRootPathChange( self, onospath ):
+ def OnosRootPathChange(self, onospath):
"""
Change ONOS root path in file:bash_profile
onospath: path of onos root
@@ -171,22 +170,22 @@ class connection( foundation ):
line = open(filepath, 'r').readlines()
lenall = len(line) - 1
for i in range(lenall):
- if "export ONOS_ROOT" in line[i]:
- line[i] = 'export ONOS_ROOT=' + onospath + 'onos\n'
+ if "export ONOS_ROOT" in line[i]:
+ line[i] = 'export ONOS_ROOT=' + onospath + 'onos\n'
NewFile = open(filepath, 'w')
NewFile.writelines(line)
NewFile.close
print "Done!"
- def OnosConnectionSet (self):
+ def OnosConnectionSet(self):
"""
Intergrate for ONOS connection setup
"""
if self.masterusername == 'root':
filepath = '/root/'
- else :
+ else:
filepath = '/home/' + self.masterusername + '/'
- filepath = os.path.join( filepath, "onos/tools/dev/bash_profile" )
+ filepath = os.path.join(filepath, "onos/tools/dev/bash_profile")
self.AddEnvIntoBashrc("source " + filepath + "\n")
self.AddEnvIntoBashrc("export OCT=" + self.OCT)
self.AddEnvIntoBashrc("export OC1=" + self.OC1)