Jump to content

Recommended Posts

Posted

I don't know if its something that you guys get in to, but I have been asked to produce unit tests for our newly deployed servers so initially I wrote a script that tested everything you could imagine for newly deployed servers and VMs. OS version, KMS server, KMS Key, FW info and that the FW matched what was expected, services, software installed the list goes on and on and to be fair on, and has grown over time.

 

So yesterday I was migrating service from 2K8 to 2K12 servers and was asked about how infrastructure would be testing the servers and migrated services. So the first bit was well we already test our deployments against a desired baseline we have a script for that, but what about the services being migrated? I did not have anything built, so I had heard about pester testing and to get to gips with it I threw together the follow tests script together to test DFS, one of the services recently migrated. This is the pester I came up with while in meetings yesterday afternoon. (its only a starter, already adding tests for checking ports, roots and file systems)

 

Describe "Simple Validation of DFS" {

[CmdletBinding()]

Param(

[Parameter(Mandatory)]

[Alias('Host')]

[string]$ComputerName

)

BEGIN {

Try {

$HostSession = New-PSSession -ComputerName $ComputerName -ErrorAction Stop

}

Catch {

Throw "Unable to connect to host '$ComputerName' - Aborting Tests."

}

 

[string]$HName = $HostSession.ComputerName

}

 

PROCESS {

$SupportHostOS = 'Server 2012 R2'

It "These tests can only be run on the on the following OS ($($SupportHostOS))" {

$OS = (invoke-Command -Session $HostSession {

Get-WmiObject -Class Win32_OperatingSystem

}).Caption

($SupportHostOS | ForEach-Object {$OS -like "*$_*"}) -contains $true | Should Be $true

}

It "The DFS Namespace service should be Running" {

(Invoke-Command -Session $HostSession {

Get-Service -Name DFS}).status | Should Be 'Running'

}

 

It "The DFS Namespace service should be set to Auto Start" {

(Invoke-Command -Session $HostSession {

Get-WmiObject -Class Win32_Service -Property StartMode -Filter "Name='DFS'"}).StartMode | Should Be "Auto"

}

It "The DFS Replication service should be Running" {

(Invoke-Command -Session $HostSession {

Get-Service -Name DFSR}).status | Should Be 'Running'

}

 

It "The DFS Namespace service should be set to Auto Start" {

(Invoke-Command -Session $HostSession {

Get-WmiObject -Class Win32_Service -Property StartMode -Filter "Name='DFSR'"}).StartMode | Should Be "Auto"

}

}

}

 

Probably not something most would consider, but the idea behind these tests and indeed the baseline test I wrote a while ago is that it starts to inform our desired state for servers and desired state for individual services. With the advent of Cloud the ability to manage the amount of servers has gone beyond the capabilities of what Group Policy can do, so DSC is now becoming the de facto way to manage servers on mass (in fact the only way to manage Nano Server) this type of testing is also good for a quick and dirty way to check the status of a server after any change has been made (intentionally or not) I am not saying rewrite SCOM or OMS here but if a service goes down those tools are useful but the unit testing could help narrow the problem even faster and is worth the time it takes upfront if it saves downtime later.

 

 

Food for thought....

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...