Skip to content

Commit 6ccb3d4

Browse files
author
dragonfly91
committed
Ensuring tests passing after set vault context changes
1 parent 67ed99c commit 6ccb3d4

File tree

8 files changed

+122
-111
lines changed

8 files changed

+122
-111
lines changed

src/ResourceManager/RecoveryServices.Backup/Cmdlets/Container/GetAzureRmRecoveryServicesContainer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
2828
/// Get list of containers
2929
/// </summary>
3030
[Cmdlet(VerbsCommon.Get, "AzureRmRecoveryServicesContainer"), OutputType(typeof(List<AzureRmRecoveryServicesContainerBase>), typeof(AzureRmRecoveryServicesContainerBase))]
31-
public class GetAzureRmRecoveryServicesContainer : RecoveryServicesBackupVaultCmdletBase
31+
public class GetAzureRmRecoveryServicesContainer : RecoveryServicesBackupCmdletBase
3232
{
3333
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Container.ContainerType)]
3434
[ValidateNotNullOrEmpty]
@@ -54,7 +54,6 @@ public override void ExecuteCmdlet()
5454

5555
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>()
5656
{
57-
{ContainerParams.Vault, Vault},
5857
{ContainerParams.ContainerType, ContainerType},
5958
{ContainerParams.Name, Name},
6059
{ContainerParams.ResourceGroupName, ResourceGroupName},

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Cmdlets.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,11 @@
8686
<Compile Include="Cmdlets\RecoveryPoint\GetAzureRMRecoveryServicesRecoveryPoint.cs" />
8787
<Compile Include="Cmdlets\Restore\RestoreAzureRMRecoveryServicesBackupItem.cs" />
8888
<Compile Include="Properties\AssemblyInfo.cs" />
89-
<Compile Include="RecoveryServicesBackupVaultCmdletBase.cs" />
9089
<Compile Include="RecoveryServicesBackupCmdletBase.cs" />
9190
<Compile Include="CmdletParameterHelpMessages.cs" />
9291
</ItemGroup>
9392
<ItemGroup>
9493
<Folder Include="Cmdlets\Backup\" />
95-
<Folder Include="Cmdlets\Item\" />
96-
<Folder Include="Cmdlets\RecoveryPoint\" />
97-
<Folder Include="Cmdlets\Restore\" />
98-
<Folder Include="Cmdlets\Jobs\" />
9994
</ItemGroup>
10095
<ItemGroup>
10196
<ProjectReference Include="..\..\Common\Commands.Common\Commands.Common.csproj">

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.HydraAdapter/BMSAPIs/ContainerAPIs.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,15 @@
2222
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
2323
{
2424
public partial class HydraAdapter
25-
{
25+
{
2626
/// <summary>
2727
/// Fetches protection containers in the vault according to the query params
2828
/// </summary>
2929
/// <param name="parameters"></param>
3030
/// <returns></returns>
31-
public IEnumerable<ProtectionContainerResource> ListContainers(string resourceGroupName, string resourceName, ProtectionContainerListQueryParams queryParams)
31+
public IEnumerable<ProtectionContainerResource> ListContainers(ProtectionContainerListQueryParams queryParams)
3232
{
33-
resourceName = BmsAdapter.GetResourceName();
34-
resourceGroupName = BmsAdapter.GetResourceGroupName();
35-
36-
var listResponse = BmsAdapter.Client.Container.ListAsync(resourceGroupName, resourceName, queryParams,
33+
var listResponse = BmsAdapter.Client.Container.ListAsync(BmsAdapter.GetResourceGroupName(), BmsAdapter.GetResourceName(), queryParams,
3734
BmsAdapter.GetCustomRequestHeaders(), BmsAdapter.CmdletCancellationToken).Result;
3835
return listResponse.ItemList.ProtectionContainers;
3936
}
@@ -46,7 +43,7 @@ public BaseRecoveryServicesJobResponse RefreshContainers()
4643
{
4744
string resourceName = BmsAdapter.GetResourceName();
4845
string resourceGroupName = BmsAdapter.GetResourceName();
49-
46+
5047
var response = BmsAdapter.Client.Container.RefreshAsync(
5148
resourceGroupName, resourceName,
5249
BmsAdapter.GetCustomRequestHeaders(), AzureFabricName, BmsAdapter.CmdletCancellationToken).Result;

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public BaseRecoveryServicesJobResponse EnableProtection()
5656
if (policy == null)
5757
{
5858
// throw error -- TBD
59-
}
59+
}
6060

6161
AzureRmRecoveryServicesIaasVmItem item = (AzureRmRecoveryServicesIaasVmItem)
6262
ProviderData.ProviderParameters[ItemParams.Item];
@@ -176,7 +176,7 @@ public List<AzureRmRecoveryServicesRecoveryPointBase> ListRecoveryPoints()
176176
TimeSpan duration = endDate - startDate;
177177

178178
if (duration.TotalDays > 30)
179-
{
179+
{
180180
throw new Exception("Time difference should not be more than 30 days"); //tbd: Correct nsg and exception type
181181
}
182182

@@ -192,7 +192,7 @@ public List<AzureRmRecoveryServicesRecoveryPointBase> ListRecoveryPoints()
192192
public ProtectionPolicyResponse CreatePolicy()
193193
{
194194
string policyName = (string)ProviderData.ProviderParameters[PolicyParams.PolicyName];
195-
Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.WorkloadType workloadType =
195+
Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.WorkloadType workloadType =
196196
(Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.WorkloadType)ProviderData.ProviderParameters[PolicyParams.WorkloadType];
197197
BackupManagementType backupManagementType = (BackupManagementType)ProviderData.ProviderParameters[
198198
PolicyParams.BackupManagementType];
@@ -307,7 +307,6 @@ public List<AzureRmRecoveryServicesContainerBase> ListProtectionContainers()
307307
{
308308
string name = (string)this.ProviderData.ProviderParameters[ContainerParams.Name];
309309
ContainerRegistrationStatus status = (ContainerRegistrationStatus)this.ProviderData.ProviderParameters[ContainerParams.Status];
310-
ARSVault vault = (ARSVault)this.ProviderData.ProviderParameters[ContainerParams.Vault];
311310
string resourceGroupName = (string)this.ProviderData.ProviderParameters[ContainerParams.ResourceGroupName];
312311

313312
ProtectionContainerListQueryParams queryParams = new ProtectionContainerListQueryParams();
@@ -321,7 +320,7 @@ public List<AzureRmRecoveryServicesContainerBase> ListProtectionContainers()
321320
// 3. Filter by Status
322321
queryParams.RegistrationStatus = status.ToString();
323322

324-
var listResponse = HydraAdapter.ListContainers(vault.ResouceGroupName, vault.Name, queryParams);
323+
var listResponse = HydraAdapter.ListContainers(queryParams);
325324

326325
List<AzureRmRecoveryServicesContainerBase> containerModels = ConversionHelpers.GetContainerModelList(listResponse);
327326

@@ -365,9 +364,9 @@ public AzureRmRecoveryServicesSchedulePolicyBase GetDefaultSchedulePolicyObject(
365364
public AzureRmRecoveryServicesRetentionPolicyBase GetDefaultRetentionPolicyObject()
366365
{
367366
AzureRmRecoveryServicesLongTermRetentionPolicy defaultRetention = new AzureRmRecoveryServicesLongTermRetentionPolicy();
368-
367+
369368
//Default time is 10:30 local time
370-
DateTime retentionTime = GenerateRandomTime();
369+
DateTime retentionTime = GenerateRandomTime();
371370

372371
//Daily Retention policy
373372
defaultRetention.IsDailyScheduleEnabled = true;
@@ -392,7 +391,7 @@ public AzureRmRecoveryServicesRetentionPolicyBase GetDefaultRetentionPolicyObjec
392391
defaultRetention.MonthlySchedule.RetentionScheduleFormatType = Models.RetentionScheduleFormat.Weekly;
393392

394393
//Initialize day based schedule
395-
defaultRetention.MonthlySchedule.RetentionScheduleDaily = GetDailyRetentionFormat();
394+
defaultRetention.MonthlySchedule.RetentionScheduleDaily = GetDailyRetentionFormat();
396395

397396
//Initialize Week based schedule
398397
defaultRetention.MonthlySchedule.RetentionScheduleWeekly = GetWeeklyRetentionFormat();
@@ -458,7 +457,7 @@ private void ValidateAzureVMProtectionPolicy(AzureRmRecoveryServicesPolicyBase p
458457
if (policy == null || policy.GetType() != typeof(AzureRmRecoveryServicesIaasVmPolicy))
459458
{
460459
throw new ArgumentException(string.Format(Resources.InvalidProtectionPolicyException,
461-
typeof(AzureRmRecoveryServicesIaasVmPolicy).ToString()));
460+
typeof(AzureRmRecoveryServicesIaasVmPolicy).ToString()));
462461
}
463462

464463
ValidateAzureVMWorkloadType(policy.WorkloadType);
@@ -472,7 +471,7 @@ private void ValidateAzureVMSchedulePolicy(AzureRmRecoveryServicesSchedulePolicy
472471
if (policy == null || policy.GetType() != typeof(AzureRmRecoveryServicesSimpleSchedulePolicy))
473472
{
474473
throw new ArgumentException(string.Format(Resources.InvalidSchedulePolicyException,
475-
typeof(AzureRmRecoveryServicesSimpleSchedulePolicy).ToString()));
474+
typeof(AzureRmRecoveryServicesSimpleSchedulePolicy).ToString()));
476475
}
477476

478477
// call validation
@@ -484,14 +483,14 @@ private void ValidateAzureVMRetentionPolicy(AzureRmRecoveryServicesRetentionPoli
484483
if (policy == null || policy.GetType() != typeof(AzureRmRecoveryServicesLongTermRetentionPolicy))
485484
{
486485
throw new ArgumentException(string.Format(Resources.InvalidRetentionPolicyException,
487-
typeof(AzureRmRecoveryServicesLongTermRetentionPolicy).ToString()));
486+
typeof(AzureRmRecoveryServicesLongTermRetentionPolicy).ToString()));
488487
}
489488

490489
// call validation
491490
policy.Validate();
492491
}
493492

494-
private AzureIaaSVMProtectableItem GetAzureVMProtectableObject( string azureVMName, string azureVMRGName, bool isComputeAzureVM)
493+
private AzureIaaSVMProtectableItem GetAzureVMProtectableObject(string azureVMName, string azureVMRGName, bool isComputeAzureVM)
495494
{
496495
//TriggerDiscovery if needed
497496

@@ -512,7 +511,7 @@ private AzureIaaSVMProtectableItem GetAzureVMProtectableObject( string azureVMNa
512511
//ThrowTerminatingError(new ErrorRecord(new Exception(Resources.AzureVMNotFound), string.Empty, ErrorCategory.InvalidArgument, null));
513512
}
514513
}
515-
if(protectableObject == null)
514+
if (protectableObject == null)
516515
{
517516
// TBD throw exception.
518517
}
@@ -623,9 +622,9 @@ private HttpStatusCode TrackRefreshContainerOperation(string operationResultLink
623622
}
624623
catch (Exception ex)
625624
{
626-
// TBD throw exception
625+
// TBD throw exception
627626
throw ex;
628-
}
627+
}
629628
}
630629

631630
if (status == HttpStatusCode.NoContent)

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
function Test-GetContainerScenario
1616
{
1717
$vault = Get-AzureRmRecoveryServicesVault -ResourceGroupName "phaniktRSV" -Name "phaniktRs1";
18-
$containers = Get-AzureRmRecoveryServicesContainer -Vault $vault -ContainerType "AzureVM" -Status "Registered";
18+
Set-AzureRmRecoveryServicesVaultContext -Vault $vault;
19+
$containers = Get-AzureRmRecoveryServicesContainer -ContainerType "AzureVM" -Status "Registered";
1920
foreach ($container in $containers)
2021
{
2122
echo $container.Name $container.ResourceGroupName;
2223
}
2324
Assert-AreEqual $containers[0].Name "mylinux1";
2425

25-
$namedContainer = Get-AzureRmRecoveryServicesContainer -Vault $vault -ContainerType "AzureVM" -Status "Registered" -Name "mylinux1";
26+
$namedContainer = Get-AzureRmRecoveryServicesContainer -ContainerType "AzureVM" -Status "Registered" -Name "mylinux1";
2627
Assert-AreEqual $namedContainer.Name "mylinux1";
2728

28-
$rgFilteredContainer = Get-AzureRmRecoveryServicesContainer -Vault $vault -ContainerType "AzureVM" -Status "Registered" -Name "mylinux1" -ResourceGroupName "00prjai12";
29+
$rgFilteredContainer = Get-AzureRmRecoveryServicesContainer -ContainerType "AzureVM" -Status "Registered" -Name "mylinux1" -ResourceGroupName "00prjai12";
2930
echo $rgFilteredContainer.Name $rgFilteredContainer.ResourceGroupName;
3031
}

0 commit comments

Comments
 (0)