Skip to content

Commit e76223d

Browse files
Fixing bug for replication to Managed disk for HyperV to Azure scenario in Azure site recovery service (#26147)
* Bug fix for H2A replication to MD * Updated change log * Updated tests * Updated help file
1 parent 3d587fb commit e76223d

File tree

7 files changed

+4626
-1077
lines changed

7 files changed

+4626
-1077
lines changed

Diff for: src/RecoveryServices/RecoveryServices.SiteRecovery.Test/ScenarioTests/B2A/AsrB2ATests.ps1

+17-1
Original file line numberDiff line numberDiff line change
@@ -927,10 +927,26 @@ function Test-CreateRPIWithMangedDisksForReplication
927927
param([string] $vaultSettingsFilePath)
928928

929929
Import-AzRecoveryServicesAsrVaultSettingsFile -Path $vaultSettingsFilePath
930+
$PrimaryFabricName = "ToPowershell"
930931
$fabric = Get-AsrFabric -FriendlyName $PrimaryFabricName
931932
$pc = Get-ASRProtectionContainer -Fabric $fabric
932933
$ProtectionContainerMapping = Get-ASRProtectionContainerMapping -ProtectionContainer $pc
933934
$policy = Get-AzRecoveryServicesAsrPolicy -Name $PolicyName
934935
$VM= Get-AsrProtectableItem -ProtectionContainer $pc -FriendlyName $VMName
935-
$EnableDRjob = New-AzRecoveryServicesAsrReplicationProtectedItem -ProtectableItem $VM -Name $VM.Name -ProtectionContainerMapping $ProtectionContainerMapping[0] -RecoveryAzureStorageAccountId $StorageAccountID -OSDiskName $VMName -OS Windows -RecoveryResourceGroupId $RecoveryResourceGroupId -UseManagedDisksForReplication True
936+
937+
Assert-ThrowsContains { New-AzRecoveryServicesAsrReplicationProtectedItem `
938+
-ProtectableItem $VM[0] `
939+
-Name $VM[0].Name `
940+
-ProtectionContainerMapping $ProtectionContainerMapping[0] `
941+
-RecoveryAzureStorageAccountId $StorageAccountID `
942+
-OSDiskName $VMName `
943+
-OS Windows `
944+
-RecoveryResourceGroupId $RecoveryResourceGroupId `
945+
-UseManagedDisksForReplication True } `
946+
"Only one of the input parameters are expected not both either RecoveryAzureStorageAccountId or UseManagedDisksForReplication"
947+
948+
$EnableDRjob = New-AzRecoveryServicesAsrReplicationProtectedItem -ProtectableItem $VM[0] -Name $VM[0].Name -ProtectionContainerMapping $ProtectionContainerMapping[0] -LogStorageAccountId $StorageAccountID -OSDiskName $VMName -OS Windows -RecoveryResourceGroupId $RecoveryResourceGroupId -UseManagedDisksForReplication True
949+
WaitForJobCompletion -JobId $EnableDRjob.Name
950+
$Job = Get-AzRecoveryServicesAsrJob -Name $EnableDRjob.Name
951+
Assert-True { $Job.State -eq "Succeeded" }
936952
}

Diff for: src/RecoveryServices/RecoveryServices.SiteRecovery.Test/SessionRecords/RecoveryServices.SiteRecovery.Test.AsrB2ATests/CreateRPIWithMangedDisksForReplication.json

+4,552-1,049
Large diffs are not rendered by default.

Diff for: src/RecoveryServices/RecoveryServices.SiteRecovery/Properties/Resources.Designer.cs

+10-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/RecoveryServices/RecoveryServices.SiteRecovery/Properties/Resources.resx

+3
Original file line numberDiff line numberDiff line change
@@ -546,4 +546,7 @@ Recommended Action: To cleanup the resources created by Test failover run the Te
546546
<data name="UnsupportedReplicationProviderOperation" xml:space="preserve">
547547
<value>Unsupported replication provider {0} for this {1} operation</value>
548548
</data>
549+
<data name="IncorrectParameters" xml:space="preserve">
550+
<value>Only one of the input parameters are expected not both either RecoveryAzureStorageAccountId or UseManagedDisksForReplication </value>
551+
</data>
549552
</root>

Diff for: src/RecoveryServices/RecoveryServices.SiteRecovery/ReplicationProtectedItem/NewAzureRmRecoveryServicesAsrReplicationProtectedItem.cs

+23-6
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ public class NewAzureRmRecoveryServicesAsrReplicationProtectedItem : SiteRecover
223223
/// <summary>
224224
/// Gets or sets the ID of the Azure storage account to replicate to.
225225
/// </summary>
226-
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)]
227-
[Parameter(ParameterSetName = ASRParameterSets.HyperVSiteToAzure, Mandatory = true)]
226+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure)]
227+
[Parameter(ParameterSetName = ASRParameterSets.HyperVSiteToAzure)]
228228
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzureWithoutDiskDetails)]
229229
[ValidateNotNullOrEmpty]
230230
public string RecoveryAzureStorageAccountId { get; set; }
@@ -841,6 +841,13 @@ private void EnterpriseAndHyperVToAzure(EnableProtectionInput input)
841841
this.UseManagedDisk));
842842
}
843843

844+
if(!string.IsNullOrEmpty(this.RecoveryAzureStorageAccountId)
845+
&& !string.IsNullOrEmpty(this.UseManagedDisksForReplication))
846+
{
847+
throw new PSArgumentException(
848+
string.Format(Resources.IncorrectParameters));
849+
}
850+
844851
if (!string.IsNullOrEmpty(this.RecoveryAzureNetworkId))
845852
{
846853
providerSettings.TargetAzureNetworkId = this.RecoveryAzureNetworkId;
@@ -906,15 +913,25 @@ private void EnterpriseAndHyperVToAzure(EnableProtectionInput input)
906913
}
907914
}
908915

916+
string deploymentType = string.Empty;
909917
if (this.RecoveryAzureStorageAccountId != null)
910918
{
911919
providerSettings.TargetStorageAccountId =
912920
this.RecoveryAzureStorageAccountId;
921+
deploymentType = Utilities.GetValueFromArmId(
922+
this.RecoveryAzureStorageAccountId,
923+
ARMResourceTypeConstants.Providers);
913924
}
914-
915-
var deploymentType = Utilities.GetValueFromArmId(
916-
this.RecoveryAzureStorageAccountId,
917-
ARMResourceTypeConstants.Providers);
925+
else
926+
{
927+
if(this.LogStorageAccountId != null)
928+
{
929+
deploymentType = Utilities.GetValueFromArmId(
930+
this.LogStorageAccountId,
931+
ARMResourceTypeConstants.Providers);
932+
}
933+
}
934+
918935
if (deploymentType.ToLower()
919936
.Contains(Constants.Classic.ToLower()))
920937
{

Diff for: src/RecoveryServices/RecoveryServices/ChangeLog.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed bug for making RecoveryAzureStorageAccountId parameter optional in `New-ASRReplicationProtectedItem` cmdlet of H2A.
2122

2223
## Version 7.1.0
2324
* Added MUA support for CMK Encryption properties of Recovery Services Vault. Updated the VaultProperty command to use underlying Vault APIs.

Diff for: src/RecoveryServices/RecoveryServices/help/New-AzRecoveryServicesAsrReplicationProtectedItem.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Enables replication for an ASR protectable item by creating a replication protec
1515
### EnterpriseToEnterprise (Default)
1616
```
1717
New-AzRecoveryServicesAsrReplicationProtectedItem [-VmmToVmm] -ProtectableItem <ASRProtectableItem>
18-
-Name <String> -ProtectionContainerMapping <ASRProtectionContainerMapping>
18+
-Name <String> -ProtectionContainerMapping <ASRProtectionContainerMapping>
1919
[-WaitForCompletion] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2020
```
2121

@@ -56,8 +56,9 @@ New-AzRecoveryServicesAsrReplicationProtectedItem [-VMwareToAzure] -ProtectableI
5656
```
5757
New-AzRecoveryServicesAsrReplicationProtectedItem [-HyperVToAzure] -ProtectableItem <ASRProtectableItem>
5858
-Name <String> [-RecoveryVmName <String>] -ProtectionContainerMapping <ASRProtectionContainerMapping>
59-
-RecoveryAzureStorageAccountId <String> -RecoveryResourceGroupId <String> [-UseManagedDisk <String>] [-UseManagedDisksForReplication <String>]
60-
[-WaitForCompletion] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
59+
-RecoveryAzureStorageAccountId <String> -RecoveryResourceGroupId <String> [-UseManagedDisk <String>]
60+
[-UseManagedDisksForReplication <String>] [-WaitForCompletion] [-DefaultProfile <IAzureContextContainer>]
61+
[-WhatIf] [-Confirm] [<CommonParameters>]
6162
```
6263

6364
### HyperVSiteToAzure
@@ -72,36 +73,36 @@ New-AzRecoveryServicesAsrReplicationProtectedItem [-HyperVToAzure] -ProtectableI
7273
[-RecoveryVmTag <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
7374
[-DiskTag <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
7475
[-RecoveryNicTag <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
75-
[-UseManagedDisk <String>] [-UseManagedDisksForReplication <String>] [-WaitForCompletion] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
76-
[-Confirm] [<CommonParameters>]
76+
[-UseManagedDisk <String>] [-UseManagedDisksForReplication <String>] [-WaitForCompletion]
77+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
7778
```
7879

7980
### AzureToAzure
8081
```
8182
New-AzRecoveryServicesAsrReplicationProtectedItem [-AzureToAzure]
8283
-AzureToAzureDiskReplicationConfiguration <ASRAzuretoAzureDiskReplicationConfig[]> -AzureVmId <String>
83-
-Name <String> [-RecoveryVmName <String>] -ProtectionContainerMapping <ASRProtectionContainerMapping>
84-
[-RecoveryAzureNetworkId <String>] [-RecoveryAzureSubnetName <String>] -RecoveryResourceGroupId <String>
85-
[-ReplicationGroupName <String>] [-RecoveryCloudServiceId <String>] [-RecoveryAvailabilityZone <String>]
84+
-Name <String> -ProtectionContainerMapping <ASRProtectionContainerMapping> [-RecoveryAzureNetworkId <String>]
85+
[-RecoveryAzureSubnetName <String>] -RecoveryResourceGroupId <String> [-ReplicationGroupName <String>]
86+
[-RecoveryCloudServiceId <String>] [-RecoveryAvailabilityZone <String>]
8687
[-RecoveryProximityPlacementGroupId <String>] [-RecoveryVirtualMachineScaleSetId <String>]
8788
[-RecoveryCapacityReservationGroupId <String>] [-RecoveryAvailabilitySetId <String>]
8889
[-RecoveryBootDiagStorageAccountId <String>] [-DiskEncryptionVaultId <String>]
8990
[-DiskEncryptionSecretUrl <String>] [-KeyEncryptionKeyUrl <String>] [-KeyEncryptionVaultId <String>]
90-
[-WaitForCompletion] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
91+
[-WaitForCompletion] [-RecoveryExtendedLocation <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
92+
[-Confirm] [<CommonParameters>]
9193
```
9294

9395
### AzureToAzureWithoutDiskDetails
9496
```
9597
New-AzRecoveryServicesAsrReplicationProtectedItem [-AzureToAzure] -AzureVmId <String> -Name <String>
96-
[-RecoveryVmName <String>] -ProtectionContainerMapping <ASRProtectionContainerMapping>
97-
[-RecoveryAzureStorageAccountId <String>] -LogStorageAccountId <String> [-RecoveryAzureNetworkId <String>]
98-
[-RecoveryAzureSubnetName <String>] -RecoveryResourceGroupId <String> [-ReplicationGroupName <String>]
99-
[-RecoveryAvailabilityZone <String>] [-RecoveryProximityPlacementGroupId <String>]
100-
[-RecoveryVirtualMachineScaleSetId <String>] [-RecoveryCapacityReservationGroupId <String>]
101-
[-RecoveryAvailabilitySetId <String>] [-RecoveryBootDiagStorageAccountId <String>]
102-
[-DiskEncryptionVaultId <String>] [-DiskEncryptionSecretUrl <String>] [-KeyEncryptionKeyUrl <String>]
103-
[-KeyEncryptionVaultId <String>] [-WaitForCompletion] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
104-
[-Confirm] [<CommonParameters>]
98+
-ProtectionContainerMapping <ASRProtectionContainerMapping> [-RecoveryAzureStorageAccountId <String>]
99+
-LogStorageAccountId <String> [-RecoveryAzureNetworkId <String>] [-RecoveryAzureSubnetName <String>]
100+
-RecoveryResourceGroupId <String> [-ReplicationGroupName <String>] [-RecoveryAvailabilityZone <String>]
101+
[-RecoveryProximityPlacementGroupId <String>] [-RecoveryVirtualMachineScaleSetId <String>]
102+
[-RecoveryCapacityReservationGroupId <String>] [-RecoveryAvailabilitySetId <String>]
103+
[-RecoveryBootDiagStorageAccountId <String>] [-DiskEncryptionVaultId <String>]
104+
[-DiskEncryptionSecretUrl <String>] [-KeyEncryptionKeyUrl <String>] [-KeyEncryptionVaultId <String>]
105+
[-WaitForCompletion] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
105106
```
106107

107108
### ReplicateVMwareToAzure
@@ -799,7 +800,6 @@ Accept pipeline input: False
799800
Accept wildcard characters: False
800801
```
801802
802-
803803
### -RecoveryNicTag
804804
Specify the tags for the target NICs of the VM.
805805
@@ -865,7 +865,7 @@ Name of the recovery Vm created after failover.
865865
866866
```yaml
867867
Type: System.String
868-
Parameter Sets: VMwareToAzureWithDiskType, VMwareToAzure, EnterpriseToAzure, HyperVSiteToAzure, AzureToAzure, AzureToAzureWithoutDiskDetails, ReplicateVMwareToAzure, ReplicateVMwareToAzureWithDiskInput
868+
Parameter Sets: VMwareToAzureWithDiskType, VMwareToAzure, EnterpriseToAzure, HyperVSiteToAzure, ReplicateVMwareToAzure, ReplicateVMwareToAzureWithDiskInput
869869
Aliases:
870870

871871
Required: False

0 commit comments

Comments
 (0)