[Compute] az vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooks - #33758
Conversation
|
Hi William (@william051200), |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
az vmss lifecycle-hooks &az vmss lifecycle-hooks-event: Add new command groups to support vmss lifecycle hooksaz vmss lifecycle-hooks/ lifecycle-hooks-event: Add new command groups to support vmss lifecycle hooks
az vmss lifecycle-hooks/ lifecycle-hooks-event: Add new command groups to support vmss lifecycle hooksaz vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooks
There was a problem hiding this comment.
Pull request overview
This PR adds new preview command groups under the vmss command module to manage VM Scale Set lifecycle hooks and to interact with platform-generated lifecycle hook events, along with scenario tests and recordings.
Changes:
- Add
az vmss lifecycle-hookcommands (add/update/remove/show/list) backed by new custom implementations. - Add
az vmss lifecycle-hook-eventcommands, including AAZ-generated list/show/update and custom wrappers for update/approve/reject with client-side validation. - Add scenario tests and a recording to validate core command behaviors.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py | Adds scenario tests for lifecycle-hook and lifecycle-hook-event command groups. |
| src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vmss_lifecycle_hook_event.yaml | Adds recording for lifecycle-hook-event list scenario. |
| src/azure-cli/azure/cli/command_modules/vm/custom.py | Implements lifecycle hook CRUD and lifecycle hook event update/approve/reject helpers. |
| src/azure-cli/azure/cli/command_modules/vm/commands.py | Registers new command groups and wires validators. |
| src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/lifecycle_hook_event/_update.py | Adds AAZ-generated vmss lifecycle-hook-event update. |
| src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/lifecycle_hook_event/_show.py | Adds AAZ-generated vmss lifecycle-hook-event show. |
| src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/lifecycle_hook_event/_list.py | Adds AAZ-generated vmss lifecycle-hook-event list. |
| src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/lifecycle_hook_event/init.py | Exposes lifecycle_hook_event AAZ commands for loading. |
| src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/lifecycle_hook_event/__cmd_group.py | Registers the AAZ command group for lifecycle hook events. |
| src/azure-cli/azure/cli/command_modules/vm/_validators.py | Adds validators for hook removal and lifecycle-hook-event update/action behaviors. |
| src/azure-cli/azure/cli/command_modules/vm/_params.py | Adds argument definitions/enums for lifecycle hook and lifecycle hook event commands. |
| src/azure-cli/azure/cli/command_modules/vm/_help.py | Adds help content for the new command groups/commands. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # AZURE CLI VM TEST DEFINITIONS | ||
| import json | ||
| import os | ||
| import datetime |
| def _commit_vmss_lifecycle_hooks(cmd, resource_group_name, vmss_name, hooks, no_wait): | ||
| from .operations.vmss import VMSSCreate, convert_show_result_to_snake_case | ||
| vmss = get_vmss_modified_by_aaz(cmd, resource_group_name, vmss_name) | ||
| vmss = convert_show_result_to_snake_case(vmss) | ||
| vmss["lifecycle_hooks_profile"] = {"lifecycle_hooks": hooks} | ||
| vmss["resource_group"] = resource_group_name | ||
| vmss["vm_scale_set_name"] = vmss_name | ||
| vmss["no_wait"] = no_wait | ||
| return VMSSCreate(cli_ctx=cmd.cli_ctx)(command_args=vmss) |
| helps['vmss lifecycle-hook-event'] = """ | ||
| type: group | ||
| short-summary: Manage virtual machine scale set lifecycle hook events. | ||
| """ |
az vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooksaz vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooks
|
Compute |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
Automated sensitive-information remediation ran on this pull request.
If a credential was exposed, rotate or revoke it immediately. Detected values are never copied into this comment. ✅ Keep the redaction · ❌ Dispute the redaction GitHub only supports a fixed reaction set, so 👍 represents ✅ and 👎 represents ❌. The bot-created reactions are only poll choices. Posted by agent-assist (autonomous bug-fix pipeline). |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
🔔 Routing this PR to @Azure/act-observability-squad. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 14 changed files in this pull request and generated no new comments.
Suppressed comments (7)
src/azure-cli/azure/cli/command_modules/vm/custom.py:5245
instance_idsis accepted byvmss_lifecycle_hook_event_approvebut never used (the validator resolvestarget_resource_ids). Removing the unused parameter avoids pylint noise and makes it clearinstance-idsis handled in validation.
def vmss_lifecycle_hook_event_approve(cmd, resource_group_name, vmss_name, lifecycle_hook_event_name,
target_resource_ids=None, instance_ids=None):
src/azure-cli/azure/cli/command_modules/vm/custom.py:5252
instance_idsis accepted byvmss_lifecycle_hook_event_rejectbut never used (the validator resolvestarget_resource_ids). Removing the unused parameter avoids pylint noise and makes it clearinstance-idsis handled in validation.
def vmss_lifecycle_hook_event_reject(cmd, resource_group_name, vmss_name, lifecycle_hook_event_name,
target_resource_ids=None, instance_ids=None):
src/azure-cli/azure/cli/command_modules/vm/_validators.py:2924
_resolve_vmss_lifecycle_hook_event_target_resourcesreadsevent['properties']['targetResources']from an AAZ Show result, but it doesn't unregister global transforms like the custom lifecycle-hook-event commands do. If global transforms are enabled, the response keys may be snake_cased (e.g.target_resources), causing this to resolve an empty target list and potentially reject valid--instance-ids/ approve/reject operations. Unregister transforms (and/or accept both key shapes) before parsing.
def _resolve_vmss_lifecycle_hook_event_target_resources(cmd, namespace):
from azure.cli.core.azclierror import InvalidArgumentValueError
from .aaz.latest.vmss.lifecycle_hook_event import Show as _lifecycleHookEventShow
event = _lifecycleHookEventShow(cli_ctx=cmd.cli_ctx)(command_args={
src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:4729
- Grammar: this comment should use present tense (the commands still require a platform-generated event).
# Not including approve/reject/show and update --action-state as they required live platform-generated event
src/azure-cli/azure/cli/command_modules/vm/_help.py:3082
- The
vmss lifecycle-hook-eventcommand group is registered as preview (is_preview=True), but the help short-summary doesn't indicate preview. This makes the help output inconsistent with the command registration and withvmss lifecycle-hookhelp.
helps['vmss lifecycle-hook-event'] = """
type: group
short-summary: Manage virtual machine scale set lifecycle hook events.
"""
src/azure-cli/azure/cli/command_modules/vm/_params.py:1187
- The linked requirements for
vmss lifecycle-hook-event updateinclude escape hatches like--target-resources(rawtargetResources[]) and--body(full PATCH payload), mutually exclusive with the higher-level flags. The custom command currently only exposes--action-state/--wait-until/--instance-ids, which prevents advanced scenarios (e.g., mixed target states) and diverges from the stated contract.
with self.argument_context('vmss lifecycle-hook-event update') as c:
c.argument('action_state', arg_type=get_enum_type(LifecycleHookActionState),
help="State of the lifecycle hook for the target resource. The customer can patch this property to "
"move the lifecycle hook to a terminal state.")
c.argument('wait_until',
help='Specifies the exact UTC timestamp in ISO 8601 format till which the event would remain in '
'the current lifecycle state waiting for an action from the customer. Beyond this timestamp, '
'the platform will apply the defaultAction for the event.')
src/azure-cli/azure/cli/command_modules/vm/custom.py:5221
instance_idsis accepted byvmss_lifecycle_hook_event_updatebut never used in the function body. This can trigger pylintunused-argumentwarnings and is confusing since resolution happens in the validator viatarget_resource_ids. Consider removing it from the signature (the validator can still consume the CLI arg) or renaming to_instance_ids.
This issue also appears in the following locations of the same file:
- line 5244
- line 5251
def vmss_lifecycle_hook_event_update(cmd, resource_group_name, vmss_name, lifecycle_hook_event_name,
action_state=None, wait_until=None, target_resource_ids=None, instance_ids=None):
|
🔔 Routing this PR to @Azure/act-observability-squad. |
🤖 PR Validation —⚠️ Review suggested
Related command
az vmss lifecycle-hook add/list/remove/show/updateaz vmss lifecycle-hook-event approve/list/reject/show/updateDescription
Resolve #33652
aaz Azure/aaz#1046
Testing Guide
Refer to
azure-cli\src\azure-cli\azure\cli\command_modules\vm\tests\latest\test_vm_commands.py:test_vmss_lifecycle_hooktest_vmss_lifecycle_hook_eventaz vmss lifecycle-hook-event approve/reject/updateare not included in the test cases as they required live platform-generated event. Service team will be helping with the test locally.History Notes
[Compute]
az vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooksThis 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.