summaryrefslogtreecommitdiffstats
path: root/testcases/Controllers/ODL/OpenDaylightTesting.py
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2016-10-15 19:17:13 +0200
committerJose Lausuch <jose.lausuch@ericsson.com>2016-10-18 14:03:28 +0000
commitd04a2af1d4864014492702a8a48bf1171cae6bcb (patch)
tree5b7204ff3bef35325163d8b480144e0b20ca7244 /testcases/Controllers/ODL/OpenDaylightTesting.py
parentd4f57cb256542e42cfafd586b8c9ef025e6ef005 (diff)
Add OpenDaylightTesting unit tests
It adds unit tests checking OpenDaylightTesting. Several minor issues have also been fixed in this module when writing these unit tests: - the exceptions raised by main are caught when the testcases are launched from cmdline, - a warning message indicates that the temporarily files cannot be removed. JIRA: FUNCTEST-512 Change-Id: I873f0bbf4c3b7f416ca5515580e8aeab90773fdc Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'testcases/Controllers/ODL/OpenDaylightTesting.py')
-rwxr-xr-xtestcases/Controllers/ODL/OpenDaylightTesting.py39
1 files changed, 22 insertions, 17 deletions
diff --git a/testcases/Controllers/ODL/OpenDaylightTesting.py b/testcases/Controllers/ODL/OpenDaylightTesting.py
index 591faac5c..e302b569e 100755
--- a/testcases/Controllers/ODL/OpenDaylightTesting.py
+++ b/testcases/Controllers/ODL/OpenDaylightTesting.py
@@ -9,12 +9,12 @@ 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
-import functest.core.TestCasesBase as TestCasesBase
+from functest.core import TestCasesBase
import functest.utils.functest_logger as ft_logger
import functest.utils.openstack_utils as op_utils
@@ -56,9 +56,9 @@ class ODLTestCases(TestCasesBase.TestCasesBase):
def copy_opnf_testcases(cls):
opnfv_testcases_dir = (os.path.dirname(os.path.abspath(__file__)) +
"/custom_tests/neutron/")
- file = opnfv_testcases_dir + "001__reachability.robot"
+ f = opnfv_testcases_dir + "001__reachability.robot"
try:
- shutil.copy(file, cls.neutron_suite_dir)
+ 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))
@@ -107,7 +107,7 @@ class ODLTestCases(TestCasesBase.TestCasesBase):
except KeyError as e:
self.logger.error("Cannot run ODL testcases. Please check "
"%s" % str(e))
- return False
+ return self.EX_RUN_ERROR
if (self.copy_opnf_testcases() and
self.set_robotframework_vars(odlusername, odlpassword)):
try:
@@ -119,11 +119,11 @@ class ODLTestCases(TestCasesBase.TestCasesBase):
return self.EX_RUN_ERROR
stdout_file = self.res_dir + 'stdout.txt'
with open(stdout_file, 'w+') as stdout:
- run(*dirs, variable=variables,
- output=self.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)
self.logger.info("\n" + stdout.read())
self.logger.info("ODL results were successfully generated")
@@ -137,7 +137,7 @@ class ODLTestCases(TestCasesBase.TestCasesBase):
try:
os.remove(stdout_file)
except OSError:
- pass
+ self.logger.warning("Cannot remove {}".format(stdout_file))
return self.EX_OK
else:
return self.EX_RUN_ERROR
@@ -156,7 +156,9 @@ class ODLTestCases(TestCasesBase.TestCasesBase):
kwargs['odlrestconfport'] = '8181'
kwargs['odlusername'] = 'admin'
kwargs['odlpassword'] = 'admin'
- installer_type = os.environ['INSTALLER_TYPE']
+ 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']
@@ -220,8 +222,11 @@ if __name__ == '__main__':
args = vars(parser.parse_args())
odl = ODLTestCases()
- result = odl.main(**args)
- if result != TestCasesBase.TestCasesBase.EX_OK:
- sys.exit(result)
- if args['pushtodb']:
- sys.exit(odl.push_to_db())
+ 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)