Skip to content

RecoveryServices.Backup Bugfixes #5025

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

Merged
merged 10 commits into from
Dec 4, 2017
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
2 changes: 2 additions & 0 deletions src/ResourceManager/RecoveryServices.Backup/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
- Additional information about change #1
-->
## Current Release
* Fixed bug - Get-AzureRmRecoveryServicesBackupItem should do case insensitive comparison for container name filter.
* Fixed bug - AzureVmItem now has a property that shows the last time a backup operation has happened - LastBackupTime.

## Version 4.0.1
* Fixed assembly loading issue that caused some cmdlets to fail when executing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public class AzureVmItem : ItemBase
/// </summary>
public string LastBackupStatus { get; set; }

/// <summary>
/// Last Backup Time for the item
/// </summary>
public DateTime? LastBackupTime { get; set; }

/// <summary>
/// Protection Policy Name for the Item
/// </summary>
Expand All @@ -63,6 +68,7 @@ public AzureVmItem(ProtectedItemResource protectedItemResource,
{
AzureIaaSVMProtectedItem protectedItem = (AzureIaaSVMProtectedItem)protectedItemResource.Properties;
LastBackupStatus = protectedItem.LastBackupStatus;
LastBackupTime = protectedItem.LastBackupTime;
ProtectionPolicyName = policyName;
ProtectionState =
EnumUtils.GetEnum<ItemProtectionState>(protectedItem.ProtectionState.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ public List<ItemBase> ListProtectedItems()

var delimIndex = containerUri.IndexOf(';');
string containerName = containerUri.Substring(delimIndex + 1);
return containerName.Equals(container.Name);
return containerName.ToLower().Equals(container.Name.ToLower());
}).ToList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function Test-AzureVMGetItems
-Name $vm.Name;
Assert-True { $items.Count -eq 1 }
Assert-True { $items.VirtualMachineId -contains $vm.Id }
Assert-NotNull $items[0].LastBackupTime

# VARIATION-3: Get items for container with ProtectionStatus filter
$items = Get-AzureRmRecoveryServicesBackupItem `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<package id="Microsoft.Azure.Management.Network" version="15.1.0-preview" targetFramework="net452" />
<package id="Microsoft.Azure.Management.RecoveryServices" version="4.2.0-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.RecoveryServices.Backup" version="2.1.0-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Resources" version="2.18.14-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Resources" version="2.20.0-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Storage" version="4.1.0-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Test.Framework" version="1.0.6179.26854-prerelease" targetFramework="net45" />
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.6.7-preview" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,55 +60,17 @@ public override void ExecuteCmdlet()
ExecutionBlock(() =>
{
base.ExecuteCmdlet();
StorageAccountName = StorageAccountName.ToLower();
ResourceIdentity identity = new ResourceIdentity();
identity.ResourceName = StorageAccountName;
identity.ResourceProviderNamespace = "Microsoft.ClassicStorage/storageAccounts";
identity.ResourceProviderApiVersion = "2015-12-01";
identity.ResourceType = string.Empty;
identity.ParentResourcePath = string.Empty;

GenericResource resource = null;
try
{
WriteDebug(string.Format("Query Microsoft.ClassicStorage with name = {0}",
StorageAccountName));
resource = RmClient.Resources.GetAsync(
StorageAccountResourceGroupName,
identity.ResourceProviderNamespace,
identity.ParentResourcePath,
identity.ResourceType,
identity.ResourceName,
identity.ResourceProviderApiVersion,
CancellationToken.None).Result;
}
catch (Exception)
{
identity.ResourceProviderNamespace = "Microsoft.Storage/storageAccounts";
identity.ResourceProviderApiVersion = "2016-01-01";
resource = RmClient.Resources.GetAsync(
StorageAccountResourceGroupName,
identity.ResourceProviderNamespace,
identity.ParentResourcePath,
identity.ResourceType,
identity.ResourceName,
identity.ResourceProviderApiVersion,
CancellationToken.None).Result;
}

string storageAccountId = resource.Id;
string storageAccountlocation = resource.Location;
string storageAccountType = resource.Type;

WriteDebug(string.Format("StorageId = {0}", storageAccountId));
GenericResource storageAccountResource = GetStorageAccountResource();
WriteDebug(string.Format("StorageId = {0}", storageAccountResource.Id));

PsBackupProviderManager providerManager = new PsBackupProviderManager(
new Dictionary<Enum, object>()
{
{RestoreBackupItemParams.RecoveryPoint, RecoveryPoint},
{RestoreBackupItemParams.StorageAccountId, storageAccountId},
{RestoreBackupItemParams.StorageAccountLocation, storageAccountlocation},
{RestoreBackupItemParams.StorageAccountType, storageAccountType}
{RestoreBackupItemParams.StorageAccountId, storageAccountResource.Id},
{RestoreBackupItemParams.StorageAccountLocation, storageAccountResource.Location},
{RestoreBackupItemParams.StorageAccountType, storageAccountResource.Type}
}, ServiceClientAdapter);

IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(
Expand All @@ -119,5 +81,46 @@ public override void ExecuteCmdlet()
HandleCreatedJob(jobResponse, Resources.RestoreOperation);
}, ShouldProcess(RecoveryPoint.ItemName, VerbsData.Restore));
}

private GenericResource GetStorageAccountResource()
{
StorageAccountName = StorageAccountName.ToLower();
ResourceIdentity identity = new ResourceIdentity();
identity.ResourceName = StorageAccountName;
identity.ResourceProviderNamespace = "Microsoft.ClassicStorage/storageAccounts";
identity.ResourceProviderApiVersion = "2015-12-01";
identity.ResourceType = string.Empty;
identity.ParentResourcePath = string.Empty;

GenericResource resource = null;
try
{
WriteDebug(string.Format("Query Microsoft.ClassicStorage with name = {0}",
StorageAccountName));
resource = RmClient.Resources.GetAsync(
StorageAccountResourceGroupName,
identity.ResourceProviderNamespace,
identity.ParentResourcePath,
identity.ResourceType,
identity.ResourceName,
identity.ResourceProviderApiVersion,
CancellationToken.None).Result;
}
catch (Exception)
{
identity.ResourceProviderNamespace = "Microsoft.Storage/storageAccounts";
identity.ResourceProviderApiVersion = "2016-01-01";
resource = RmClient.Resources.GetAsync(
StorageAccountResourceGroupName,
identity.ResourceProviderNamespace,
identity.ParentResourcePath,
identity.ResourceType,
identity.ResourceName,
identity.ResourceProviderApiVersion,
CancellationToken.None).Result;
}

return resource;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
Expand All @@ -26,7 +26,6 @@
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using ResourcesNS = Microsoft.Azure.Management.Internal.Resources;
using SystemNet = System.Net;
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
{
Expand All @@ -52,7 +51,7 @@ protected void InitializeAzureBackupCmdlet()
{
ServiceClientAdapter = new ServiceClientAdapter(DefaultContext);

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

WriteDebug("Client Created successfully");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.4.2.0-preview\lib\net45\Microsoft.Azure.Management.RecoveryServices.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.20.0-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Test.Framework">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Test.Framework.1.0.6179.26854-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
Expand Down Expand Up @@ -144,10 +148,10 @@
<None Include="ScenarioTests\RecoveryServicesTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.RecoveryServices.Test.ScenarioTests.RecoveryServicesTests\VaultCredFileDownloadTest.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<None Include="SessionRecords\Microsoft.Azure.Commands.RecoveryServices.Test.ScenarioTests.RecoveryServicesTests\TestGetRSVaultSettingsFile.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.RecoveryServices.Test.ScenarioTests.RecoveryServicesTests\VaultCRUDTests.json">
<None Include="SessionRecords\Microsoft.Azure.Commands.RecoveryServices.Test.ScenarioTests.RecoveryServicesTests\TestRecoveryServicesVaultCRUD.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ public RecoveryServicesTests(ITestOutputHelper output)

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void VaultCRUDTests()
public void TestRecoveryServicesVaultCRUD()
{
TestController.NewInstance.RunPsTest("Test-RecoveryServicesVaultCRUDTests");
TestController.NewInstance.RunPsTest("Test-RecoveryServicesVaultCRUD");
}

[Fact]
[Trait(Category.RunType, Category.LiveOnly)]
public void VaultCredFileDownloadTest()
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetRSVaultSettingsFile()
{
TestController.NewInstance.RunPsTest("Test-RecoveryServicesVaultCredFileDownloadTest");
TestController.NewInstance.RunPsTest("Test-GetRSVaultSettingsFile");
}
}
}
Loading