aboutsummaryrefslogtreecommitdiffstats
path: root/testcases/Controllers/ODL/OpenDaylightTesting.py
diff options
context:
space:
mode:
Diffstat (limited to 'testcases/Controllers/ODL/OpenDaylightTesting.py')
-rwxr-xr-xtestcases/Controllers/ODL/OpenDaylightTesting.py173
1 files changed, 89 insertions, 84 deletions
diff --git a/testcases/Controllers/ODL/OpenDaylightTesting.py b/testcases/Controllers/ODL/OpenDaylightTesting.py
index 173de87f9..e302b569e 100755
--- a/testcases/Controllers/ODL/OpenDaylightTesting.py
+++ b/testcases/Controllers/ODL/OpenDaylightTesting.py
@@ -1,6 +1,7 @@
#!/usr/bin/python
import argparse
+import errno
import fileinput
import os
import re
@@ -8,13 +9,13 @@ import shutil
import sys
import urlparse
-from robot import run
from robot.api import ExecutionResult, ResultVisitor
from robot.errors import RobotError
+import robot.run
from robot.utils.robottime import timestamp_to_secs
+from functest.core import TestCasesBase
import functest.utils.functest_logger as ft_logger
-import functest.utils.functest_utils as ft_utils
import functest.utils.openstack_utils as op_utils
@@ -39,7 +40,7 @@ class ODLResultVisitor(ResultVisitor):
return self._data
-class ODLTestCases:
+class ODLTestCases(TestCasesBase.TestCasesBase):
repos = "/home/opnfv/repos/"
odl_test_repo = repos + "odl_test/"
@@ -48,22 +49,20 @@ class ODLTestCases:
res_dir = '/home/opnfv/functest/results/odl/'
logger = ft_logger.Logger("opendaylight").getLogger()
+ def __init__(self):
+ self.case_name = "odl"
+
@classmethod
def copy_opnf_testcases(cls):
opnfv_testcases_dir = (os.path.dirname(os.path.abspath(__file__)) +
"/custom_tests/neutron/")
- files = [opnfv_testcases_dir + "001__reachability.robot",
- opnfv_testcases_dir + "040__delete_ports.robot",
- opnfv_testcases_dir + "050__delete_subnets.robot",
- opnfv_testcases_dir + "060__delete_networks.robot"]
- for f in files:
- try:
- shutil.copy(f, cls.neutron_suite_dir)
- except IOError as e:
- cls.logger.error(
- "Cannot copy OPNFV's testcases to ODL directory: "
- "%s" % str(e))
- return False
+ f = opnfv_testcases_dir + "001__reachability.robot"
+ try:
+ shutil.copy(f, cls.neutron_suite_dir)
+ except IOError as e:
+ cls.logger.error(
+ "Cannot copy OPNFV's testcase to ODL directory: %s" % str(e))
+ return False
return True
@classmethod
@@ -81,9 +80,19 @@ class ODLTestCases:
cls.logger.error("Cannot set ODL creds: %s" % str(e))
return False
- @classmethod
- def run(cls, **kwargs):
- dirs = [cls.basic_suite_dir, cls.neutron_suite_dir]
+ def parse_results(self):
+ result = ExecutionResult(self.res_dir + 'output.xml')
+ visitor = ODLResultVisitor()
+ result.visit(visitor)
+ self.criteria = result.suite.status
+ self.start_time = timestamp_to_secs(result.suite.starttime)
+ self.stop_time = timestamp_to_secs(result.suite.endtime)
+ self.details = {}
+ self.details['description'] = result.suite.name
+ self.details['tests'] = visitor.get_data()
+
+ def main(self, **kwargs):
+ dirs = [self.basic_suite_dir, self.neutron_suite_dir]
try:
odlusername = kwargs['odlusername']
odlpassword = kwargs['odlpassword']
@@ -96,49 +105,60 @@ class ODLTestCases:
'PORT:' + kwargs['odlwebport'],
'RESTCONFPORT:' + kwargs['odlrestconfport']]
except KeyError as e:
- cls.logger.error("Cannot run ODL testcases. Please check "
- "%s" % str(e))
- return False
- if (cls.copy_opnf_testcases() and
- cls.set_robotframework_vars(odlusername, odlpassword)):
+ self.logger.error("Cannot run ODL testcases. Please check "
+ "%s" % str(e))
+ return self.EX_RUN_ERROR
+ if (self.copy_opnf_testcases() and
+ self.set_robotframework_vars(odlusername, odlpassword)):
try:
- os.makedirs(cls.res_dir)
- except OSError:
- pass
- stdout_file = cls.res_dir + 'stdout.txt'
+ os.makedirs(self.res_dir)
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ self.logger.exception(
+ "Cannot create {}".format(self.res_dir))
+ return self.EX_RUN_ERROR
+ stdout_file = self.res_dir + 'stdout.txt'
with open(stdout_file, 'w+') as stdout:
- run(*dirs, variable=variables,
- output=cls.res_dir + 'output.xml',
- log='NONE',
- report='NONE',
- stdout=stdout)
+ robot.run(*dirs, variable=variables,
+ output=self.res_dir + 'output.xml',
+ log='NONE',
+ report='NONE',
+ stdout=stdout)
stdout.seek(0, 0)
- cls.logger.info("\n" + stdout.read())
- cls.logger.info("ODL results were successfully generated")
+ self.logger.info("\n" + stdout.read())
+ self.logger.info("ODL results were successfully generated")
+ try:
+ self.parse_results()
+ self.logger.info("ODL results were successfully parsed")
+ except RobotError as e:
+ self.logger.error("Run tests before publishing: %s" %
+ e.message)
+ return self.EX_RUN_ERROR
try:
os.remove(stdout_file)
except OSError:
- pass
- return True
+ self.logger.warning("Cannot remove {}".format(stdout_file))
+ return self.EX_OK
else:
- return False
+ return self.EX_RUN_ERROR
- @classmethod
- def functest_run(cls):
- kclient = op_utils.get_keystone_client()
- keystone_url = kclient.service_catalog.url_for(
- service_type='identity', endpoint_type='publicURL')
- neutron_url = kclient.service_catalog.url_for(
- service_type='network', endpoint_type='publicURL')
- kwargs = {'keystoneip': urlparse.urlparse(keystone_url).hostname}
- kwargs['neutronip'] = urlparse.urlparse(neutron_url).hostname
- kwargs['odlip'] = kwargs['neutronip']
- kwargs['odlwebport'] = '8080'
- kwargs['odlrestconfport'] = '8181'
- kwargs['odlusername'] = 'admin'
- kwargs['odlpassword'] = 'admin'
+ def run(self):
try:
- installer_type = os.environ['INSTALLER_TYPE']
+ kclient = op_utils.get_keystone_client()
+ keystone_url = kclient.service_catalog.url_for(
+ service_type='identity', endpoint_type='publicURL')
+ neutron_url = kclient.service_catalog.url_for(
+ service_type='network', endpoint_type='publicURL')
+ kwargs = {'keystoneip': urlparse.urlparse(keystone_url).hostname}
+ kwargs['neutronip'] = urlparse.urlparse(neutron_url).hostname
+ kwargs['odlip'] = kwargs['neutronip']
+ kwargs['odlwebport'] = '8080'
+ kwargs['odlrestconfport'] = '8181'
+ kwargs['odlusername'] = 'admin'
+ kwargs['odlpassword'] = 'admin'
+ installer_type = None
+ if 'INSTALLER_TYPE' in os.environ:
+ installer_type = os.environ['INSTALLER_TYPE']
kwargs['osusername'] = os.environ['OS_USERNAME']
kwargs['ostenantname'] = os.environ['OS_TENANT_NAME']
kwargs['ospassword'] = os.environ['OS_PASSWORD']
@@ -154,34 +174,15 @@ class ODLTestCases:
else:
kwargs['odlip'] = os.environ['SDN_CONTROLLER_IP']
except KeyError as e:
- cls.logger.error("Cannot run ODL testcases. Please check env var: "
- "%s" % str(e))
- return False
-
- return cls.run(**kwargs)
-
- @classmethod
- def push_to_db(cls):
- try:
- result = ExecutionResult(cls.res_dir + 'output.xml')
- visitor = ODLResultVisitor()
- result.visit(visitor)
- start_time = timestamp_to_secs(result.suite.starttime)
- stop_time = timestamp_to_secs(result.suite.endtime)
- details = {}
- details['description'] = result.suite.name
- details['tests'] = visitor.get_data()
- if not ft_utils.push_results_to_db(
- "functest", "odl", start_time, stop_time,
- result.suite.status, details):
- cls.logger.error("Cannot push ODL results to DB")
- return False
- else:
- cls.logger.info("ODL results were successfully pushed to DB")
- return True
- except RobotError as e:
- cls.logger.error("Run tests before publishing: %s" % e.message)
+ self.logger.error("Cannot run ODL testcases. "
+ "Please check env var: "
+ "%s" % str(e))
+ return self.EX_RUN_ERROR
+ except Exception:
+ self.logger.exception("Cannot run ODL testcases.")
+ return self.EX_RUN_ERROR
+ return self.main(**kwargs)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
@@ -220,8 +221,12 @@ if __name__ == '__main__':
action='store_true')
args = vars(parser.parse_args())
- if not ODLTestCases.run(**args):
- sys.exit(os.EX_SOFTWARE)
- if args['pushtodb']:
- sys.exit(not ODLTestCases.push_to_db())
- sys.exit(os.EX_OK)
+ odl = ODLTestCases()
+ try:
+ result = odl.main(**args)
+ if result != TestCasesBase.TestCasesBase.EX_OK:
+ sys.exit(result)
+ if args['pushtodb']:
+ sys.exit(odl.push_to_db())
+ except Exception:
+ sys.exit(TestCasesBase.TestCasesBase.EX_RUN_ERROR)