Skip to content

Commit

Permalink
Added check for properly loading extensions azdev verify load_all (#…
Browse files Browse the repository at this point in the history
…6765)

* added check for properly loading extensions to CI

* static check

* load-all

load-all
  • Loading branch information
williexu authored Jul 11, 2018
1 parent 663db88 commit 2020059
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scripts/ci/test_extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/azure-cli-core/azure/cli/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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())

Expand Down
20 changes: 16 additions & 4 deletions tools/automation/verify/verify_load_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

0 comments on commit 2020059

Please sign in to comment.