diff --git a/src/azure-cli/azure/cli/command_modules/acr/cache.py b/src/azure-cli/azure/cli/command_modules/acr/cache.py index a2ab97c6cee..26aa7897c1b 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/cache.py +++ b/src/azure-cli/azure/cli/command_modules/acr/cache.py @@ -16,6 +16,9 @@ IdentityProperties, UserIdentityProperties ) +from knack.log import get_logger + +logger = get_logger(__name__) def acr_cache_show(cmd, @@ -66,6 +69,7 @@ def acr_cache_create(cmd, identity=None): rg = get_resource_group_name_by_registry_name(cmd.cli_ctx, registry_name, resource_group_name) + logger.warning("If cache rule '%s' already exists, it will be overwritten.", name) # Handle credential set if cred_set: diff --git a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_commands_mock.py b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_commands_mock.py index 95c8e3c34db..4c6fa0bfff7 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_commands_mock.py +++ b/src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_commands_mock.py @@ -51,6 +51,7 @@ ) from azure.cli.command_modules.acr._docker_utils import ResourceNotFound from azure.cli.command_modules.acr._constants import ACR_AUDIENCE_RESOURCE_NAME +from azure.cli.command_modules.acr.cache import acr_cache_create from azure.cli.core.mock import DummyCli @@ -64,6 +65,26 @@ class AcrMockCommandsTests(unittest.TestCase): + @mock.patch('azure.cli.command_modules.acr.cache.logger.warning') + @mock.patch('azure.cli.command_modules.acr.cache.get_resource_group_name_by_registry_name') + def test_cache_create_warns_that_existing_rule_is_overwritten( + self, mock_get_resource_group, mock_warning): + cmd = self._setup_cmd() + client = mock.MagicMock() + mock_get_resource_group.return_value = 'testresourcegroup' + + acr_cache_create( + cmd=cmd, + client=client, + registry_name='testregistry', + name='testcache', + source_repo='mcr.microsoft.com/mcr/hello-world', + target_repo='hello-world') + + mock_warning.assert_called_once_with( + "If cache rule '%s' already exists, it will be overwritten.", + 'testcache') + @mock.patch('azure.cli.command_modules.acr.repository.get_access_credentials', autospec=True) @mock.patch('requests.request', autospec=True) def test_repository_list(self, mock_requests_get, mock_get_access_credentials):