11 from robot.api import ExecutionResult, ResultVisitor
12 from robot.utils.robottime import timestamp_to_secs
14 import functest.utils.functest_logger as ft_logger
15 import functest.utils.functest_utils as ft_utils
18 class ODLResultVisitor(ResultVisitor):
23 def visit_test(self, test):
25 output['name'] = test.name
26 output['parent'] = test.parent.name
27 output['status'] = test.status
28 output['startime'] = test.starttime
29 output['endtime'] = test.endtime
30 output['critical'] = test.critical
31 output['text'] = test.message
32 output['elapsedtime'] = test.elapsedtime
33 self._data.append(output)
41 repos = "/home/opnfv/repos/"
42 odl_test_repo = repos + "odl_test/"
43 neutron_suite_dir = odl_test_repo + "csit/suites/openstack/neutron/"
44 basic_suite_dir = odl_test_repo + "csit/suites/integration/basic/"
45 res_dir = '/home/opnfv/functest/results/odl/'
46 logger = ft_logger.Logger("opendaylight").getLogger()
49 def copy_opnf_testcases(cls):
50 opnfv_testcases_dir = (os.path.dirname(os.path.abspath(__file__)) +
51 "/custom_tests/neutron/")
52 files = [opnfv_testcases_dir + "001__reachability.robot",
53 opnfv_testcases_dir + "040__delete_ports.robot",
54 opnfv_testcases_dir + "050__delete_subnets.robot",
55 opnfv_testcases_dir + "060__delete_networks.robot"]
58 shutil.copy(f, cls.neutron_suite_dir)
61 "Cannot copy OPNFV's testcases to ODL directory", e)
66 def set_robotframework_vars(cls, odlusername="admin", odlpassword="admin"):
67 odl_variables_files = cls.odl_test_repo + 'csit/variables/Variables.py'
69 cls.logger.debug(cls.neutron_suite_dir + '__init__.robot')
70 for line in fileinput.input(odl_variables_files,
72 print re.sub("AUTH = .*",
73 ("AUTH = [u'" + odlusername + "', u'" +
77 except Exception as e:
78 cls.logger.error("Cannot set ODL creds", e)
82 def run(cls, **kwargs):
83 dirs = [cls.basic_suite_dir, cls.neutron_suite_dir]
85 odlusername = kwargs['odlusername']
86 odlpassword = kwargs['odlpassword']
87 variables = ['KEYSTONE:' + kwargs['keystoneip'],
88 'NEUTRON:' + kwargs['neutronip'],
89 'OSUSERNAME:"' + kwargs['osusername'] + '"',
90 'OSTENANTNAME:"' + kwargs['ostenantname'] + '"',
91 'OSPASSWORD:"' + kwargs['ospassword'] + '"',
92 'ODL_SYSTEM_IP:' + kwargs['odlip'],
93 'PORT:' + kwargs['odlwebport'],
94 'RESTCONFPORT:' + kwargs['odlrestconfport']]
96 cls.logger.error("Cannot run ODL testcases. Please check", e)
98 if (cls.copy_opnf_testcases() and
99 cls.set_robotframework_vars(odlusername, odlpassword)):
101 os.makedirs(cls.res_dir)
104 stdout_file = cls.res_dir + 'stdout.txt'
105 with open(stdout_file, 'w') as stdout:
106 result = run(*dirs, variable=variables,
107 output=cls.res_dir + 'output.xml',
108 log=cls.res_dir + 'log.html',
109 report=cls.res_dir + 'report.html',
112 with open(stdout_file, 'r') as stdout:
113 cls.logger.info("\n" + stdout.read())
121 result = ExecutionResult(cls.res_dir + 'output.xml')
122 visitor = ODLResultVisitor()
123 result.visit(visitor)
124 start_time = timestamp_to_secs(result.suite.starttime)
125 stop_time = timestamp_to_secs(result.suite.endtime)
127 details['description'] = result.suite.name
128 details['tests'] = visitor.get_data()
129 if not ft_utils.push_results_to_db(
130 "functest", "odl", None, start_time, stop_time,
131 result.suite.status, details):
132 cls.logger.error("Cannot push ODL results to DB")
138 if __name__ == '__main__':
139 parser = argparse.ArgumentParser()
140 parser.add_argument('-k', '--keystoneip',
143 parser.add_argument('-n', '--neutronip',
146 parser.add_argument('-a', '--osusername',
147 help='Username for OpenStack',
149 parser.add_argument('-b', '--ostenantname',
150 help='Tenantname for OpenStack',
152 parser.add_argument('-c', '--ospassword',
153 help='Password for OpenStack',
155 parser.add_argument('-o', '--odlip',
156 help='OpenDaylight IP',
158 parser.add_argument('-w', '--odlwebport',
159 help='OpenDaylight Web Portal Port',
161 parser.add_argument('-r', '--odlrestconfport',
162 help='OpenDaylight RESTConf Port',
164 parser.add_argument('-d', '--odlusername',
165 help='Username for ODL',
167 parser.add_argument('-e', '--odlpassword',
168 help='Password for ODL',
170 parser.add_argument('-p', '--pushtodb',
171 help='Push results to DB',
174 args = vars(parser.parse_args())
175 ODLTestCases.run(**args)
177 sys.exit(not ODLTestCases.push_to_db())