Skip to content

Commit 539a61a

Browse files
author
dragonfly91
committed
Get Item Bug Fixes and Test Records
1 parent 92853e5 commit 539a61a

File tree

3 files changed

+134
-63
lines changed

3 files changed

+134
-63
lines changed

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,24 +447,40 @@ public List<AzureRmRecoveryServicesBackupItemBase> ListProtectedItems()
447447
return containerUri.Contains(container.Name);
448448
}).ToList();
449449

450-
List<AzureRmRecoveryServicesBackupItemBase> itemModels = ConversionHelpers.GetItemModelList(protectedItems, container);
450+
List<ProtectedItemResponse> protectedItemGetResponses = new List<ProtectedItemResponse>();
451451

452452
// 2. Filter by item's friendly name
453453
if (!string.IsNullOrEmpty(name))
454454
{
455-
itemModels = itemModels.Where(itemModel =>
455+
protectedItems = protectedItems.Where(protectedItem =>
456456
{
457-
return ((AzureRmRecoveryServicesBackupIaasVmItem)itemModel).Name == name;
457+
Dictionary<UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id);
458+
string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItem.Id);
459+
return protectedItemUri.Contains(name);
458460
}).ToList();
459461

460462
GetProtectedItemQueryParam getItemQueryParams = new GetProtectedItemQueryParam();
461463
getItemQueryParams.Expand = "extendedinfo";
462464

465+
for (int i = 0; i < protectedItems.Count; i++)
466+
{
467+
Dictionary<UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItems[i].Id);
468+
string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItems[i].Id);
469+
string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItems[i].Id);
470+
471+
var getResponse = HydraAdapter.GetProtectedItem(containerUri, protectedItemUri, getItemQueryParams);
472+
protectedItemGetResponses.Add(getResponse);
473+
}
474+
}
475+
476+
List<AzureRmRecoveryServicesBackupItemBase> itemModels = ConversionHelpers.GetItemModelList(protectedItems, container);
477+
478+
if (!string.IsNullOrEmpty(name))
479+
{
463480
for (int i = 0; i < itemModels.Count; i++)
464481
{
465-
var getResponse = HydraAdapter.GetProtectedItem(container.Name, itemModels[i].Name, getItemQueryParams);
466482
AzureRmRecoveryServicesBackupIaasVmItemExtendedInfo extendedInfo = new AzureRmRecoveryServicesBackupIaasVmItemExtendedInfo();
467-
var hydraExtendedInfo = ((AzureIaaSVMProtectedItem)getResponse.Item.Properties).ExtendedInfo;
483+
var hydraExtendedInfo = ((AzureIaaSVMProtectedItem)protectedItemGetResponses[i].Item.Properties).ExtendedInfo;
468484
if (hydraExtendedInfo.OldestRecoveryPoint.HasValue)
469485
{
470486
extendedInfo.OldestRecoveryPoint = hydraExtendedInfo.OldestRecoveryPoint;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
function Test-GetItemScenario
1616
{
17-
$vault = Get-AzureRmRecoveryServicesVault -ResourceGroupName "pstestrg" -Name "pstestrsvault";
17+
$vault = Get-AzureRmRecoveryServicesVault -ResourceGroupName "RsvTestRG" -Name "PsTestRsVault";
1818
Set-AzureRmRecoveryServicesVaultContext -Vault $vault;
1919

20-
$namedContainer = Get-AzureRmRecoveryServicesContainer -ContainerType "AzureVM" -Status "Registered" -Name "pstestv2vm1";
21-
Assert-AreEqual $namedContainer.FriendlyName "pstestv2vm1";
20+
$namedContainer = Get-AzureRmRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered";
21+
Assert-AreEqual $namedContainer[2].FriendlyName "mkheranirmvm1";
2222

23-
$item = Get-AzureRmRecoveryServices=Item -Container $namedContainer -WorkloadType "AzureVM";
23+
$item = Get-AzureRmRecoveryServicesBackupItem -Container $namedContainer[2] -WorkloadType "AzureVM" -Name "mkheranirmvm1";
2424
echo $item.Name;
2525
}
2626

0 commit comments

Comments
 (0)