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

Fixing bug for replication to Managed disk for HyperV to Azure scenario in Azure site recovery service #26147

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -927,10 +927,26 @@ function Test-CreateRPIWithMangedDisksForReplication
param([string] $vaultSettingsFilePath)

Import-AzRecoveryServicesAsrVaultSettingsFile -Path $vaultSettingsFilePath
$PrimaryFabricName = "ToPowershell"
$fabric = Get-AsrFabric -FriendlyName $PrimaryFabricName
$pc = Get-ASRProtectionContainer -Fabric $fabric
$ProtectionContainerMapping = Get-ASRProtectionContainerMapping -ProtectionContainer $pc
$policy = Get-AzRecoveryServicesAsrPolicy -Name $PolicyName
$VM= Get-AsrProtectableItem -ProtectionContainer $pc -FriendlyName $VMName
$EnableDRjob = New-AzRecoveryServicesAsrReplicationProtectedItem -ProtectableItem $VM -Name $VM.Name -ProtectionContainerMapping $ProtectionContainerMapping[0] -RecoveryAzureStorageAccountId $StorageAccountID -OSDiskName $VMName -OS Windows -RecoveryResourceGroupId $RecoveryResourceGroupId -UseManagedDisksForReplication True

Assert-ThrowsContains { New-AzRecoveryServicesAsrReplicationProtectedItem `
-ProtectableItem $VM[0] `
-Name $VM[0].Name `
-ProtectionContainerMapping $ProtectionContainerMapping[0] `
-RecoveryAzureStorageAccountId $StorageAccountID `
-OSDiskName $VMName `
-OS Windows `
-RecoveryResourceGroupId $RecoveryResourceGroupId `
-UseManagedDisksForReplication True } `
"Only one of the input parameters are expected not both either RecoveryAzureStorageAccountId or UseManagedDisksForReplication"

$EnableDRjob = New-AzRecoveryServicesAsrReplicationProtectedItem -ProtectableItem $VM[0] -Name $VM[0].Name -ProtectionContainerMapping $ProtectionContainerMapping[0] -LogStorageAccountId $StorageAccountID -OSDiskName $VMName -OS Windows -RecoveryResourceGroupId $RecoveryResourceGroupId -UseManagedDisksForReplication True
WaitForJobCompletion -JobId $EnableDRjob.Name
$Job = Get-AzRecoveryServicesAsrJob -Name $EnableDRjob.Name
Assert-True { $Job.State -eq "Succeeded" }
}

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,7 @@ Recommended Action: To cleanup the resources created by Test failover run the Te
<data name="UnsupportedReplicationProviderOperation" xml:space="preserve">
<value>Unsupported replication provider {0} for this {1} operation</value>
</data>
<data name="IncorrectParameters" xml:space="preserve">
<value>Only one of the input parameters are expected not both either RecoveryAzureStorageAccountId or UseManagedDisksForReplication </value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ public class NewAzureRmRecoveryServicesAsrReplicationProtectedItem : SiteRecover
/// <summary>
/// Gets or sets the ID of the Azure storage account to replicate to.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)]
msJinLei marked this conversation as resolved.
Show resolved Hide resolved
[Parameter(ParameterSetName = ASRParameterSets.HyperVSiteToAzure, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure)]
[Parameter(ParameterSetName = ASRParameterSets.HyperVSiteToAzure)]
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzureWithoutDiskDetails)]
[ValidateNotNullOrEmpty]
public string RecoveryAzureStorageAccountId { get; set; }
Expand Down Expand Up @@ -841,6 +841,13 @@ private void EnterpriseAndHyperVToAzure(EnableProtectionInput input)
this.UseManagedDisk));
}

if(!string.IsNullOrEmpty(this.RecoveryAzureStorageAccountId)
&& !string.IsNullOrEmpty(this.UseManagedDisksForReplication))
{
throw new PSArgumentException(
string.Format(Resources.IncorrectParameters));
}

if (!string.IsNullOrEmpty(this.RecoveryAzureNetworkId))
{
providerSettings.TargetAzureNetworkId = this.RecoveryAzureNetworkId;
Expand Down Expand Up @@ -906,15 +913,25 @@ private void EnterpriseAndHyperVToAzure(EnableProtectionInput input)
}
}

string deploymentType = string.Empty;
if (this.RecoveryAzureStorageAccountId != null)
{
providerSettings.TargetStorageAccountId =
this.RecoveryAzureStorageAccountId;
deploymentType = Utilities.GetValueFromArmId(
this.RecoveryAzureStorageAccountId,
ARMResourceTypeConstants.Providers);
}

var deploymentType = Utilities.GetValueFromArmId(
this.RecoveryAzureStorageAccountId,
ARMResourceTypeConstants.Providers);
else
{
if(this.LogStorageAccountId != null)
{
deploymentType = Utilities.GetValueFromArmId(
this.LogStorageAccountId,
ARMResourceTypeConstants.Providers);
}
}

if (deploymentType.ToLower()
.Contains(Constants.Classic.ToLower()))
{
Expand Down
1 change: 1 addition & 0 deletions src/RecoveryServices/RecoveryServices/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Fixed bug for making RecoveryAzureStorageAccountId parameter optional in `New-ASRReplicationProtectedItem` cmdlet of H2A.

## Version 7.1.0
* Added MUA support for CMK Encryption properties of Recovery Services Vault. Updated the VaultProperty command to use underlying Vault APIs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Enables replication for an ASR protectable item by creating a replication protec
### EnterpriseToEnterprise (Default)
```
New-AzRecoveryServicesAsrReplicationProtectedItem [-VmmToVmm] -ProtectableItem <ASRProtectableItem>
-Name <String> -ProtectionContainerMapping <ASRProtectionContainerMapping>
-Name <String> -ProtectionContainerMapping <ASRProtectionContainerMapping>
[-WaitForCompletion] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

Expand Down Expand Up @@ -56,8 +56,9 @@ New-AzRecoveryServicesAsrReplicationProtectedItem [-VMwareToAzure] -ProtectableI
```
New-AzRecoveryServicesAsrReplicationProtectedItem [-HyperVToAzure] -ProtectableItem <ASRProtectableItem>
-Name <String> [-RecoveryVmName <String>] -ProtectionContainerMapping <ASRProtectionContainerMapping>
-RecoveryAzureStorageAccountId <String> -RecoveryResourceGroupId <String> [-UseManagedDisk <String>] [-UseManagedDisksForReplication <String>]
[-WaitForCompletion] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
-RecoveryAzureStorageAccountId <String> -RecoveryResourceGroupId <String> [-UseManagedDisk <String>]
[-UseManagedDisksForReplication <String>] [-WaitForCompletion] [-DefaultProfile <IAzureContextContainer>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

### HyperVSiteToAzure
Expand All @@ -72,36 +73,36 @@ New-AzRecoveryServicesAsrReplicationProtectedItem [-HyperVToAzure] -ProtectableI
[-RecoveryVmTag <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
[-DiskTag <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
[-RecoveryNicTag <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
[-UseManagedDisk <String>] [-UseManagedDisksForReplication <String>] [-WaitForCompletion] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
[-Confirm] [<CommonParameters>]
[-UseManagedDisk <String>] [-UseManagedDisksForReplication <String>] [-WaitForCompletion]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### AzureToAzure
```
New-AzRecoveryServicesAsrReplicationProtectedItem [-AzureToAzure]
-AzureToAzureDiskReplicationConfiguration <ASRAzuretoAzureDiskReplicationConfig[]> -AzureVmId <String>
-Name <String> [-RecoveryVmName <String>] -ProtectionContainerMapping <ASRProtectionContainerMapping>
[-RecoveryAzureNetworkId <String>] [-RecoveryAzureSubnetName <String>] -RecoveryResourceGroupId <String>
[-ReplicationGroupName <String>] [-RecoveryCloudServiceId <String>] [-RecoveryAvailabilityZone <String>]
-Name <String> -ProtectionContainerMapping <ASRProtectionContainerMapping> [-RecoveryAzureNetworkId <String>]
[-RecoveryAzureSubnetName <String>] -RecoveryResourceGroupId <String> [-ReplicationGroupName <String>]
[-RecoveryCloudServiceId <String>] [-RecoveryAvailabilityZone <String>]
[-RecoveryProximityPlacementGroupId <String>] [-RecoveryVirtualMachineScaleSetId <String>]
[-RecoveryCapacityReservationGroupId <String>] [-RecoveryAvailabilitySetId <String>]
[-RecoveryBootDiagStorageAccountId <String>] [-DiskEncryptionVaultId <String>]
[-DiskEncryptionSecretUrl <String>] [-KeyEncryptionKeyUrl <String>] [-KeyEncryptionVaultId <String>]
[-WaitForCompletion] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-WaitForCompletion] [-RecoveryExtendedLocation <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
[-Confirm] [<CommonParameters>]
```

### AzureToAzureWithoutDiskDetails
```
New-AzRecoveryServicesAsrReplicationProtectedItem [-AzureToAzure] -AzureVmId <String> -Name <String>
[-RecoveryVmName <String>] -ProtectionContainerMapping <ASRProtectionContainerMapping>
[-RecoveryAzureStorageAccountId <String>] -LogStorageAccountId <String> [-RecoveryAzureNetworkId <String>]
[-RecoveryAzureSubnetName <String>] -RecoveryResourceGroupId <String> [-ReplicationGroupName <String>]
[-RecoveryAvailabilityZone <String>] [-RecoveryProximityPlacementGroupId <String>]
[-RecoveryVirtualMachineScaleSetId <String>] [-RecoveryCapacityReservationGroupId <String>]
[-RecoveryAvailabilitySetId <String>] [-RecoveryBootDiagStorageAccountId <String>]
[-DiskEncryptionVaultId <String>] [-DiskEncryptionSecretUrl <String>] [-KeyEncryptionKeyUrl <String>]
[-KeyEncryptionVaultId <String>] [-WaitForCompletion] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
[-Confirm] [<CommonParameters>]
-ProtectionContainerMapping <ASRProtectionContainerMapping> [-RecoveryAzureStorageAccountId <String>]
-LogStorageAccountId <String> [-RecoveryAzureNetworkId <String>] [-RecoveryAzureSubnetName <String>]
-RecoveryResourceGroupId <String> [-ReplicationGroupName <String>] [-RecoveryAvailabilityZone <String>]
[-RecoveryProximityPlacementGroupId <String>] [-RecoveryVirtualMachineScaleSetId <String>]
[-RecoveryCapacityReservationGroupId <String>] [-RecoveryAvailabilitySetId <String>]
[-RecoveryBootDiagStorageAccountId <String>] [-DiskEncryptionVaultId <String>]
[-DiskEncryptionSecretUrl <String>] [-KeyEncryptionKeyUrl <String>] [-KeyEncryptionVaultId <String>]
[-WaitForCompletion] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### ReplicateVMwareToAzure
Expand Down Expand Up @@ -799,7 +800,6 @@ Accept pipeline input: False
Accept wildcard characters: False
```


### -RecoveryNicTag
Specify the tags for the target NICs of the VM.

Expand Down Expand Up @@ -865,7 +865,7 @@ Name of the recovery Vm created after failover.

```yaml
Type: System.String
Parameter Sets: VMwareToAzureWithDiskType, VMwareToAzure, EnterpriseToAzure, HyperVSiteToAzure, AzureToAzure, AzureToAzureWithoutDiskDetails, ReplicateVMwareToAzure, ReplicateVMwareToAzureWithDiskInput
Parameter Sets: VMwareToAzureWithDiskType, VMwareToAzure, EnterpriseToAzure, HyperVSiteToAzure, ReplicateVMwareToAzure, ReplicateVMwareToAzureWithDiskInput
Aliases:

Required: False
Expand Down