3 This file include basis functions
7 # All rights reserved. This program and the accompanying materials
8 # are made available under the terms of the Apache License, Version 2.0
9 # which accompanies this distribution, and is available at
10 # http://www.apache.org/licenses/LICENSE-2.0
20 import functest.utils.functest_utils as ft_utils
27 # currentpath = os.getcwd()
28 REPO_PATH = ft_utils.FUNCTEST_REPO + '/'
29 currentpath = REPO_PATH + 'opnfv_tests/Controllers/ONOS/Teston/CI'
30 self.cipath = currentpath
31 self.logdir = os.path.join(currentpath, 'log')
32 self.workhome = currentpath[0: currentpath.rfind('opnfv_tests') - 1]
34 filename = time.strftime('%Y-%m-%d-%H-%M-%S') + '.log'
35 self.logfilepath = os.path.join(self.logdir, filename)
36 self.starttime = datetime.datetime.now()
38 def log(self, loginfo):
40 Record log in log directory for deploying test environment
42 loginfo(input): record info
44 logging.basicConfig(level=logging.INFO,
45 format='%(asctime)s %(filename)s:%(message)s',
46 datefmt='%d %b %Y %H:%M:%S',
47 filename=self.logfilepath,
49 filelog = logging.FileHandler(self.logfilepath)
50 logging.getLogger('Functest').addHandler(filelog)
53 def getdefaultpara(self):
55 Get Default Parameters value
58 ft_utils.get_functest_config('results.test_db_url'))
59 self.masterusername = str(
60 ft_utils.get_functest_config('ONOS.general.onosbench_username'))
61 self.masterpassword = str(
62 ft_utils.get_functest_config('ONOS.general.onosbench_password'))
63 self.agentusername = str(
64 ft_utils.get_functest_config('ONOS.general.onoscli_username'))
65 self.agentpassword = str(
66 ft_utils.get_functest_config('ONOS.general.onoscli_password'))
68 ft_utils.get_functest_config('ONOS.general.runtimeout')
69 self.OCT = str(ft_utils.get_functest_config('ONOS.environment.OCT'))
70 self.OC1 = str(ft_utils.get_functest_config('ONOS.environment.OC1'))
71 self.OC2 = str(ft_utils.get_functest_config('ONOS.environment.OC2'))
72 self.OC3 = str(ft_utils.get_functest_config('ONOS.environment.OC3'))
73 self.OCN = str(ft_utils.get_functest_config('ONOS.environment.OCN'))
74 self.OCN2 = str(ft_utils.get_functest_config('ONOS.environment.OCN2'))
75 self.installer_master = str(
76 ft_utils.get_functest_config('ONOS.environment.installer_master'))
77 self.installer_master_username = str(ft_utils.get_functest_config(
78 'ONOS.environment.installer_master_username'))
79 self.installer_master_password = str(ft_utils.get_functest_config(
80 'ONOS.environment.installer_master_password'))
81 self.hosts = [self.OC1, self.OCN, self.OCN2]
82 self.localhost = self.OCT
85 cmd = "cat " + self.logfilepath + " | grep Fail"
86 Resultbuffer = os.popen(cmd).read()
87 duration = datetime.datetime.now() - self.starttime
90 if re.search("[1-9]+", Resultbuffer):
91 self.log("Testcase Fails\n" + Resultbuffer)
94 self.log("Testcases Pass")
96 payload = {'timestart': str(self.starttime),
97 'duration': str(duration), 'status': Result}