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 from functest.utils.constants import CONST
23 class Foundation(object):
27 # currentpath = os.getcwd()
28 currentpath = ('{0}/sdn/onos/teston/ci'
29 .format(CONST.__getattribute__('dir_functest_data')))
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
57 self.Result_DB = CONST.__getattribute__("results_test_db_url")
58 self.masterusername = CONST.__getattribute__('ONOS_onosbench_username')
59 self.masterpassword = CONST.__getattribute__('ONOS_onosbench_password')
60 self.agentusername = CONST.__getattribute__('ONOS_onoscli_username')
61 self.agentpassword = CONST.__getattribute__('ONOS_onoscli_password')
62 self.runtimeout = CONST.__getattribute__('ONOS_runtimeout')
63 self.OCT = CONST.__getattribute__('ONOS_environment_OCT')
64 self.OC1 = CONST.__getattribute__('ONOS_environment_OC1')
65 self.OC2 = CONST.__getattribute__('ONOS_environment_OC2')
66 self.OC3 = CONST.__getattribute__('ONOS_environment_OC3')
67 self.OCN = CONST.__getattribute__('ONOS_environment_OCN')
68 self.OCN2 = CONST.__getattribute__('ONOS_environment_OCN2')
69 self.installer_master = CONST.__getattribute__(
70 'ONOS_environment_installer_master')
71 self.installer_master_username = (
72 CONST.__getattribute__(
73 'ONOS_environment_installer_master_username'))
74 self.installer_master_password = (
75 CONST.__getattribute__(
76 'ONOS_environment_installer_master_password'))
77 self.hosts = [self.OC1, self.OCN, self.OCN2]
78 self.localhost = self.OCT
81 cmd = "cat " + self.logfilepath + " | grep Fail"
82 Resultbuffer = os.popen(cmd).read()
83 duration = datetime.datetime.now() - self.starttime
86 if re.search("[1-9]+", Resultbuffer):
87 self.log("Testcase Fails\n" + Resultbuffer)
90 self.log("Testcases Pass")
92 payload = {'timestart': str(self.starttime),
93 'duration': str(duration), 'status': Result}