Skip to content

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
merged 20 commits into from Feb 6, 2015
Merged
Show file tree
Hide file tree
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 Jan 8, 2015
090cad3
missing proj file for status changes
eshaparmar Jan 9, 2015
1b23ac7
Added missing 'StatusMessage' field from the format file
eshaparmar Jan 12, 2015
d1c6c2f
Changed the format of the timestamp to {0:U} instead of {0:u} to make…
eshaparmar Jan 13, 2015
c1b54ea
Changed the timestamp returned by the cmdlet to return in localtime z…
eshaparmar Jan 14, 2015
1517b7f
changed the timestamp type to datetimeoffset from datetime
eshaparmar Jan 15, 2015
801a8d9
Merge branch 'dev' into dscstatus
eshaparmar Jan 21, 2015
909a5c8
Updated the new cmdlet for the changes in the latest common library
eshaparmar Jan 21, 2015
60815a1
Initial code for the unit tests for Get-AzureVMDSCExtensionStatus cmdlet
eshaparmar Jan 21, 2015
3422a93
Merge branch 'dev' into dscstatus_ut
eshaparmar Jan 21, 2015
13e247f
Added comments to the cmdlet class
eshaparmar Jan 22, 2015
205c1d6
Added comments
eshaparmar Jan 23, 2015
2bd0fd1
Merge branch 'dev' into dscstatus_ut
eshaparmar Jan 29, 2015
732c543
Merge branch 'dev' into dscstatus_ut
eshaparmar Jan 30, 2015
009d555
Merge branch 'dscstatus_ut' into dscstatus
eshaparmar Jan 30, 2015
b9dc26c
Added .snk file for signing the service mgmt extension test assembly
eshaparmar Feb 2, 2015
9e06c2c
Added .snk file for signing the service mgmt extension test assembly
eshaparmar Feb 2, 2015
c8e51fa
PR comments incorporated
eshaparmar Feb 5, 2015
11b46c3
Fixed a failing test and converted it to XUnit
eshaparmar Feb 5, 2015
2bef41c
Removed old version of WindowsAzure.Common
eshaparmar Feb 5, 2015
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>TRACE;SIGN</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DelaySign>true</DelaySign>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>MSSharedLibKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Hyak.Common">
Expand Down Expand Up @@ -70,6 +73,10 @@
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop">
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Management.Compute, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Compute.8.0.0\lib\net40\Microsoft.WindowsAzure.Management.Compute.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Management">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.0.0\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
</Reference>
Expand All @@ -91,6 +98,10 @@
<HintPath>..\..\..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="xunit, Version=1.9.2.1705, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
Expand All @@ -107,19 +118,29 @@
<ItemGroup>
<Compile Include="DSC\DscExtensionConfigurationParsingHelperTests.cs" />
<Compile Include="DSC\DscExtensionSettingsSerializerTests.cs" />
<Compile Include="DSC\UnitTests\GetAzureVmDscExtensionStatusUnitTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Common\Commands.Common\Commands.Common.csproj">
<Project>{5EE72C53-1720-4309-B54B-5FB79703195F}</Project>
<Name>Commands.Common</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Common\Commands.ScenarioTests.Common\Commands.ScenarioTests.Common.csproj">
<Project>{C1BDA476-A5CC-4394-914D-48B0EC31A710}</Project>
<Name>Commands.ScenarioTests.Common</Name>
</ProjectReference>
<ProjectReference Include="..\..\Services\Commands.Utilities\Commands.Utilities.csproj">
<Project>{4900EC4E-8DEB-4412-9108-0BC52F81D457}</Project>
<Name>Commands.Utilities</Name>
</ProjectReference>
<ProjectReference Include="..\Commands.ServiceManagement\Commands.ServiceManagement.csproj">
<Project>{e1ca72ba-8374-45f6-904d-fd34ecdf5b6f}</Project>
<Name>Commands.ServiceManagement</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="MSSharedLibKey.snk" />
Copy link
Contributor

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.

Copy link
Contributor

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.

<None Include="packages.config" />
<None Include="Resources\DSC\Configurations\CorporateClientConfiguration.ps1" />
<None Include="Resources\DSC\Configurations\DomainControllerConfiguration.ps1" />
Expand Down
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 not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
<Compile Include="IaaS\Extensions\DSC\DscPrivateSettings.cs" />
<Compile Include="IaaS\Extensions\DSC\DscPublicSettings.cs" />
<Compile Include="IaaS\Extensions\DSC\DscSettingsSerializer.cs" />
<Compile Include="IaaS\Extensions\DSC\GetAzureVMDscExtensionStatus.cs" />
<Compile Include="IaaS\Extensions\DSC\GetDscResourceException.cs" />
<Compile Include="IaaS\Extensions\DSC\RemoveAzureVMDscExtension.cs" />
<Compile Include="IaaS\Extensions\DSC\GetAzureVMDscExtension.cs" />
Expand All @@ -216,6 +217,7 @@
<Compile Include="IaaS\Extensions\DSC\ConfigurationParseResult.cs" />
<Compile Include="IaaS\Extensions\DSC\ServiceManagementBaseCmdletExtentions.cs" />
<Compile Include="IaaS\Extensions\DSC\PublishAzureVMDscConfiguration.cs" />
<Compile Include="IaaS\Extensions\DSC\VirtualMachineDscExtensionStatusContext.cs" />
<Compile Include="IaaS\Extensions\MicrosoftAntimalware\GetAzureVMMicrosoftAntimalwareExtension.cs" />
<Compile Include="IaaS\Extensions\MicrosoftAntimalware\RemoveAzureVMMicrosoftAntimalwareExtension.cs" />
<Compile Include="IaaS\Extensions\MicrosoftAntimalware\SetAzureVMMicrosoftAntimalwareExtension.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal void ExecuteCommand()
State = r.State,
RoleName = VM.GetInstance().RoleName,
PublicConfiguration = PublicConfiguration,
PrivateConfiguration = SecureStringHelper.GetSecureString(PrivateConfiguration),
PrivateConfiguration = SecureStringHelper.GetSecureString(PrivateConfiguration)
};

if (publicSettings == null)
Expand All @@ -99,6 +99,7 @@ protected override void ProcessRecord()
base.ProcessRecord();
ExecuteCommand();
}

}
}

Loading