Skip to content

Commit 3636735

Browse files
committed
Merge pull request #19 from huangpf/dev
AzureRT: Fix Get-AzureVM
2 parents 9e72ff5 + bb43e0f commit 3636735

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

src/AzurePowershell.sln

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio 2013
3-
VisualStudioVersion = 12.0.31101.0MinimumVisualStudioVersion = 10.0.40219.1
3+
VisualStudioVersion = 12.0.31101.0
4+
MinimumVisualStudioVersion = 10.0.40219.1
45
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8531411A-0137-4E27-9C5E-49E07C245048}"
56
ProjectSection(SolutionItems) = preProject
67
local.runsettings = local.runsettings

src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,12 @@ public void AzureDeploymentTest()
626626
Assert.IsTrue(ce.Message.Contains("The date specified in parameter EndTime is not within the correct range."));
627627
}
628628

629+
// Negative test for Get-AzureVM
630+
var vmRoleList1 = vmPowershellCmdlets.GetAzureVM();
631+
Assert.IsFalse(vmRoleList1.Any(r => r.DeploymentName == deploymentName));
632+
var vmRoleList2 = vmPowershellCmdlets.GetAzureVM(serviceName);
633+
Assert.IsFalse(vmRoleList2.Any(r => r.DeploymentName == deploymentName));
634+
629635
vmPowershellCmdlets.RemoveAzureDeployment(serviceName, DeploymentSlotType.Production, true);
630636

631637
pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, serviceName, DeploymentSlotType.Production);

src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,9 +1330,9 @@ internal Collection<ManagementOperationContext> NewAzureVM(string serviceName, S
13301330
return result;
13311331
}
13321332

1333-
public Collection<SM.PersistentVMRoleListContext> GetAzureVM(string vmName = null)
1333+
public Collection<SM.PersistentVMRoleListContext> GetAzureVM(string serviceName = null)
13341334
{
1335-
return RunPSCmdletAndReturnAll<SM.PersistentVMRoleListContext>(new GetAzureVMCmdletInfo(vmName, null));
1335+
return RunPSCmdletAndReturnAll<SM.PersistentVMRoleListContext>(new GetAzureVMCmdletInfo(null, serviceName));
13361336
}
13371337

13381338
public SM.PersistentVMRoleContext GetAzureVM(string vmName, string serviceName)

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/PersistentVMs/GetAzureVM.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,18 @@ protected override void ExecuteCommand()
101101
private List<T> GetVMContextList<T>(string serviceName, NSM.DeploymentGetResponse deployment)
102102
where T : PVM.PersistentVMRoleContext, new()
103103
{
104-
var vmRoles = new List<NSM.Role>(deployment.Roles.Where(
105-
r => string.IsNullOrEmpty(Name)
106-
|| r.RoleName.Equals(Name, StringComparison.InvariantCultureIgnoreCase)));
104+
Func<NSM.Role, bool> typeMatched =
105+
r => string.Equals(r.RoleType, PersistentVMRoleStr, StringComparison.OrdinalIgnoreCase);
107106

108-
return GetVMContextList<T>(serviceName, deployment, vmRoles);
107+
Func<NSM.Role, bool> nameMatched =
108+
r => string.IsNullOrEmpty(this.Name) || r.RoleName.Equals(this.Name, StringComparison.InvariantCultureIgnoreCase);
109+
110+
var vmRoles = new List<NSM.Role>(deployment.Roles.Where(r => typeMatched(r) && nameMatched(r)));
111+
112+
return CreateVMContextList<T>(serviceName, deployment, vmRoles);
109113
}
110114

111-
private List<T> GetVMContextList<T>(string serviceName, NSM.DeploymentGetResponse deployment, List<NSM.Role> vmRoles)
115+
private List<T> CreateVMContextList<T>(string serviceName, NSM.DeploymentGetResponse deployment, List<NSM.Role> vmRoles)
112116
where T : PVM.PersistentVMRoleContext, new()
113117
{
114118
var roleContexts = new List<T>();

0 commit comments

Comments
 (0)