From c605365ac7a605eb486daa04089d71c739ef12dd Mon Sep 17 00:00:00 2001 From: Jiashuo Li <4003950+jiasli@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:10:52 +0800 Subject: [PATCH] {testsdk} Copy command index to random config dir (#28853) --- .azure-pipelines/templates/azdev_setup.yml | 3 +++ src/azure-cli-core/azure/cli/core/mock.py | 24 ++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.azure-pipelines/templates/azdev_setup.yml b/.azure-pipelines/templates/azdev_setup.yml index 10cb77e1c3..b39abaf187 100644 --- a/.azure-pipelines/templates/azdev_setup.yml +++ b/.azure-pipelines/templates/azdev_setup.yml @@ -31,6 +31,9 @@ steps: if [ "${{ parameters.EnableCompactAAZ }}" == 'True' ]; then python $CLI_REPO_PATH/scripts/compact_aaz.py fi + + # Verify installation and build command index + az --version displayName: 'azdev setup' env: CLI_REPO_PATH: ${{ parameters.CLIRepoPath }} diff --git a/src/azure-cli-core/azure/cli/core/mock.py b/src/azure-cli-core/azure/cli/core/mock.py index b2bc6f3b7e..7fa63bc390 100644 --- a/src/azure-cli-core/azure/cli/core/mock.py +++ b/src/azure-cli-core/azure/cli/core/mock.py @@ -32,17 +32,23 @@ class DummyCli(AzCli): self.env_patch = patch.dict(os.environ, {'AZURE_CONFIG_DIR': config_dir}) self.env_patch.start() + # Always copy command index to avoid initializing it again + files_to_copy = ['commandIndex.json'] # In recording mode, copy login credentials from global config dir to the dummy config dir if os.getenv(ENV_VAR_TEST_LIVE, '').lower() == 'true': - if os.path.exists(GLOBAL_CONFIG_DIR): - ensure_dir(config_dir) - import shutil - for file in ['azureProfile.json', 'msal_token_cache.bin', 'clouds.config', 'msal_token_cache.json', - 'service_principal_entries.json']: - try: - shutil.copy(os.path.join(GLOBAL_CONFIG_DIR, file), config_dir) - except FileNotFoundError: - pass + files_to_copy.extend([ + 'azureProfile.json', 'clouds.config', + 'msal_token_cache.bin', 'msal_token_cache.json', + 'service_principal_entries.bin', 'service_principal_entries.json' + ]) + + ensure_dir(config_dir) + import shutil + for file in files_to_copy: + try: + shutil.copy(os.path.join(GLOBAL_CONFIG_DIR, file), config_dir) + except FileNotFoundError: + pass super(DummyCli, self).__init__( cli_name='az',