Skip to content

Commit

Permalink
Replace Start-Sleep with Start-TestSleep to avoid waiting during play…
Browse files Browse the repository at this point in the history
…back (Azure#24463)
  • Loading branch information
vidai-msft authored and qinzhouxu committed Jun 5, 2024
1 parent 2a86d5c commit a746030
Show file tree
Hide file tree
Showing 26 changed files with 225 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Describe 'Remove-AzADDomainService' {
It 'DeleteViaIdentity' {
$ReplicaSet = New-AzADDomainServiceReplicaSetObject -Location $env.Location -SubnetId $env.SubnetId
$NewAdDomain = New-AzADDomainService -name $env.ADdomainName -ResourceGroupName $env.ResourceGroupName -DomainName $env.ADDomainNameCom -ReplicaSet $ReplicaSet
# Start-Sleep -s 120
Start-TestSleep 120
$GetADDomainExample = Get-AzADDomainService -ResourceGroupName $env.ResourceGroupName -Name $env.ADdomainName
Remove-AzADDomainService -InputObject $GetADDomainExample
$GetADDomainList = Get-AzADDomainService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Describe 'Update-AzADDomainService' {
}

It 'UpdateViaIdentityExpanded' {
# Start-Sleep -s 240
Start-TestSleep 240
$GetADDomainExample = Get-AzADDomainService -ResourceGroupName $env.ResourceGroupName -Name $env.ADdomainName
$UpdateADDomain = Update-AzADDomainService -InputObject $GetADDomainExample -DomainSecuritySettingTlsV1 $env.TlsV1Status2
$UpdateADDomain.DomainSecuritySettingTlsV1 | Should -Be $env.TlsV1Status2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ Describe 'Remove-AzDataMigrationToSqlDb' {
$sourcePassword = ConvertTo-SecureString $env.TestDeleteDatabaseMigrationDb.SourceSqlConnectionPassword -AsPlainText -Force

$instance = New-AzDataMigrationToSqlDb -ResourceGroupName $env.TestDeleteDatabaseMigrationDb.ResourceGroupName -SqlDbInstanceName $env.TestDeleteDatabaseMigrationDb.SqlDbInstanceName -MigrationService $env.TestDeleteDatabaseMigrationDb.MigrationService -TargetSqlConnectionAuthentication $env.TestDeleteDatabaseMigrationDb.TargetSqlConnectionAuthentication -TargetSqlConnectionDataSource $env.TestDeleteDatabaseMigrationDb.TargetSqlConnectionDataSource -TargetSqlConnectionPassword $targetPassword -TargetSqlConnectionUserName $env.TestDeleteDatabaseMigrationDb.TargetSqlConnectionUserName -SourceSqlConnectionAuthentication $env.TestDeleteDatabaseMigrationDb.SourceSqlConnectionAuthentication -SourceSqlConnectionDataSource $env.TestDeleteDatabaseMigrationDb.SourceSqlConnectionDataSource -SourceSqlConnectionUserName $env.TestDeleteDatabaseMigrationDb.SourceSqlConnectionUserName -SourceSqlConnectionPassword $sourcePassword -SourceDatabaseName $env.TestDeleteDatabaseMigrationDb.SourceDatabaseName -TargetDbName $env.TestDeleteDatabaseMigrationDb.TargetDbName -Scope $env.TestDeleteDatabaseMigrationDb.Scope
Start-Sleep -Seconds 5

Start-TestSleep -Seconds 5

Remove-AzDataMigrationToSqlDb -ResourceGroupName $env.TestDeleteDatabaseMigrationDb.ResourceGroupName -SqlDbInstanceName $env.TestDeleteDatabaseMigrationDb.SqlDbInstanceName -TargetDbName $env.TestDeleteDatabaseMigrationDb.TargetDbName -Force

Start-Sleep -Seconds 5
Start-TestSleep -Seconds 5


$dbMig = Get-AzDataMigrationToSqlDb -ResourceGroupName $env.TestDeleteDatabaseMigrationDb.ResourceGroupName -SqlDbInstanceName $env.TestDeleteDatabaseMigrationDb.SqlDbInstanceName -TargetDbName $env.TestDeleteDatabaseMigrationDb.TargetDbName -ErrorAction SilentlyContinue


$assert = ($dbMig -eq $null)
$assert | Should be $true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Describe 'Backup-AzDataProtectionBackupInstanceAdhoc' {
$jobstatus = "InProgress"
while($jobstatus -eq "InProgress")
{
Start-Sleep -Seconds 5
Start-TestSleep -Seconds 5
$currentjob = Get-AzDataProtectionJob -Id $jobid -SubscriptionId $sub -ResourceGroupName $rgName -VaultName $vaultName
$jobstatus = $currentjob.Status
}
Expand All @@ -38,21 +38,21 @@ Describe 'Backup-AzDataProtectionBackupInstanceAdhoc' {

It 'OssBackup' {
# Test trigger Backup for Oss DB
# Delete this test
# Delete this test
$sub = $env.TestOssBackupScenario.SubscriptionId
$rgName = $env.TestOssBackupScenario.ResourceGroupName
$vaultName = $env.TestOssBackupScenario.VaultName
$policyName = $env.TestOssBackupScenario.PolicyName
$policyName = $env.TestOssBackupScenario.PolicyName
$dataSourceId = $env.TestOssBackupScenario.OssDbId
$serverName = $env.TestOssBackupScenario.OssServerName
$keyVault = $env.TestOssBackupScenario.KeyVault
$secretURI = $env.TestOssBackupScenario.SecretURI

$vault = Get-AzDataProtectionBackupVault -SubscriptionId $sub -ResourceGroupName $rgName -VaultName $vaultName
$policy = Get-AzDataProtectionBackupPolicy -SubscriptionId $sub -VaultName $vaultName -ResourceGroupName $rgName | where {$_.Name -eq $policyName}

$instance = Get-AzDataProtectionBackupInstance -Subscription $sub -ResourceGroup $rgName -Vault $vaultName | Where-Object {($_.Property.DataSourceInfo.Type -eq "Microsoft.DBforPostgreSQL/servers/databases") -and ($_.Property.DataSourceInfo.ResourceId -match $serverName)}

($instance -ne $null) | Should be $true

$backupJob = Backup-AzDataProtectionBackupInstanceAdhoc -BackupInstanceName $instance.Name -ResourceGroupName $rgName -SubscriptionId $sub -VaultName $vaultName -BackupRuleOptionRuleName $policy.Property.PolicyRule[0].Name -TriggerOptionRetentionTagOverride $policy.Property.PolicyRule[0].Trigger.TaggingCriterion[0].TagInfoTagName
Expand All @@ -61,7 +61,7 @@ Describe 'Backup-AzDataProtectionBackupInstanceAdhoc' {
$jobstatus = "InProgress"
while($jobstatus -ne "Completed")
{
Start-Sleep -Seconds 10
Start-TestSleep -Seconds 10
$currentjob = Get-AzDataProtectionJob -Id $jobid -SubscriptionId $sub -ResourceGroupName $rgName -VaultName $vaultName
$jobstatus = $currentjob.Status
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,34 @@ Describe 'BlobHardeningScenario' {

$vault = Get-AzDataProtectionBackupVault -SubscriptionId $subId -ResourceGroupName $resourceGroupName -VaultName $vaultName
$pol = Get-AzDataProtectionBackupPolicy -SubscriptionId $subId -VaultName $vaultName -ResourceGroupName $resourceGroupName | Where { $_.Name -match $policyName }

$instance = Get-AzDataProtectionBackupInstance -SubscriptionId $subId -ResourceGroupName $resourceGroupName -VaultName $vaultName | Where { $_.Name -match $storageAcountName }

# Remove-BI
if($instance -ne $null){
Remove-AzDataProtectionBackupInstance -Name $instance[0].Name -SubscriptionId $subId -ResourceGroupName $resourceGroupName -VaultName $vaultName
}

Start-Sleep -Seconds 8
Start-TestSleep -Seconds 8

# new backup config and initialize BI
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName

$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
$containers=Get-AzStorageContainer -Context $storageAccount.Context
$backupConfig = New-AzDataProtectionBackupConfigurationClientObject -DatasourceType AzureBlob -VaultedBackupContainer $containers.Name

$backupConfig = New-AzDataProtectionBackupConfigurationClientObject -DatasourceType AzureBlob -VaultedBackupContainer $containers.Name
$backupConfig.ContainersList = $backupConfig.ContainersList[1,3,4]

$backupInstanceClientObject = Initialize-AzDataProtectionBackupInstance -DatasourceType AzureBlob -DatasourceLocation $vault.Location -PolicyId $pol[0].Id -DatasourceId $storageAccId -BackupConfiguration $backupConfig

# assign permissions and validate
# assign permissions and validate
Set-AzDataProtectionMSIPermission -VaultResourceGroup $resourceGroupName -VaultName $vaultName -BackupInstance $backupInstanceClientObject -PermissionsScope ResourceGroup

$operationResponse = Test-AzDataProtectionBackupInstanceReadiness -ResourceGroupName $resourceGroupName -VaultName $vaultName -SubscriptionId $subId -BackupInstance $backupInstanceClientObject.Property -NoWait
$operationId = $operationResponse.Target.Split("/")[-1].Split("?")[0]

While((Get-AzDataProtectionOperationStatus -OperationId $operationId -Location $vault.Location -SubscriptionId $subId).Status -eq "Inprogress"){
Start-Sleep -Seconds 10
Start-TestSleep -Seconds 10
}

# backup
Expand All @@ -59,7 +59,7 @@ Describe 'BlobHardeningScenario' {
$instance = Get-AzDataProtectionBackupInstance -SubscriptionId $subId -ResourceGroupName $resourceGroupName -VaultName $vaultName | Where { $_.Name -match $storageAcountName }

while($instance.Property.CurrentProtectionState -ne "ProtectionConfigured"){
Start-Sleep -Seconds 10
Start-TestSleep -Seconds 10
$instance = Get-AzDataProtectionBackupInstance -SubscriptionId $subId -ResourceGroupName $resourceGroupName -VaultName $vaultName | Where { $_.Name -match $storageAcountName }
}

Expand All @@ -74,15 +74,15 @@ Describe 'BlobHardeningScenario' {
$jobstatus = "InProgress"
while($jobstatus -ne "Completed")
{
Start-Sleep -Seconds 10
Start-TestSleep -Seconds 10
$currentjob = Get-AzDataProtectionJob -Id $jobid -SubscriptionId $subId -ResourceGroupName $resourceGroupName -VaultName $vaultName
$jobstatus = $currentjob.Status
}
$jobstatus | Should be "Completed"
$jobstatus | Should be "Completed"
}

It 'TriggerRestore' -skip {
# TODO: OLR should throw an error in case of vaulted backups
# TODO: OLR should throw an error in case of vaulted backups

$subId = $env.TestBlobHardeningScenario.SubscriptionId
$crossSubscriptionId = $env.TestBlobHardeningScenario.CrossSubscriptionId
Expand Down Expand Up @@ -112,7 +112,7 @@ Describe 'BlobHardeningScenario' {
foreach($crossSubContainerName in $targetCrossSubContainers.Name){
Remove-AzStorageContainer -Context $targetCrossSubStorageAccount.Context -Name $crossSubContainerName -Confirm:$false -Force
}

# remove containers in target storage account
Set-AzContext -SubscriptionId $subId
$targetStorageAccount = Get-AzStorageAccount -ResourceGroupName $targetStorageAccountRGName -Name $targetStorageAccountName
Expand All @@ -128,7 +128,7 @@ Describe 'BlobHardeningScenario' {
$validateRestore.ObjectType | Should be "OperationJobExtendedInfo"

$restoreJob = Start-AzDataProtectionBackupInstanceRestore -SubscriptionId $subId -ResourceGroupName $resourceGroupName -VaultName $vaultName -BackupInstanceName $instance.BackupInstanceName -Parameter $restoreReq

$restoreReqCSR = Initialize-AzDataProtectionRestoreRequest -DatasourceType AzureBlob -SourceDataStore VaultStore -RestoreLocation $vault.Location -RecoveryPoint $rp[0].Name -ItemLevelRecovery -RestoreType AlternateLocation -TargetResourceId $targetCrossSubStorageAccId -ContainersList $backedUpContainers[0,1]

$validateRestore = Test-AzDataProtectionBackupInstanceRestore -Name $instance[0].Name -ResourceGroupName $resourceGroupName -SubscriptionId $subId -VaultName $vaultName -RestoreRequest $restoreReqCSR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Describe 'DiskBackupScenario' {
It 'EndtoEndTest' {
$vaultName = $env.TestDiskBackupScenario.VaultName
$rgName = $env.TestDiskBackupScenario.ResourceGroupName
$diskId = $env.TestDiskBackupScenario.DiskId
$diskId = $env.TestDiskBackupScenario.DiskId
$snapshotRg = $env.TestDiskBackupScenario.SnapshotRG
$restoreDiskId = $env.TestDiskBackupScenario.RestoreDiskId
$policyName = $env.TestDiskBackupScenario.NewPolicyName
Expand All @@ -25,7 +25,7 @@ Describe 'DiskBackupScenario' {
$defaultPolicy = Get-AzDataProtectionPolicyTemplate -DatasourceType AzureDisk
$policyId = "/subscriptions/" + $sub + "/resourceGroups/" + $rgName + "/providers/Microsoft.DataProtection/backupVaults/" + $vaultName + "/backupPolicies/" + $policyName
$backupInstance = Initialize-AzDataProtectionBackupInstance -DatasourceType AzureDisk -DatasourceLocation centraluseuap -PolicyId $policyId -DatasourceId $diskId -SnapshotResourceGroupId $snapshotRg

$instances = Get-AzDataProtectionBackupInstance -SubscriptionId $sub -ResourceGroupName $rgName -VaultName $vaultName
$instance = $instances | where-Object {$_.Property.DataSourceInfo.ResourceId -eq $diskId}
$backupInstanceName = $instance.Name
Expand All @@ -34,24 +34,24 @@ Describe 'DiskBackupScenario' {
$protectionStatus = $instance.Property.ProtectionStatus.Status
while($protectionStatus -ne "ProtectionConfigured")
{
Start-Sleep -Seconds 5
Start-TestSleep -Seconds 5

$instance = Get-AzDataProtectionBackupInstance -SubscriptionId $sub -ResourceGroupName $rgName -VaultName $vaultName -Name $backupInstanceName
$protectionStatus = $instance.Property.ProtectionStatus.Status

# configure backup if not configured
}

$backupPolicyId = $instance.Property.PolicyInfo.PolicyId
$backupPolicyId = $instance.Property.PolicyInfo.PolicyId
$policy = Get-AzDataProtectionBackupPolicy -SubscriptionId $sub -VaultName $vaultName -ResourceGroupName $rgName | Where-Object { $_.Id -eq $backupPolicyId }

$job = Backup-AzDataProtectionBackupInstanceAdhoc -SubscriptionId $sub -ResourceGroupName $rgName -VaultName $vaultName -BackupInstanceName $backupInstanceName -BackupRuleOptionRuleName $policy.Property.PolicyRule[0].Name -TriggerOptionRetentionTagOverride $policy.Property.PolicyRule[0].Trigger.TaggingCriterion[0].TagInfoTagName

$jobid = $job.JobId.Split("/")[-1]
$jobstatus = "InProgress"
while($jobstatus -ne "Completed")
{
Start-Sleep -Seconds 5
Start-TestSleep -Seconds 5
$currentjob = Get-AzDataProtectionJob -Id $jobid -SubscriptionId $sub -ResourceGroupName $rgName -VaultName $vaultName
$jobstatus = $currentjob.Status
}
Expand All @@ -64,7 +64,7 @@ Describe 'DiskBackupScenario' {
$jobstatus = "InProgress"
while($jobstatus -ne "Completed")
{
Start-Sleep -Seconds 5
Start-TestSleep -Seconds 5
$currentjob = Get-AzDataProtectionJob -Id $jobid -SubscriptionId $sub -ResourceGroupName $rgName -VaultName $vaultName
$jobstatus = $currentjob.Status
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ Describe 'Initialize-AzDataProtectionRestoreRequest' {
$sub = $env.TestBlobsRestore.SubscriptionId
$rgName = $env.TestBlobsRestore.ResourceGroupName
$vaultName = $env.TestBlobsRestore.VaultName

# $Debug preference = "Continue"
Write-Debug -Message $sub
Write-Debug -Message $rgName
Write-Debug -Message $vaultName

$instances = Get-AzDataProtectionBackupInstance -Subscription $sub -ResourceGroup $rgName -Vault $vaultName | Where-Object {($_.Property.DataSourceInfo.Type -eq "Microsoft.Storage/storageAccounts/blobServices") -and ($_.Property.CurrentProtectionState -eq "ProtectionConfigured")}

if($instances.Count -gt 0){

$pointInTimeRange = Find-AzDataProtectionRestorableTimeRange -BackupInstanceName $instances[0].BackupInstanceName -ResourceGroupName $rgName -SubscriptionId $sub -VaultName $vaultName -SourceDataStoreType OperationalStore -StartTime (Get-Date).AddDays(-30).ToString("yyyy-MM-ddTHH:mm:ss.0000000Z") -EndTime (Get-Date).AddDays(0).ToString("yyyy-MM-ddTHH:mm:ss.0000000Z")
$vault = Get-AzDataProtectionBackupVault -ResourceGroupName $rgName -SubscriptionId $sub -VaultName $vaultName
$BlobResReq = Initialize-AzDataProtectionRestoreRequest -DatasourceType AzureBlob -SourceDataStore OperationalStore -RestoreLocation $vault.Location -RestoreType OriginalLocation -BackupInstance $instances[0] -PointInTime (Get-Date -Date $pointInTimeRange.RestorableTimeRange.EndTime)

$restoreJob = Start-AzDataProtectionBackupInstanceRestore -BackupInstanceName $instances[0].BackupInstanceName -ResourceGroupName $rgName -VaultName $vaultName -SubscriptionId $sub -Parameter $BlobResReq
$restoreJob = Start-AzDataProtectionBackupInstanceRestore -BackupInstanceName $instances[0].BackupInstanceName -ResourceGroupName $rgName -VaultName $vaultName -SubscriptionId $sub -Parameter $BlobResReq
$jobid = $restoreJob.JobId.Split("/")[-1]
$jobstatus = "InProgress"
while($jobstatus -ne "Completed")
{
Start-Sleep -Seconds 10
Start-TestSleep -Seconds 10
$currentjob = Get-AzDataProtectionJob -Id $jobid -SubscriptionId $sub -ResourceGroupName $rgName -VaultName $vaultName
$jobstatus = $currentjob.Status
}
Expand Down
Loading

0 comments on commit a746030

Please sign in to comment.