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
21 from functest.utils.functest_utils import FUNCTEST_REPO as FUNCTEST_REPO
28 # currentpath = os.getcwd()
29 REPO_PATH = FUNCTEST_REPO + '/'
30 currentpath = REPO_PATH + 'testcases/Controllers/ONOS/Teston/CI'
31 self.cipath = currentpath
32 self.logdir = os.path.join(currentpath, 'log')
33 self.workhome = currentpath[0: currentpath.rfind('testcases') - 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)
55 def getdefaultpara(self):
57 Get Default Parameters value
59 with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
60 functest_yaml = yaml.safe_load(f)
62 self.Result_DB = str(functest_yaml.get("results").get("test_db_url"))
63 self.masterusername = str(functest_yaml.get("ONOS").get("general").
64 get('onosbench_username'))
65 self.masterpassword = str(functest_yaml.get("ONOS").get("general").
66 get("onosbench_password"))
67 self.agentusername = str(functest_yaml.get("ONOS").get("general").
68 get("onoscli_username"))
69 self.agentpassword = str(functest_yaml.get("ONOS").get("general").
70 get("onoscli_password"))
71 self.runtimeout = functest_yaml.get("ONOS").get("general").get(
73 self.OCT = str(functest_yaml.get("ONOS").get("environment").get("OCT"))
74 self.OC1 = str(functest_yaml.get("ONOS").get("environment").get("OC1"))
75 self.OC2 = str(functest_yaml.get("ONOS").get("environment").get("OC2"))
76 self.OC3 = str(functest_yaml.get("ONOS").get("environment").get("OC3"))
77 self.OCN = str(functest_yaml.get("ONOS").get("environment").get("OCN"))
78 self.OCN2 = str(functest_yaml.get("ONOS").
79 get("environment").get("OCN2"))
80 self.installer_master = str(functest_yaml.get("ONOS").
81 get("environment").get("installer_master"))
82 self.installer_master_username = str(functest_yaml.get("ONOS").
84 get("installer_master_username"))
85 self.installer_master_password = str(functest_yaml.get("ONOS").
87 get("installer_master_password"))
88 self.hosts = [self.OC1, self.OCN, self.OCN2]
89 self.localhost = self.OCT
92 cmd = "cat " + self.logfilepath + " | grep Fail"
93 Resultbuffer = os.popen(cmd).read()
94 duration = datetime.datetime.now() - self.starttime
97 if re.search("[1-9]+", Resultbuffer):
98 self.log("Testcase Fails\n" + Resultbuffer)
101 self.log("Testcases Pass")
103 payload = {'timestart': str(self.starttime),
104 'duration': str(duration), 'status': Result}