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
21 import functest.utils.functest_utils as ft_utils
24 class Foundation(object):
28 # currentpath = os.getcwd()
29 currentpath = ('{0}/sdn/onos/teston/ci'
30 .format(CONST.__getattribute__('dir_functest_data')))
31 self.cipath = currentpath
32 self.logdir = os.path.join(currentpath, 'log')
33 self.workhome = currentpath[0: currentpath.rfind('opnfv_tests') - 1]
35 filename = time.strftime('%Y-%m-%d-%H-%M-%S') + '.log'
36 self.logfilepath = os.path.join(self.logdir, filename)
37 self.starttime = datetime.datetime.now()
39 def log(self, loginfo):
41 Record log in log directory for deploying test environment
43 loginfo(input): record info
45 logging.basicConfig(level=logging.INFO,
46 format='%(asctime)s %(filename)s:%(message)s',
47 datefmt='%d %b %Y %H:%M:%S',
48 filename=self.logfilepath,
50 filelog = logging.FileHandler(self.logfilepath)
51 logging.getLogger('Functest').addHandler(filelog)
54 def getdefaultpara(self):
56 Get Default Parameters value
58 self.Result_DB = ft_utils.get_db_url()
59 self.masterusername = CONST.__getattribute__('ONOS_onosbench_username')
60 self.masterpassword = CONST.__getattribute__('ONOS_onosbench_password')
61 self.agentusername = CONST.__getattribute__('ONOS_onoscli_username')
62 self.agentpassword = CONST.__getattribute__('ONOS_onoscli_password')
63 self.runtimeout = CONST.__getattribute__('ONOS_runtimeout')
64 self.OCT = CONST.__getattribute__('ONOS_environment_OCT')
65 self.OC1 = CONST.__getattribute__('ONOS_environment_OC1')
66 self.OC2 = CONST.__getattribute__('ONOS_environment_OC2')
67 self.OC3 = CONST.__getattribute__('ONOS_environment_OC3')
68 self.OCN = CONST.__getattribute__('ONOS_environment_OCN')
69 self.OCN2 = CONST.__getattribute__('ONOS_environment_OCN2')
70 self.installer_master = CONST.__getattribute__(
71 'ONOS_environment_installer_master')
72 self.installer_master_username = (
73 CONST.__getattribute__(
74 'ONOS_environment_installer_master_username'))
75 self.installer_master_password = (
76 CONST.__getattribute__(
77 'ONOS_environment_installer_master_password'))
78 self.hosts = [self.OC1, self.OCN, self.OCN2]
79 self.localhost = self.OCT
82 cmd = "cat " + self.logfilepath + " | grep Fail"
83 Resultbuffer = os.popen(cmd).read()
84 duration = datetime.datetime.now() - self.starttime
87 if re.search("[1-9]+", Resultbuffer):
88 self.log("Testcase Fails\n" + Resultbuffer)
91 self.log("Testcases Pass")
93 payload = {'timestart': str(self.starttime),
94 'duration': str(duration), 'status': Result}