Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public void TestStorageFileShare()
public void TestStorageFileShareGetUsage()
{
TestController.NewInstance.RunPsTest(_logger, "Test-StorageFileShareGetUsage");
}
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestShareSoftDeletee()
{
TestController.NewInstance.RunPsTest(_logger, "Test-ShareSoftDelete");
}
}
}
101 changes: 101 additions & 0 deletions src/Storage/Storage.Management.Test/ScenarioTests/StorageFileTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,107 @@ function Test-StorageFileShareGetUsage
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Test Storage File Share Soft Delete
.DESCRIPTION
SmokeTest
#>
function Test-ShareSoftDelete
{
# Setup
$rgname = Get-StorageManagementTestResourceName;

try
{
# Test
$stoname = 'sto' + $rgname;
$stotype = 'Standard_LRS';
$loc = Get-ProviderLocation ResourceManagement;
$kind = 'StorageV2'
$shareName1 = "share1"+ $rgname
$shareName2 = "share2"+ $rgname

Write-Verbose "RGName: $rgname | Loc: $loc"
New-AzResourceGroup -Name $rgname -Location $loc;

$loc = Get-ProviderLocation_Stage ResourceManagement;
New-AzStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype -Kind $kind
$stos = Get-AzStorageAccount -ResourceGroupName $rgname;

# Enable Share Soft delete
Update-AzStorageFileServiceProperty -ResourceGroupName $rgname -StorageAccountName $stoname -EnableShareDeleteRetentionPolicy $true -ShareRetentionDays 5
$servicePropertie = Get-AzStorageFileServiceProperty -ResourceGroupName $rgname -StorageAccountName $stoname
Assert-AreEqual $true $servicePropertie.ShareDeleteRetentionPolicy.Enabled
Assert-AreEqual 5 $servicePropertie.ShareDeleteRetentionPolicy.Days

#create Shares
New-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName1
$share = Get-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName1
Assert-AreEqual $rgname $share.ResourceGroupName
Assert-AreEqual $stoname $share.StorageAccountName
Assert-AreEqual $shareName1 $share.Name
New-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName2

#delete share
Remove-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName1 -Force

#list share check
$share = Get-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -IncludeDeleted
$deletedShareVersion = $share[0].Version
Assert-AreEqual 2 $share.Count
Assert-AreEqual $shareName1 $share[0].Name
Assert-AreEqual $null $share[0].ShareUsageBytes
Assert-AreEqual $true $share[0].Deleted
Assert-AreNotEqual $null $share[0].DeletedTime
Assert-AreNotEqual $null $share[0].Version
Assert-AreEqual $shareName2 $share[1].Name
Assert-AreEqual $null $share[1].Deleted
Assert-AreEqual $null $share[1].DeletedTime
Assert-AreEqual $null $share[1].Version

$share = Get-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname
Assert-AreEqual 1 $share.Count
Assert-AreEqual $shareName2 $share[0].Name
Assert-AreEqual $null $share[0].Deleted
Assert-AreEqual $null $share[0].DeletedTime
Assert-AreEqual $null $share[0].Version

# restore share and check
if ($env:AZURE_TEST_MODE -eq "Record")
{
# sleep 1 miniute if record. Don't need sleep in replay
sleep 60
}
Restore-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName1 -DeletedShareVersion $deletedShareVersion

$share = Get-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname
Assert-AreEqual 2 $share.Count
Assert-AreEqual $shareName1 $share[0].Name
Assert-AreEqual $null $share[0].Deleted
Assert-AreEqual $null $share[0].DeletedTime
Assert-AreEqual $null $share[0].Version
Assert-AreEqual $shareName2 $share[1].Name
Assert-AreEqual $null $share[1].Deleted
Assert-AreEqual $null $share[1].DeletedTime
Assert-AreEqual $null $share[1].Version

$share = Get-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -IncludeDeleted
Assert-AreEqual 2 $share.Count

# Disable Share Soft delete
Update-AzStorageFileServiceProperty -ResourceGroupName $rgname -StorageAccountName $stoname -EnableShareDeleteRetentionPolicy $false
$servicePropertie = Get-AzStorageFileServiceProperty -ResourceGroupName $rgname -StorageAccountName $stoname
Assert-AreEqual $false $servicePropertie.ShareDeleteRetentionPolicy.Enabled

Remove-AzStorageAccount -Force -ResourceGroupName $rgname -Name $stoname;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}


Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/Storage/Storage.Management/Az.Storage.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ CmdletsToExport = 'Get-AzStorageAccount', 'Get-AzStorageAccountKey',
'Get-AzStorageFileHandle', 'Close-AzStorageFileHandle',
'New-AzRmStorageShare', 'Remove-AzRmStorageShare',
'Get-AzRmStorageShare', 'Update-AzRmStorageShare',
'Update-AzStorageFileServiceProperty',
'Get-AzStorageFileServiceProperty', 'Restore-AzRmStorageShare',
'Get-AzDataLakeGen2ChildItem', 'Get-AzDataLakeGen2Item',
'New-AzDataLakeGen2Item', 'Move-AzDataLakeGen2Item',
'Remove-AzDataLakeGen2Item', 'Update-AzDataLakeGen2Item',
Expand Down
7 changes: 7 additions & 0 deletions src/Storage/Storage.Management/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
- Additional information about change #1
-->
## Upcoming Release
* Supported enable/disable/get share soft delete properties on file Service of a Storage account
- `Update-AzStorageFileServiceProperty`
- `Get-AzStorageFileServiceProperty`
* Supported list file shares include the deleted ones of a Storage account, and Get single file share usage
- `Get-AzRmStorageShare`
* Supported restore a deleted file share
- `Restore-AzRmStorageShare`
* Changed the cmdlets for modify blob service properties, won't get the orginal properties from server, but only set the modified properties to server.
- `Enable-AzStorageBlobDeleteRetentionPolicy`
- `Disable-AzStorageBlobDeleteRetentionPolicy`
Expand Down
106 changes: 106 additions & 0 deletions src/Storage/Storage.Management/File/GetAzStorageFileServiceProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.Management.Storage
{
using Microsoft.Azure.Commands.Management.Storage.Models;
using Microsoft.Azure.Management.Storage;
using Microsoft.Azure.Management.Storage.Models;
using System;
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;

/// <summary>
/// Modify Azure Storage service properties
/// </summary>
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + StorageFileServiceProperty, DefaultParameterSetName = AccountNameParameterSet), OutputType(typeof(PSFileServiceProperties))]
public class GetAzStorageFileServicePropertyCommand : StorageFileBaseCmdlet
{

/// <summary>
/// AccountName Parameter Set
/// </summary>
private const string AccountNameParameterSet = "AccountName";

/// <summary>
/// Account object parameter set
/// </summary>
private const string AccountObjectParameterSet = "AccountObject";

/// <summary>
/// BlobServiceProperties ResourceId parameter set
/// </summary>
private const string PropertiesResourceIdParameterSet = "FileServicePropertiesResourceId";

[Parameter(
Position = 0,
Mandatory = true,
HelpMessage = "Resource Group Name.",
ParameterSetName = AccountNameParameterSet)]
[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Parameter(
Position = 1,
Mandatory = true,
HelpMessage = "Storage Account Name.",
ParameterSetName = AccountNameParameterSet)]
[ResourceNameCompleter("Microsoft.Storage/storageAccounts", nameof(ResourceGroupName))]
[Alias(AccountNameAlias, NameAlias)]
[ValidateNotNullOrEmpty]
public string StorageAccountName { get; set; }

[Parameter(Mandatory = true,
HelpMessage = "Storage account object",
ValueFromPipeline = true,
ParameterSetName = AccountObjectParameterSet)]
[ValidateNotNullOrEmpty]
public PSStorageAccount StorageAccount { get; set; }

[Parameter(
Position = 0,
Mandatory = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Input a Storage account Resource Id, or a File service properties Resource Id.",
ParameterSetName = PropertiesResourceIdParameterSet)]
[ValidateNotNullOrEmpty]
public string ResourceId { get; set; }

public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();
switch (ParameterSetName)
{
case AccountObjectParameterSet:
this.ResourceGroupName = StorageAccount.ResourceGroupName;
this.StorageAccountName = StorageAccount.StorageAccountName;
break;
case PropertiesResourceIdParameterSet:
ResourceIdentifier blobServicePropertiesResource = new ResourceIdentifier(ResourceId);
this.ResourceGroupName = blobServicePropertiesResource.ResourceGroupName;
this.StorageAccountName = PSBlobServiceProperties.GetStorageAccountNameFromResourceId(ResourceId);
break;
default:
// For AccountNameParameterSet, the ResourceGroupName and StorageAccountName can get from input directly
break;
}
FileServiceProperties serviceProperties = this.StorageClient.FileServices.GetServiceProperties(this.ResourceGroupName, this.StorageAccountName);

WriteObject(new PSFileServiceProperties(serviceProperties));
}
}
}
17 changes: 15 additions & 2 deletions src/Storage/Storage.Management/File/GetAzureStorageShare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public class GetAzureStorageShareCommand : StorageFileBaseCmdlet
ParameterSetName = ShareResourceIdParameterSet)]
public string Name { get; set; }


[Parameter(HelpMessage = "Specify this parameter to get the Share Usage in Bytes.",
Mandatory = false,
ParameterSetName = AccountObjectSingleParameterSet)]
Expand All @@ -121,6 +120,14 @@ public class GetAzureStorageShareCommand : StorageFileBaseCmdlet
Mandatory = false,
ParameterSetName = ShareResourceIdParameterSet)]
public SwitchParameter GetShareUsage { get; set; }

[Parameter(Mandatory = false,
HelpMessage = "Include deleted shares, by default list shares won't include deleted shares",
ParameterSetName = AccountNameParameterSet)]
[Parameter(Mandatory = false,
HelpMessage = "Include deleted shares, by default list shares won't include deleted shares",
ParameterSetName = AccountObjectParameterSet)]
public SwitchParameter IncludeDeleted { get; set; }

public override void ExecuteCmdlet()
{
Expand Down Expand Up @@ -164,9 +171,15 @@ public override void ExecuteCmdlet()
}
else
{
ListSharesExpand? listSharesExpand = null;
if (this.IncludeDeleted.IsPresent)
{
listSharesExpand = ListSharesExpand.Deleted;
}
IPage<FileShareItem> shares = this.StorageClient.FileShares.List(
this.ResourceGroupName,
this.StorageAccountName);
this.StorageAccountName,
expand: listSharesExpand);
WriteShareList(shares);
while (shares.NextPageLink != null)
{
Expand Down
Loading