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

[Container Registry] Migrate to track2 SDK #18611

Merged
merged 8 commits into from
Jun 30, 2021
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
7 changes: 6 additions & 1 deletion src/azure-cli-core/azure/cli/core/profiles/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ def default_api_version(self):
'role_definitions': '2018-01-01-preview',
'provider_operations_metadata': '2018-01-01-preview'
}),
ResourceType.MGMT_CONTAINERREGISTRY: '2020-11-01-preview',
ResourceType.MGMT_CONTAINERREGISTRY: SDKProfile('2020-11-01-preview', {
'agent_pools': '2019-06-01-preview',
'tasks': '2019-06-01-preview',
'task_runs': '2019-06-01-preview',
'runs': '2019-06-01-preview',
}),
ResourceType.DATA_KEYVAULT: '7.0',
ResourceType.DATA_PRIVATE_KEYVAULT: '7.2',
ResourceType.DATA_KEYVAULT_ADMINISTRATION_BACKUP: '7.2-preview',
Expand Down
3 changes: 2 additions & 1 deletion src/azure-cli/azure/cli/command_modules/acr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class ACRCommandsLoader(AzCommandsLoader):
def __init__(self, cli_ctx=None):
from azure.cli.core.profiles import ResourceType
super(ACRCommandsLoader, self).__init__(cli_ctx=cli_ctx,
resource_type=ResourceType.MGMT_CONTAINERREGISTRY)
resource_type=ResourceType.MGMT_CONTAINERREGISTRY,
operation_group='webhooks')
Copy link
Contributor

Choose a reason for hiding this comment

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

why this operation group as default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We just want 2020-11-01-preview as default, the webhooks is belong to 2020-11-01-preview.
You can refer to other modules that use multiple versions. like monitor

Copy link
Contributor

@adewaleo adewaleo Jun 24, 2021

Choose a reason for hiding this comment

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

oh so by choosing webhooks, because it isn't in one of the other profiles like agent_pools? If so can we use a more general operation_group name like registries? Also shouldn't this work fine without specifying operation_group, given the loader would use the default operation_group which should use default api version?

            'agent_pools': '2019-06-01-preview',
            'tasks': '2019-06-01-preview',
            'task_runs': '2019-06-01-preview',
            'runs': '2019-06-01-preview',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

        ResourceType.MGMT_CONTAINERREGISTRY: SDKProfile('2020-11-01-preview', {
            'agent_pools': '2019-06-01-preview',
            'tasks': '2019-06-01-preview',
            'task_runs': '2019-06-01-preview',
            'runs': '2019-06-01-preview',
        }),

In this profile, we defined a default apiversion and some other groups using special version.
But in the base class ACRCommandsLoader, it doesn't know which one should be used as default.
Why we use webhooks? Actually we use other group is ok. Because it will use default apiversion 2020-11-01-preview when group name is not in special group list defined in profile.
I just want to tell ACRCommandsLoader to use 2020-11-01-preview as default version.

Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if we don't set operation_group='webhooks'? What is the default version in this case?

Copy link
Contributor Author

@00Kai0 00Kai0 Jul 1, 2021

Choose a reason for hiding this comment

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

When we run get_models, we need a parameter operation_group to tell get_models to use which model in which api version, like this line.
If we don't clarify using which api_version/operation_group, then it will find it from AzLoader

This is why we need this operation_group here.

In monitor, it rarely uses get_models and always clarify operation_group when using. This's why you don't find operation_group in AzLoader of monitor.

Copy link
Contributor

Choose a reason for hiding this comment

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

So when operation_group='webhooks' is not set, get_models can't get the default api-version of ResourceType.MGMT_CONTAINERREGISTRY, right?


def load_command_table(self, args):
from azure.cli.command_modules.acr.commands import load_command_table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import time

from msrest import Deserializer
from msrest.polling import PollingMethod, LROPoller
from msrestazure.azure_exceptions import CloudError
from azure.core.exceptions import HttpResponseError
from azure.core.polling import PollingMethod, LROPoller

from ._constants import get_acr_task_models, get_succeeded_agentpool_status, get_finished_agentpool_status

Expand All @@ -26,7 +26,7 @@ def deserialize_agentpool(response):
return LROPoller(
client=client,
initial_response=client.get(
resource_group_name, registry_name, agent_pool_name, raw=True),
resource_group_name, registry_name, agent_pool_name, cls=lambda x, y, z: x),
jsntcy marked this conversation as resolved.
Show resolved Hide resolved
deserialization_callback=deserialize_agentpool,
polling_method=RunPolling(
cmd=cmd,
Expand All @@ -50,9 +50,9 @@ def __init__(self, cmd, registry_name, agent_pool_name, timeout=30):
self.operation_result = None

def initialize(self, client, initial_response, deserialization_callback):
self._client = client
self._client = client._client # pylint: disable=protected-access
self._response = initial_response
self._url = initial_response.request.url
self._url = initial_response.http_request.url
self._deserialize = deserialization_callback

self._set_operation_status(initial_response)
Expand Down Expand Up @@ -84,13 +84,13 @@ def resource(self):

def _set_operation_status(self, response):
AgentPoolStatus = self._cmd.get_models('ProvisioningState')
if response.status_code == 200 or response.status_code == 404:
if response.http_response.status_code == 200 or response.http_response.status_code == 404:
self.operation_result = self._deserialize(response)
self.operation_status = self.operation_result.provisioning_state or AgentPoolStatus.succeeded.value
return
raise CloudError(response)
raise HttpResponseError(response)

def _update_status(self):
self._response = self._client.send(
self._response = self._client._pipeline.run( # pylint: disable=protected-access
self._client.get(self._url), stream=False)
self._set_operation_status(self._response)
16 changes: 8 additions & 8 deletions src/azure-cli/azure/cli/command_modules/acr/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ def get_premium_sku(cmd):


def get_valid_os(cmd):
OS = cmd.get_models('OS')
OS = cmd.get_models('OS', operation_group='task_runs')
return [item.value.lower() for item in OS]


def get_valid_architecture(cmd):
Architecture = cmd.get_models('Architecture')
Architecture = cmd.get_models('Architecture', operation_group='task_runs')
return [item.value.lower() for item in Architecture]


def get_valid_variant(cmd):
Variant = cmd.get_models('Variant')
Variant = cmd.get_models('Variant', operation_group='task_runs')
return [item.value.lower() for item in Variant]


def get_finished_run_status(cmd):
RunStatus = cmd.get_models('RunStatus')
RunStatus = cmd.get_models('RunStatus', operation_group='task_runs')
return [RunStatus.succeeded.value,
RunStatus.failed.value,
RunStatus.canceled.value,
Expand All @@ -66,22 +66,22 @@ def get_finished_run_status(cmd):


def get_succeeded_run_status(cmd):
RunStatus = cmd.get_models('RunStatus')
RunStatus = cmd.get_models('RunStatus', operation_group='task_runs')
return [RunStatus.succeeded.value]


def get_acr_task_models(cmd):
from azure.cli.core.profiles import get_sdk
return get_sdk(cmd.cli_ctx, ResourceType.MGMT_CONTAINERREGISTRY, 'models')
return get_sdk(cmd.cli_ctx, ResourceType.MGMT_CONTAINERREGISTRY, 'models', operation_group='tasks')


def get_succeeded_agentpool_status(cmd):
AgentPoolStatus = cmd.get_models('ProvisioningState')
AgentPoolStatus = cmd.get_models('ProvisioningState', operation_group='agent_pools')
return [AgentPoolStatus.succeeded.value]


def get_finished_agentpool_status(cmd):
AgentPoolStatus = cmd.get_models('ProvisioningState')
AgentPoolStatus = cmd.get_models('ProvisioningState', operation_group='agent_pools')
return [AgentPoolStatus.succeeded.value,
AgentPoolStatus.failed.value,
AgentPoolStatus.canceled.value]
7 changes: 4 additions & 3 deletions src/azure-cli/azure/cli/command_modules/acr/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@


def load_arguments(self, _): # pylint: disable=too-many-statements
SkuName, PasswordName, DefaultAction, PolicyStatus, WebhookAction, WebhookStatus, TaskStatus, \
BaseImageTriggerType, RunStatus, SourceRegistryLoginMode, UpdateTriggerPayloadType, \
SkuName, PasswordName, DefaultAction, PolicyStatus, WebhookAction, WebhookStatus, \
TokenStatus, ZoneRedundancy = self.get_models(
'SkuName', 'PasswordName', 'DefaultAction', 'PolicyStatus', 'WebhookAction', 'WebhookStatus',
'TaskStatus', 'BaseImageTriggerType', 'RunStatus', 'SourceRegistryLoginMode', 'UpdateTriggerPayloadType',
'TokenStatus', 'ZoneRedundancy')
TaskStatus, BaseImageTriggerType, SourceRegistryLoginMode, UpdateTriggerPayloadType = self.get_models(
'TaskStatus', 'BaseImageTriggerType', 'SourceRegistryLoginMode', 'UpdateTriggerPayloadType', operation_group='tasks')
RunStatus = self.get_models('RunStatus', operation_group='runs')

with self.argument_context('acr') as c:
c.argument('tags', arg_type=tags_type)
Expand Down
12 changes: 6 additions & 6 deletions src/azure-cli/azure/cli/command_modules/acr/_run_polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import time

from azure.core.polling import PollingMethod, LROPoller
from msrest import Deserializer
from msrest.polling import PollingMethod, LROPoller
from msrestazure.azure_exceptions import CloudError

from ._constants import get_acr_task_models, get_finished_run_status, get_succeeded_run_status
Expand All @@ -26,7 +26,7 @@ def deserialize_run(response):
return LROPoller(
client=client,
initial_response=client.get(
resource_group_name, registry_name, run_id, raw=True),
resource_group_name, registry_name, run_id, cls=lambda x, y, z: x),
deserialization_callback=deserialize_run,
polling_method=RunPolling(
cmd=cmd,
Expand All @@ -50,9 +50,9 @@ def __init__(self, cmd, registry_name, run_id, timeout=30):
self.operation_result = None

def initialize(self, client, initial_response, deserialization_callback):
self._client = client
self._client = client._client # pylint: disable=protected-access
self._response = initial_response
self._url = initial_response.request.url
self._url = initial_response.http_request.url
self._deserialize = deserialization_callback

self._set_operation_status(initial_response)
Expand Down Expand Up @@ -86,13 +86,13 @@ def resource(self):

def _set_operation_status(self, response):
RunStatus = self._cmd.get_models('RunStatus')
if response.status_code == 200:
if response.http_response.status_code == 200:
self.operation_result = self._deserialize(response)
self.operation_status = self.operation_result.status or RunStatus.queued.value
return
raise CloudError(response)

def _update_status(self):
self._response = self._client.send(
self._response = self._client._pipeline.run( # pylint: disable=protected-access
self._client.get(self._url), stream=False)
self._set_operation_status(self._response)
29 changes: 15 additions & 14 deletions src/azure-cli/azure/cli/command_modules/acr/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from knack.util import CLIError
from knack.log import get_logger

from msrestazure.azure_exceptions import CloudError
from azure.cli.core.commands import LongRunningOperation
from azure.cli.core.commands.parameters import get_resources_in_subscription
from azure.core.exceptions import ResourceNotFoundError

from ._constants import (
REGISTRY_RESOURCE_TYPE,
Expand Down Expand Up @@ -198,7 +198,8 @@ def get_validate_platform(cmd, platform):
"""Gets and validates the Platform from both flags
:param str platform: The name of Platform passed by user in --platform flag
"""
OS, Architecture = cmd.get_models('OS', 'Architecture')
OS, Architecture = cmd.get_models('OS', 'Architecture', operation_group='runs')

# Defaults
platform_os = OS.linux.value
platform_arch = Architecture.amd64.value
Expand Down Expand Up @@ -285,10 +286,14 @@ def get_custom_registry_credentials(cmd,
:param str password: The password for custom registry (plain text or a key vault secret URI)
:param str identity: The task managed identity used for the credential
"""
Credentials, SourceRegistryCredentials, CustomRegistryCredentials, SecretObject, \
SecretObjectType = cmd.get_models(
'Credentials', 'CustomRegistryCredentials', 'SourceRegistryCredentials', 'SecretObject',
'SecretObjectType',
operation_group='tasks')
jsntcy marked this conversation as resolved.
Show resolved Hide resolved

source_registry_credentials = None
if auth_mode:
SourceRegistryCredentials = cmd.get_models('SourceRegistryCredentials')
source_registry_credentials = SourceRegistryCredentials(
login_mode=auth_mode)

Expand All @@ -301,11 +306,6 @@ def get_custom_registry_credentials(cmd,
if not username and not password:
is_identity_credential = identity is not None

CustomRegistryCredentials, SecretObject, SecretObjectType = cmd.get_models(
'CustomRegistryCredentials',
'SecretObject',
'SecretObjectType')

if not is_remove:
if is_identity_credential:
custom_reg_credential = CustomRegistryCredentials(
Expand All @@ -328,17 +328,15 @@ def get_custom_registry_credentials(cmd,

custom_registries = {login_server: custom_reg_credential}

Credentials = cmd.get_models('Credentials')
return Credentials(
source_registry=source_registry_credentials,
custom_registries=custom_registries
)


def build_timers_info(cmd, schedules):
TimerTrigger, TriggerStatus = cmd.get_models(
'TimerTrigger', 'TriggerStatus')
timer_triggers = []
TriggerStatus, TimerTrigger = cmd.get_models('TriggerStatus', 'TimerTrigger', operation_group='tasks')
Copy link
Contributor

Choose a reason for hiding this comment

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

when operation_group is empty it will try to load from the general sdk right? 2020 in this case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When operation_group is empty it will load the default version 2020-11-01-preview.
It has been defined in _shared.py.
For tasks, we need 2019-06-01-preview


# Provide a default name for the timer if no name was provided.
for index, schedule in enumerate(schedules, start=1):
Expand Down Expand Up @@ -507,11 +505,14 @@ def create_default_scope_map(cmd,
raise CLIError('The default scope map was already configured with different repository permissions.' +
'\nPlease use "az acr scope-map update -r {} -n {} --add <REPO> --remove <REPO>" to update.'
.format(registry_name, scope_map_name))
except CloudError:
except ResourceNotFoundError:
pass
logger.info('Creating a scope map "%s" for provided permissions.', scope_map_name)
poller = scope_map_client.create(resource_group_name, registry_name, scope_map_name,
actions, scope_map_description)
scope_map_request = {
'actions': actions,
'scope_map_description': scope_map_description
}
poller = scope_map_client.begin_create(resource_group_name, registry_name, scope_map_name, scope_map_request)
jsntcy marked this conversation as resolved.
Show resolved Hide resolved
scope_map = LongRunningOperation(cmd.cli_ctx)(poller)
return scope_map

Expand Down
28 changes: 16 additions & 12 deletions src/azure-cli/azure/cli/command_modules/acr/agentpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def acr_agentpool_create(cmd,
registry, resource_group_name = get_registry_by_name(
cmd.cli_ctx, registry_name, resource_group_name)

AgentPool = cmd.get_models('AgentPool')
AgentPool = cmd.get_models('AgentPool', operation_group='agent_pools')

agentpool_create_parameters = AgentPool(
location=registry.location,
Expand All @@ -43,10 +43,10 @@ def acr_agentpool_create(cmd,
)

try:
return client.create(resource_group_name=resource_group_name,
registry_name=registry_name,
agent_pool_name=agent_pool_name,
agent_pool=agentpool_create_parameters)
return client.begin_create(resource_group_name=resource_group_name,
registry_name=registry_name,
agent_pool_name=agent_pool_name,
agent_pool=agentpool_create_parameters)
jsntcy marked this conversation as resolved.
Show resolved Hide resolved
except ValidationError as e:
raise CLIError(e)

Expand All @@ -61,11 +61,15 @@ def acr_agentpool_update(cmd,
_, resource_group_name = validate_managed_registry(
cmd, registry_name, resource_group_name)

AgentPoolUpdateParameters = cmd.get_models('AgentPoolUpdateParameters', operation_group='agent_pools')

update_parameters = AgentPoolUpdateParameters(count=count)

Comment on lines +64 to +67
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these changes related to how the SDK is being loaded now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unified operation parameter style

We have two ways to load these parameters, model style and json style. example

try:
return client.update(resource_group_name=resource_group_name,
registry_name=registry_name,
agent_pool_name=agent_pool_name,
count=count)
return client.begin_update(resource_group_name=resource_group_name,
jsntcy marked this conversation as resolved.
Show resolved Hide resolved
registry_name=registry_name,
agent_pool_name=agent_pool_name,
update_parameters=update_parameters)
except ValidationError as e:
raise CLIError(e)

Expand All @@ -84,9 +88,9 @@ def acr_agentpool_delete(cmd,
user_confirmation("Are you sure you want to delete the agentpool '{}' in registry '{}'?".format(
agent_pool_name, registry_name), yes)
try:
response = client.delete(resource_group_name=resource_group_name,
registry_name=registry_name,
agent_pool_name=agent_pool_name)
response = client.begin_delete(resource_group_name=resource_group_name,
jsntcy marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

The result is not polled.

Then at L104, delete_agentpool_with_polling creates another LROPoller. This causes Message: The subscription '00000000-0000-0000-0000-000000000000' could not be found. error:

https://dev.azure.com/azclitools/public/_build/results?buildId=199090&view=logs&jobId=76ded334-3544-5630-8508-787a6cf96d29&j=76ded334-3544-5630-8508-787a6cf96d29&t=c62dd615-c6c6-5fdb-a846-07cb3711ef74

2024-10-22T02:44:50.2849766Z _________________ AcrAgentPoolCommandsTests.test_acr_agentpool _________________
2024-10-22T02:44:50.2850177Z [gw0] linux -- Python 3.11.8 /opt/az/bin/python3
2024-10-22T02:44:50.2850492Z self = <azure.cli.testsdk.base.ExecutionResult object at 0x7f3290732150>
2024-10-22T02:44:50.2850820Z cli_ctx = <azure.cli.core.mock.DummyCli object at 0x7f3292f7a610>
2024-10-22T02:44:50.2851257Z command = 'acr agentpool delete -n agents2 -r clireg000002 -y'
2024-10-22T02:44:50.2851538Z expect_failure = False
2024-10-22T02:44:50.2851646Z 
2024-10-22T02:44:50.2851910Z     def _in_process_execute(self, cli_ctx, command, expect_failure=False):
2024-10-22T02:44:50.2852202Z         from io import StringIO
2024-10-22T02:44:50.2852491Z         from vcr.errors import CannotOverwriteExistingCassetteException
2024-10-22T02:44:50.2852748Z     
2024-10-22T02:44:50.2853053Z         if command.startswith('az '):
2024-10-22T02:44:50.2853300Z             command = command[3:]
2024-10-22T02:44:50.2853508Z     
2024-10-22T02:44:50.2853723Z         stdout_buf = StringIO()
2024-10-22T02:44:50.2853965Z         logging_buf = StringIO()
2024-10-22T02:44:50.2854190Z         try:
2024-10-22T02:44:50.2854472Z             # issue: stderr cannot be redirect in this form, as a result some failure information
2024-10-22T02:44:50.2854774Z             # is lost when command fails.
2024-10-22T02:44:50.2855091Z >           self.exit_code = cli_ctx.invoke(shlex.split(command), out_file=stdout_buf) or 0
2024-10-22T02:44:50.2855250Z 
2024-10-22T02:44:50.2855640Z /opt/az/lib/python3.11/site-packages/azure/cli/testsdk/base.py:302: 
2024-10-22T02:44:50.2855962Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2024-10-22T02:44:50.2856368Z /opt/az/lib/python3.11/site-packages/knack/cli.py:245: in invoke
2024-10-22T02:44:50.2856673Z     exit_code = self.exception_handler(ex)
2024-10-22T02:44:50.2857120Z /opt/az/lib/python3.11/site-packages/azure/cli/core/__init__.py:129: in exception_handler
2024-10-22T02:44:50.2857436Z     return handle_exception(ex)
2024-10-22T02:44:50.2857710Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2024-10-22T02:44:50.2857832Z 
2024-10-22T02:44:50.2858523Z ex = ResourceNotFoundError("(SubscriptionNotFound) The subscription '00000000-0000-0000-0000-000000000000' could not be found.\nCode: SubscriptionNotFound\nMessage: The subscription '00000000-0000-0000-0000-000000000000' could not be found.")
2024-10-22T02:44:50.2858968Z args = (), kwargs = {}
2024-10-22T02:44:50.2859061Z 
2024-10-22T02:44:50.2859465Z     def _handle_main_exception(ex, *args, **kwargs):  # pylint: disable=unused-argument
2024-10-22T02:44:50.2859815Z         if isinstance(ex, CannotOverwriteExistingCassetteException):
2024-10-22T02:44:50.2860154Z             # This exception usually caused by a no match HTTP request. This is a product error
2024-10-22T02:44:50.2860476Z             # that is caused by change of SDK invocation.
2024-10-22T02:44:50.2860737Z             raise ex
2024-10-22T02:44:50.2860936Z     
2024-10-22T02:44:50.2861159Z >       raise CliExecutionError(ex)
2024-10-22T02:44:50.2861514Z E       azure.cli.testsdk.exceptions.CliExecutionError: The CLI throws exception ResourceNotFoundError during execution and fails the command.
2024-10-22T02:44:50.2861723Z 
2024-10-22T02:44:50.2862130Z /opt/az/lib/python3.11/site-packages/azure/cli/testsdk/patches.py:35: CliExecutionError
2024-10-22T02:44:50.2862297Z 
2024-10-22T02:44:50.2862562Z During handling of the above exception, another exception occurred:
2024-10-22T02:44:50.2862699Z 
2024-10-22T02:44:50.2863019Z self = <command_modules.acr.tests.latest.test_acr_agentpool_commands.AcrAgentPoolCommandsTests testMethod=test_acr_agentpool>
2024-10-22T02:44:50.2863666Z resource_group = 'clitest.rg000001'
2024-10-22T02:44:50.2863776Z 
2024-10-22T02:44:50.2864004Z     @ResourceGroupPreparer()
2024-10-22T02:44:50.2864265Z     def test_acr_agentpool(self, resource_group):
2024-10-22T02:44:50.2864550Z         # Agentpool prerequisites for agentpool testing
2024-10-22T02:44:50.2864807Z         self.kwargs.update({
2024-10-22T02:44:50.2865188Z             'registry_name': self.create_random_name('clireg', 20),
2024-10-22T02:44:50.2865546Z             'agents1_name': 'agents1',
2024-10-22T02:44:50.2865880Z             'agents2_name': 'agents2',
2024-10-22T02:44:50.2866196Z             'rg_loc': 'eastus',
2024-10-22T02:44:50.2866500Z             'sku': 'Premium',
2024-10-22T02:44:50.2866817Z             'vnet_name': 'agentvnets',
2024-10-22T02:44:50.2867156Z             'subnet_name': 'agentsubnets'
2024-10-22T02:44:50.2867386Z         })
2024-10-22T02:44:50.2867784Z         self.cmd('acr create -n {registry_name} -g {rg} -l {rg_loc} --sku {sku}',
2024-10-22T02:44:50.2868219Z                  checks=[self.check('name', '{registry_name}'),
2024-10-22T02:44:50.2868611Z                          self.check('location', '{rg_loc}'),
2024-10-22T02:44:50.2869000Z                          self.check('adminUserEnabled', False),
2024-10-22T02:44:50.2869407Z                          self.check('sku.name', '{sku}'),
2024-10-22T02:44:50.2869787Z                          self.check('sku.tier', '{sku}'),
2024-10-22T02:44:50.2870203Z                          self.check('provisioningState', 'Succeeded')])
2024-10-22T02:44:50.2870723Z         response = self.cmd('network vnet create -n {vnet_name} --subnet-name {subnet_name} -g {rg} -l {rg_loc}',
2024-10-22T02:44:50.2871212Z                             checks=[self.check('newVNet.name', '{vnet_name}'),
2024-10-22T02:44:50.2871656Z                                     self.check('newVNet.location', '{rg_loc}'),
2024-10-22T02:44:50.2872445Z                                     self.check('newVNet.provisioningState', 'Succeeded'),
2024-10-22T02:44:50.2872965Z                                     self.check('newVNet.subnets[0].name', '{subnet_name}'),
2024-10-22T02:44:50.2873504Z                                     self.check('newVNet.subnets[0].provisioningState', 'Succeeded')]).get_output_in_json()
2024-10-22T02:44:50.2873841Z         self.kwargs.update({
2024-10-22T02:44:50.2874239Z             'subnet_id': response['newVNet']['subnets'][0]['id']
2024-10-22T02:44:50.2874501Z         })
2024-10-22T02:44:50.2874694Z     
2024-10-22T02:44:50.2874938Z         # Create a default S1 count 1 agentpool.
2024-10-22T02:44:50.2875377Z         self.cmd('acr agentpool create -n {agents1_name} -r {registry_name}',
2024-10-22T02:44:50.2875796Z                  checks=[self.check('name', '{agents1_name}'),
2024-10-22T02:44:50.2876164Z                          self.check('count', 1),
2024-10-22T02:44:50.2876516Z                          self.check('tier', 'S1'),
2024-10-22T02:44:50.2876931Z                          self.check('virtualNetworkSubnetResourceId', 'None'),
2024-10-22T02:44:50.2877359Z                          self.check('provisioningState', 'Succeeded'),
2024-10-22T02:44:50.2877739Z                          self.check('os', 'Linux'),
2024-10-22T02:44:50.2878105Z                          self.check('location', '{rg_loc}'),
2024-10-22T02:44:50.2878468Z                          self.check('resourceGroup', '{rg}')])
2024-10-22T02:44:50.2878719Z     
2024-10-22T02:44:50.2878964Z         # Create a S2 tier agentpool in a VNET.
2024-10-22T02:44:50.2879465Z         self.cmd('acr agentpool create -n {agents2_name} -r {registry_name} --tier s2 --subnet-id {subnet_id}',
2024-10-22T02:44:50.2879941Z                  checks=[self.check('name', '{agents2_name}'),
2024-10-22T02:44:50.2880311Z                          self.check('count', 1),
2024-10-22T02:44:50.2880670Z                          self.check('tier', 'S2'),
2024-10-22T02:44:50.2881291Z                          self.check('virtualNetworkSubnetResourceId', '{subnet_id}'),
2024-10-22T02:44:50.2881868Z                          self.check('provisioningState', 'Succeeded'),
2024-10-22T02:44:50.2882251Z                          self.check('os', 'Linux'),
2024-10-22T02:44:50.2882625Z                          self.check('location', '{rg_loc}'),
2024-10-22T02:44:50.2882989Z                          self.check('resourceGroup', '{rg}')])
2024-10-22T02:44:50.2883221Z         # List agentpools
2024-10-22T02:44:50.2883555Z         self.cmd('acr agentpool list -r {registry_name}',
2024-10-22T02:44:50.2883920Z                  checks=[self.check('[0].name', '{agents2_name}'),
2024-10-22T02:44:50.2884283Z                          self.check('[1].name', '{agents1_name}')])
2024-10-22T02:44:50.2884508Z     
2024-10-22T02:44:50.2884699Z         # Delete Agent 2
2024-10-22T02:44:50.2885061Z >       self.cmd('acr agentpool delete -n {agents2_name} -r {registry_name} -y')
2024-10-22T02:44:50.2885201Z 
2024-10-22T02:44:50.2885638Z /opt/az/lib/python3.11/site-packages/azure/cli/command_modules/acr/tests/latest/test_acr_agentpool_commands.py:67: 
2024-10-22T02:44:50.2885982Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2024-10-22T02:44:50.2886431Z /opt/az/lib/python3.11/site-packages/azure/cli/testsdk/base.py:176: in cmd
2024-10-22T02:44:50.2886808Z     return execute(self.cli_ctx, command, expect_failure=expect_failure).assert_with_checks(checks)
2024-10-22T02:44:50.2887346Z /opt/az/lib/python3.11/site-packages/azure/cli/testsdk/base.py:251: in __init__
2024-10-22T02:44:50.2887755Z     self._in_process_execute(cli_ctx, command, expect_failure=expect_failure)
2024-10-22T02:44:50.2888270Z /opt/az/lib/python3.11/site-packages/azure/cli/testsdk/base.py:314: in _in_process_execute
2024-10-22T02:44:50.2888603Z     raise ex.exception
2024-10-22T02:44:50.2888997Z /opt/az/lib/python3.11/site-packages/knack/cli.py:233: in invoke
2024-10-22T02:44:50.2889314Z     cmd_result = self.invocation.execute(args)
2024-10-22T02:44:50.2889792Z /opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py:666: in execute
2024-10-22T02:44:50.2890109Z     raise ex
2024-10-22T02:44:50.2890550Z /opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py:733: in _run_jobs_serially
2024-10-22T02:44:50.2890941Z     results.append(self._run_job(expanded_arg, cmd_copy))
2024-10-22T02:44:50.2891463Z /opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py:703: in _run_job
2024-10-22T02:44:50.2891806Z     result = cmd_copy(params)
2024-10-22T02:44:50.2892295Z /opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py:336: in __call__
2024-10-22T02:44:50.2892647Z     return self.handler(*args, **kwargs)
2024-10-22T02:44:50.2893148Z /opt/az/lib/python3.11/site-packages/azure/cli/core/commands/command_operation.py:121: in handler
2024-10-22T02:44:50.2893511Z     return op(**command_args)
2024-10-22T02:44:50.2894096Z /opt/az/lib/python3.11/site-packages/azure/cli/command_modules/acr/agentpool.py:104: in acr_agentpool_delete
2024-10-22T02:44:50.2894561Z     return delete_agentpool_with_polling(cmd, client, agent_pool_name, registry_name, resource_group_name)
2024-10-22T02:44:50.2895388Z /opt/az/lib/python3.11/site-packages/azure/cli/command_modules/acr/_agentpool_polling.py:28: in delete_agentpool_with_polling
2024-10-22T02:44:50.2895772Z     initial_response=client.get(
2024-10-22T02:44:50.2896255Z /opt/az/lib/python3.11/site-packages/azure/core/tracing/decorator.py:94: in wrapper_use_tracer
2024-10-22T02:44:50.2896603Z     return func(*args, **kwargs)
2024-10-22T02:44:50.2897163Z /opt/az/lib/python3.11/site-packages/azure/mgmt/containerregistry/v2019_06_01_preview/operations/_agent_pools_operations.py:336: in get
2024-10-22T02:44:50.2897635Z     map_error(status_code=response.status_code, response=response, error_map=error_map)
2024-10-22T02:44:50.2898016Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2024-10-22T02:44:50.2898157Z 
2024-10-22T02:44:50.2898522Z status_code = 404
2024-10-22T02:44:50.2899107Z response = <RequestsTransportResponse: 404 Not Found, Content-Type: application/json; charset=utf-8>
2024-10-22T02:44:50.2899980Z error_map = {304: <class 'azure.core.exceptions.ResourceNotModifiedError'>, 401: <class 'azure.core.exceptions.ClientAuthenticatio..., 404: <class 'azure.core.exceptions.ResourceNotFoundError'>, 409: <class 'azure.core.exceptions.ResourceExistsError'>}
2024-10-22T02:44:50.2900340Z 
2024-10-22T02:44:50.2900572Z     def map_error(
2024-10-22T02:44:50.2900915Z         status_code: int, response: _HttpResponseCommonAPI, error_map: Mapping[int, Type[HttpResponseError]]
2024-10-22T02:44:50.2901303Z     ) -> None:
2024-10-22T02:44:50.2901546Z         if not error_map:
2024-10-22T02:44:50.2901787Z             return
2024-10-22T02:44:50.2902054Z         error_type = error_map.get(status_code)
2024-10-22T02:44:50.2902330Z         if not error_type:
2024-10-22T02:44:50.2902574Z             return
2024-10-22T02:44:50.2902851Z         error = error_type(response=response)
2024-10-22T02:44:50.2903124Z >       raise error
2024-10-22T02:44:50.2903726Z E       azure.core.exceptions.ResourceNotFoundError: (SubscriptionNotFound) The subscription '00000000-0000-0000-0000-000000000000' could not be found.
2024-10-22T02:44:50.2904144Z E       Code: SubscriptionNotFound
2024-10-22T02:44:50.2904637Z E       Message: The subscription '00000000-0000-0000-0000-000000000000' could not be found.
2024-10-22T02:44:50.2904821Z 
2024-10-22T02:44:50.2905270Z /opt/az/lib/python3.11/site-packages/azure/core/exceptions.py:161: ResourceNotFoundError

This is similar to #17185.

registry_name=registry_name,
agent_pool_name=agent_pool_name)

if no_wait:
logger.warning("Started to delete the agent pool '%s': %s", agent_pool_name, response.status())
Expand Down
4 changes: 2 additions & 2 deletions src/azure-cli/azure/cli/command_modules/acr/credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def acr_credential_show(cmd, client, registry_name, resource_group_name=None):

def acr_credential_renew(cmd, client, registry_name, password_name, resource_group_name=None):
registry, resource_group_name = get_registry_by_name(cmd.cli_ctx, registry_name, resource_group_name)

regenerate_credential_parameters = {'name': password_name}
if registry.admin_user_enabled: # pylint: disable=no-member
return client.regenerate_credential(
resource_group_name, registry_name, password_name)
resource_group_name, registry_name, regenerate_credential_parameters)

raise admin_not_enabled_error(registry_name)

Expand Down
Loading