-
Notifications
You must be signed in to change notification settings - Fork 3k
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
{Core} Move clouds.config to config dir #26138
base: dev
Are you sure you want to change the base?
Conversation
️✔️acr
️✔️acs
️✔️advisor
️✔️ams
️✔️apim
️✔️appconfig
️✔️appservice
️✔️aro
️✔️backup
️✔️batch
️✔️batchai
️✔️billing
️✔️botservice
️✔️cdn
️✔️cloud
️✔️cognitiveservices
️✔️config
️✔️configure
️✔️consumption
️✔️container
️✔️core
️✔️cosmosdb
️✔️databoxedge
️✔️dla
️✔️dls
️✔️dms
️✔️eventgrid
️✔️eventhubs
️✔️feedback
️✔️find
️✔️hdinsight
️✔️identity
️✔️iot
️✔️keyvault
️✔️kusto
️✔️lab
️✔️managedservices
️✔️maps
️✔️marketplaceordering
️✔️monitor
️✔️netappfiles
️✔️network
️✔️policyinsights
️✔️privatedns
️✔️profile
️✔️rdbms
️✔️redis
️✔️relay
️✔️resource
️✔️role
️✔️search
️✔️security
️✔️servicebus
️✔️serviceconnector
️✔️servicefabric
️✔️signalr
️✔️sql
️✔️sqlvm
️✔️storage
️✔️synapse
️✔️telemetry
️✔️util
️✔️vm
|
Hi @bebound, |
Core |
os.makedirs(GLOBAL_CONFIG_DIR) | ||
with open(CLOUD_CONFIG_FILE, 'w') as configfile: | ||
if not os.path.isdir(os.path.dirname(get_cloud_config_file(cli_ctx))): | ||
os.makedirs(os.path.dirname(get_cloud_config_file(cli_ctx))) |
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.
This folder has been created by
azure-cli/src/azure-cli-core/azure/cli/core/__init__.py
Lines 77 to 78 in 63121ed
azure_folder = self.config.config_dir | |
ensure_dir(azure_folder) |
I don't know if this function is called when
cli_ctx
does not exist.
@@ -18,8 +18,14 @@ | |||
|
|||
logger = get_logger(__name__) | |||
|
|||
# This default cloud name. If you use DummyCli(random_config_dir=True), use get_cloud_config_file() instead. | |||
CLOUD_CONFIG_FILE = os.path.join(GLOBAL_CONFIG_DIR, 'clouds.config') |
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.
The original implementation is wrong.
get_default_cli
uses GLOBAL_CONFIG_DIR
for knack.cli.CLI.__init__
's config_dir
argument:
azure-cli/src/azure-cli-core/azure/cli/core/__init__.py
Lines 902 to 903 in 63121ed
return AzCli(cli_name='az', | |
config_dir=GLOBAL_CONFIG_DIR, |
The location of clouds.config
is also built from GLOBAL_CONFIG_DIR
.
If knack.cli.CLI.__init__
's config_dir
doesn't use GLOBAL_CONFIG_DIR
, but another location, like what has been done in #25689:
azure-cli/src/azure-cli-core/azure/cli/core/mock.py
Lines 28 to 29 in b223dd9
config_dir=os.path.join(GLOBAL_CONFIG_DIR, 'dummy_cli_config_dir', | |
random_string()) if random_config_dir else GLOBAL_CONFIG_DIR, |
Then the location of clouds.config
will still be under GLOBAL_CONFIG_DIR
, because it directly uses CLOUD_CONFIG_FILE
, instead of cli_ctx.config.config_dir
. This defeats the purpose of overriding config_dir
.
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.
profile._storage
is an azure.cli.core._session.ACCOUNT
which is a persisted JSON. It can easily be replaced by an in-memory dict
during tests, but cloud.config
is an INI file, which introduces inconsistency. See #14436 (comment)
def get_cloud_config_file(cli_ctx=None): | ||
return os.path.join(cli_ctx.config.config_dir, 'clouds.config') if cli_ctx else CLOUD_CONFIG_FILE |
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.
Calling this function multiple times is tedious. Perhaps we simply save it as cli_ctx.cloud_config
?
Description
Related PR: #25689
At present,
CLOUD_CONFIG_FILE
is always~/.azure/clouds.config
.TestProfile
consists of different login test. When runaz login
, cloud config file is updated bylogin
->_set_subscriptions
->set_cloud_subscription
.azure-cli/src/azure-cli-core/azure/cli/core/cloud.py
Lines 581 to 598 in acd8f2c
Simultaneous writing may lead to file interruption.
This PR fixes this bug by enabling
random_config_dir
in these test and move cloud config tocli_ctx.config.config_dir
.Testing Guide
History Notes
[Component Name 1] BREAKING CHANGE:
az command a
: Make some customer-facing breaking change[Component Name 2]
az command b
: Add some customer-facing featureThis 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.