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
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.6.0" />
<PackageReference Include="Microsoft.Azure.Management.NetApp" Version="1.7.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.1.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ function Test-AccountActiveDirectory
$accName1 = Get-ResourceName
$accName2 = Get-ResourceName
$accName3 = Get-ResourceName
$resourceLocation = Get-ProviderLocation "Microsoft.NetApp"

#$resourceLocation = Get-ProviderLocation "Microsoft.NetApp"
$resourceLocation = 'westus2'

$activeDirectory1 = @{
Username = "sdkuser"
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="...")]#>
Expand Down Expand Up @@ -57,7 +58,7 @@ function Test-AccountActiveDirectory
$newTagValue = "tagValue1"
#$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-ThrowsContains{ New-AzNetAppFilesAccount -ResourceGroupName $resourceGroup -Location $resourceLocation -Name $accName1 -Tag @{$newTagName = $newTagValue} -ActiveDirectory $activeDirectories} 'Only one active directory allowed';
#Assert-True { $false }
}
catch
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// ----------------------------------------------------------------------------------
//
// 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.
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;

namespace Microsoft.Azure.Commands.NetAppFiles.Test.ScenarioTests.ScenarioTest
{
public class ActiveDirectoryTests
{
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;

public ActiveDirectoryTests(Xunit.Abstractions.ITestOutputHelper output)
{
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
}

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

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestActiveDirectoryPipelines()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ActiveDirectoryPipelines");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# ----------------------------------------------------------------------------------
#
# 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.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Test Active Directory cmdLet CRUD operations
#>
function Test-ActiveDirectoryCrud
{
$resourceGroup = Get-ResourceGroupName
$accName1 = Get-ResourceName
$activeDirectoryName1 = Get-ResourceName
$activeDirectoryName2 = Get-ResourceName
$accName2 = Get-ResourceName
#$resourceLocation = Get-ProviderLocation "Microsoft.NetApp"
$resourceLocation = 'westus2'
$adUsername = "sdkuser"
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="...")]#>
$adPassword = "sdkpass"
$adDomain = "sdkdomain"
$adDns = "192.0.2.2"
$adSmbServerName = "PSSMBSName"
$adSmbServerName2 = "PSMBSName2"

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

# try creating an Account -
$newTagName = "tag1"
$newTagValue = "tagValue1"
$retrievedAcc = New-AzNetAppFilesAccount -ResourceGroupName $resourceGroup -Location $resourceLocation -Name $accName1 -Tag @{$newTagName = $newTagValue}
Assert-AreEqual $accName1 $retrievedAcc.Name
$sPass = ConvertTo-SecureString $adPassword -AsPlainText -Force
# create and check ActiveDirectory
$retrievedAd = New-AzNetAppFilesActiveDirectory -ResourceGroupName $resourceGroup -AccountName $accName1 -AdName $activeDirectoryName1 -Username $adUsername -Password $sPass -Domain $adDomain -Dns $adDns -SmbServerName $adSmbServerName
$activeDirectoryId = $retrievedAd.ActiveDirectoryId
Assert-AreEqual $adDomain $retrievedAd.Domain
Assert-AreEqual $adUsername $retrievedAd.Username
Assert-AreEqual $adDns $retrievedAd.Dns
Assert-AreEqual $adSmbServerName $retrievedAd.SmbServerName

# get and check account
$retrievedAcc = Get-AzNetAppFilesAccount -ResourceGroupName $resourceGroup -Name $accName1
Assert-AreEqual $adSmbServerName $retrievedAcc.ActiveDirectories[0].SmbServerName
Assert-AreEqual $adUsername $retrievedAcc.ActiveDirectories[0].Username

# get and check a ActiveDirectory by id and check again
$getRetrievedAd = Get-AzNetAppFilesActiveDirectory -ResourceGroupName $resourceGroup -AccountName $accName1 -ActiveDirectoryId $activeDirectoryId
Assert-AreEqual $activeDirectoryName1 $getRetrievedAd.AdName
Assert-AreEqual $adDomain $getRetrievedAd.Domain
Assert-AreEqual $adUsername $getRetrievedAd.Username
Assert-AreEqual $adDns $getRetrievedAd.Dns
Assert-AreEqual $adSmbServerName $getRetrievedAd.SmbServerName

#update AD
$getUpdateddAd = Update-AzNetAppFilesActiveDirectory -ResourceGroupName $resourceGroup -AccountName $accName1 -ActiveDirectoryId $getRetrievedAd.ActiveDirectoryId -SmbServerName $adSmbServerName2 -Password $sPass
Assert-AreEqual $adSmbServerName2 $getUpdateddAd.SmbServerName

# delete activeDirectory retrieved
# but test the WhatIf first, should not be removed
Remove-AzNetAppFilesActiveDirectory -ResourceGroupName $resourceGroup -AccountName $accName1 -ActiveDirectoryId $getRetrievedAd.ActiveDirectoryId -WhatIf
$retrievedActiveDirectoryList = Get-AzNetAppFilesActiveDirectory -ResourceGroupName $resourceGroup -AccountName $accName1
Assert-AreEqual 1 $retrievedActiveDirectoryList.Length

#remove by name
Remove-AzNetAppFilesActiveDirectory -ResourceGroupName $resourceGroup -AccountName $accName1 -ActiveDirectoryId $getRetrievedAd.ActiveDirectoryId
Start-Sleep -s 15
$retrievedActiveDirectoryList = Get-AzNetAppFilesActiveDirectory -ResourceGroupName $resourceGroup -AccountName $accName1
Assert-AreEqual 0 $retrievedActiveDirectoryList.Length
}
finally
{
# Cleanup
Clean-ResourceGroup $resourceGroup
}
}

<#
.SYNOPSIS
Test activeDirectory Pipeline operations (uses command aliases)
#>
function Test-ActiveDirectoryPipelines
{
$resourceGroup = Get-ResourceGroupName
$accName1 = Get-ResourceName
#$resourceLocation = Get-ProviderLocation "Microsoft.NetApp"
$resourceLocation = 'westus2'
$activeDirectoryName1 = Get-ResourceName
$adUsername = "sdkuser"
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="...")]#>
$adPassword = "sdkpass"
$adDomain = "sdkdomain"
$adDns = "192.0.2.2"
$adSmbServerName = "PSSMBSName"

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

New-AnfAccount -ResourceGroupName $resourceGroup -Location $resourceLocation -Name $accName1
$sPass = ConvertTo-SecureString $adPassword -AsPlainText -Force
#create AD piping in Account
$retrievedAd = Get-AzNetAppFilesAccount -ResourceGroupName $resourceGroup -Name $accName1 | New-AzNetAppFilesActiveDirectory -AdName $activeDirectoryName1 -Username $adUsername -Password $sPass -Domain $adDomain -Dns $adDns -SmbServerName $adSmbServerName

$getRetrievedAd = Get-AzNetAppFilesAccount -ResourceGroupName $resourceGroup -Name $accName1 | Get-AzNetAppFilesActiveDirectory -ActiveDirectoryId $retrievedAd.ActiveDirectoryId
}
finally
{
# Cleanup
Clean-ResourceGroup $resourceGroup
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// ----------------------------------------------------------------------------------
//
// 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.
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;

namespace Microsoft.Azure.Commands.NetAppFiles.Test.ScenarioTests.ScenarioTest
{
public class BackupPolicyTests
{
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;

public BackupPolicyTests(Xunit.Abstractions.ITestOutputHelper output)
{
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
}

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

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestBackupPolicyPipelines()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-BackupPolicyPipelines");
}
}
}
150 changes: 150 additions & 0 deletions src/NetAppFiles/NetAppFiles.Test/ScenarioTests/BackupPolicyTests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# ----------------------------------------------------------------------------------
#
# 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.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Test Backup Policy CRUD operations
#>
function Test-BackupPolicyCrud
{
$resourceGroup = Get-ResourceGroupName
$accName1 = Get-ResourceName
$backupPolicyName1 = Get-ResourceName
$backupPolicyName2 = Get-ResourceName
$accName2 = Get-ResourceName
$resourceLocation = Get-ProviderLocation "Microsoft.NetApp"
$dailyBackupsToKeep = 4
$weeklyBackupsToKeep = 3
$monthlyBackupsToKeep = 2
$yearlyBackupsToKeep = 1
$backupLocation = "southcentralus"

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

# try creating an Account -
$newTagName = "tag1"
$newTagValue = "tagValue1"
$retrievedAcc = New-AzNetAppFilesAccount -ResourceGroupName $resourceGroup -Location $backupLocation -Name $accName1 -Tag @{$newTagName = $newTagValue}
Assert-AreEqual $accName1 $retrievedAcc.Name

# create and check BackupPolicy
$retrievedBackupPolicy = New-AzNetAppFilesBackupPolicy -ResourceGroupName $resourceGroup -Location $backupLocation -AccountName $accName1 -Name $backupPolicyName1 -Tag @{$newTagName = $newTagValue} -Enabled -DailyBackupsToKeep $dailyBackupsToKeep -WeeklyBackupsToKeep $weeklyBackupsToKeep -MonthlyBackupsToKeep $monthlyBackupsToKeep -YearlyBackupsToKeep $yearlyBackupsToKeep
Assert-AreEqual "$accName1/$backupPolicyName1" $retrievedBackupPolicy.Name
Assert-True {$retrievedBackupPolicy.Enabled}
Assert-AreEqual $dailyBackupsToKeep $retrievedBackupPolicy.DailyBackupsToKeep
Assert-AreEqual $weeklyBackupsToKeep $retrievedBackupPolicy.WeeklyBackupsToKeep
Assert-AreEqual $monthlyBackupsToKeep $retrievedBackupPolicy.MonthlyBackupsToKeep
#returns 0 atm service side issue
#Assert-AreEqual $yearlyBackupsToKeep $retrievedBackupPolicy.YearlyBackupsToKeep

# get and check a BackupPolicy by name and check again
$getRetrievedBackupPolicy = Get-AzNetAppFilesBackupPolicy -ResourceGroupName $resourceGroup -AccountName $accName1 -Name $backupPolicyName1
Assert-AreEqual "$accName1/$backupPolicyName1" $getRetrievedBackupPolicy.Name
Assert-True {$retrievedBackupPolicy.Enabled}
Assert-AreEqual $dailyBackupsToKeep $getRetrievedBackupPolicy.DailyBackupsToKeep
Assert-AreEqual $weeklyBackupsToKeep $getRetrievedBackupPolicy.WeeklyBackupsToKeep
Assert-AreEqual $monthlyBackupsToKeep $getRetrievedBackupPolicy.MonthlyBackupsToKeep
#returns 0 atm service side issue
#Assert-AreEqual $yearlyBackupsToKeep $retrievedBackupPolicy.YearlyBackupsToKeep

$updatedDailyBackupsToKeep = 2
$updatedBackupPolicy = Update-AzNetAppFilesBackupPolicy -ResourceGroupName $resourceGroup -Location $backupLocation -AccountName $accName1 -Name $backupPolicyName1 -DailyBackupsToKeep $updatedDailyBackupsToKeep
Assert-AreEqual $updatedDailyBackupsToKeep $updatedBackupPolicy.DailyBackupsToKeep

#create second BackupPolicy
$secondBackupPolicy = New-AzNetAppFilesBackupPolicy -ResourceGroupName $resourceGroup -Location $backupLocation -AccountName $accName1 -Name $backupPolicyName2 -Tag @{$newTagName = $newTagValue} -Enabled -DailyBackupsToKeep $dailyBackupsToKeep -WeeklyBackupsToKeep $weeklyBackupsToKeep -MonthlyBackupsToKeep $monthlyBackupsToKeep -YearlyBackupsToKeep $yearlyBackupsToKeep
Assert-AreEqual "$accName1/$backupPolicyName2" $secondBackupPolicy.Name
Assert-True {$retrievedBackupPolicy.Enabled}
Assert-AreEqual $dailyBackupsToKeep $secondBackupPolicy.DailyBackupsToKeep
Assert-AreEqual $weeklyBackupsToKeep $secondBackupPolicy.WeeklyBackupsToKeep
Assert-AreEqual $monthlyBackupsToKeep $secondBackupPolicy.MonthlyBackupsToKeep
#returns 0 atm service side issue
#Assert-AreEqual $yearlyBackupsToKeep $retrievedBackupPolicy.YearlyBackupsToKeep

# get and check BackupPolicies by Account (list)
$retrievedBackupPolicyList = Get-AzNetAppFilesBackupPolicy -ResourceGroupName $resourceGroup -AccountName $accName1
# check the names but the order does not appear to be guaranteed (perhaps because the names are randomly generated)
Assert-AreEqual 2 $retrievedBackupPolicyList.Length
Assert-True {"$accName1/$backupPolicyName1" -eq $retrievedBackupPolicyList[0].Name -or "$accName1/$backupPolicyName2" -eq $retrievedBackupPolicyList[0].Name}
Assert-True {"$accName1/$backupPolicyName1" -eq $retrievedBackupPolicyList[1].Name -or "$accName1/$backupPolicyName2" -eq $retrievedBackupPolicyList[1].Name}

# get and check a BackupPolicy by name
$getRetrievedBackupPolicy = Get-AzNetAppFilesBackupPolicy -ResourceGroupName $resourceGroup -AccountName $accName1 -Name $backupPolicyName1
Assert-AreEqual $accName1 $retrievedAcc.Name

# get and check the BackupPolicy again using the resource id just obtained
$getRetrievedBackupPolicyById = Get-AzNetAppFilesBackupPolicy -ResourceId $retrievedBackupPolicy.Id
Assert-AreEqual "$accName1/$backupPolicyName1" $getRetrievedBackupPolicyById.Name

# delete one BackupPolicy retrieved by id and one by name and check removed
Remove-AzNetAppFilesBackupPolicy -ResourceId $getRetrievedBackupPolicyById.Id

# but test the WhatIf first, should not be removed
Remove-AzNetAppFilesBackupPolicy -ResourceGroupName $resourceGroup -AccountName $accName1 -Name $backupPolicyName2 -WhatIf
$retrievedBackupPolicyList = Get-AzNetAppFilesBackupPolicy -ResourceGroupName $resourceGroup -AccountName $accName1
Assert-AreEqual 1 $retrievedBackupPolicyList.Length

#remove by name
Remove-AzNetAppFilesBackupPolicy -ResourceGroupName $resourceGroup -AccountName $accName1 -Name $backupPolicyName2
$retrievedBackupPolicyList = Get-AzNetAppFilesBackupPolicy -ResourceGroupName $resourceGroup -AccountName $accName1
Assert-AreEqual 0 $retrievedBackupPolicyList.Length
}
finally
{
# Cleanup
Clean-ResourceGroup $resourceGroup
}
}

<#
.SYNOPSIS
Test BackupPolicy Pipeline operations (uses command aliases)
#>
function Test-BackupPolicyPipelines
{
$resourceGroup = Get-ResourceGroupName
$accName1 = Get-ResourceName
$backupPolicyName1 = Get-ResourceName
$backupPolicyName2 = Get-ResourceName
$accName2 = Get-ResourceName
$resourceLocation = Get-ProviderLocation "Microsoft.NetApp"
$dailyBackupsToKeep = 4
$weeklyBackupsToKeep = 3
$monthlyBackupsToKeep = 2
$yearlyBackupsToKeep = 1
$backupLocation = "eastus2euap"

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

New-AnfAccount -ResourceGroupName $resourceGroup -Location $backupLocation -Name $accName1
$newTagName = "tag1"
$newTagValue = "tagValue1"

$retrievedBackupPolicy = Get-AnfAccount -ResourceGroupName $resourceGroup -Name $accName1 | New-AzNetAppFilesBackupPolicy -Name $backupPolicyName1 -Tag @{$newTagName = $newTagValue} -Enabled -DailyBackupsToKeep $dailyBackupsToKeep -WeeklyBackupsToKeep $weeklyBackupsToKeep -MonthlyBackupsToKeep $monthlyBackupsToKeep -YearlyBackupsToKeep $yearlyBackupsToKeep

# get the policy by piping in from account
$getRetrievedBackupPolicy = Get-AnfAccount -ResourceGroupName $resourceGroup -Name $accName1 | Get-AzNetAppFilesBackupPolicy -Name $backupPolicyName1
}
finally
{
# Cleanup
Clean-ResourceGroup $resourceGroup
}
}
Loading