# http://www.apache.org/licenses/LICENSE-2.0
#
"""
-from environment import environment
-import time
+import json
import pexpect
import requests
-import json
+import time
+
+from environment import environment
+import functest.utils.functest_logger as ft_logger
class client(environment):
+ logger = ft_logger.Logger("client").getLogger()
+
def __init__(self):
environment.__init__(self)
self.loginfo = environment()
[len(lastshowscreeninfo)::])
lastshowscreeninfo = curshowscreeninfo
if Result == 0:
- print "Done!"
+ self.logger.info("Done!")
return
time.sleep(1)
circletime += 1
def onosstart(self):
# This is the compass run machine user&pass,you need to modify
- print "Test Begin....."
+ self.logger.info("Test Begin.....")
self.OnosConnectionSet()
masterhandle = self.SSHlogin(self.localhost, self.masterusername,
self.masterpassword)
import os
import pexpect
import re
+
from foundation import foundation
+import functest.utils.functest_logger as ft_logger
class connection(foundation):
+ logger = ft_logger.Logger("connection").getLogger()
+
def __init__(self):
foundation.__init__(self)
self.loginfo = foundation()
username: login user name
password: login password
"""
- print("Now Adding an user to known hosts " + ipaddr)
+ self.logger.info("Now Adding an user to known hosts " + ipaddr)
login = handle
login.sendline("ssh -l %s -p 8101 %s" % (username, ipaddr))
index = 0
"""
Generate ssh keys, used for some server have no sshkey.
"""
- print "Now Generating SSH keys..."
+ self.logger.info("Now Generating SSH keys...")
# Here file name may be id_rsa or id_ecdsa or others
# So here will have a judgement
keysub = handle
parameters:
password: root login password
"""
- print("Now changing to user root")
+ self.logger.info("Now changing to user root")
login = pexpect.spawn("su - root")
index = 0
while index != 2:
"""
Exit root user.
"""
- print("Now Release user root")
+ self.logger.info("Now Release user root")
login = pexpect.spawn("exit")
index = login.expect(['logout', pexpect.EOF, pexpect.TIMEOUT])
if index == 0:
parameters:
envalue: environment value to add
"""
- print "Now Adding bash environment"
+ self.logger.info("Now Adding bash environment")
fileopen = open("/etc/profile", 'r')
findContext = 1
while findContext:
Change ONOS root path in file:bash_profile
onospath: path of onos root
"""
- print "Now Changing ONOS Root Path"
+ self.logger.info("Now Changing ONOS Root Path")
filepath = onospath + 'onos/tools/dev/bash_profile'
line = open(filepath, 'r').readlines()
lenall = len(line) - 1
NewFile = open(filepath, 'w')
NewFile.writelines(line)
NewFile.close
- print "Done!"
+ self.logger.info("Done!")
def OnosConnectionSet(self):
"""
#
"""
-import os
-import time
import pexpect
+import pxssh
import re
+import os
import sys
-import pxssh
+import time
+
from connection import connection
+import functest.utils.functest_logger as ft_logger
class environment(connection):
+ logger = ft_logger.Logger("environment").getLogger()
+
def __init__(self):
connection.__init__(self)
self.loginfo = connection()
handle: current working handle
codeurl: clone code url
"""
- print "Now loading test codes! Please wait in patient..."
+ self.logger.info("Now loading test codes! Please wait in patient...")
originalfolder = sys.path[0]
- print originalfolder
+ self.logger.info(originalfolder)
gitclone = handle
gitclone.sendline("git clone " + codeurl)
index = 0
parameters:
handle(input): current working handle
"""
- print "Now Cleaning test environment"
+ self.logger.info("Now Cleaning test environment")
handle.sendline("sudo apt-get install -y mininet")
handle.prompt()
handle.sendline("sudo pip install configobj")
cmd(input): onos-push-keys xxx(xxx is device)
password(input): login in password
"""
- print "Now Pushing Onos Keys:" + cmd
+ self.logger.info("Now Pushing Onos Keys:" + cmd)
Pushkeys = handle
Pushkeys.sendline(cmd)
Result = 0
break
time.sleep(2)
Pushkeys.prompt()
- print "Done!"
+ self.logger.info("Done!")
def SetOnosEnvVar(self, handle, masterpass, agentpass):
"""
masterpass: scripts running server's password
agentpass: onos cluster&compute node password
"""
- print "Now Setting test environment"
+ self.logger.info("Now Setting test environment")
for host in self.hosts:
- print "try to connect " + str(host)
+ self.logger.info("try to connect " + str(host))
result = self.CheckSshNoPasswd(host)
if not result:
- print ("ssh login failed,try to copy master publickey" +
- "to agent " + str(host))
+ self.logger.info(
+ "ssh login 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)
user: onos&compute node user
password: onos&compute node password
"""
- print "Now Changing ONOS name&password"
+ self.logger.info("Now Changing ONOS name&password")
filepath = self.home + '/onos/tools/build/envDefaults'
line = open(filepath, 'r').readlines()
lenall = len(line) - 1
NewFile = open(filepath, 'w')
NewFile.writelines(line)
NewFile.close
- print "Done!"
+ self.logger.info("Done!")
def ChangeTestCasePara(self, testcase, user, password):
"""
user: onos&compute node user
password: onos&compute node password
"""
- print "Now Changing " + testcase + " name&password"
+ self.logger.info("Now Changing " + testcase + " name&password")
if self.masterusername == 'root':
filepath = '/root/'
else:
login.sendline('ls -l')
# match prompt
login.prompt()
- print("SSH login " + ipaddr + " success!")
+ self.logger.info("SSH login " + ipaddr + " success!")
return login
def SSHRelease(self, handle):
str(publickey) + ">>/root/.ssh/authorized_keys\'")
tmphandle.prompt()
self.SSHRelease(tmphandle)
- print "Add OCT PublicKey to " + host + " success"
+ self.logger.info("Add OCT PublicKey to " + host + " success")
def OnosEnvSetup(self, handle):
"""