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

Deprecated new_name in Undelete #18690

Merged
merged 4 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# --------------------------------------------------------------------------

import functools
import warnings
from typing import ( # pylint: disable=unused-import
Union, Optional, Any, Iterable, Dict, List,
TYPE_CHECKING
Expand Down Expand Up @@ -624,14 +625,13 @@ def undelete_container(self, deleted_container_name, deleted_container_version,
Specifies the name of the deleted container to restore.
:param str deleted_container_version:
Specifies the version of the deleted container to restore.
:keyword str new_name:
The new name for the deleted container to be restored to.
If not specified deleted_container_name will be used as the restored container name.
:keyword int timeout:
The timeout parameter is expressed in seconds.
:rtype: ~azure.storage.blob.ContainerClient
"""
new_name = kwargs.pop('new_name', None)
if new_name:
warnings.warn("`new_name` is no longer supported.", DeprecationWarning)
container = self.get_container_client(new_name or deleted_container_name)
try:
container._client.container.restore(deleted_container_name=deleted_container_name, # pylint: disable = protected-access
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# --------------------------------------------------------------------------
# pylint: disable=invalid-overridden-method
import functools
import warnings
from typing import ( # pylint: disable=unused-import
Union, Optional, Any, Iterable, Dict, List,
TYPE_CHECKING
Expand Down Expand Up @@ -568,14 +569,13 @@ async def undelete_container(self, deleted_container_name, deleted_container_ver
Specifies the name of the deleted container to restore.
:param str deleted_container_version:
Specifies the version of the deleted container to restore.
:keyword str new_name:
The new name for the deleted container to be restored to.
If not specified deleted_container_name will be used as the restored container name.
:keyword int timeout:
The timeout parameter is expressed in seconds.
:rtype: ~azure.storage.blob.aio.ContainerClient
"""
new_name = kwargs.pop('new_name', None)
if new_name:
warnings.warn("`new_name` is no longer supported.", DeprecationWarning)
container = self.get_container_client(new_name or deleted_container_name)
try:
await container._client.container.restore(deleted_container_name=deleted_container_name, # pylint: disable = protected-access
Expand Down

This file was deleted.

Large diffs are not rendered by default.

This file was deleted.

Large diffs are not rendered by default.

41 changes: 5 additions & 36 deletions sdk/storage/azure-storage-blob/tests/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# --------------------------------------------------------------------------

import sys
import time
from datetime import datetime, timedelta
from time import sleep

Expand Down Expand Up @@ -795,8 +796,7 @@ def test_delete_container_with_lease_id(self, resource_group, location, storage_
@pytest.mark.playback_test_only
@GlobalStorageAccountPreparer()
def test_undelete_container(self, resource_group, location, storage_account, storage_account_key):
# container soft delete should enabled by SRP call or use armclient, so make this test as playback only.

# TODO: container soft delete should enabled by SRP call or use ARM, so make this test as playback only.
bsc = BlobServiceClient(self.account_url(storage_account, "blob"), storage_account_key)
container_client = self._create_container(bsc)

Expand All @@ -809,49 +809,20 @@ def test_undelete_container(self, resource_group, location, storage_account, sto
container_list = list(bsc.list_containers(include_deleted=True))
self.assertTrue(len(container_list) >= 1)

restored_version = 0
for container in container_list:
# find the deleted container and restore it
if container.deleted and container.name == container_client.container_name:
restored_ctn_client = bsc.undelete_container(container.name, container.version,
new_name="restored" + str(restored_version))
restored_version += 1
restored_ctn_client = bsc.undelete_container(container.name, container.version)

# to make sure the deleted container is restored
props = restored_ctn_client.get_container_properties()
self.assertIsNotNone(props)

@pytest.mark.playback_test_only
@GlobalStorageAccountPreparer()
def test_restore_to_existing_container(self, resource_group, location, storage_account, storage_account_key):
# container soft delete should enabled by SRP call or use armclient, so make this test as playback only.

bsc = BlobServiceClient(self.account_url(storage_account, "blob"), storage_account_key)
# get an existing container
existing_container_client = self._create_container(bsc, prefix="existing")
container_client = self._create_container(bsc)

# Act
container_client.delete_container()
# to make sure the container deleted
with self.assertRaises(ResourceNotFoundError):
container_client.get_container_properties()

container_list = list(bsc.list_containers(include_deleted=True))
self.assertTrue(len(container_list) >= 1)

for container in container_list:
# find the deleted container and restore it
if container.deleted and container.name == container_client.container_name:
with self.assertRaises(HttpResponseError):
bsc.undelete_container(container.name, container.version,
new_name=existing_container_client.container_name)

@pytest.mark.live_test_only # sas token is dynamically generated
@pytest.mark.playback_test_only # we need container soft delete enabled account
@GlobalStorageAccountPreparer()
def test_restore_with_sas(self, resource_group, location, storage_account, storage_account_key):
# container soft delete should enabled by SRP call or use armclient, so make this test as playback only.
# TODO: container soft delete should enabled by SRP call or use ARM, so make this test as playback only.
token = generate_account_sas(
storage_account.name,
storage_account_key,
Expand All @@ -873,9 +844,7 @@ def test_restore_with_sas(self, resource_group, location, storage_account, stora
for container in container_list:
# find the deleted container and restore it
if container.deleted and container.name == container_client.container_name:
restored_ctn_client = bsc.undelete_container(container.name, container.version,
new_name="restored" + str(restored_version))
restored_version += 1
restored_ctn_client = bsc.undelete_container(container.name, container.version)

# to make sure the deleted container is restored
props = restored_ctn_client.get_container_properties()
Expand Down
39 changes: 3 additions & 36 deletions sdk/storage/azure-storage-blob/tests/test_container_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import time
from time import sleep

import pytest
Expand Down Expand Up @@ -869,8 +870,7 @@ async def test_delete_container_with_lease_id(self, resource_group, location, st
@GlobalStorageAccountPreparer()
@AsyncStorageTestCase.await_prepared_test
async def test_undelete_container(self, resource_group, location, storage_account, storage_account_key):
# container soft delete should enabled by SRP call or use armclient, so make this test as playback only.
pytest.skip('This will be added back along with STG74 features')
# TODO: container soft delete should enabled by SRP call or use ARM, so make this test as playback only.
bsc = BlobServiceClient(self.account_url(storage_account, "blob"), storage_account_key)
container_client = await self._create_container(bsc)

Expand All @@ -885,48 +885,15 @@ async def test_undelete_container(self, resource_group, location, storage_accoun
container_list.append(c)
self.assertTrue(len(container_list) >= 1)

restored_version = 0
for container in container_list:
# find the deleted container and restore it
if container.deleted and container.name == container_client.container_name:
restored_ctn_client = await bsc.undelete_container(container.name, container.version,
new_name="restoredctn" + str(restored_version))
restored_version += 1
restored_ctn_client = await bsc.undelete_container(container.name, container.version)

# to make sure the deleted container is restored
props = await restored_ctn_client.get_container_properties()
self.assertIsNotNone(props)

@pytest.mark.playback_test_only
@GlobalStorageAccountPreparer()
@AsyncStorageTestCase.await_prepared_test
async def test_restore_to_existing_container(self, resource_group, location, storage_account, storage_account_key):
pytest.skip('This will be added back along with STG74 features')
# container soft delete should enabled by SRP call or use armclient, so make this test as playback only.

bsc = BlobServiceClient(self.account_url(storage_account, "blob"), storage_account_key)
# get an existing container
existing_container_client = await self._create_container(bsc, prefix="existing")
container_client = await self._create_container(bsc)

# Act
await container_client.delete_container()
# to make sure the container deleted
with self.assertRaises(ResourceNotFoundError):
await container_client.get_container_properties()

container_list = list()
async for c in bsc.list_containers(include_deleted=True):
container_list.append(c)
self.assertTrue(len(container_list) >= 1)

for container in container_list:
# find the deleted container and restore it
if container.deleted and container.name == container_client.container_name:
with self.assertRaises(HttpResponseError):
await bsc.undelete_container(container.name, container.version,
new_name=existing_container_client.container_name)

@GlobalStorageAccountPreparer()
@AsyncStorageTestCase.await_prepared_test
async def test_list_names(self, resource_group, location, storage_account, storage_account_key):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import warnings
from typing import Optional, Dict, Any

try:
Expand Down Expand Up @@ -294,14 +295,13 @@ def undelete_file_system(self, name, deleted_version, **kwargs):
Specifies the name of the deleted filesystem to restore.
:param str deleted_version:
Specifies the version of the deleted filesystem to restore.
:keyword str new_name:
The new name for the deleted filesystem to be restored to.
If not specified "name" will be used as the restored filesystem name.
:keyword int timeout:
The timeout parameter is expressed in seconds.
:rtype: ~azure.storage.filedatalake.FileSystemClient
"""
new_name = kwargs.pop('new_name', None)
if new_name:
warnings.warn("`new_name` is no longer supported.", DeprecationWarning)
file_system = self.get_file_system_client(new_name or name)
self._blob_service_client.undelete_container(
name, deleted_version, new_name=new_name, **kwargs) # pylint: disable=protected-access
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# license information.
# --------------------------------------------------------------------------
# pylint: disable=invalid-overridden-method
import warnings
from typing import Optional, Any, Dict

from azure.core.paging import ItemPaged
Expand Down Expand Up @@ -244,14 +245,13 @@ async def undelete_file_system(self, name, deleted_version, **kwargs):
Specifies the name of the deleted filesystem to restore.
:param str deleted_version:
Specifies the version of the deleted filesystem to restore.
:keyword str new_name:
The new name for the deleted filesystem to be restored to.
If not specified "name" will be used as the restored filesystem name.
:keyword int timeout:
The timeout parameter is expressed in seconds.
:rtype: ~azure.storage.filedatalake.FileSystemClient
"""
new_name = kwargs.pop('new_name', None)
if new_name:
warnings.warn("`new_name` is no longer supported.", DeprecationWarning)
await self._blob_service_client.undelete_container(name, deleted_version, new_name=new_name, **kwargs) # pylint: disable=protected-access
file_system = self.get_file_system_client(new_name or name)
return file_system
Expand Down
Loading