From e7da4975cc7232f89a116da2487f2953465d9214 Mon Sep 17 00:00:00 2001 From: John R Barker Date: Wed, 21 Nov 2018 11:15:56 +0000 Subject: [PATCH] Botmeta validate path macros (#48980) BOTMETA validation - use path macros Rather than hard coding the list of path macros, read them directly from BOTMETA --- test/sanity/code-smell/botmeta.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/test/sanity/code-smell/botmeta.py b/test/sanity/code-smell/botmeta.py index 56dea07f71f..d9d02503cc7 100755 --- a/test/sanity/code-smell/botmeta.py +++ b/test/sanity/code-smell/botmeta.py @@ -64,20 +64,18 @@ def main(): if botmeta_support != 'core': print('%s:%d:%d: .github/BOTMETA.yml MUST be support: core' % (path, 0, 0)) - # We have two macros to define locations, ensure they haven't been removed - module_utils_path = botmeta.get('macros', {}).get('module_utils', '') - modules_path = botmeta.get('macros', {}).get('modules', '') - - if module_utils_path != 'lib/ansible/module_utils': - print('%s:%d:%d: [macros][module_utils] has been changed or removed' % (path, 0, 0)) - - if modules_path != 'lib/ansible/modules': - print('%s:%d:%d: [macros][modules] has been changed or removed' % (path, 0, 0)) - - # See if all `files:` are valid + # Find all path (none-team) macros so we can substitute them + macros = botmeta.get('macros', {}) + path_macros = [] + for macro in macros: + if macro.startswith('team_'): + continue + path_macros.append(macro) + + # Ensure all `files` correspond to a file for file in botmeta['files']: - file = file.replace('$module_utils', module_utils_path) - file = file.replace('$modules', modules_path) + for macro in path_macros: + file = file.replace('$' + macro, botmeta.get('macros', {}).get(macro, '')) if not os.path.exists(file): # Not a file or directory, though maybe the prefix to one? # https://github.com/ansible/ansibullbot/pull/1023 @@ -91,4 +89,4 @@ if __name__ == '__main__': # Possible future work # * Schema for `macros:` - currently ignored due to team_ansible # * Ensure that all $teams mention in `files:` exist in `$macros` -# * Validate GitHub names - possibly expensive lookup needed +# * Validate GitHub names - possibly expensive lookup needed - No should be validated when module is added - gundalow