Skip to content

Commit 2260b15

Browse files
author
Maddie Clayton
authored
Merge branch 'preview' into update-clientruntime
2 parents 8d9f698 + c0dc48c commit 2260b15

File tree

24 files changed

+210931
-277600
lines changed

24 files changed

+210931
-277600
lines changed

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/AzureRM.Resources.ps1

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function New-AzureRmResourceGroupDeployment
9696
END {}
9797
}
9898

99-
function Remove-AzureRmResourceGroup
99+
function Remove-AzureRmResourceGroup
100100
{
101101
[CmdletBinding()]
102102
param(
@@ -113,6 +113,124 @@ function Remove-AzureRmResourceGroup
113113
END {}
114114
}
115115

116+
function New-AzureRmRoleAssignmentWithId
117+
{
118+
[CmdletBinding()]
119+
param(
120+
[Guid] [Parameter()] [alias("Id", "PrincipalId")] $ObjectId,
121+
[string] [Parameter()] [alias("Email", "UserPrincipalName")] $SignInName,
122+
[string] [Parameter()] [alias("SPN", "ServicePrincipalName")] $ApplicationId,
123+
[string] [Parameter()] $ResourceGroupName,
124+
[string] [Parameter()] $ResourceName,
125+
[string] [Parameter()] $ResourceType,
126+
[string] [Parameter()] $ParentResource,
127+
[string] [Parameter()] $Scope,
128+
[string] [Parameter()] $RoleDefinitionName,
129+
[Guid] [Parameter()] $RoleDefinitionId,
130+
[switch] [Parameter()] $AllowDelegation,
131+
[Guid] [Parameter()] $RoleAssignmentId
132+
)
133+
134+
$profile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
135+
$cmdlet = New-Object -TypeName Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand
136+
$cmdlet.DefaultProfile = $profile
137+
$cmdlet.CommandRuntime = $PSCmdlet.CommandRuntime
138+
139+
if ($ObjectId -ne $null -and $ObjectId -ne [System.Guid]::Empty)
140+
{
141+
$cmdlet.ObjectId = $ObjectId
142+
}
143+
144+
if (-not ([string]::IsNullOrEmpty($SignInName)))
145+
{
146+
$cmdlet.SignInName = $SignInName
147+
}
148+
149+
if (-not ([string]::IsNullOrEmpty($ApplicationId)))
150+
{
151+
$cmdlet.ApplicationId = $ApplicationId
152+
}
153+
154+
if (-not ([string]::IsNullOrEmpty($ResourceGroupName)))
155+
{
156+
$cmdlet.ResourceGroupName = $ResourceGroupName
157+
}
158+
159+
if (-not ([string]::IsNullOrEmpty($ResourceName)))
160+
{
161+
$cmdlet.ResourceName = $ResourceName
162+
}
163+
164+
if (-not ([string]::IsNullOrEmpty($ResourceType)))
165+
{
166+
$cmdlet.ResourceType = $ResourceType
167+
}
168+
169+
if (-not ([string]::IsNullOrEmpty($ParentResource)))
170+
{
171+
$cmdlet.ParentResource = $ParentResource
172+
}
173+
174+
if (-not ([string]::IsNullOrEmpty($Scope)))
175+
{
176+
$cmdlet.Scope = $Scope
177+
}
178+
179+
if (-not ([string]::IsNullOrEmpty($RoleDefinitionName)))
180+
{
181+
$cmdlet.RoleDefinitionName = $RoleDefinitionName
182+
}
183+
184+
if ($RoleDefinitionId -ne $null -and $RoleDefinitionId -ne [System.Guid]::Empty)
185+
{
186+
$cmdlet.RoleDefinitionId = $RoleDefinitionId
187+
}
188+
189+
if ($AllowDelegation.IsPresent)
190+
{
191+
$cmdlet.AllowDelegation = $true
192+
}
193+
194+
if ($RoleAssignmentId -ne $null -and $RoleAssignmentId -ne [System.Guid]::Empty)
195+
{
196+
$cmdlet.RoleAssignmentId = $RoleAssignmentId
197+
}
198+
199+
$cmdlet.ExecuteCmdlet()
200+
}
201+
202+
function New-AzureRmRoleDefinitionWithId
203+
{
204+
[CmdletBinding()]
205+
param(
206+
[Microsoft.Azure.Commands.Resources.Models.Authorization.PSRoleDefinition] [Parameter()] $Role,
207+
[string] [Parameter()] $InputFile,
208+
[Guid] [Parameter()] $RoleDefinitionId
209+
)
210+
211+
$profile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
212+
$cmdlet = New-Object -TypeName Microsoft.Azure.Commands.Resources.NewAzureRoleDefinitionCommand
213+
$cmdlet.DefaultProfile = $profile
214+
$cmdlet.CommandRuntime = $PSCmdlet.CommandRuntime
215+
216+
if (-not ([string]::IsNullOrEmpty($InputFile)))
217+
{
218+
$cmdlet.InputFile = $InputFile
219+
}
220+
221+
if ($Role -ne $null)
222+
{
223+
$cmdlet.Role = $Role
224+
}
225+
226+
if ($RoleDefinitionId -ne $null -and $RoleDefinitionId -ne [System.Guid]::Empty)
227+
{
228+
$cmdlet.RoleDefinitionId = $RoleDefinitionId
229+
}
230+
231+
$cmdlet.ExecuteCmdlet()
232+
}
233+
116234
function Get-Context
117235
{
118236
return [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile.DefaultContext
@@ -122,7 +240,7 @@ function Get-ResourcesClient
122240
{
123241
param([Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContext] $context)
124242
$factory = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.ClientFactory
125-
[System.Type[]]$types = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContext],
243+
[System.Type[]]$types = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContext],
126244
[string]
127245
$method = [Microsoft.Azure.Commands.Common.Authentication.IClientFactory].GetMethod("CreateArmClient", $types)
128246
$closedMethod = $method.MakeGenericMethod([Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient])

src/ResourceManager/DataFactoryV2/Commands.DataFactoryV2.Test/ScenarioTests/DataFactoriesScenarioTestsBase.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ protected void SetupManagementClients(MockContext context)
5656
subscriptionsClient,
5757
graphClient,
5858
authorizationManagementClient);
59-
60-
AuthorizationClient.RoleAssignmentNames.Enqueue(new Guid("6558f9a7-689c-41d3-93bd-3281fbe3d26f"));
6159
}
6260

6361
protected void RunPowerShellTest(XunitTracingInterceptor logger, params string[] scripts)

src/ResourceManager/DataFactoryV2/Commands.DataFactoryV2.Test/ScenarioTests/IntegrationRuntimeTests.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ function Test-SsisAzure-IntegrationRuntime
122122
}
123123

124124
if ($catalogAdminPassword -eq $null){
125+
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Fake password to resource that has been deleted.")]#>
125126
$catalogAdminPassword = 'fakepassord'
126127
}
127128

@@ -285,10 +286,11 @@ function Test-Shared-IntegrationRuntime
285286
-Type 'SelfHosted' `
286287
-Force
287288

288-
New-AzureRMRoleAssignment `
289+
New-AzureRMRoleAssignmentWithId `
289290
-ObjectId $linkeddf.Identity.PrincipalId `
290291
-RoleDefinitionId 'b24988ac-6180-42a0-ab88-20f7382dd24c' `
291-
-Scope $shared.Id
292+
-Scope $shared.Id `
293+
-RoleAssignmentId 6558f9a7-689c-41d3-93bd-3281fbe3d26f
292294

293295
Wait-Seconds 20
294296

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/Conversions/RecoveryPointConversions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public static List<RecoveryPointBase> GetPSAzureRecoveryPoints(
8383
EncryptionEnabled = recPoint.IsSourceVMEncrypted.HasValue ?
8484
recPoint.IsSourceVMEncrypted.Value : false,
8585
IlrSessionActive = isInstantILRSessionActive,
86+
IsManagedVirtualMachine = recPoint.IsManagedVirtualMachine.HasValue ?
87+
recPoint.IsManagedVirtualMachine.Value : false,
8688
OriginalSAEnabled = recPoint.OriginalStorageAccountOption.HasValue ?
8789
recPoint.OriginalStorageAccountOption.Value : false,
8890
};

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/AzureVmModels/AzureVmRecoveryPoint.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public class AzureVmRecoveryPoint : RecoveryPointBase
5858
/// </summary>
5959
public bool IlrSessionActive { get; set; }
6060

61+
/// <summary>
62+
/// Identifies if the virtual machine has a managed disks.
63+
/// </summary>
64+
public bool IsManagedVirtualMachine { get; set; }
65+
6166
/// <summary>
6267
/// Required details for recovering an encrypted VM.
6368
/// Applicable only when the EncryptionEnabled flag is true.

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/CmdletParamEnums.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public enum RestoreBackupItemParams
5353
StorageAccountId,
5454
StorageAccountLocation,
5555
StorageAccountType,
56+
TargetResourceGroupName,
5657
OsaOption
5758
}
5859

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Models/Properties/Resources.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/IaasVmPsBackupProvider.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,17 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
262262
ProviderData[RestoreBackupItemParams.StorageAccountLocation].ToString();
263263
string storageAccountType =
264264
ProviderData[RestoreBackupItemParams.StorageAccountType].ToString();
265+
string targetResourceGroupName =
266+
ProviderData.ContainsKey(RestoreBackupItemParams.TargetResourceGroupName) ?
267+
ProviderData[RestoreBackupItemParams.TargetResourceGroupName].ToString() : null;
265268
bool osaOption = (bool)ProviderData[RestoreBackupItemParams.OsaOption];
266269

267270
var response = ServiceClientAdapter.RestoreDisk(
268271
rp,
269272
storageAccountId,
270273
storageAccountLocation,
271274
storageAccountType,
275+
targetResourceGroupName,
272276
osaOption,
273277
vaultName: vaultName,
274278
resourceGroupName: resourceGroupName,

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.ServiceClientAdapter/BMSAPIs/RestoreDiskAPIs.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public RestAzureNS.AzureOperationResponse RestoreDisk(
3737
string storageAccountId,
3838
string storageAccountLocation,
3939
string storageAccountType,
40+
string targetResourceGroupName,
4041
bool osaOption,
4142
string vaultName = null,
4243
string resourceGroupName = null,
@@ -64,6 +65,11 @@ public RestAzureNS.AzureOperationResponse RestoreDisk(
6465
throw new Exception(string.Format(Resources.RestoreDiskStorageTypeError, vmType));
6566
}
6667

68+
if (targetResourceGroupName != null && rp.IsManagedVirtualMachine == false)
69+
{
70+
Logger.Instance.WriteWarning(Resources.UnManagedBackupVmWarning);
71+
}
72+
6773
IaasVMRestoreRequest restoreRequest = new IaasVMRestoreRequest()
6874
{
6975
CreateNewCloudService = false,
@@ -72,6 +78,8 @@ public RestAzureNS.AzureOperationResponse RestoreDisk(
7278
Region = vaultLocation,
7379
StorageAccountId = storageAccountId,
7480
SourceResourceId = rp.SourceResourceId,
81+
TargetResourceGroupId = targetResourceGroupName ??
82+
"/subscriptions/" + BmsAdapter.Client.SubscriptionId + "/resourceGroups/" + targetResourceGroupName,
7583
OriginalStorageAccountOption = useOsa,
7684
};
7785

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/IaasVm/Common.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ function Get-RandomSuffix(
4848
}
4949

5050
function Create-ResourceGroup(
51-
[string] $location)
51+
[string] $location,
52+
[int] $nick = -1)
5253
{
5354
$name = "PSTestRG" + @(Get-RandomSuffix)
55+
if($nick -gt -1)
56+
{
57+
$name += $nick
58+
}
5459

5560
$resourceGroup = Get-AzureRmResourceGroup -Name $name -ErrorAction Ignore
5661

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Test/ScenarioTests/IaasVm/ItemTests.ps1

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ function Test-AzureVMFullRestore
235235
{
236236
$location = Get-ResourceGroupLocation
237237
$resourceGroupName = Create-ResourceGroup $location
238+
$targetResourceGroupName = Create-ResourceGroup $location 1
238239

239240
try
240241
{
@@ -245,7 +246,7 @@ function Test-AzureVMFullRestore
245246
$item = Enable-Protection $vault $vm
246247
$backupJob = Backup-Item $vault $item
247248
$rp = Get-RecoveryPoint $vault $item $backupJob
248-
249+
249250
Assert-ThrowsContains { Restore-AzureRmRecoveryServicesBackupItem `
250251
-VaultId $vault.ID `
251252
-VaultLocation $vault.Location `
@@ -255,20 +256,32 @@ function Test-AzureVMFullRestore
255256
-UseOriginalStorageAccount } `
256257
"This recovery point doesn’t have the capability to restore disks to their original storage account. Re-run the restore command without the UseOriginalStorageAccountForDisks parameter.";
257258

258-
$restoreJob = Restore-AzureRmRecoveryServicesBackupItem `
259+
$restoreJob1 = Restore-AzureRmRecoveryServicesBackupItem `
259260
-VaultId $vault.ID `
260261
-VaultLocation $vault.Location `
261262
-RecoveryPoint $rp `
262263
-StorageAccountName $saName `
263264
-StorageAccountResourceGroupName $resourceGroupName | `
264265
Wait-AzureRmRecoveryServicesBackupJob -VaultId $vault.ID
265266

266-
Assert-True { $restoreJob.Status -eq "Completed" }
267+
Assert-True { $restoreJob1.Status -eq "Completed" }
268+
269+
$restoreJob2 = Restore-AzureRmRecoveryServicesBackupItem `
270+
-VaultId $vault.ID `
271+
-VaultLocation $vault.Location `
272+
-RecoveryPoint $rp `
273+
-StorageAccountName $saName `
274+
-StorageAccountResourceGroupName $resourceGroupName `
275+
-TargetResourceGroupName $targetResourceGroupName | `
276+
Wait-AzureRmRecoveryServicesBackupJob -VaultId $vault.ID
277+
278+
Assert-True { $restoreJob2.Status -eq "Completed" }
267279
}
268280
finally
269281
{
270282
# Cleanup
271283
Cleanup-ResourceGroup $resourceGroupName
284+
Cleanup-ResourceGroup $targetResourceGroupName
272285
}
273286
}
274287

0 commit comments

Comments
 (0)