aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xci/run_tests.py12
-rwxr-xr-xtestcases/Controllers/ODL/OpenDaylightTesting.py104
2 files changed, 60 insertions, 56 deletions
diff --git a/ci/run_tests.py b/ci/run_tests.py
index 638a6edf..834a29bf 100755
--- a/ci/run_tests.py
+++ b/ci/run_tests.py
@@ -17,12 +17,14 @@ import argparse
import functest.ci.generate_report as generate_report
import functest.ci.tier_builder as tb
+import functest.core.TestCasesBase as TestCasesBase
import functest.utils.functest_logger as ft_logger
import functest.utils.functest_utils as ft_utils
import functest.utils.openstack_clean as os_clean
import functest.utils.openstack_snapshot as os_snapshot
import functest.utils.openstack_utils as os_utils
-from functest.testcases.Controllers.ODL.OpenDaylightTesting import ODLTestCases
+import functest.testcases.Controllers.ODL.OpenDaylightTesting as odl_test
+
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--test", dest="test", action='store',
@@ -101,10 +103,10 @@ def run_test(test, tier_name):
flags += " -r"
if test_name == 'odl':
- result = ODLTestCases.functest_run()
- if result and REPORT_FLAG:
- result = ODLTestCases.push_to_db()
- result = not result
+ odl = odl_test.ODLTestCases()
+ result = odl.run()
+ if result == TestCasesBase.TestCasesBase.EX_OK and REPORT_FLAG:
+ result = odl.push_to_db()
else:
cmd = ("%s%s" % (EXEC_SCRIPT, flags))
logger.debug("Executing command '%s'" % cmd)
diff --git a/testcases/Controllers/ODL/OpenDaylightTesting.py b/testcases/Controllers/ODL/OpenDaylightTesting.py
index 35a2ee11..0ee37b64 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
@@ -13,8 +14,8 @@ from robot.api import ExecutionResult, ResultVisitor
from robot.errors import RobotError
from robot.utils.robottime import timestamp_to_secs
+import functest.core.TestCasesBase as 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,6 +49,9 @@ 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__)) +
@@ -76,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']
@@ -91,35 +105,44 @@ class ODLTestCases:
'PORT:' + kwargs['odlwebport'],
'RESTCONFPORT:' + kwargs['odlrestconfport']]
except KeyError as e:
- cls.logger.error("Cannot run ODL testcases. Please check "
- "%s" % str(e))
+ self.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)):
+ 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',
+ 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
+ return self.EX_OK
else:
- return False
+ return self.EX_RUN_ERROR
- @classmethod
- def functest_run(cls):
+ def run(self):
kclient = op_utils.get_keystone_client()
keystone_url = kclient.service_catalog.url_for(
service_type='identity', endpoint_type='publicURL')
@@ -149,34 +172,12 @@ 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
+ return self.main(**kwargs)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
@@ -215,8 +216,9 @@ if __name__ == '__main__':
action='store_true')
args = vars(parser.parse_args())
- if not ODLTestCases.run(**args):
- sys.exit(os.EX_SOFTWARE)
+ odl = ODLTestCases()
+ result = odl.main(**args)
+ if result != TestCasesBase.TestCasesBase.EX_OK:
+ sys.exit(result)
if args['pushtodb']:
- sys.exit(not ODLTestCases.push_to_db())
- sys.exit(os.EX_OK)
+ sys.exit(odl.push_to_db())
dify this command line for # debugging purposes. For example: # # docker-toool -c swift-proxy -r -e /bin/bash -u root -i -n test # # will run the swift proxy container as user root, executing /bin/bash, # # named 'test', and will run interactively (eg -ti). def parse_opts(argv): parser = argparse.ArgumentParser("Tool to start docker containers via " "TripleO configurations") parser.add_argument('-f', '--config', help="""File to use as docker startup configuration data.""", default='/var/lib/docker-container-startup-configs.json') parser.add_argument('-r', '--run', action='store_true', help="""Run the container as specified with --container.""", default=False) parser.add_argument('-e', '--command', help="""Override the command used to run the container.""", default='') parser.add_argument('-c', '--container', help="""Specify a container to run or show the command for.""", default='') parser.add_argument('-u', '--user', help="""User to run container as.""", default='') parser.add_argument('-n', '--name', help="""Name of container.""", default='') parser.add_argument('-i', '--interactive', action='store_true', help="""Start docker container interactively (-ti).""", default=False) opts = parser.parse_args(argv[1:]) return opts def docker_arg_map(key, value): value = str(value).encode('ascii', 'ignore') return { 'environment': "--env=%s" % value, # 'image': value, 'net': "--net=%s" % value, 'pid': "--pid=%s" % value, 'privileged': "--privileged=%s" % value.lower(), #'restart': "--restart=%s" % "false", 'user': "--user=%s" % value, 'volumes': "--volume=%s" % value, 'volumes_from': "--volumes-from=%s" % value, }.get(key, None) def run_docker_container(opts, container_name): container_found = False with open(opts.config) as f: json_data = json.load(f) for step in (json_data or []): if step is None: continue for container in (json_data[step] or []): if container == container_name: print('container found: %s' % container) container_found = True # A few positional arguments: command = '' image = '' cmd = [ docker_cmd, 'run', '--name', opts.name or container ] for container_data in (json_data[step][container] or []): if container_data == "environment": for env in (json_data[step][container][container_data] or []): arg = docker_arg_map("environment", env) if arg: cmd.append(arg) elif container_data == "volumes": for volume in (json_data[step][container][container_data] or []): arg = docker_arg_map("volumes", volume) if arg: cmd.append(arg) elif container_data == "volumes_from": for volume in (json_data[step][container][container_data] or []): arg = docker_arg_map("volumes_from", volume) if arg: cmd.append(arg) elif container_data == 'command': command = json_data[step][container][container_data] elif container_data == 'image': image = json_data[step][container][container_data] else: # Only add a restart if we're not interactive if container_data == 'restart': if opts.interactive: continue if container_data == 'user': if opts.user: continue arg = docker_arg_map(container_data, json_data[step][container][container_data]) if arg: cmd.append(arg) if opts.user: cmd.append('--user') cmd.append(opts.user) if opts.interactive: cmd.append('-ti') # May as well remove it when we're done too cmd.append('--rm') cmd.append(image) if opts.command: cmd.append(opts.command) elif command: cmd.extend(command) print ' '.join(cmd) if opts.run: os.execl(docker_cmd, *cmd) if not container_found: print("Container '%s' not found!" % container_name) def list_docker_containers(opts): print opts with open(opts.config) as f: json_data = json.load(f) for step in (json_data or []): if step is None: continue print step for container in (json_data[step] or []): print('\tcontainer: %s' % container) for container_data in (json_data[step][container] or []): #print('\t\tcontainer_data: %s' % container_data) if container_data == "start_order": print('\t\tstart_order: %s' % json_data[step][container][container_data]) opts = parse_opts(sys.argv) if opts.container: run_docker_container(opts, opts.container) else: list_docker_containers(opts)