-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
{Core} Add run_az_cmd
for internal az
-related cmd execution
#29899
base: dev
Are you sure you want to change the base?
Conversation
️✔️AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
Core |
Args: | ||
args: cmd to be executed, array of string, like `["az", "--version"]` | ||
out_file: The file to send output to. file-like object | ||
Returns: | ||
result: cmd execution result object, containing `result`, `error`, `exit_code` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use the :param
convention.
if args[0] != "az": | ||
raise ArgumentUsageError('Invalid cmd. run_az_cmd must be used to run `az` related cmds, ' | ||
'like ["az", "--version"]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can allow passing the command args without az
, such as ['version']
.
This is the case for calling self.cmd
within ScenarioTest
.
from azure.cli.core import get_default_cli | ||
cli = get_default_cli() | ||
cli.invoke(args, out_file=out_file) | ||
return cli.result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If exception raised during cli.invoke, then no result can be fetched by caller but the exception itself.
from azure.cli.core.azclierror import ArgumentUsageError | ||
if not isinstance(args, list): | ||
raise ArgumentUsageError("Invalid args. run_az_cmd args must be a list") | ||
if args[0] == "az": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If args[0] != "az", what will happen? Should it raise error or return immediately with warning instead of continuing to call cli.invoke?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
act as @jiasli suggested, support az version
and version
as self.cmd
does in our ScenarioTest
. Related code as below:
if command.startswith('az '):
command = command[3:]
e7354b5
to
f9bffc8
Compare
Related command
Description
Testing Guide
History Notes
[Component Name 1] BREAKING CHANGE:
az command a
: Make some customer-facing breaking change[Component Name 2]
az command b
: Add some customer-facing featureThis checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.