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

remove-disk and resolve health error API #15

Open
wants to merge 14 commits into
base: Az.RecoveryServices_preview
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,19 @@ public void A2ANewAsrReplicationProtectedItemDisk()
{
this.RunPowerShellTest(_logger, Constants.NewModel, "Test-AddReplicationProtectedItemDisk");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void A2ARemoveReplicationProtectedItemDisk()
{
this.RunPowerShellTest(_logger, Constants.NewModel, "Test-RemoveReplicationProtectedItemDisk");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void A2ARemoveReplicationProtectedItemHealthError()
{
this.RunPowerShellTest(_logger, Constants.NewModel, "Test-ResolveHealthError");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,274 @@ function Test-AddReplicationProtectedItemDisk{
WaitForJobCompletion -JobId $addDRjob.Name
WaitForAddDisksIRCompletion -affectedObjectId $addDRjob.TargetObjectId

$pe = Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName
Assert-NotNull($pe)

<#
.SYNOPSIS
Test RemoveReplicationProtectedItemDisk new parametersets
#>

function Test-RemoveReplicationProtectedItemDisk{
param([string] $seed ='600')
$primaryPolicyName = getPrimaryPolicy
$recoveryPolicyName = getRecoveryPolicy

$primaryContainerMappingName = getPrimaryContainerMapping
$recoveryContainerMappingName = getRecoveryContainerMapping

$primaryContainerName = getPrimaryContainer
$recoveryContainerName = getRecoveryContainer
$vaultRgLocation = getVaultRgLocation
$vaultName = getVaultName
$vaultLocation = getVaultLocation
$vaultRg = getVaultRg
$primaryLocation = getPrimaryLocation
$recoveryLocation = getRecoveryLocation
$primaryFabricName = getPrimaryFabric
$recoveryFabricName = getRecoveryFabric
$RecoveryReplicaDiskAccountType = "Premium_LRS"
$RecoveryTargetDiskAccountType = "Premium_LRS"
$policyName = getPrimaryPolicy
$mappingName = getPrimaryContainerMapping
$primaryNetMapping = getPrimaryNetworkMapping

New-AzResourceGroup -name $vaultRg -location $vaultRgLocation -force
[Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(20 * 1000)
# vault Creation
New-AzRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName -Location $vaultLocation
[Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(20 * 1000)
$Vault = Get-AzRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName
Set-ASRVaultContext -Vault $Vault
# fabric Creation
### AzureToAzure New paramset
$fabJob= New-AzRecoveryServicesAsrFabric -Azure -Name $primaryFabricName -Location $primaryLocation
WaitForJobCompletion -JobId $fabJob.Name
$fab = Get-AzRecoveryServicesAsrFabric -Name $primaryFabricName
Assert-true { $fab.name -eq $primaryFabricName }
Assert-AreEqual $fab.FabricSpecificDetails.Location $primaryLocation

$fabJob= New-AzRecoveryServicesAsrFabric -Azure -Name $recoveryFabricName -Location $recoveryLocation
WaitForJobCompletion -JobId $fabJob.Name
$fab = Get-AzRecoveryServicesAsrFabric -Name $recoveryFabricName
Assert-true { $fab.name -eq $recoveryFabricName }
Assert-AreEqual $fab.FabricSpecificDetails.Location $recoveryLocation
$pf = get-asrFabric -Name $primaryFabricName
$rf = get-asrFabric -Name $recoveryFabricName

### AzureToAzure (Default)
$job = New-AzRecoveryServicesAsrProtectionContainer -Name $primaryContainerName -Fabric $pf
WaitForJobCompletion -JobId $Job.Name
$pc = Get-asrProtectionContainer -name $primaryContainerName -Fabric $pf
Assert-NotNull($pc)
$job = New-AzRecoveryServicesAsrProtectionContainer -Name $recoveryContainerName -Fabric $rf
WaitForJobCompletion -JobId $Job.Name
$rc = Get-asrProtectionContainer -name $recoveryContainerName -Fabric $rf
Assert-NotNull($rc)

#create policy and mapping
$job = New-AzRecoveryServicesAsrPolicy -Name $policyName -RecoveryPointRetentionInHours 12 -AzureToAzure
WaitForJobCompletion -JobId $job.Name
$policy = Get-AzRecoveryServicesAsrPolicy -Name $policyName
$job = New-AzRecoveryServicesAsrProtectionContainerMapping -Name $mappingName -Policy $policy -PrimaryProtectionContainer $pc -RecoveryProtectionContainer $rc
WaitForJobCompletion -JobId $job.Name
$mapping = Get-AzRecoveryServicesAsrProtectionContainerMapping -Name $mappingName -ProtectionContainer $pc

$v2VmIdRec = createRecoveryAzureVm
$recRgName = getRecoveryResourceGroupName
$index =$v2VmIdRec.IndexOf("/providers/")
$recRg =$v2VmIdRec.Substring(0,$index)
$RecoveryAzureNetworkId = $recRg + "/providers/Microsoft.Network/virtualNetworks/" + $recRgName
$v2VmId = createAzureVm
$vmName = getAzureVmName
$logStg = createCacheStorageAccount
$vm = get-azVm -ResourceGroupName $vmName -Name $vmName
$vhdid =$vm.StorageProfile.OSDisk.ManagedDisk.Id
$index =$v2VmId.IndexOf("/providers/")
$Rg =$v2VmId.Substring(0,$index)
$PrimaryAzureNetworkId = $Rg + "/providers/Microsoft.Network/virtualNetworks/" + $vmName

#network mapping
$job = New-AzRecoveryServicesAsrNetworkMapping -AzureToAzure -Name $primaryNetMapping -PrimaryFabric $pf -PrimaryAzureNetworkId $PrimaryAzureNetworkId -RecoveryFabric $rf -RecoveryAzureNetworkId $RecoveryAzureNetworkId
WaitForJobCompletion -JobId $job.Name

#enable Replication
$v = New-AzRecoveryServicesAsrAzureToAzureDiskReplicationConfig -managed -LogStorageAccountId $logStg `
-DiskId $vhdid -RecoveryResourceGroupId $recRg -RecoveryReplicaDiskAccountType $RecoveryReplicaDiskAccountType `
-RecoveryTargetDiskAccountType $RecoveryTargetDiskAccountType
$enableDRjob = New-AzRecoveryServicesAsrReplicationProtectedItem -AzureToAzure -AzureVmId $v2VmId -Name $vmName -ProtectionContainerMapping $mapping -RecoveryResourceGroupId $recRg -AzureToAzureDiskReplicationConfiguration $v
WaitForJobCompletion -JobId $enableDRjob.Name
WaitForIRCompletion -affectedObjectId $enableDRjob.TargetObjectId

#add diskId
$pe = Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName
Assert-NotNull($pe)

#create disk and attach
$diskName = getAzureDataDiskName
$newDiskConfig = New-AzDiskConfig -Location $vm.Location -CreateOption Empty -DiskSizeGB 5
$newDisk = New-AzDisk -ResourceGroupName $vm.ResourceGroupName -DiskName $diskName -Disk $newDiskConfig
$vm = Add-AzVMDataDisk -VM $vm -Name $diskName -CreateOption Attach -ManagedDiskId $newDisk.Id -Lun 5
Update-azVm -ResourceGroupName $vmName -VM $vm

#wait for the add-disk health warning to appear
Write-Host $("Waiting for Add-Disk health warning...") -ForegroundColor Yellow
$HealthQueryWaitTimeInSeconds = 10
do
{
$pe = Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName
$healthError = $pe.ReplicationHealthErrors | where-object {$_.ErrorCode -eq 153039}

if($healthError -eq $null)
{
Write-Host $("Waiting for Add-Disk health warning...") -ForegroundColor Yellow
Write-Host $("Waiting for: " + $HealthQueryWaitTimeInSeconds.ToString + " Seconds") -ForegroundColor Yellow
[Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait($HealthQueryWaitTimeInSeconds * 1000)
}
}While($healthError -eq $null)

#add disks
$disk2= New-AzRecoveryServicesAsrAzureToAzureDiskReplicationConfig -DiskId $newDisk.Id -LogStorageAccountId $pe.ProviderSpecificDetails.A2ADiskDetails[0].PrimaryStagingAzureStorageAccountId -ManagedDisk -RecoveryReplicaDiskAccountType $RecoveryReplicaDiskAccountType -RecoveryResourceGroupId $pe.ProviderSpecificDetails.A2ADiskDetails[0].RecoveryResourceGroupId -RecoveryTargetDiskAccountType $RecoveryTargetDiskAccountType
$addDRjob = Add-AzRecoveryServicesAsrReplicationProtectedItemDisk -ReplicationProtectedItem $pe -AzureToAzureDiskReplicationConfiguration $disk2
WaitForJobCompletion -JobId $addDRjob.Name

#get disk to deattach
| $removeDisk = $pe.ProviderSpecificDetails.A2ADiskDetails | where-object {$_.AllowedDiskLevelOperation.Count -eq 1}
Assert-NotNull($removeDisk)
$vm = get-azVm -ResourceGroupName $vmName -Name $vmName
$removeDiskId = $vm.StorageProfile.DataDisks | Where-Object {$_.ManagedDisk.Name -eq $removeDisk.DiskName}
$removeDRjob = Remove-AzRecoveryServicesAsrReplicationProtectedItemDisk -ReplicationProtectedItem $pe -DiskId $removeDiskId.ManagedDisk.Id
WaitForJobCompletion -JobId $removeDRjob.Name

$pe = Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName
Assert-NotNull($pe)
}


<#
.SYNOPSIS
Test ResolveHealthError new parametersets
#>

function Test-ResolveHealthError{
param([string] $seed ='557')
$primaryPolicyName = getPrimaryPolicy
$recoveryPolicyName = getRecoveryPolicy

$primaryContainerMappingName = getPrimaryContainerMapping
$recoveryContainerMappingName = getRecoveryContainerMapping

$primaryContainerName = getPrimaryContainer
$recoveryContainerName = getRecoveryContainer
$vaultRgLocation = getVaultRgLocation
$vaultName = getVaultName
$vaultLocation = getVaultLocation
$vaultRg = getVaultRg
$primaryLocation = getPrimaryLocation
$recoveryLocation = getRecoveryLocation
$primaryFabricName = getPrimaryFabric
$recoveryFabricName = getRecoveryFabric
$RecoveryReplicaDiskAccountType = "Premium_LRS"
$RecoveryTargetDiskAccountType = "Premium_LRS"
$policyName = getPrimaryPolicy
$mappingName = getPrimaryContainerMapping
$primaryNetMapping = getPrimaryNetworkMapping

New-AzResourceGroup -name $vaultRg -location $vaultRgLocation -force
[Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(20 * 1000)
# vault Creation
New-AzRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName -Location $vaultLocation
[Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(20 * 1000)
$Vault = Get-AzRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName
Set-ASRVaultContext -Vault $Vault
# fabric Creation
### AzureToAzure New paramset
$fabJob= New-AzRecoveryServicesAsrFabric -Azure -Name $primaryFabricName -Location $primaryLocation
WaitForJobCompletion -JobId $fabJob.Name
$fab = Get-AzRecoveryServicesAsrFabric -Name $primaryFabricName
Assert-true { $fab.name -eq $primaryFabricName }
Assert-AreEqual $fab.FabricSpecificDetails.Location $primaryLocation

$fabJob= New-AzRecoveryServicesAsrFabric -Azure -Name $recoveryFabricName -Location $recoveryLocation
WaitForJobCompletion -JobId $fabJob.Name
$fab = Get-AzRecoveryServicesAsrFabric -Name $recoveryFabricName
Assert-true { $fab.name -eq $recoveryFabricName }
Assert-AreEqual $fab.FabricSpecificDetails.Location $recoveryLocation
$pf = get-asrFabric -Name $primaryFabricName
$rf = get-asrFabric -Name $recoveryFabricName

### AzureToAzure (Default)
$job = New-AzRecoveryServicesAsrProtectionContainer -Name $primaryContainerName -Fabric $pf
WaitForJobCompletion -JobId $Job.Name
$pc = Get-asrProtectionContainer -name $primaryContainerName -Fabric $pf
Assert-NotNull($pc)
$job = New-AzRecoveryServicesAsrProtectionContainer -Name $recoveryContainerName -Fabric $rf
WaitForJobCompletion -JobId $Job.Name
$rc = Get-asrProtectionContainer -name $recoveryContainerName -Fabric $rf
Assert-NotNull($rc)

#create policy and mapping
$job = New-AzRecoveryServicesAsrPolicy -Name $policyName -RecoveryPointRetentionInHours 12 -AzureToAzure
WaitForJobCompletion -JobId $job.Name
$policy = Get-AzRecoveryServicesAsrPolicy -Name $policyName
$job = New-AzRecoveryServicesAsrProtectionContainerMapping -Name $mappingName -Policy $policy -PrimaryProtectionContainer $pc -RecoveryProtectionContainer $rc
WaitForJobCompletion -JobId $job.Name
$mapping = Get-AzRecoveryServicesAsrProtectionContainerMapping -Name $mappingName -ProtectionContainer $pc

$v2VmIdRec = createRecoveryAzureVm
$recRgName = getRecoveryResourceGroupName
$index =$v2VmIdRec.IndexOf("/providers/")
$recRg =$v2VmIdRec.Substring(0,$index)
$RecoveryAzureNetworkId = $recRg + "/providers/Microsoft.Network/virtualNetworks/" + $recRgName
$v2VmId = createAzureVm
$vmName = getAzureVmName
$logStg = createCacheStorageAccount
$vm = get-azVm -ResourceGroupName $vmName -Name $vmName
$vhdid =$vm.StorageProfile.OSDisk.ManagedDisk.Id
$index =$v2VmId.IndexOf("/providers/")
$Rg =$v2VmId.Substring(0,$index)
$PrimaryAzureNetworkId = $Rg + "/providers/Microsoft.Network/virtualNetworks/" + $vmName

#network mapping
$job = New-AzRecoveryServicesAsrNetworkMapping -AzureToAzure -Name $primaryNetMapping -PrimaryFabric $pf -PrimaryAzureNetworkId $PrimaryAzureNetworkId -RecoveryFabric $rf -RecoveryAzureNetworkId $RecoveryAzureNetworkId
WaitForJobCompletion -JobId $job.Name

#enable Replication
$v = New-AzRecoveryServicesAsrAzureToAzureDiskReplicationConfig -managed -LogStorageAccountId $logStg `
-DiskId $vhdid -RecoveryResourceGroupId $recRg -RecoveryReplicaDiskAccountType $RecoveryReplicaDiskAccountType `
-RecoveryTargetDiskAccountType $RecoveryTargetDiskAccountType
$enableDRjob = New-AzRecoveryServicesAsrReplicationProtectedItem -AzureToAzure -AzureVmId $v2VmId -Name $vmName -ProtectionContainerMapping $mapping -RecoveryResourceGroupId $recRg -AzureToAzureDiskReplicationConfiguration $v
WaitForJobCompletion -JobId $enableDRjob.Name
WaitForIRCompletion -affectedObjectId $enableDRjob.TargetObjectId

#add diskId
$pe = Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName
Assert-NotNull($pe)

#create disk and attach
$diskName = getAzureDataDiskName
$newDiskConfig = New-AzDiskConfig -Location $vm.Location -CreateOption Empty -DiskSizeGB 5
$newDisk = New-AzDisk -ResourceGroupName $vm.ResourceGroupName -DiskName $diskName -Disk $newDiskConfig
$vm = Add-AzVMDataDisk -VM $vm -Name $diskName -CreateOption Attach -ManagedDiskId $newDisk.Id -Lun 5
Update-azVm -ResourceGroupName $vmName -VM $vm

#wait for the add-disk health warning to appear
Write-Host $("Waiting for Add-Disk health warning...") -ForegroundColor Yellow
$HealthQueryWaitTimeInSeconds = 10
do
{
$pe = Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName
$healthError = $pe.ReplicationHealthErrors | where-object {$_.ErrorCode -eq 153039}

if($healthError -eq $null)
{
Write-Host $("Waiting for Add-Disk health warning...") -ForegroundColor Yellow
Write-Host $("Waiting for: " + $HealthQueryWaitTimeInSeconds.ToString + " Seconds") -ForegroundColor Yellow
[Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait($HealthQueryWaitTimeInSeconds * 1000)
}
}While($healthError -eq $null)

#resolve health error
$addDRjob = Remove-AzureRmRecoveryServicesAsrReplicationProtectedItemHealthError -ReplicationProtectedItem $pe -ErrorId $healthError.ErrorId
WaitForJobCompletion -JobId $addDRjob.Name
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,62 @@ public PSSiteRecoveryLongRunningOperation AddDisks(
return result;
}

/// <summary>
/// Remove disks from replication protected item.
/// </summary>
/// <param name="fabricName">Fabric Name</param>
/// <param name="protectionContainerName">Protection Container Name</param>
/// <param name="replicationProtectedItemName">Replication Protected Item Name</param>
/// <param name="input">Remove disks input.</param>
/// <returns>Job response</returns>
public PSSiteRecoveryLongRunningOperation RemoveDisks(
string fabricName,
string protectionContainerName,
string replicationProtectedItemName,
RemoveDisksInput input)
{
var op = this.GetSiteRecoveryClient()
.ReplicationProtectedItems.BeginRemoveDisksWithHttpMessagesAsync(
fabricName,
protectionContainerName,
replicationProtectedItemName,
input,
this.GetRequestHeaders(true))
.GetAwaiter()
.GetResult();

var result = SiteRecoveryAutoMapperProfile.Mapper.Map<PSSiteRecoveryLongRunningOperation>(op);
return result;
}

/// <summary>
/// Removes the Health error from replication protected item.
/// </summary>
/// <param name="fabricName">Fabric Name</param>
/// <param name="protectionContainerName">Protection Container Name</param>
/// <param name="replicationProtectedItemName">Replication Protected Item Name</param>
/// <param name="input">Remove disks input.</param>
/// <returns>Job response</returns>
public PSSiteRecoveryLongRunningOperation ResolveHealthError(
string fabricName,
string protectionContainerName,
string replicationProtectedItemName,
ResolveHealthInput input)
{
var op = this.GetSiteRecoveryClient()
.ReplicationProtectedItems.BeginResolveHealthErrorsWithHttpMessagesAsync(
fabricName,
protectionContainerName,
replicationProtectedItemName,
input,
this.GetRequestHeaders(true))
.GetAwaiter()
.GetResult();

var result = SiteRecoveryAutoMapperProfile.Mapper.Map<PSSiteRecoveryLongRunningOperation>(op);
return result;
}

/// <summary>
/// Retrieves Protected Items.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ public ASRHealthError(HealthError healthError)
this.ErrorMessage = healthError.ErrorMessage;
this.PossibleCauses = healthError.PossibleCauses;
this.RecommendedAction = healthError.RecommendedAction;
this.ErrorId = healthError.ErrorId;
this.CustomerResolvability = healthError.CustomerResolvability;
this.RecoveryProviderErrorMessage = healthError.RecoveryProviderErrorMessage;
}

Expand Down Expand Up @@ -255,6 +257,16 @@ public ASRHealthError(HealthError healthError)
/// Recovery Provider error message.
/// </summary>
public string RecoveryProviderErrorMessage { get; set; }

/// <summary>
/// Id of error.
/// </summary>
public string ErrorId { get; set; }

/// <summary>
/// CustomerResolvability of error.
/// </summary>
public string CustomerResolvability { get; set; }
}

/// <summary>
Expand Down
Loading