Skip to content

Commit aed34e9

Browse files
committed
adding a single StorSimple scenario test
1 parent 04e2aa8 commit aed34e9

File tree

7 files changed

+6452
-53
lines changed

7 files changed

+6452
-53
lines changed

src/ServiceManagement/StorSimple/Commands.StorSimple.Test/Commands.StorSimple.Test.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
<ItemGroup>
120120
<Compile Include="Properties\AssemblyInfo.cs" />
121121
<Compile Include="ScenarioTests\BackupPolicyTests.cs" />
122+
<Compile Include="ScenarioTests\BackupTests.cs" />
122123
<Compile Include="ScenarioTests\StorSimpleTestBase.cs" />
123124
</ItemGroup>
124125
<ItemGroup>
@@ -143,6 +144,9 @@
143144
<None Include="ScenarioTests\BackupPolicyTests.ps1">
144145
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
145146
</None>
147+
<None Include="ScenarioTests\BackupTests.ps1">
148+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
149+
</None>
146150
<None Include="ScenarioTests\Configuration\ConfigurationReader.ps1">
147151
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
148152
</None>
@@ -152,6 +156,9 @@
152156
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.StorSimple.Test.ScenarioTests.BackupPolicyTests\TestNewBackupPolicyConfig.json">
153157
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
154158
</None>
159+
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.StorSimple.Test.ScenarioTests.BackupTests\TestCreateGetRestoreDeleteBackup.json">
160+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
161+
</None>
155162
</ItemGroup>
156163
<ItemGroup>
157164
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
16+
using Xunit;
17+
18+
namespace Microsoft.WindowsAzure.Commands.StorSimple.Test.ScenarioTests
19+
{
20+
public class BackupTests : StorSimpleTestBase
21+
{
22+
[Fact]
23+
[Trait(Category.AcceptanceType, Category.CheckIn)]
24+
public void TestCreateGetRestoreDeleteBackup()
25+
{
26+
RunPowerShellTest("Test-CreateGetRestoreDeleteBackup");
27+
}
28+
}
29+
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
<#
16+
.SYNOPSIS
17+
Generates unique name with given prefix
18+
#>
19+
function Generate-Name ($prefix)
20+
{
21+
$s = "Test" + $prefix
22+
#$s += "_"
23+
#$s += Get-Random
24+
$s
25+
}
26+
27+
<#
28+
.SYNOPSIS
29+
Polls for a job to finish, and returns the JobStatus object
30+
#>
31+
function Wait-Job ($taskId)
32+
{
33+
do {
34+
[Microsoft.WindowsAzure.Commands.Utilities.Common.TestMockSupport]::Delay(3000) #sleep for 3sec
35+
$taskStatus = Get-AzureStorSimpleTask -InstanceId $taskId
36+
$result = $taskStatus.AsyncTaskAggregatedResult
37+
} while($result -eq [Microsoft.WindowsAzure.Management.StorSimple.Models.AsyncTaskAggregatedResult]"InProgress")
38+
Assert-AreEqual $result ([Microsoft.WindowsAzure.Management.StorSimple.Models.AsyncTaskAggregatedResult]"Succeeded")
39+
}
40+
41+
<#
42+
.SYNOPSIS
43+
Returns default values for the test
44+
#>
45+
function Get-DefaultValue ($key)
46+
{
47+
$defaults = @{
48+
StorageAccountName = "wuscisclcis1diagj5sy4";
49+
StorageAccountPrimaryAccessKey = "gLm0tjCPJAUKzBFEVjN92ZtEwKnQK8MLasuX/ymNwMRQWFGmUA5sWZUZt9u8JfouhhYyzb3v5RQWtZSX+GxMbg==";
50+
StorageAccountSecondaryAccessKey = "zLo+ziNdEX86ffu6OURQFNRL5lrLJpf9J9T8TOk6ne/Mpl7syq1DUp4TIprBt+DGPzo4ytAON+H1N4p6GRwVHg=="
51+
}
52+
53+
return $defaults[$key];
54+
}
55+
56+
<#
57+
.SYNOPSIS
58+
Gets device name to use for the test
59+
#>
60+
function Get-DeviceName ()
61+
{
62+
$selectedResource = Select-AzureStorSimpleResource -ResourceName OneSDK-Resource -RegistrationKey "1975530557201809476:eOqMQdvHon3lGwKVYctxZVnwpZcqi8ZS1uyCLJAl6Wg=:JovQDqP1KyWdh4m3mYkdzQ==#4edfc1cde41104e5"
63+
$deviceName = (Get-AzureStorSimpleDevice) | Where{$_.Status -eq "Online"} | Select-Object -first 1 -wait | Select -ExpandProperty "FriendlyName"
64+
$pass = Assert-NotNull $deviceName
65+
$deviceName
66+
}
67+
68+
<#
69+
.SYNOPSIS
70+
Creates pre-req objects for backup related tests
71+
#>
72+
function SetupObjects-BackupScenario($deviceName, $dcName, $acrName, $iqn, $vdName)
73+
{
74+
$storageAccountName = Get-DefaultValue -key "StorageAccountName"
75+
$storageAccountKey = Get-DefaultValue -Key "StorageAccountPrimaryAccessKey"
76+
$sacToUse = Get-AzureStorSimpleStorageAccountCredential -Name $storageAccountName
77+
if($sacToUse -eq $null)
78+
{
79+
New-AzureStorSimpleStorageAccountCredential -Name $storageAccountName -Key $storageAccountKey -UseSSL $true -WaitForComplete
80+
$sacToUse = Get-AzureStorSimpleStorageAccountCredential -Name $storageAccountName
81+
}
82+
Assert-NotNull $sacToUse
83+
84+
$sacToUse | New-AzureStorSimpleDeviceVolumeContainer -Name $dcName -DeviceName $deviceName -BandWidthRate 256 -WaitForComplete
85+
$dcToUse = Get-AzureStorSimpleDeviceVolumeContainer -DeviceName $deviceName -VolumeContainerName $dcName
86+
Assert-NotNull $dcToUse
87+
88+
New-AzureStorSimpleAccessControlRecord -Name $acrName -iqn $iqn -WaitForComplete
89+
$acrList = @()
90+
$acrList += Get-AzureStorSimpleAccessControlRecord -ACRName $acrName
91+
Assert-AreNotEqual 0 @($acrList).Count
92+
93+
$dcToUse | New-AzureStorSimpleDeviceVolume -DeviceName $deviceName -Name $vdName -Size 2000000000 -AccessControlRecords $acrList -AppType PrimaryVolume -Online $true -EnableDefaultBackup $false -EnableMonitoring $false -WaitForComplete
94+
$vdToUse = Get-AzureStorSimpleDeviceVolume -DeviceName $deviceName -VolumeName $vdName
95+
Assert-NotNull $vdToUse
96+
}
97+
98+
<#
99+
.SYNOPSIS
100+
Deletes pre-req objects for backup related tests
101+
#>
102+
function CleanupObjects-BackupScenario($deviceName, $dcName, $acrName, $vdName)
103+
{
104+
Set-AzureStorSimpleDeviceVolume -DeviceName $deviceName -VolumeName $vdName -Online $false -WaitForComplete
105+
Remove-AzureStorSimpleDeviceVolume -DeviceName $deviceName -VolumeName $vdName -Force -WaitForComplete
106+
107+
Remove-AzureStorSimpleAccessControlRecord -Name $acrName -Force -WaitForComplete
108+
109+
[Microsoft.WindowsAzure.Commands.Utilities.Common.TestMockSupport]::Delay(90000)
110+
Get-AzureStorSimpleDeviceVolumeContainer -DeviceName $deviceName -Name $dcName | Remove-AzureStorSimpleDeviceVolumeContainer -DeviceName $deviceName -Force -WaitForComplete
111+
}
112+
113+
<#
114+
.SYNOPSIS
115+
Creates a custom backup policy
116+
#>
117+
function Create-CustomBackupPolicy($deviceName, $vdName, $bpName)
118+
{
119+
$vdToUse = Get-AzureStorSimpleDeviceVolume -DeviceName $deviceName -VolumeName $vdName
120+
Assert-NotNull $vdToUse
121+
122+
$schedule1 = New-AzureStorSimpleDeviceBackupScheduleAddConfig -BackupType LocalSnapshot -RecurrenceType Daily -RecurrenceValue 10 -RetentionCount 5 -Enabled $true
123+
$schedule2 = New-AzureStorSimpleDeviceBackupScheduleAddConfig -BackupType CloudSnapshot -RecurrenceType Hourly -RecurrenceValue 1 -RetentionCount 5 -Enabled $true
124+
$scheduleArray = @()
125+
$scheduleArray += $schedule1
126+
$scheduleArray += $schedule2
127+
$volumeArray = @()
128+
$volumeArray += $vdToUse.InstanceId
129+
130+
New-AzureStorSimpleDeviceBackupPolicy -DeviceName $deviceName -BackupPolicyName $bpName -BackupSchedulesToAdd $scheduleArray -VolumeIdsToAdd $volumeArray -WaitForComplete
131+
$bpToUse = Get-AzureStorSimpleDeviceBackupPolicy -DeviceName $deviceName -BackupPolicyName $bpName
132+
Assert-NotNull $bpToUse
133+
}
134+
135+
<#
136+
.SYNOPSIS
137+
Tests create, get, restore, delete of backup.
138+
#>
139+
function Test-CreateGetRestoreDeleteBackup
140+
{
141+
# Unique object names
142+
$dcName = Generate-Name("VolumeContainer")
143+
$acrName = Generate-Name("ACR")
144+
$iqn = Generate-Name("IQN")
145+
$vdName = Generate-Name("Volume")
146+
$bpName = Generate-Name("BackupPolicy")
147+
148+
# Setup
149+
$deviceName = Get-DeviceName
150+
SetupObjects-BackupScenario $deviceName $dcName $acrName $iqn $vdName
151+
152+
# Test
153+
Create-CustomBackupPolicy $deviceName $vdName $bpName
154+
$bpToUse = Get-AzureStorSimpleDeviceBackupPolicy -DeviceName $deviceName -BackupPolicyName $bpName
155+
$bpId = $bpToUse.InstanceId
156+
157+
Start-AzureStorSimpleDeviceBackupJob -DeviceName $deviceName -BackupPolicyId $bpId -BackupType CloudSnapshot -WaitForComplete
158+
159+
$retryCount = 0
160+
do {
161+
[Microsoft.WindowsAzure.Commands.Utilities.Common.TestMockSupport]::Delay(5000*$retryCount)
162+
$backupToRestore = Get-AzureStorSimpleDeviceBackup -DeviceName $deviceName -BackupPolicyId $bpId -First 1
163+
$retryCount += 1
164+
} while(($backupToRestore -eq $null) -and ($retryCount -lt 10))
165+
Assert-NotNull $backupToRestore
166+
167+
$backupId = $backupToRestore.InstanceId
168+
169+
Start-AzureStorSimpleDeviceBackupRestoreJob -DeviceName $deviceName -BackupId $backupId -Force -WaitForComplete
170+
171+
Remove-AzureStorSimpleDeviceBackup -DeviceName $deviceName -BackupId $backupId -Force -WaitForComplete
172+
173+
Remove-AzureStorSimpleDeviceBackupPolicy -DeviceName $deviceName -BackupPolicyId $bpId -Force -WaitForComplete
174+
175+
#Cleanup
176+
CleanupObjects-BackupScenario $deviceName $dcName $acrName $vdName
177+
}

src/ServiceManagement/StorSimple/Commands.StorSimple.Test/ScenarioTests/StorSimpleTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected void SetupManagementClients()
4343
{
4444
var storSimpleManagementClient = GetStorSimpleClient();
4545
var cloudServiceClient = GetCloudServiceClient();
46-
helper.SetupManagementClients(storSimpleManagementClient, cloudServiceClient);
46+
helper.SetupSomeOfManagementClients(storSimpleManagementClient, cloudServiceClient);
4747

4848
//helper.SetupSomeOfManagementClients();
4949
}

src/ServiceManagement/StorSimple/Commands.StorSimple.Test/SessionRecords/Microsoft.WindowsAzure.Commands.StorSimple.Test.ScenarioTests.BackupPolicyTests/TestNewBackupPolicyAddConfigDefaultValues.json

Lines changed: 26 additions & 26 deletions
Large diffs are not rendered by default.

src/ServiceManagement/StorSimple/Commands.StorSimple.Test/SessionRecords/Microsoft.WindowsAzure.Commands.StorSimple.Test.ScenarioTests.BackupPolicyTests/TestNewBackupPolicyConfig.json

Lines changed: 26 additions & 26 deletions
Large diffs are not rendered by default.

src/ServiceManagement/StorSimple/Commands.StorSimple.Test/SessionRecords/Microsoft.WindowsAzure.Commands.StorSimple.Test.ScenarioTests.BackupTests/TestCreateGetRestoreDeleteBackup.json

Lines changed: 6186 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)