AzureBackup live tests: clean up vault dependencies before resource group removal - #3336
Conversation
…roup removal (microsoft#3312) Backup Vault resources (RSV and DPP) block resource group deletion when they still contain backup instances, protected items, registered containers, backup policies, or soft-deleted items. The live test pipeline previously invoked Remove-TestResources.ps1 directly and left orphaned resource groups behind. Changes: - Add tools/Azure.Mcp.Tools.AzureBackup/tests/remove-test-resources-pre.ps1 which disables soft delete on each vault, undeletes and hard-deletes all backup instances/protected items, unregisters storage containers, and removes all backup policies. The script is idempotent and tolerant of missing resources. - Update eng/pipelines/templates/jobs/live-test.yml to invoke $(TestResourcesPath)/remove-test-resources-pre.ps1 when present, in the correct sequence relative to remove-test-resources.yml. The hook is a no-op for toolsets that do not need it. Fixes microsoft#3312
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
This PR addresses AzureBackup live-test resource-group leaks by introducing a pre-cleanup hook that removes Azure Backup vault dependency chains (soft-delete items, backup instances, containers, policies) before the standard Remove-TestResources.ps1 resource-group deletion runs.
Changes:
- Added an AzureBackup-specific
remove-test-resources-pre.ps1script to disable soft delete and purge vault dependencies in the correct order. - Updated the live-test pipeline job template to optionally invoke
remove-test-resources-pre.ps1(if present) beforeremove-test-resources.ymlfor both stdio and http legs.
Invoking Livetests
Copilot submitted PRs are not trustworthy by default. Users with write access to the repo need to validate the contents of this PR before leaving a comment with the text /azp run mcp - pullrequest - live. This will trigger the necessary livetest workflows to complete required validation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tools/Azure.Mcp.Tools.AzureBackup/tests/remove-test-resources-pre.ps1 | Adds ordered, best-effort cleanup logic to remove vault dependencies that block vault/RG deletion. |
| eng/pipelines/templates/jobs/live-test.yml | Invokes an optional pre-cleanup script before the standard test-resource removal steps (stdio + http). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Drop `SupportsShouldProcess` from `[CmdletBinding()]`. The script does not call `$PSCmdlet.ShouldProcess`, so advertising -WhatIf / -Confirm was misleading. - Omit `-SoftDeleteRetentionDurationInDay 0` when disabling DPP soft delete. The service validates retention against a 14-180 day range and rejects `0`, which would leave soft delete enabled and block vault cleanup.
Description
Fixes #3312.
Backup Vault resources (Recovery Services Vaults and Data Protection Backup Vaults) cannot be deleted while they still contain backup instances, protected items, registered containers, backup policies, or soft-deleted items. The
Azure.Mcp.Tools.AzureBackuplive tests intentionally leave soft-deleted items behind (they exist so that theundeletelive tests have real soft-deleted items to restore). When the pipeline then invokesRemove-TestResources.ps1, Azure refuses to delete the vault, which in turn blocks resource group deletion — leaving orphaned resource groups behind and requiring manual cleanup.Fix
Introduces a generic
remove-test-resources-pre.ps1hook that runs beforeremove-test-resources.yml, so toolsets that own resources with dependency chains can perform ordered cleanup.New file
tools/Azure.Mcp.Tools.AzureBackup/tests/remove-test-resources-pre.ps1Set-AzRecoveryServicesVaultProperty, DPP viaUpdate-AzDataProtectionBackupVault).-ErrorAction SilentlyContinueon discovery calls and try/catch on per-item mutations so a single failure does not halt cleanup.Pipeline changes
eng/pipelines/templates/jobs/live-test.ymlAzurePowerShell@5step before eachremove-test-resources.ymlinvocation (one for the stdio leg, one for the http leg) that:$(TestResourcesPath)/remove-test-resources-pre.ps1.$env:RESOURCE_GROUP(set byNew-TestResources.ps1).condition: succeededOrFailed()gated onCI_HAS_DEPLOYED_RESOURCES = true, andcontinueOnError: true, so it runs even after test failures and never blocks the downstreamremove-test-resources.yml.eng/common/**is intentionally left untouched (it is auto-synced from the Azure SDK common repo).Acceptance criteria mapping
remove-test-resources-pre.ps1remove-test-resources.ymlRemove-AzResourceGrouprunsTesting
PyYAML(16 steps, valid structure).[System.Management.Automation.Language.Parser]::ParseFile(no syntax errors).Az.RecoveryServices.BackupandAz.DataProtectionmodules.Invoke-Cspell.ps1).Azure.Mcp.Tools.AzureBackuplive-test build executes; a follow-up run against the same subscription should show the previously orphaned resource groups being cleaned up automatically.Invoking Livetests
Copilot submitted PRs are not trustworthy by default. Users with
writeaccess to the repo need to validate the contents of this PR before leaving a comment with the text/azp run mcp - pullrequest - live. This will trigger the necessary livetest workflows to complete required validation.