diff --git a/scripts/ci/test_extensions.sh b/scripts/ci/test_extensions.sh index 5035a06ee0e..ea0e54a7658 100755 --- a/scripts/ci/test_extensions.sh +++ b/scripts/ci/test_extensions.sh @@ -27,7 +27,7 @@ for ext in $output; do exit_code=1 echo "Failed to load:" $ext fi - azdev verify load_all + azdev verify load-all if [ $? != 0 ] then exit_code=1 diff --git a/src/azure-cli-core/azure/cli/core/__init__.py b/src/azure-cli-core/azure/cli/core/__init__.py index 5bb3027a409..240d250ef0b 100644 --- a/src/azure-cli-core/azure/cli/core/__init__.py +++ b/src/azure-cli-core/azure/cli/core/__init__.py @@ -25,6 +25,7 @@ EXCLUDED_PARAMS = ['self', 'raw', 'polling', 'custom_headers', 'operation_config', 'content_version', 'kwargs', 'client', 'no_wait'] +EVENT_FAILED_EXTENSION_LOAD = 'MainLoader.OnFailedExtensionLoad' class AzCli(CLI): @@ -192,6 +193,7 @@ def _handle_extension_suppressions(extensions): elapsed_time = timeit.default_timer() - start_time logger.debug("Loaded extension '%s' in %.3f seconds.", ext_name, elapsed_time) except Exception: # pylint: disable=broad-except + self.cli_ctx.raise_event(EVENT_FAILED_EXTENSION_LOAD, extension_name=ext_name) logger.warning("Unable to load extension '%s'. Use --debug for more information.", ext_name) logger.debug(traceback.format_exc()) diff --git a/tools/automation/verify/verify_load_all.py b/tools/automation/verify/verify_load_all.py index d4ee4f489a1..c9ad88a9fd4 100644 --- a/tools/automation/verify/verify_load_all.py +++ b/tools/automation/verify/verify_load_all.py @@ -6,20 +6,32 @@ """Verify all commands and arguments are loaded without errors. """ +FAILED_TO_LOAD = [] +EXTENSION_FAILURE_EXCLUSIONS = [] + def init(root): - parser = root.add_parser('load_all', help='Load the full command table, command arguments and help.') + parser = root.add_parser('load-all', help='Load the full command table, command arguments and help.') parser.set_defaults(func=verify_load_all) def verify_load_all(_): - from azure.cli.core import get_default_cli + from azure.cli.core import get_default_cli, EVENT_FAILED_EXTENSION_LOAD from azure.cli.core.file_util import get_all_help, create_invoker_and_load_cmds_and_args print('Loading all commands, arguments, and help...') - # setup CLI to enable command loader + # setup CLI to enable command loader and register event az_cli = get_default_cli() + az_cli.register_event(EVENT_FAILED_EXTENSION_LOAD, extension_failed_load_handler) # load commands, args, and help create_invoker_and_load_cmds_and_args(az_cli) loaded_help = get_all_help(az_cli) - print('Everything loaded successfully.') + + # verify each installed extension is properly loaded + if not FAILED_TO_LOAD or set(FAILED_TO_LOAD).issubset(set(EXTENSION_FAILURE_EXCLUSIONS)): + print('Everything loaded successfully.') + else: + raise Exception('Exceptions failed to load: {}'.format(', '.join(FAILED_TO_LOAD))) + +def extension_failed_load_handler(_, **kwargs): + FAILED_TO_LOAD.append(kwargs.get('extension_name'))