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

[NetAppFiles]Added Revert cmdlet, update to 2020-02-01 apiversion #12891

Merged
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
2 changes: 1 addition & 1 deletion src/NetAppFiles/NetAppFiles.Test/NetAppFiles.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.NetApp" Version="1.4.0" />
<PackageReference Include="Microsoft.Azure.Management.NetApp" Version="1.6.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.1.1" />
</ItemGroup>

Expand Down
13 changes: 8 additions & 5 deletions src/NetAppFiles/NetAppFiles.Test/ScenarioTests/AccountTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ function Test-AccountActiveDirectory
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="...")]#>
Password = "sdkpass"
Domain = "sdkdomain"
Dns = "127.0.0.1"
Dns = "192.0.2.2"
SmbServerName = "PSSMBSName"
}
$activeDirectory2 = @{
Username = "sdkuser1"
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="...")]#>
Password = "sdkpass1"
Domain = "sdkdomain"
Dns = "127.0.0.1"
Dns = "192.0.2.2"
SmbServerName = "PSSMBSName"
}

Expand All @@ -55,13 +55,16 @@ function Test-AccountActiveDirectory
# create and check account 1
$newTagName = "tag1"
$newTagValue = "tagValue1"
$retrievedAcc = New-AzNetAppFilesAccount -ResourceGroupName $resourceGroup -Location $resourceLocation -Name $accName1 -Tag @{$newTagName = $newTagValue} -ActiveDirector $activeDirectories
Assert-True { $false }
#$retrievedAcc = New-AzNetAppFilesAccount -ResourceGroupName $resourceGroup -Location $resourceLocation -Name $accName1 -Tag @{$newTagName = $newTagValue} -ActiveDirector $activeDirectories

Assert-ThrowsContains{ New-AzNetAppFilesAccount -ResourceGroupName $resourceGroup -Location $resourceLocation -Name $accName1 -Tag @{$newTagName = $newTagValue} -ActiveDirector $activeDirectories} 'Only one active directory allowed';
#Assert-True { $false }
}
catch
{
$ErrorMessage = $_.Exception.Message
Assert-True { ($ErrorMessage -contains 'Only one active directory allowed') }
#Assert-True { ($ErrorMessage -contains 'Only one active directory allowed') }
Assert-True { ($ErrorMessage -contains 'Only one') }
#Assert-AreEqual $accName1 $retrievedAcc.Name
}

Expand Down
6 changes: 3 additions & 3 deletions src/NetAppFiles/NetAppFiles.Test/ScenarioTests/Common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ function Get-ProviderLocation($provider)

if ($location -eq $null)
{
return "westus2"
return "westcentralus"
} else
{
return $location.Locations[0]
}
}

return "westus2"
return "westcentralus"
}

return "westus2"
return "westcentralus"
}

<#
Expand Down
15 changes: 15 additions & 0 deletions src/NetAppFiles/NetAppFiles.Test/ScenarioTests/SnapshotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,20 @@ public void TestSnapshotPipelines()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-SnapshotPipelines");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestCreateVolumeFromSnapshot()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateVolumeFromSnapshot");
}


[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestRestoreVolumeFromSnapshot()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-RestoreVolumeFromSnapshot");
}
}
}
146 changes: 146 additions & 0 deletions src/NetAppFiles/NetAppFiles.Test/ScenarioTests/SnapshotTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,150 @@ function Test-SnapshotPipelines
# Cleanup
Clean-ResourceGroup $resourceGroup
}
}

<#
.SYNOPSIS
Test Create new Volume from a Snapshot operation
#>
function Test-CreateVolumeFromSnapshot
{
$currentSub = (Get-AzureRmContext).Subscription
$subsid = $currentSub.SubscriptionId

$resourceGroup = Get-ResourceGroupName
$accName = Get-ResourceName
$poolName = Get-ResourceName
$volName = Get-ResourceName
$snName1 = Get-ResourceName
$snName2 = Get-ResourceName
$gibibyte = 1024 * 1024 * 1024
$usageThreshold = 100 * $gibibyte
$doubleUsage = 2 * $usageThreshold
$resourceLocation = Get-ProviderLocation "Microsoft.NetApp" "eastus" -UseCanonical
$subnetName = "default"
$standardPoolSize = 4398046511104
$serviceLevel = "Premium"
$vnetName = $resourceGroup + "-vnet"

$subnetId = "/subscriptions/$subsId/resourceGroups/$resourceGroup/providers/Microsoft.Network/virtualNetworks/$vnetName/subnets/$subnetName"

try
{
# create the resource group
New-AzResourceGroup -Name $resourceGroup -Location $resourceLocation

# create virtual network
$virtualNetwork = New-AzVirtualNetwork -ResourceGroupName $resourceGroup -Location $resourceLocation -Name $vnetName -AddressPrefix 10.0.0.0/16
$delegation = New-AzDelegation -Name "netAppVolumes" -ServiceName "Microsoft.Netapp/volumes"
Add-AzVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $virtualNetwork -AddressPrefix "10.0.1.0/24" -Delegation $delegation | Set-AzVirtualNetwork

# create the resource group
New-AzResourceGroup -Name $resourceGroupName -Location $resourceLocation

# create account, pool and volume
$retrievedAcc = New-AzNetAppFilesAccount -ResourceGroupName $resourceGroup -Location $resourceLocation -AccountName $accName

$retrievedPool = New-AzNetAppFilesPool -ResourceGroupName $resourceGroup -Location $resourceLocation -AccountName $accName -PoolName $poolName -PoolSize $standardPoolSize -ServiceLevel $serviceLevel

$retrievedVolume = New-AzNetAppFilesVolume -ResourceGroupName $resourceGroup -Location $resourceLocation -AccountName $accName -PoolName $poolName -VolumeName $volName -CreationToken $volName -UsageThreshold $usageThreshold -ServiceLevel $serviceLevel -SubnetId $subnetId
Assert-AreEqual "$accName/$poolName/$volName" $retrievedVolume.Name
Assert-AreEqual $serviceLevel $retrievedVolume.ServiceLevel

# create two snapshots and check
$retrieveSn = New-AzNetAppFilesSnapshot -ResourceGroupName $resourceGroup -Location $resourceLocation -AccountName $accName -PoolName $poolName -VolumeName $volName -SnapshotName $snName1 -FileSystemId $retrievedVolume.FileSystemId
Assert-AreEqual "$accName/$poolName/$volName/$snName1" $retrieveSn.Name
# check created date has been populated
Assert-NotNull $retrieveSn.Created

# get and check a snapshot by name
$retrievedSnapshot = Get-AzNetAppFilesSnapshot -ResourceGroupName $resourceGroup -AccountName $accName -PoolName $poolName -VolumeName $volName -SnapshotName $snName1
Assert-AreEqual "$accName/$poolName/$volName/$snName1" $retrievedSnapshot.Name

# get and check the snapshot again using the resource id just obtained
$retrievedSnapshotById = Get-AzNetAppFilesSnapshot -ResourceId $retrievedSnapshot.Id
Assert-AreEqual "$accName/$poolName/$volName/$snName1" $retrievedSnapshotById.Name

# Create volume from snapshot
$restoredVolume = New-AzNetAppFilesVolume -ResourceGroupName $resourceGroup -Location $resourceLocation -AccountName $accName -PoolName $poolName -VolumeName $volName -CreationToken $volName -UsageThreshold $usageThreshold -ServiceLevel $serviceLevel -SubnetId $subnetId -SnapshotId $retrievedSnapshot.SnapshotId
Assert-AreEqual $retrievedVolume.Name $restoredVolume.Name
}
finally
{
# Cleanup
Clean-ResourceGroup $resourceGroup
}
}

<#
.SYNOPSIS
Test Restore/Revert Volume from one of its Snapshots
#>
function Test-RestoreVolumeFromSnapshot
{
$currentSub = (Get-AzureRmContext).Subscription
$subsid = $currentSub.SubscriptionId

$resourceGroup = Get-ResourceGroupName
$accName = Get-ResourceName
$poolName = Get-ResourceName
$volName = Get-ResourceName
$snName1 = Get-ResourceName
$snName2 = Get-ResourceName
$gibibyte = 1024 * 1024 * 1024
$usageThreshold = 100 * $gibibyte
$doubleUsage = 2 * $usageThreshold
$resourceLocation = Get-ProviderLocation "Microsoft.NetApp" "eastus" -UseCanonical
$subnetName = "default"
$standardPoolSize = 4398046511104
$serviceLevel = "Premium"
$vnetName = $resourceGroup + "-vnet"

$subnetId = "/subscriptions/$subsId/resourceGroups/$resourceGroup/providers/Microsoft.Network/virtualNetworks/$vnetName/subnets/$subnetName"

try
{
# create the resource group
New-AzResourceGroup -Name $resourceGroup -Location $resourceLocation

# create virtual network
$virtualNetwork = New-AzVirtualNetwork -ResourceGroupName $resourceGroup -Location $resourceLocation -Name $vnetName -AddressPrefix 10.0.0.0/16
$delegation = New-AzDelegation -Name "netAppVolumes" -ServiceName "Microsoft.Netapp/volumes"
Add-AzVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $virtualNetwork -AddressPrefix "10.0.1.0/24" -Delegation $delegation | Set-AzVirtualNetwork

# create the resource group
New-AzResourceGroup -Name $resourceGroupName -Location $resourceLocation

# create account, pool and volume
$retrievedAcc = New-AzNetAppFilesAccount -ResourceGroupName $resourceGroup -Location $resourceLocation -AccountName $accName

$retrievedPool = New-AzNetAppFilesPool -ResourceGroupName $resourceGroup -Location $resourceLocation -AccountName $accName -PoolName $poolName -PoolSize $standardPoolSize -ServiceLevel $serviceLevel

$retrievedVolume = New-AzNetAppFilesVolume -ResourceGroupName $resourceGroup -Location $resourceLocation -AccountName $accName -PoolName $poolName -VolumeName $volName -CreationToken $volName -UsageThreshold $usageThreshold -ServiceLevel $serviceLevel -SubnetId $subnetId
Assert-AreEqual "$accName/$poolName/$volName" $retrievedVolume.Name
Assert-AreEqual $serviceLevel $retrievedVolume.ServiceLevel

# create two snapshots and check
$retrieveSn = New-AzNetAppFilesSnapshot -ResourceGroupName $resourceGroup -Location $resourceLocation -AccountName $accName -PoolName $poolName -VolumeName $volName -SnapshotName $snName1 -FileSystemId $retrievedVolume.FileSystemId
Assert-AreEqual "$accName/$poolName/$volName/$snName1" $retrieveSn.Name
# check created date has been populated
Assert-NotNull $retrieveSn.Created

# get and check a snapshot by name
$retrievedSnapshot = Get-AzNetAppFilesSnapshot -ResourceGroupName $resourceGroup -AccountName $accName -PoolName $poolName -VolumeName $volName -SnapshotName $snName1
Assert-AreEqual "$accName/$poolName/$volName/$snName1" $retrievedSnapshot.Name

# get and check the snapshot again using the resource id just obtained
$retrievedSnapshotById = Get-AzNetAppFilesSnapshot -ResourceId $retrievedSnapshot.Id
Assert-AreEqual "$accName/$poolName/$volName/$snName1" $retrievedSnapshotById.Name

# revert the volume from snapshot
Restore-AzNetAppFilesVolume -ResourceGroupName $resourceGroup -AccountName $accName -PoolName $poolName -VolumeName $volName -SnapshotId $retrievedSnapshot.SnapshotId

}
finally
{
# Cleanup
Clean-ResourceGroup $resourceGroup
}
}
Loading