Last active
June 26, 2020 07:08
-
-
Save felixfontein/964068eed7e8d233f77abe097eef31a7 to your computer and use it in GitHub Desktop.
Check meta/runtime.yml and validate collection with ansible/ansible's ansible_builtin_runtime.yml. Is now part of https://github.com/ansible-collections/community.internal_test_tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import os | |
import sys | |
import yaml | |
COLLECTION_NAME = 'community.general' | |
if len(sys.argv) > 1: | |
COLLECTION_NAME = sys.argv[1] | |
def check_plugins(ansible_builtin_routing, local_routing, plugin_type, base_path): | |
ansible_routing = ansible_builtin_routing['plugin_routing'].get(plugin_type, {}) | |
local_routing = local_routing['plugin_routing'].get(plugin_type, {}) | |
found_plugins = set() | |
for dirpath, _, filenames in os.walk(base_path): | |
for filename in filenames: | |
if not filename.endswith('.py') or filename == '__init__.py': | |
continue | |
path = os.path.join(dirpath, filename) | |
if os.path.islink(path) and dirpath == base_path and plugin_type == 'modules': | |
continue | |
rel_path = os.path.relpath(path, base_path) | |
plugin_name = os.path.split(rel_path)[1][:-3] if '/' in rel_path else rel_path[:-3] | |
found_plugins.add(plugin_name) | |
if plugin_name in ansible_routing: | |
routing_entry = ansible_routing[plugin_name] | |
if routing_entry['redirect'] != COLLECTION_NAME + '.' + plugin_name: | |
print('WARNING: {0} MOVED TO {1}'.format(path, routing_entry['redirect'])) | |
for name, entry in ansible_routing.items(): | |
if 'redirect' in entry and entry['redirect'].startswith(COLLECTION_NAME + '.'): | |
redirect_name = entry['redirect'][len(COLLECTION_NAME) + 1:] | |
if redirect_name not in found_plugins: | |
print('WARNING: {0} {1} is redirected to {2}, but cannot find {3} here!'.format(plugin_type, name, entry['redirect'], redirect_name)) | |
for name, entry in local_routing.items(): | |
if name not in found_plugins: | |
if 'tombstone' in entry: | |
continue | |
if 'redirect' in entry: | |
continue | |
print('WARNING: {0} {1} does not seem to exist!'.format(plugin_type, name)) | |
def main(): | |
with open('../../../../ansible/lib/ansible/config/ansible_builtin_runtime.yml', 'r') as f: | |
ansible_builtin_routing = yaml.safe_load(f) | |
with open('meta/runtime.yml', 'r') as f: | |
local_routing = yaml.safe_load(f) | |
for plugin_type in ['become', 'cache', 'callback', 'connection', 'doc_fragments', 'filter', 'inventory', 'lookup', 'modules']: | |
base_path = os.path.join('plugins', plugin_type) | |
check_plugins(ansible_builtin_routing, local_routing, plugin_type, base_path) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment