-
Notifications
You must be signed in to change notification settings - Fork 4k
Adding new dsc extension status cmdlet #102
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
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
304d396
initial code changes for dsc extension status cmdlet
eshaparmar 090cad3
missing proj file for status changes
eshaparmar 1b23ac7
Added missing 'StatusMessage' field from the format file
eshaparmar d1c6c2f
Changed the format of the timestamp to {0:U} instead of {0:u} to make…
eshaparmar c1b54ea
Changed the timestamp returned by the cmdlet to return in localtime z…
eshaparmar 1517b7f
changed the timestamp type to datetimeoffset from datetime
eshaparmar 801a8d9
Merge branch 'dev' into dscstatus
eshaparmar 909a5c8
Updated the new cmdlet for the changes in the latest common library
eshaparmar 60815a1
Initial code for the unit tests for Get-AzureVMDSCExtensionStatus cmdlet
eshaparmar 3422a93
Merge branch 'dev' into dscstatus_ut
eshaparmar 13e247f
Added comments to the cmdlet class
eshaparmar 205c1d6
Added comments
eshaparmar 2bd0fd1
Merge branch 'dev' into dscstatus_ut
eshaparmar 732c543
Merge branch 'dev' into dscstatus_ut
eshaparmar 009d555
Merge branch 'dscstatus_ut' into dscstatus
eshaparmar b9dc26c
Added .snk file for signing the service mgmt extension test assembly
eshaparmar 9e06c2c
Added .snk file for signing the service mgmt extension test assembly
eshaparmar c8e51fa
PR comments incorporated
eshaparmar 11b46c3
Fixed a failing test and converted it to XUnit
eshaparmar 2bef41c
Removed old version of WindowsAzure.Common
eshaparmar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
272 changes: 272 additions & 0 deletions
272
...s.ServiceManagement.Extensions.Test/DSC/UnitTests/GetAzureVMDscExtensionStatusUnitTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,272 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions; | ||
using Microsoft.WindowsAzure.Commands.ServiceManagement.Model; | ||
using Xunit; | ||
|
||
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Extensions.Test.DSC.UnitTests | ||
{ | ||
using NSM = Management.Compute.Models; | ||
|
||
public class GetAzureVmDscExtensionStatusUnitTest | ||
{ | ||
private readonly GetAzureVmDscExtensionStatusCommand getAzureVmDscExtensionStatusCmdlet; | ||
private const string ServiceName = "dsc-service"; | ||
|
||
public GetAzureVmDscExtensionStatusUnitTest() | ||
{ | ||
getAzureVmDscExtensionStatusCmdlet = new GetAzureVmDscExtensionStatusCommand(); | ||
} | ||
|
||
[Fact] | ||
public void TestGetService() | ||
{ | ||
//when service name is passed as argument in the cmdlet | ||
getAzureVmDscExtensionStatusCmdlet.GetService(ServiceName, null); | ||
Assert.Equal(ServiceName, getAzureVmDscExtensionStatusCmdlet.Service); | ||
|
||
//when vm object is passed as argument in the cmdlet | ||
getAzureVmDscExtensionStatusCmdlet.GetService("", GetAzureVM(ServiceName, ServiceName)); | ||
Assert.Equal(ServiceName, getAzureVmDscExtensionStatusCmdlet.Service); | ||
} | ||
|
||
[Fact] | ||
public void TestGetVirtualMachineDscStatusContextListWithServiceName() | ||
{ | ||
getAzureVmDscExtensionStatusCmdlet.Service = ServiceName; | ||
|
||
// service has multiple vm's | ||
var roles = new List<NSM.Role> {CreateRole("dscmachine01"), CreateRole("dscmachine02")}; | ||
var roleInstances = new List<NSM.RoleInstance> | ||
{ | ||
CreateRoleInstance("dscmachine01"), | ||
CreateRoleInstance("dscmachine02") | ||
}; | ||
|
||
var deploymentResponse = CreateDeploymentGetResponse(ServiceName, roles, roleInstances); | ||
var dscExtensionStatusContexts = | ||
getAzureVmDscExtensionStatusCmdlet | ||
.GetVirtualMachineDscStatusContextList(deploymentResponse); | ||
Assert.Null(getAzureVmDscExtensionStatusCmdlet.Name); | ||
Assert.Null(getAzureVmDscExtensionStatusCmdlet.VmName); | ||
Assert.NotNull(dscExtensionStatusContexts); | ||
Assert.Equal(dscExtensionStatusContexts.Count, 2); | ||
|
||
} | ||
|
||
[Fact] | ||
public void TestGetVirtualMachineDscStatusContextListWithServiceNameAndVmName() | ||
{ | ||
getAzureVmDscExtensionStatusCmdlet.Service = ServiceName; | ||
getAzureVmDscExtensionStatusCmdlet.Name = "dscmachine01"; | ||
|
||
// service has multiple vm's | ||
var roles = new List<NSM.Role> {CreateRole("dscmachine01"), CreateRole("dscmachine02")}; | ||
var roleInstances = new List<NSM.RoleInstance> | ||
{ | ||
CreateRoleInstance("dscmachine01"), | ||
CreateRoleInstance("dscmachine02") | ||
}; | ||
|
||
var deploymentResponse = CreateDeploymentGetResponse(ServiceName, roles, roleInstances); | ||
var dscExtensionStatusContexts = | ||
getAzureVmDscExtensionStatusCmdlet | ||
.GetVirtualMachineDscStatusContextList(deploymentResponse); | ||
Assert.NotNull(getAzureVmDscExtensionStatusCmdlet.Name); | ||
Assert.Null(getAzureVmDscExtensionStatusCmdlet.VmName); | ||
Assert.NotNull(dscExtensionStatusContexts); | ||
Assert.Equal(dscExtensionStatusContexts.Count, 1); | ||
|
||
} | ||
|
||
[Fact] | ||
public void TestGetVirtualMachineDscStatusContextListWithServiceNameAndIncorrectVmName() | ||
{ | ||
getAzureVmDscExtensionStatusCmdlet.Service = ServiceName; | ||
getAzureVmDscExtensionStatusCmdlet.Name = "some-blah"; | ||
|
||
// service has multiple vm's | ||
var roles = new List<NSM.Role> {CreateRole("dscmachine01"), CreateRole("dscmachine02")}; | ||
var roleInstances = new List<NSM.RoleInstance> | ||
{ | ||
CreateRoleInstance("dscmachine01"), | ||
CreateRoleInstance("dscmachine02") | ||
}; | ||
|
||
var deploymentResponse = CreateDeploymentGetResponse(ServiceName, roles, roleInstances); | ||
var dscExtensionStatusContexts = | ||
getAzureVmDscExtensionStatusCmdlet | ||
.GetVirtualMachineDscStatusContextList(deploymentResponse); | ||
Assert.NotNull(getAzureVmDscExtensionStatusCmdlet.Name); | ||
Assert.Null(getAzureVmDscExtensionStatusCmdlet.VmName); | ||
Assert.Equal(dscExtensionStatusContexts.Count, 0); | ||
|
||
} | ||
|
||
[Fact] | ||
public void TestGetVirtualMachineDscStatusContextListWithVm() | ||
{ | ||
getAzureVmDscExtensionStatusCmdlet.Service = ServiceName; | ||
getAzureVmDscExtensionStatusCmdlet.VmName = "dscmachine02"; | ||
|
||
// service has multiple vm's | ||
var roles = new List<NSM.Role> {CreateRole("dscmachine02")}; | ||
var roleInstances = new List<NSM.RoleInstance> {CreateRoleInstance("dscmachine02")}; | ||
|
||
var deploymentResponse = CreateDeploymentGetResponse(ServiceName, roles, roleInstances); | ||
var dscExtensionStatusContexts = | ||
getAzureVmDscExtensionStatusCmdlet | ||
.GetVirtualMachineDscStatusContextList(deploymentResponse); | ||
Assert.Null(getAzureVmDscExtensionStatusCmdlet.Name); | ||
Assert.NotNull(getAzureVmDscExtensionStatusCmdlet.VmName); | ||
Assert.Equal(dscExtensionStatusContexts.Count, 1); | ||
} | ||
|
||
[Fact] | ||
public void TestCreateDscStatusContext() | ||
{ | ||
getAzureVmDscExtensionStatusCmdlet.Service = ServiceName; | ||
|
||
var roles = new List<NSM.Role> {CreateRole("dscmachine02")}; | ||
var roleInstances = new List<NSM.RoleInstance> {CreateRoleInstance("dscmachine02")}; | ||
var context = | ||
getAzureVmDscExtensionStatusCmdlet.CreateDscStatusContext( | ||
roles[0], roleInstances[0]); | ||
Assert.NotNull(context); | ||
Assert.Equal(context.Name, "dscmachine02"); | ||
Assert.Equal(context.StatusCode, 1); | ||
Assert.Equal(context.ServiceName, ServiceName); | ||
Assert.Equal(context.Status, "Success"); | ||
Assert.Equal(context.StatusMessage, "Dsc Configuration was applied successful"); | ||
Assert.Equal(context.DscConfigurationLog.Count(), GetFormattedMessage().Count()); | ||
} | ||
|
||
private IPersistentVM GetAzureVM(String roleName, String serviceName) | ||
{ | ||
var vm = new PersistentVM {RoleName = roleName}; | ||
var vmContext = new PersistentVMRoleContext | ||
{ | ||
DeploymentName = roleName, | ||
Name = roleName, | ||
ServiceName = serviceName, | ||
VM = vm | ||
}; | ||
|
||
return vmContext; | ||
} | ||
|
||
private NSM.DeploymentGetResponse CreateDeploymentGetResponse(string serviceName, IList<NSM.Role> roles, | ||
IList<NSM.RoleInstance> roleInstances) | ||
{ | ||
var response = new NSM.DeploymentGetResponse | ||
{ | ||
Name = serviceName, | ||
Configuration = "config", | ||
Status = Management.Compute.Models.DeploymentStatus.Starting, | ||
PersistentVMDowntime = new NSM.PersistentVMDowntime | ||
{ | ||
EndTime = DateTime.Now, | ||
StartTime = DateTime.Now, | ||
Status = "", | ||
}, | ||
LastModifiedTime = DateTime.Now, | ||
Roles = roles, | ||
RoleInstances = roleInstances | ||
}; | ||
|
||
return response; | ||
} | ||
|
||
private NSM.RoleInstance CreateRoleInstance(String roleName) | ||
{ | ||
var roleInstance = new NSM.RoleInstance | ||
{ | ||
RoleName = roleName, | ||
ResourceExtensionStatusList = CreateResourceExtensionStatus() | ||
}; | ||
return roleInstance; | ||
} | ||
|
||
private NSM.Role CreateRole(String roleName) | ||
{ | ||
var role = new NSM.Role | ||
{ | ||
RoleName = roleName | ||
}; | ||
|
||
return role; | ||
} | ||
|
||
private List<NSM.ResourceExtensionStatus> CreateResourceExtensionStatus() | ||
{ | ||
var resourceExtensionStatusList = new List<NSM.ResourceExtensionStatus>(); | ||
|
||
var resourceBgiExtensionStatus = new NSM.ResourceExtensionStatus | ||
{ | ||
HandlerName = "BGIInfo" | ||
}; | ||
var resourceDscExtensionStatus = new NSM.ResourceExtensionStatus | ||
{ | ||
HandlerName = "Microsoft.Powershell.DSC", | ||
ExtensionSettingStatus = CreateExtensionSettingStatus() | ||
}; | ||
|
||
resourceExtensionStatusList.Add(resourceBgiExtensionStatus); | ||
resourceExtensionStatusList.Add(resourceDscExtensionStatus); | ||
|
||
return resourceExtensionStatusList; | ||
} | ||
|
||
private NSM.ResourceExtensionConfigurationStatus CreateExtensionSettingStatus() | ||
{ | ||
var extensionSettingStatus = new NSM.ResourceExtensionConfigurationStatus | ||
{ | ||
Code = 1, | ||
Status = "Success", | ||
FormattedMessage = new NSM.GuestAgentFormattedMessage | ||
{ | ||
Message = "Dsc Configuration was applied successful" | ||
}, | ||
Timestamp = new DateTime(), | ||
SubStatusList = CreateResourceExtensionSubStatus(1, CreateGuestAgentFormattedMessage()) | ||
}; | ||
|
||
return extensionSettingStatus; | ||
} | ||
|
||
private List<NSM.ResourceExtensionSubStatus> CreateResourceExtensionSubStatus(int code, | ||
NSM.GuestAgentFormattedMessage formattedMessage) | ||
{ | ||
var resourceExtensionSubStatusList = new List<NSM.ResourceExtensionSubStatus>(); | ||
var resourceExtensionSubStatus = new NSM.ResourceExtensionSubStatus | ||
{ | ||
Code = code, | ||
FormattedMessage = formattedMessage, | ||
Status = "Success", | ||
Name = "DSC Status" | ||
}; | ||
resourceExtensionSubStatusList.Add(resourceExtensionSubStatus); | ||
return resourceExtensionSubStatusList; | ||
} | ||
|
||
private NSM.GuestAgentFormattedMessage CreateGuestAgentFormattedMessage() | ||
{ | ||
var formattedMessage = new NSM.GuestAgentFormattedMessage | ||
{ | ||
Message = | ||
"[ESPARMAR-2012R2]:LCM:[Start Set]\r\n[ESPARMAR-2012R2]:LCM:[Start Resource] " + | ||
"[[WindowsFeature]IIS]\r\n[ESPARMAR-2012R2]:LCM:[Start Test] [[WindowsFeature]IIS]\r\n[ESPARMAR-2012R2]" | ||
}; | ||
return formattedMessage; | ||
} | ||
|
||
private IEnumerable<string> GetFormattedMessage() | ||
{ | ||
const string message = "[ESPARMAR-2012R2]:LCM:[Start Set]\r\n[ESPARMAR-2012R2]:LCM:[Start Resource] " + | ||
"[[WindowsFeature]IIS]\r\n[ESPARMAR-2012R2]:LCM:[Start Test] [[WindowsFeature]IIS]\r\n[ESPARMAR-2012R2]"; | ||
|
||
return message.Split(new[] {"\r\n", "\n"}, StringSplitOptions.None); | ||
} | ||
} | ||
} |
Binary file added
BIN
+160 Bytes
src/ServiceManagement/Compute/Commands.ServiceManagement.Extensions.Test/MSSharedLibKey.snk
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check with Yugang on delay signing and directly referencing the snk file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spoke with Yugang offline - once there is a common place for the .snk file all duplicates will be removed. We thought about putting a duplicate .snk file but decided to go with the pattern that is followed so far ( to be consistent). Ideally, yes there should be a common place for the .snk file.