Skip to content

Commit 87e230f

Browse files
author
maddieclayton
authored
Merge pull request Azure#5025 from MabOneSdk/bugFixesNov
RecoveryServices.Backup Bugfixes
2 parents a4846a2 + 83df84f commit 87e230f

File tree

18 files changed

+1948
-834
lines changed

18 files changed

+1948
-834
lines changed

src/ResourceManager/RecoveryServices.Backup/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Fixed bug - Get-AzureRmRecoveryServicesBackupItem should do case insensitive comparison for container name filter.
22+
* Fixed bug - AzureVmItem now has a property that shows the last time a backup operation has happened - LastBackupTime.
2123

2224
## Version 4.0.1
2325
* Fixed assembly loading issue that caused some cmdlets to fail when executing

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public class AzureVmItem : ItemBase
3939
/// </summary>
4040
public string LastBackupStatus { get; set; }
4141

42+
/// <summary>
43+
/// Last Backup Time for the item
44+
/// </summary>
45+
public DateTime? LastBackupTime { get; set; }
46+
4247
/// <summary>
4348
/// Protection Policy Name for the Item
4449
/// </summary>
@@ -63,6 +68,7 @@ public AzureVmItem(ProtectedItemResource protectedItemResource,
6368
{
6469
AzureIaaSVMProtectedItem protectedItem = (AzureIaaSVMProtectedItem)protectedItemResource.Properties;
6570
LastBackupStatus = protectedItem.LastBackupStatus;
71+
LastBackupTime = protectedItem.LastBackupTime;
6672
ProtectionPolicyName = policyName;
6773
ProtectionState =
6874
EnumUtils.GetEnum<ItemProtectionState>(protectedItem.ProtectionState.ToString());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ public List<ItemBase> ListProtectedItems()
677677

678678
var delimIndex = containerUri.IndexOf(';');
679679
string containerName = containerUri.Substring(delimIndex + 1);
680-
return containerName.Equals(container.Name);
680+
return containerName.ToLower().Equals(container.Name.ToLower());
681681
}).ToList();
682682
}
683683

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function Test-AzureVMGetItems
4747
-Name $vm.Name;
4848
Assert-True { $items.Count -eq 1 }
4949
Assert-True { $items.VirtualMachineId -contains $vm.Id }
50+
Assert-NotNull $items[0].LastBackupTime
5051

5152
# VARIATION-3: Get items for container with ProtectionStatus filter
5253
$items = Get-AzureRmRecoveryServicesBackupItem `

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<package id="Microsoft.Azure.Management.Network" version="15.1.0-preview" targetFramework="net452" />
88
<package id="Microsoft.Azure.Management.RecoveryServices" version="4.2.0-preview" targetFramework="net45" />
99
<package id="Microsoft.Azure.Management.RecoveryServices.Backup" version="2.1.0-preview" targetFramework="net45" />
10-
<package id="Microsoft.Azure.Management.Resources" version="2.18.14-preview" targetFramework="net45" />
10+
<package id="Microsoft.Azure.Management.Resources" version="2.20.0-preview" targetFramework="net45" />
1111
<package id="Microsoft.Azure.Management.Storage" version="4.1.0-preview" targetFramework="net45" />
1212
<package id="Microsoft.Azure.Test.Framework" version="1.0.6179.26854-prerelease" targetFramework="net45" />
1313
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.6.7-preview" targetFramework="net45" />

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup/Cmdlets/Restore/RestoreAzureRMRecoveryServicesBackupItem.cs

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -60,55 +60,17 @@ public override void ExecuteCmdlet()
6060
ExecutionBlock(() =>
6161
{
6262
base.ExecuteCmdlet();
63-
StorageAccountName = StorageAccountName.ToLower();
64-
ResourceIdentity identity = new ResourceIdentity();
65-
identity.ResourceName = StorageAccountName;
66-
identity.ResourceProviderNamespace = "Microsoft.ClassicStorage/storageAccounts";
67-
identity.ResourceProviderApiVersion = "2015-12-01";
68-
identity.ResourceType = string.Empty;
69-
identity.ParentResourcePath = string.Empty;
7063

71-
GenericResource resource = null;
72-
try
73-
{
74-
WriteDebug(string.Format("Query Microsoft.ClassicStorage with name = {0}",
75-
StorageAccountName));
76-
resource = RmClient.Resources.GetAsync(
77-
StorageAccountResourceGroupName,
78-
identity.ResourceProviderNamespace,
79-
identity.ParentResourcePath,
80-
identity.ResourceType,
81-
identity.ResourceName,
82-
identity.ResourceProviderApiVersion,
83-
CancellationToken.None).Result;
84-
}
85-
catch (Exception)
86-
{
87-
identity.ResourceProviderNamespace = "Microsoft.Storage/storageAccounts";
88-
identity.ResourceProviderApiVersion = "2016-01-01";
89-
resource = RmClient.Resources.GetAsync(
90-
StorageAccountResourceGroupName,
91-
identity.ResourceProviderNamespace,
92-
identity.ParentResourcePath,
93-
identity.ResourceType,
94-
identity.ResourceName,
95-
identity.ResourceProviderApiVersion,
96-
CancellationToken.None).Result;
97-
}
98-
99-
string storageAccountId = resource.Id;
100-
string storageAccountlocation = resource.Location;
101-
string storageAccountType = resource.Type;
102-
103-
WriteDebug(string.Format("StorageId = {0}", storageAccountId));
64+
GenericResource storageAccountResource = GetStorageAccountResource();
65+
WriteDebug(string.Format("StorageId = {0}", storageAccountResource.Id));
10466

10567
PsBackupProviderManager providerManager = new PsBackupProviderManager(
10668
new Dictionary<Enum, object>()
10769
{
10870
{RestoreBackupItemParams.RecoveryPoint, RecoveryPoint},
109-
{RestoreBackupItemParams.StorageAccountId, storageAccountId},
110-
{RestoreBackupItemParams.StorageAccountLocation, storageAccountlocation},
111-
{RestoreBackupItemParams.StorageAccountType, storageAccountType}
71+
{RestoreBackupItemParams.StorageAccountId, storageAccountResource.Id},
72+
{RestoreBackupItemParams.StorageAccountLocation, storageAccountResource.Location},
73+
{RestoreBackupItemParams.StorageAccountType, storageAccountResource.Type}
11274
}, ServiceClientAdapter);
11375

11476
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(
@@ -119,5 +81,46 @@ public override void ExecuteCmdlet()
11981
HandleCreatedJob(jobResponse, Resources.RestoreOperation);
12082
}, ShouldProcess(RecoveryPoint.ItemName, VerbsData.Restore));
12183
}
84+
85+
private GenericResource GetStorageAccountResource()
86+
{
87+
StorageAccountName = StorageAccountName.ToLower();
88+
ResourceIdentity identity = new ResourceIdentity();
89+
identity.ResourceName = StorageAccountName;
90+
identity.ResourceProviderNamespace = "Microsoft.ClassicStorage/storageAccounts";
91+
identity.ResourceProviderApiVersion = "2015-12-01";
92+
identity.ResourceType = string.Empty;
93+
identity.ParentResourcePath = string.Empty;
94+
95+
GenericResource resource = null;
96+
try
97+
{
98+
WriteDebug(string.Format("Query Microsoft.ClassicStorage with name = {0}",
99+
StorageAccountName));
100+
resource = RmClient.Resources.GetAsync(
101+
StorageAccountResourceGroupName,
102+
identity.ResourceProviderNamespace,
103+
identity.ParentResourcePath,
104+
identity.ResourceType,
105+
identity.ResourceName,
106+
identity.ResourceProviderApiVersion,
107+
CancellationToken.None).Result;
108+
}
109+
catch (Exception)
110+
{
111+
identity.ResourceProviderNamespace = "Microsoft.Storage/storageAccounts";
112+
identity.ResourceProviderApiVersion = "2016-01-01";
113+
resource = RmClient.Resources.GetAsync(
114+
StorageAccountResourceGroupName,
115+
identity.ResourceProviderNamespace,
116+
identity.ParentResourcePath,
117+
identity.ResourceType,
118+
identity.ResourceName,
119+
identity.ResourceProviderApiVersion,
120+
CancellationToken.None).Result;
121+
}
122+
123+
return resource;
124+
}
122125
}
123126
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup/RecoveryServicesBackupCmdletBase.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
using System.Collections.Generic;
1717
using System.Management.Automation;
1818
using Microsoft.Azure.Commands.Common.Authentication;
19-
using Microsoft.Azure.Commands.Common.Authentication.Models;
19+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
2020
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS;
2121
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
2222
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
@@ -26,7 +26,6 @@
2626
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
2727
using ResourcesNS = Microsoft.Azure.Management.Internal.Resources;
2828
using SystemNet = System.Net;
29-
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
3029

3130
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
3231
{
@@ -52,7 +51,7 @@ protected void InitializeAzureBackupCmdlet()
5251
{
5352
ServiceClientAdapter = new ServiceClientAdapter(DefaultContext);
5453

55-
WriteDebug("InsideRestore. going to create ResourceManager Client");
54+
WriteDebug("Inside Restore. Going to create ResourceClient.");
5655
RmClient = AzureSession.Instance.ClientFactory.CreateArmClient<ResourcesNS.ResourceManagementClient>(DefaultContext, AzureEnvironment.Endpoint.ResourceManager);
5756

5857
WriteDebug("Client Created successfully");

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Test/Commands.RecoveryServices.Test.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
<SpecificVersion>False</SpecificVersion>
5050
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.4.2.0-preview\lib\net45\Microsoft.Azure.Management.RecoveryServices.dll</HintPath>
5151
</Reference>
52+
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
53+
<SpecificVersion>False</SpecificVersion>
54+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.20.0-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
55+
</Reference>
5256
<Reference Include="Microsoft.Azure.Test.Framework">
5357
<SpecificVersion>False</SpecificVersion>
5458
<HintPath>..\..\..\packages\Microsoft.Azure.Test.Framework.1.0.6179.26854-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
@@ -144,10 +148,10 @@
144148
<None Include="ScenarioTests\RecoveryServicesTests.ps1">
145149
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
146150
</None>
147-
<None Include="SessionRecords\Microsoft.Azure.Commands.RecoveryServices.Test.ScenarioTests.RecoveryServicesTests\VaultCredFileDownloadTest.json">
148-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
151+
<None Include="SessionRecords\Microsoft.Azure.Commands.RecoveryServices.Test.ScenarioTests.RecoveryServicesTests\TestGetRSVaultSettingsFile.json">
152+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
149153
</None>
150-
<None Include="SessionRecords\Microsoft.Azure.Commands.RecoveryServices.Test.ScenarioTests.RecoveryServicesTests\VaultCRUDTests.json">
154+
<None Include="SessionRecords\Microsoft.Azure.Commands.RecoveryServices.Test.ScenarioTests.RecoveryServicesTests\TestRecoveryServicesVaultCRUD.json">
151155
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
152156
</None>
153157
</ItemGroup>

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Test/ScenarioTests/RecoveryServicesTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ public RecoveryServicesTests(ITestOutputHelper output)
2929

3030
[Fact]
3131
[Trait(Category.AcceptanceType, Category.CheckIn)]
32-
public void VaultCRUDTests()
32+
public void TestRecoveryServicesVaultCRUD()
3333
{
34-
TestController.NewInstance.RunPsTest("Test-RecoveryServicesVaultCRUDTests");
34+
TestController.NewInstance.RunPsTest("Test-RecoveryServicesVaultCRUD");
3535
}
3636

3737
[Fact]
38-
[Trait(Category.RunType, Category.LiveOnly)]
39-
public void VaultCredFileDownloadTest()
38+
[Trait(Category.AcceptanceType, Category.CheckIn)]
39+
public void TestGetRSVaultSettingsFile()
4040
{
41-
TestController.NewInstance.RunPsTest("Test-RecoveryServicesVaultCredFileDownloadTest");
41+
TestController.NewInstance.RunPsTest("Test-GetRSVaultSettingsFile");
4242
}
4343
}
4444
}

0 commit comments

Comments
 (0)