|
| 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 | +} |
0 commit comments