aboutsummaryrefslogtreecommitdiffstats
path: root/functest/opnfv_tests/sdn
diff options
context:
space:
mode:
Diffstat (limited to 'functest/opnfv_tests/sdn')
-rwxr-xr-xfunctest/opnfv_tests/sdn/odl/odl.py133
-rw-r--r--functest/opnfv_tests/sdn/onos/onos.py8
2 files changed, 107 insertions, 34 deletions
diff --git a/functest/opnfv_tests/sdn/odl/odl.py b/functest/opnfv_tests/sdn/odl/odl.py
index c8e9c492..ccc1101a 100755
--- a/functest/opnfv_tests/sdn/odl/odl.py
+++ b/functest/opnfv_tests/sdn/odl/odl.py
@@ -7,6 +7,15 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
+"""Define classes required to run ODL suites.
+
+It has been designed for any context. But helpers are given for
+running test suites in OPNFV environment.
+
+Example:
+ $ python odl.py
+"""
+
import argparse
import errno
import fileinput
@@ -20,12 +29,15 @@ from robot.errors import RobotError
import robot.run
from robot.utils.robottime import timestamp_to_secs
-from functest.core import testcase_base
+from functest.core import testcase
import functest.utils.functest_logger as ft_logger
import functest.utils.openstack_utils as op_utils
+__author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
+
class ODLResultVisitor(robot.api.ResultVisitor):
+ """Visitor to get result details."""
def __init__(self):
self._data = []
@@ -43,10 +55,12 @@ class ODLResultVisitor(robot.api.ResultVisitor):
self._data.append(output)
def get_data(self):
+ """Get the details of the result."""
return self._data
-class ODLTests(testcase_base.TestcaseBase):
+class ODLTests(testcase.TestCase):
+ """ODL test runner."""
repos = "/home/opnfv/repos/"
odl_test_repo = os.path.join(repos, "odl_test")
@@ -59,11 +73,17 @@ class ODLTests(testcase_base.TestcaseBase):
logger = ft_logger.Logger("opendaylight").getLogger()
def __init__(self):
- testcase_base.TestcaseBase.__init__(self)
+ testcase.TestCase.__init__(self)
self.case_name = "odl"
@classmethod
def set_robotframework_vars(cls, odlusername="admin", odlpassword="admin"):
+ """Set credentials in csit/variables/Variables.py.
+
+ Returns:
+ True if credentials are set.
+ False otherwise.
+ """
odl_variables_files = os.path.join(cls.odl_test_repo,
'csit/variables/Variables.py')
try:
@@ -74,11 +94,12 @@ class ODLTests(testcase_base.TestcaseBase):
odlpassword + "']"),
line.rstrip())
return True
- except Exception as e:
- cls.logger.error("Cannot set ODL creds: %s" % str(e))
+ except Exception as ex: # pylint: disable=broad-except
+ cls.logger.error("Cannot set ODL creds: %s", str(ex))
return False
def parse_results(self):
+ """Parse output.xml and get the details in it."""
xml_file = os.path.join(self.res_dir, 'output.xml')
result = robot.api.ExecutionResult(xml_file)
visitor = ODLResultVisitor()
@@ -90,8 +111,38 @@ class ODLTests(testcase_base.TestcaseBase):
self.details['description'] = result.suite.name
self.details['tests'] = visitor.get_data()
- def main(self, suites=default_suites, **kwargs):
+ def main(self, suites=None, **kwargs):
+ """Run the test suites
+
+ It has been designed to be called in any context.
+ It requires the following keyword arguments:
+ * odlusername,
+ * odlpassword,
+ * osauthurl,
+ * neutronip,
+ * osusername,
+ * ostenantname,
+ * ospassword,
+ * odlip,
+ * odlwebport,
+ * odlrestconfport.
+
+ Here are the steps:
+ * set all RobotFramework_variables,
+ * create the output directories if required,
+ * get the results in output.xml,
+ * delete temporary files.
+
+ Args:
+ **kwargs: Arbitrary keyword arguments.
+
+ Returns:
+ EX_OK if all suites ran well.
+ EX_RUN_ERROR otherwise.
+ """
try:
+ if not suites:
+ suites = self.default_suites
odlusername = kwargs['odlusername']
odlpassword = kwargs['odlpassword']
osauthurl = kwargs['osauthurl']
@@ -105,17 +156,17 @@ class ODLTests(testcase_base.TestcaseBase):
'ODL_SYSTEM_IP:' + kwargs['odlip'],
'PORT:' + kwargs['odlwebport'],
'RESTCONFPORT:' + kwargs['odlrestconfport']]
- except KeyError as e:
+ except KeyError as ex:
self.logger.error("Cannot run ODL testcases. Please check "
- "%s" % str(e))
+ "%s", str(ex))
return self.EX_RUN_ERROR
if self.set_robotframework_vars(odlusername, odlpassword):
try:
os.makedirs(self.res_dir)
- except OSError as e:
- if e.errno != errno.EEXIST:
+ except OSError as ex:
+ if ex.errno != errno.EEXIST:
self.logger.exception(
- "Cannot create {}".format(self.res_dir))
+ "Cannot create %s", self.res_dir)
return self.EX_RUN_ERROR
stdout_file = os.path.join(self.res_dir, 'stdout.txt')
output_dir = os.path.join(self.res_dir, 'output.xml')
@@ -131,19 +182,31 @@ class ODLTests(testcase_base.TestcaseBase):
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)
+ except RobotError as ex:
+ self.logger.error("Run tests before publishing: %s",
+ ex.message)
return self.EX_RUN_ERROR
try:
os.remove(stdout_file)
except OSError:
- self.logger.warning("Cannot remove {}".format(stdout_file))
+ self.logger.warning("Cannot remove %s", stdout_file)
return self.EX_OK
else:
return self.EX_RUN_ERROR
def run(self, **kwargs):
+ """Run suites in OPNFV environment
+
+ It basically check env vars to call main() with the keywords
+ required.
+
+ Args:
+ **kwargs: Arbitrary keyword arguments.
+
+ Returns:
+ EX_OK if all suites ran well.
+ EX_RUN_ERROR otherwise.
+ """
try:
suites = self.default_suites
try:
@@ -176,19 +239,20 @@ class ODLTests(testcase_base.TestcaseBase):
kwargs['odlwebport'] = '8181'
else:
kwargs['odlip'] = os.environ['SDN_CONTROLLER_IP']
- except KeyError as e:
+ except KeyError as ex:
self.logger.error("Cannot run ODL testcases. "
"Please check env var: "
- "%s" % str(e))
+ "%s", str(ex))
return self.EX_RUN_ERROR
- except Exception:
+ except Exception: # pylint: disable=broad-except
self.logger.exception("Cannot run ODL testcases.")
return self.EX_RUN_ERROR
return self.main(suites, **kwargs)
-class ODLParser(object):
+class ODLParser(object): # pylint: disable=too-few-public-methods
+ """Parser to run ODL test suites."""
def __init__(self):
self.parser = argparse.ArgumentParser()
@@ -226,19 +290,28 @@ class ODLParser(object):
'-p', '--pushtodb', help='Push results to DB',
action='store_true')
- def parse_args(self, argv=[]):
+ def parse_args(self, argv=None):
+ """Parse arguments.
+
+ It can call sys.exit if arguments are incorrect.
+
+ Returns:
+ the arguments from cmdline
+ """
+ if not argv:
+ argv = []
return vars(self.parser.parse_args(argv))
if __name__ == '__main__':
- odl = ODLTests()
- parser = ODLParser()
- args = parser.parse_args(sys.argv[1:])
+ ODL = ODLTests()
+ PARSER = ODLParser()
+ ARGS = PARSER.parse_args(sys.argv[1:])
try:
- result = odl.main(ODLTests.default_suites, **args)
- if result != testcase_base.TestcaseBase.EX_OK:
- sys.exit(result)
- if args['pushtodb']:
- sys.exit(odl.push_to_db())
- except Exception:
- sys.exit(testcase_base.TestcaseBase.EX_RUN_ERROR)
+ RESULT = ODL.main(ODLTests.default_suites, **ARGS)
+ if RESULT != testcase.TestCase.EX_OK:
+ sys.exit(RESULT)
+ if ARGS['pushtodb']:
+ sys.exit(ODL.push_to_db())
+ except Exception: # pylint: disable=broad-except
+ sys.exit(testcase.TestCase.EX_RUN_ERROR)
diff --git a/functest/opnfv_tests/sdn/onos/onos.py b/functest/opnfv_tests/sdn/onos/onos.py
index 8bc73832..d482ae32 100644
--- a/functest/opnfv_tests/sdn/onos/onos.py
+++ b/functest/opnfv_tests/sdn/onos/onos.py
@@ -14,7 +14,7 @@ import shutil
import time
import urlparse
-from functest.core import testcase_base
+from functest.core import testcase
from functest.utils.constants import CONST
import functest.utils.functest_logger as ft_logger
import functest.utils.functest_utils as ft_utils
@@ -24,7 +24,7 @@ import functest.utils.openstack_utils as openstack_utils
logger = ft_logger.Logger(__name__).getLogger()
-class OnosBase(testcase_base.TestcaseBase):
+class OnosBase(testcase.TestCase):
onos_repo_path = CONST.dir_repo_onos
onos_sfc_image_name = CONST.onos_sfc_image_name
onos_sfc_image_path = os.path.join(CONST.dir_functest_data,
@@ -39,10 +39,10 @@ class OnosBase(testcase_base.TestcaseBase):
self.start_time = time.time()
try:
self._run()
- res = testcase_base.TestcaseBase.EX_OK
+ res = testcase.TestCase.EX_OK
except Exception as e:
logger.error('Error with run: %s', e)
- res = testcase_base.TestcaseBase.EX_RUN_ERROR
+ res = testcase.TestCase.EX_RUN_ERROR
self.stop_time = time.time()
return res