Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .azure-pipelines/templates/azdev_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
24 changes: 15 additions & 9 deletions src/azure-cli-core/azure/cli/core/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,23 @@ def __init__(self, commands_loader_cls=None, random_config_dir=False, **kwargs):
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):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if GLOBAL_CONFIG_DIR doesn't exist, no error will occur as FileNotFoundError is ignored.

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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure_dir(config_dir) will be called anyway later in azure.cli.core.AzCli.__init__:

We can unconditionally do it here to make the code neat.

As config_dir is a sub-folder in GLOBAL_CONFIG_DIR, ensure_dir will also create GLOBAL_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',
Expand Down