diff options
Diffstat (limited to 'testcases')
-rw-r--r-- | testcases/Controllers/ONOS/Teston/adapters/client.py | 14 | ||||
-rw-r--r-- | testcases/Controllers/ONOS/Teston/adapters/connection.py | 18 | ||||
-rw-r--r-- | testcases/Controllers/ONOS/Teston/adapters/environment.py | 39 | ||||
-rw-r--r-- | testcases/Controllers/ONOS/Teston/adapters/foundation.py | 3 | ||||
-rwxr-xr-x | testcases/features/copper.py | 16 | ||||
-rwxr-xr-x | testcases/features/doctor.py | 28 | ||||
-rwxr-xr-x | testcases/features/domino.py | 9 |
7 files changed, 81 insertions, 46 deletions
diff --git a/testcases/Controllers/ONOS/Teston/adapters/client.py b/testcases/Controllers/ONOS/Teston/adapters/client.py index 77de092e4..6b3285e5e 100644 --- a/testcases/Controllers/ONOS/Teston/adapters/client.py +++ b/testcases/Controllers/ONOS/Teston/adapters/client.py @@ -10,15 +10,19 @@ Description: # 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() @@ -50,7 +54,7 @@ class client(environment): [len(lastshowscreeninfo)::]) lastshowscreeninfo = curshowscreeninfo if Result == 0: - print "Done!" + self.logger.info("Done!") return time.sleep(1) circletime += 1 @@ -61,7 +65,7 @@ class client(environment): 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) diff --git a/testcases/Controllers/ONOS/Teston/adapters/connection.py b/testcases/Controllers/ONOS/Teston/adapters/connection.py index 16f2ef32c..b2a2e3d88 100644 --- a/testcases/Controllers/ONOS/Teston/adapters/connection.py +++ b/testcases/Controllers/ONOS/Teston/adapters/connection.py @@ -16,11 +16,15 @@ Description: 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() @@ -33,7 +37,7 @@ class connection(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 @@ -78,7 +82,7 @@ class connection(foundation): """ 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 @@ -112,7 +116,7 @@ class connection(foundation): 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: @@ -129,7 +133,7 @@ class connection(foundation): """ 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: @@ -145,7 +149,7 @@ class connection(foundation): 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: @@ -165,7 +169,7 @@ class connection(foundation): 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 @@ -175,7 +179,7 @@ class connection(foundation): NewFile = open(filepath, 'w') NewFile.writelines(line) NewFile.close - print "Done!" + self.logger.info("Done!") def OnosConnectionSet(self): """ diff --git a/testcases/Controllers/ONOS/Teston/adapters/environment.py b/testcases/Controllers/ONOS/Teston/adapters/environment.py index 231677333..f2755b669 100644 --- a/testcases/Controllers/ONOS/Teston/adapters/environment.py +++ b/testcases/Controllers/ONOS/Teston/adapters/environment.py @@ -15,17 +15,21 @@ Description: # """ -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() @@ -39,9 +43,9 @@ class environment(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 @@ -82,7 +86,7 @@ class environment(connection): 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") @@ -102,7 +106,7 @@ class environment(connection): 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 @@ -121,7 +125,7 @@ class environment(connection): break time.sleep(2) Pushkeys.prompt() - print "Done!" + self.logger.info("Done!") def SetOnosEnvVar(self, handle, masterpass, agentpass): """ @@ -131,13 +135,14 @@ class environment(connection): 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) @@ -173,7 +178,7 @@ class environment(connection): 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 @@ -187,7 +192,7 @@ class environment(connection): NewFile = open(filepath, 'w') NewFile.writelines(line) NewFile.close - print "Done!" + self.logger.info("Done!") def ChangeTestCasePara(self, testcase, user, password): """ @@ -196,7 +201,7 @@ class environment(connection): 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: @@ -232,7 +237,7 @@ class environment(connection): 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): @@ -256,7 +261,7 @@ class environment(connection): 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): """ diff --git a/testcases/Controllers/ONOS/Teston/adapters/foundation.py b/testcases/Controllers/ONOS/Teston/adapters/foundation.py index 70c84ac02..3fae2a5d2 100644 --- a/testcases/Controllers/ONOS/Teston/adapters/foundation.py +++ b/testcases/Controllers/ONOS/Teston/adapters/foundation.py @@ -16,8 +16,8 @@ import logging import os import re import time - import yaml + from functest.utils.functest_utils import FUNCTEST_REPO as FUNCTEST_REPO @@ -49,7 +49,6 @@ class foundation: filemode='w') filelog = logging.FileHandler(self.logfilepath) logging.getLogger('Functest').addHandler(filelog) - print loginfo logging.info(loginfo) def getdefaultpara(self): diff --git a/testcases/features/copper.py b/testcases/features/copper.py index 73def7db2..9be909427 100755 --- a/testcases/features/copper.py +++ b/testcases/features/copper.py @@ -14,23 +14,24 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import argparse import sys import time -import argparse import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as functest_utils + parser = argparse.ArgumentParser() parser.add_argument("-r", "--report", help="Create json result file", action="store_true") args = parser.parse_args() -functest_yaml = functest_utils.get_functest_yaml() - -dirs = functest_yaml.get('general').get('directories') -COPPER_REPO = dirs.get('dir_repo_copper') +COPPER_REPO = functest_utils.get_parameter_from_yaml( + 'general.directories.dir_repo_copper') +RESULTS_DIR = functest_utils.get_parameter_from_yaml( + 'general.directories.dir_results') logger = ft_logger.Logger("copper").getLogger() @@ -40,7 +41,10 @@ def main(): start_time = time.time() - ret_val = functest_utils.execute_command(cmd, logger, exit_on_error=False) + log_file = RESULTS_DIR + "/copper.log" + ret_val = functest_utils.execute_command(cmd, + exit_on_error=False, + output_file=log_file) stop_time = time.time() duration = round(stop_time - start_time, 1) diff --git a/testcases/features/doctor.py b/testcases/features/doctor.py index 6e6f26f37..68c80a9e4 100755 --- a/testcases/features/doctor.py +++ b/testcases/features/doctor.py @@ -13,12 +13,14 @@ # 0.2: measure test duration and publish results under json format # # +import argparse +import os import time -import argparse import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as functest_utils + parser = argparse.ArgumentParser() parser.add_argument("-r", "--report", help="Create json result file", @@ -27,28 +29,40 @@ args = parser.parse_args() functest_yaml = functest_utils.get_functest_yaml() -dirs = functest_yaml.get('general').get('directories') -DOCTOR_REPO = dirs.get('dir_repo_doctor') +DOCTOR_REPO = functest_utils.get_parameter_from_yaml( + 'general.directories.dir_repo_doctor') +RESULTS_DIR = functest_utils.get_parameter_from_yaml( + 'general.directories.dir_results') logger = ft_logger.Logger("doctor").getLogger() def main(): exit_code = -1 + + # if the image name is explicitly set for the doctor suite, set it as + # enviroment variable + if 'doctor' in functest_yaml and 'image_name' in functest_yaml['doctor']: + os.environ["IMAGE_NAME"] = functest_yaml['doctor']['image_name'] + cmd = 'cd %s/tests && ./run.sh' % DOCTOR_REPO + log_file = RESULTS_DIR + "/doctor.log" + start_time = time.time() - ret = functest_utils.execute_command(cmd, logger, info=True, - exit_on_error=False) + ret = functest_utils.execute_command(cmd, + info=True, + exit_on_error=False, + output_file=log_file) stop_time = time.time() duration = round(stop_time - start_time, 1) if ret == 0: - logger.info("doctor OK") + logger.info("Doctor test case OK") test_status = 'OK' exit_code = 0 else: - logger.info("doctor FAILED") + logger.info("Doctor test case FAILED") test_status = 'NOK' details = { diff --git a/testcases/features/domino.py b/testcases/features/domino.py index cc98f546d..c717c060e 100755 --- a/testcases/features/domino.py +++ b/testcases/features/domino.py @@ -14,9 +14,9 @@ # 0.3: add report flag to push results when needed # +import argparse import time -import argparse import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as functest_utils @@ -31,15 +31,20 @@ functest_yaml = functest_utils.get_functest_yaml() dirs = functest_yaml.get('general').get('directories') DOMINO_REPO = dirs.get('dir_repo_domino') +RESULTS_DIR = functest_utils.get_parameter_from_yaml( + 'general.directories.dir_results') logger = ft_logger.Logger("domino").getLogger() def main(): cmd = 'cd %s && ./tests/run_multinode.sh' % DOMINO_REPO + log_file = RESULTS_DIR + "/domino.log" start_time = time.time() - ret = functest_utils.execute_command(cmd, logger, exit_on_error=False) + ret = functest_utils.execute_command(cmd, + exit_on_error=False, + output_file=log_file) stop_time = time.time() duration = round(stop_time - start_time, 1) |