-
Notifications
You must be signed in to change notification settings - Fork 225
fix(azure): Enable storage account and private endpoint reuse for AzureFileShare on re-runs #4154
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
fix(azure): Enable storage account and private endpoint reuse for AzureFileShare on re-runs #4154
Conversation
…reFileShare on re-runs
fix(azure): Enable storage account and private endpoint reuse for AzureFileShare on re-runs
Problem:
When LISA was re-run with preserved resource groups (using deploy:false),
the AzureFileShare feature would create new storage accounts and file shares
instead of reusing existing ones, causing resource tracking and cleanup issues.
Additionally, re-runs would fail with IndexError when private endpoints
already existed.
Changes:
1. features.py - _initialize_fileshare_information():
- Added logic to scan for existing 'lisasc*' storage accounts in the
resource group and reuse them instead of generating new random names
- Added import for get_storage_client
2. common.py - create_update_private_endpoints():
- Added check for existing private endpoints before attempting creation
- Added new helper function _get_private_endpoint_ip() that extracts
IP address using two methods:
a) From custom_dns_configs (original approach)
b) From network interface (fallback for existing endpoints)
- Fixes IndexError when private endpoint already exists but
custom_dns_configs is empty
3. storage.py - verify_cifs_basic():
- Fixed test to pass allow_shared_key_access=True since the test uses
key-based authentication (credentials stored in /etc/smbcredentials/)
- Added TODO comment to flag test for future validation with these changes
Tested:
- verify_cifs_basic: PASSED (fresh deployment)
- verify_azure_file_share: Requires validation with re-run scenario
Impact:
- Enables proper resource reuse when re-running LISA with preserved environments
- Prevents orphaned storage accounts on failed/retried test runs
- Fixes private endpoint IP retrieval for existing endpoints
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.
Pull request overview
This pull request enables resource reuse for AzureFileShare operations when LISA is re-run with preserved resource groups. The changes address issues where storage accounts and private endpoints were being recreated instead of reused, and fixes an IndexError when retrieving IP addresses from existing private endpoints.
Key changes include:
- Storage account reuse logic to scan for existing "lisasc*" accounts before creating new ones
- Private endpoint IP retrieval improvements with fallback methods and existence checking
- Test fix to explicitly pass allow_shared_key_access=True for key-based authentication
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| lisa/sut_orchestrator/azure/features.py | Adds storage account reuse logic by scanning existing accounts with "lisasc" prefix; adds get_storage_client import |
| lisa/sut_orchestrator/azure/common.py | Adds private endpoint existence check and _get_private_endpoint_ip helper with fallback IP retrieval methods (custom_dns_configs and network interface) |
| lisa/microsoft/testsuites/core/storage.py | Fixes test to pass allow_shared_key_access=True; adds TODO comment noting the test doesn't use private endpoints |
Key Test Cases:
verify_cifs_basic|verify_azure_file_share
Impacted LISA Features:
AzureFileShare, Nfs
Tested Azure Marketplace Images:
- canonical 0001-com-ubuntu-server-jammy 22_04-lts-gen2 latest
- debian debian-12 12-gen2 latest
- redhat rhel 95_gen2 latest
fix(azure): Enable storage account and private endpoint reuse for AzureFileShare on re-runs
Problem
When LISA tests are re-run on the same VM (with
keep_environment: true), the AzureFileShare feature was:/etc/fstab- Leaving stale mount entries that caused boot issuesSolution
This PR implements intelligent resource reuse with proper tracking and conditional cleanup.
Important Changes
1. Storage Account Reuse (
features.py)_storage_account_reused: booltracking flaglisasc*prefix before creating new ones@lru_cachewith module-level_storage_account_cachedict (fixes unhashable object error)2. Private Endpoint Reuse (
features.py,common.py)_private_endpoint_created_by_lisa: booltracking flagcreate_update_private_endpoints()now returnsTuple[str, bool](name, was_created)_get_private_endpoint_ip()helper with fallback methods for IP retrieval<storage_account_name>-file-pe, ensures future implementations from other tests are not impacted.3. Credential File Management (
features.py)/etc/smbcredentials/<storage_account_name>.credcredential_fileproperty for external accessCREDENTIAL_DIR = "/etc/smbcredentials"4. Safe Cleanup Logic (
features.py)_delete_file_shares()- Always deletes file shares_cleanup_private_endpoint_resources()- Conditional PE cleanup_cleanup_storage_account()- Conditional storage account cleanup_cleanup_vm_state()- Cleans fstab entries and credentialssedfor surgical fstab entry removal (not backup restore)5. Code Quality Improvements
AzureFileShareSTORAGE_ACCOUNT_PREFIX,PRIVATE_ENDPOINT_SUFFIX,CREDENTIAL_DIRCleanup Behavior Matrix
Resource Naming Conventions
lisasc<random10>lisascab12cd34ef<storage>-file-pelisascab12cd34ef-file-pe/etc/smbcredentials/<storage>.cred/etc/smbcredentials/lisascab12cd34ef.credFiles Changed
lisa/sut_orchestrator/azure/features.py- AzureFileShare class enhancementslisa/sut_orchestrator/azure/common.py- PE helper functions, cache, list_file_shareslisa/microsoft/testsuites/storage/storage.py- Simplified cleanup logiclisa/microsoft/testsuites/xfstests/xfstesting.py- Uses credential_file propertyTesting
keep_environment: trueImpact