From 823e3c72d3faf9dc8cf76be0c5b1d8961901024e Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Tue, 19 May 2015 11:19:52 -0500 Subject: [PATCH] Track errors/warnings and exit with a code equal to the total --- ansible_testing/modules.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ansible_testing/modules.py b/ansible_testing/modules.py index 2afa3706608..29235d73ef8 100644 --- a/ansible_testing/modules.py +++ b/ansible_testing/modules.py @@ -5,7 +5,9 @@ from __future__ import print_function import os import abc import ast +import sys import argparse + from fnmatch import fnmatch from ansible.utils.module_docs import get_docstring, BLACKLIST_MODULES @@ -46,15 +48,21 @@ class Validator(object): print(self.object_name) print('=' * 76) + ret = [] + for error in self.errors: print('ERROR: %s' % error) + ret.append(1) if warnings: for warning in self.warnings: print('WARNING: %s' % warning) + ret.append(1) if self.errors or (warnings and self.warnings): print() + return len(ret) + class ModuleValidator(Validator): BLACKLIST_PATTERNS = ('.git*', '*.pyc', '*.pyo', '.*') @@ -261,6 +269,8 @@ def main(): args.modules = args.modules.rstrip('/') + exit = [] + for root, dirs, files in os.walk(args.modules): basedir = root[len(args.modules)+1:].split('/', 1)[0] if basedir in BLACKLIST_DIRS: @@ -271,13 +281,15 @@ def main(): path = os.path.join(root, dirname) pv = PythonPackageValidator(os.path.abspath(path)) pv.validate() - pv.report(args.warnings) + exit.append(pv.report(args.warnings)) for filename in files: path = os.path.join(root, filename) mv = ModuleValidator(os.path.abspath(path)) mv.validate() - mv.report(args.warnings) + exit.append(mv.report(args.warnings)) + + sys.exit(sum(exit)) if __name__ == '__main__':