Skip to content

Commit 2020059

Browse files
authored
Added check for properly loading extensions azdev verify load_all (#6765)
* added check for properly loading extensions to CI * static check * load-all load-all
1 parent 663db88 commit 2020059

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

scripts/ci/test_extensions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ for ext in $output; do
2727
exit_code=1
2828
echo "Failed to load:" $ext
2929
fi
30-
azdev verify load_all
30+
azdev verify load-all
3131
if [ $? != 0 ]
3232
then
3333
exit_code=1

src/azure-cli-core/azure/cli/core/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
EXCLUDED_PARAMS = ['self', 'raw', 'polling', 'custom_headers', 'operation_config',
2727
'content_version', 'kwargs', 'client', 'no_wait']
28+
EVENT_FAILED_EXTENSION_LOAD = 'MainLoader.OnFailedExtensionLoad'
2829

2930

3031
class AzCli(CLI):
@@ -192,6 +193,7 @@ def _handle_extension_suppressions(extensions):
192193
elapsed_time = timeit.default_timer() - start_time
193194
logger.debug("Loaded extension '%s' in %.3f seconds.", ext_name, elapsed_time)
194195
except Exception: # pylint: disable=broad-except
196+
self.cli_ctx.raise_event(EVENT_FAILED_EXTENSION_LOAD, extension_name=ext_name)
195197
logger.warning("Unable to load extension '%s'. Use --debug for more information.", ext_name)
196198
logger.debug(traceback.format_exc())
197199

tools/automation/verify/verify_load_all.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,32 @@
66
"""Verify all commands and arguments are loaded without errors. """
77

88

9+
FAILED_TO_LOAD = []
10+
EXTENSION_FAILURE_EXCLUSIONS = []
11+
912
def init(root):
10-
parser = root.add_parser('load_all', help='Load the full command table, command arguments and help.')
13+
parser = root.add_parser('load-all', help='Load the full command table, command arguments and help.')
1114
parser.set_defaults(func=verify_load_all)
1215

1316

1417
def verify_load_all(_):
15-
from azure.cli.core import get_default_cli
18+
from azure.cli.core import get_default_cli, EVENT_FAILED_EXTENSION_LOAD
1619
from azure.cli.core.file_util import get_all_help, create_invoker_and_load_cmds_and_args
1720

1821
print('Loading all commands, arguments, and help...')
19-
# setup CLI to enable command loader
22+
# setup CLI to enable command loader and register event
2023
az_cli = get_default_cli()
24+
az_cli.register_event(EVENT_FAILED_EXTENSION_LOAD, extension_failed_load_handler)
2125

2226
# load commands, args, and help
2327
create_invoker_and_load_cmds_and_args(az_cli)
2428
loaded_help = get_all_help(az_cli)
25-
print('Everything loaded successfully.')
29+
30+
# verify each installed extension is properly loaded
31+
if not FAILED_TO_LOAD or set(FAILED_TO_LOAD).issubset(set(EXTENSION_FAILURE_EXCLUSIONS)):
32+
print('Everything loaded successfully.')
33+
else:
34+
raise Exception('Exceptions failed to load: {}'.format(', '.join(FAILED_TO_LOAD)))
35+
36+
def extension_failed_load_handler(_, **kwargs):
37+
FAILED_TO_LOAD.append(kwargs.get('extension_name'))

0 commit comments

Comments
 (0)