From 4fcf3d2079e505a6337abe1b850c7a7f6afddada Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Mon, 22 Aug 2016 11:48:44 +0200 Subject: Improve errors and status codes management MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Run returns the number of errors which is irrelevant to catch as they are published to DB. Useless generated files are desactivated too. Change-Id: I2baf6d5242c5f4095302a47ff90272fb95103457 Signed-off-by: Cédric Ollivier --- testcases/Controllers/ODL/OpenDaylightTesting.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/testcases/Controllers/ODL/OpenDaylightTesting.py b/testcases/Controllers/ODL/OpenDaylightTesting.py index 74e3157dc..c9c658ee6 100755 --- a/testcases/Controllers/ODL/OpenDaylightTesting.py +++ b/testcases/Controllers/ODL/OpenDaylightTesting.py @@ -59,7 +59,8 @@ class ODLTestCases: shutil.copy(f, cls.neutron_suite_dir) except IOError as e: cls.logger.error( - "Cannot copy OPNFV's testcases to ODL directory", e) + "Cannot copy OPNFV's testcases to ODL directory: " + "%s" % e.strerror) return False return True @@ -94,7 +95,8 @@ class ODLTestCases: 'PORT:' + kwargs['odlwebport'], 'RESTCONFPORT:' + kwargs['odlrestconfport']] except KeyError as e: - cls.logger.error("Cannot run ODL testcases. Please check", e) + cls.logger.error("Cannot run ODL testcases. Please check " + "%s" % e.strerror) return False if (cls.copy_opnf_testcases() and cls.set_robotframework_vars(odlusername, odlpassword)): @@ -104,16 +106,14 @@ class ODLTestCases: pass stdout_file = cls.res_dir + 'stdout.txt' with open(stdout_file, 'w') as stdout: - result = run(*dirs, variable=variables, - output=cls.res_dir + 'output.xml', - log=cls.res_dir + 'log.html', - report=cls.res_dir + 'report.html', - stdout=stdout) - + run(*dirs, variable=variables, + output=cls.res_dir + 'output.xml', + log='NONE', + report='NONE', + stdout=stdout) with open(stdout_file, 'r') as stdout: cls.logger.info("\n" + stdout.read()) - - return result + return True else: return False @@ -176,7 +176,8 @@ if __name__ == '__main__': action='store_true') args = vars(parser.parse_args()) - ODLTestCases.run(**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) -- cgit 1.2.3-korg From 0a40f5ecc5b2362e8b4dc2ec054daf611ac7f77e Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Mon, 22 Aug 2016 12:51:22 +0200 Subject: Add logs (info) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It adds logs (info) when status is ok and fixes an exception printing too. It removes one useless log (debug). Change-Id: Ia59c3985ae749b80d0e0c07f331220bd33cd8007 Signed-off-by: Cédric Ollivier --- testcases/Controllers/ODL/OpenDaylightTesting.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/testcases/Controllers/ODL/OpenDaylightTesting.py b/testcases/Controllers/ODL/OpenDaylightTesting.py index c9c658ee6..2075d13a8 100755 --- a/testcases/Controllers/ODL/OpenDaylightTesting.py +++ b/testcases/Controllers/ODL/OpenDaylightTesting.py @@ -68,7 +68,6 @@ class ODLTestCases: def set_robotframework_vars(cls, odlusername="admin", odlpassword="admin"): odl_variables_files = cls.odl_test_repo + 'csit/variables/Variables.py' try: - cls.logger.debug(cls.neutron_suite_dir + '__init__.robot') for line in fileinput.input(odl_variables_files, inplace=True): print re.sub("AUTH = .*", @@ -77,7 +76,7 @@ class ODLTestCases: line.rstrip()) return True except Exception as e: - cls.logger.error("Cannot set ODL creds", e) + cls.logger.error("Cannot set ODL creds: %s" % e.strerror) return False @classmethod @@ -113,6 +112,7 @@ class ODLTestCases: stdout=stdout) with open(stdout_file, 'r') as stdout: cls.logger.info("\n" + stdout.read()) + cls.logger.info("ODL results was sucessfully generated") return True else: return False @@ -134,6 +134,7 @@ class ODLTestCases: cls.logger.error("Cannot push ODL results to DB") return False else: + cls.logger.info("ODL results was sucessfully pushed to DB") return True except RobotError as e: cls.logger.error("Run tests before publishing: %s" % e.message) -- cgit 1.2.3-korg From 2a8caf0838fe1bbb8d6527a4ec388fa06e24494d Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Mon, 22 Aug 2016 13:40:34 +0200 Subject: Avoid opening tmp files twice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It avoids opening stdout.txt twice and removes it at the end. Change-Id: I7e006b52f49dd32543676259e0a1be2473670487 Signed-off-by: Cédric Ollivier --- testcases/Controllers/ODL/OpenDaylightTesting.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/testcases/Controllers/ODL/OpenDaylightTesting.py b/testcases/Controllers/ODL/OpenDaylightTesting.py index 2075d13a8..184cacf81 100755 --- a/testcases/Controllers/ODL/OpenDaylightTesting.py +++ b/testcases/Controllers/ODL/OpenDaylightTesting.py @@ -104,15 +104,19 @@ class ODLTestCases: except OSError: pass stdout_file = cls.res_dir + 'stdout.txt' - with open(stdout_file, 'w') as stdout: + with open(stdout_file, 'w+') as stdout: run(*dirs, variable=variables, output=cls.res_dir + 'output.xml', log='NONE', report='NONE', stdout=stdout) - with open(stdout_file, 'r') as stdout: + stdout.seek(0, 0) cls.logger.info("\n" + stdout.read()) cls.logger.info("ODL results was sucessfully generated") + try: + os.remove(stdout_file) + except OSError: + pass return True else: return False -- cgit 1.2.3-korg