Skip to content
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

{ARM} Bump api-version for Microsoft.Resources from 2021-04-01 to 2022-09-01 #25434

Merged
merged 187 commits into from
Mar 20, 2023

Conversation

zhoxing-ms
Copy link
Contributor

@zhoxing-ms zhoxing-ms commented Feb 13, 2023

Related command

Issue Close: #25049 #25828

Description

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 feature


This checklist is used to make sure that common guidelines for a pull request are followed.

@@ -61,6 +61,7 @@ class ResourceType(Enum): # pylint: disable=too-few-public-methods
MGMT_RESOURCE_DEPLOYMENTSCRIPTS = ('azure.mgmt.resource.deploymentscripts', 'DeploymentScriptsClient')
MGMT_RESOURCE_TEMPLATESPECS = ('azure.mgmt.resource.templatespecs', 'TemplateSpecsClient')
MGMT_RESOURCE_PRIVATELINKS = ('azure.mgmt.resource.privatelinks', 'ResourcePrivateLinkClient')
MGMT_RESOURCE_MANAGEDAPPLICATIONS = ('azure.mgmt.resource.managedapplications', 'ApplicationClient')
Copy link
Member

Choose a reason for hiding this comment

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

This new resource type seems not being used, why?

Copy link
Contributor Author

@zhoxing-ms zhoxing-ms Mar 20, 2023

Choose a reason for hiding this comment

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

Good question! Thanks for your reminding!
In the past, azure.mgmt.resource.managedapplications was a single version directory, the client path in _resource_managedapps_client_factory was directly imported by hardcode without using ResourceType.

def _resource_managedapps_client_factory(cli_ctx, **_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.mgmt.resource.managedapplications import ApplicationClient
return get_mgmt_service_client(cli_ctx, ApplicationClient)

In all managedapplications related custom methods, _resource_managedapps_client_factory() is directly called without using the client defined by command registration, such as:
def show_application(cmd, resource_group_name=None, application_name=None):
""" Gets a managed application.
:param str resource_group_name:the resource group name
:param str application_name:the managed application name
"""
racf = _resource_managedapps_client_factory(cmd.cli_ctx)
return racf.applications.get(resource_group_name, application_name)
def show_applicationdefinition(cmd, resource_group_name=None, application_definition_name=None):
""" Gets a managed application definition.
:param str resource_group_name:the resource group name
:param str application_definition_name:the managed application definition name
"""
racf = _resource_managedapps_client_factory(cmd.cli_ctx)
return racf.application_definitions.get(resource_group_name, application_definition_name)

Due to a breaking change in the SDK azure.mgmt.resource.managedapplications, an additional directory version folder v2018_06_01 has been added to the original directory, resulting in the ModuleNotFoundError: No module named 'azure.mgmt.resource.managedapplications.operations' issue. issue link: #25828
Therefore, we have added the new ResourceType MGMT_RESOURCE_MANAGEDAPPLICATIONS to solve the ModuleNotFoundError, because this way specifies the version path of the azure.mgmt.resource.managedapplications.operations

for rt in AZURE_API_PROFILES[self.cli_ctx.cloud.profile]:
if op_path.startswith(rt.import_prefix + '.'):
op_path = op_path.replace(rt.import_prefix,
get_versioned_sdk_path(self.cli_ctx.cloud.profile, rt,
operation_group=self.operation_group))
try:
mod_to_import, attr_path = op_path.split('#')
handler = import_module(mod_to_import)

More context: #24211 (comment)

Currently, there is indeed no direct use of the new resource type, which is not a good implementation way and can be confusing. I will refine the legacy code here

Copy link
Contributor Author

@zhoxing-ms zhoxing-ms Mar 20, 2023

Choose a reason for hiding this comment

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

Refined the legacy code, please help review again~

wangzelin007
wangzelin007 previously approved these changes Mar 20, 2023
calvinhzy
calvinhzy previously approved these changes Mar 20, 2023
yanzhudd
yanzhudd previously approved these changes Mar 20, 2023
@@ -3322,15 +3322,15 @@ def create_or_update_tag_at_scope(cmd, resource_id=None, tags=None, tag_name=Non
tag_obj = Tags(tags=tags)
TagsResource = cmd.get_models('TagsResource')
tags_resource = TagsResource(properties=tag_obj)
return rcf.tags.create_or_update_at_scope(scope=resource_id, parameters=tags_resource)
return rcf.tags.begin_create_or_update_at_scope(scope=resource_id, parameters=tags_resource)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't adding begin_ prefix be done during Track 2 migration? Does this create_or_update_at_scope work currently?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be due to the sudden breaking change in the Python SDK, which forced us to do the compatibility logic. Before that, the resource module had completed the migration of most sub RPs.
The method create_or_update_at_scope no longer exists in the Python SDK, it is directly replaced by begin_create_or_update_at_scope.
@Jing-song Could you please help confirm whether my explanation is correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

@zhoxing-ms Yes, it is right.

@jiasli
Copy link
Member

jiasli commented Mar 20, 2023

The commit history is malformed:

image

Consider rebasing to dev:

# Get the latest dev branch
git merge azure/dev

# Reset bump_resource_api_version branch to dev, without changing local files, ready to commit
git reset azure/dev

git commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ARM az resource/group/lock/tag/deployment/policy/managementapp/account management-group Auto-Assign Auto assign by bot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update API version from 2021-04-01 to 2022-09-01 for resources module