Thursday, September 14, 2017

Infrastructure/Ops validation : PnP device running a supported driver version?

Problem

We have had this problem statement at hand which requires the field engineer to validate that any engineered solution, when deployed at a customer site, is running the supported versions of the firmware and driver.



Background

Well, we already have Pester tests written and placed inside a validation kit which tests whether a deployment is as per the practices outlined in our deployment guide.
So this was only natural to add the driver version validation under this kit (firmware validation in the future release).

We use Pester (PowerShell unit testing framework) for the Infrastructure/Ops validation and PSRemotely to target all the nodes in our solution for these tests. So the code samples in the post correspond to that.




Solution

Where to store supported version info?

First, of all, we decouple the environment details (inputs) to our validation kit in a file named EnvironmentConfigData.psd1. This file follows PowerShell DSC style configuration data rules.
Inside this configuration data, we maintain a list of all supported versions under the PnPDeviceMetadata. See below 
EnvironmentConfigData.psd1 for sample :

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
@{
    AllNodes = @(
        @{
            # common node information hashtable
            NodeName = '*'; # do not edit
            Features = @('Hyper-V','Failover-Clustering', 'Data-Center-Bridging') # Do not edit
            SETTeamName = 'S2DSwitch'; # <Edit> name of the SET team
            PnPDeviceMetadata = @( # do not edit, PNPDevice metadata, used for driver version validation
                @{
                    Class = 'SCSIAdapter' #PNP device class
                    FriendlyName = 'Dell HBA330 Mini' # PNP device friendly name
                    Versions = @('2.51.15.0') # PnP device driver supported versions. Add more values if applicable
                },
                @{
                    Class = 'System'
                    FriendlyName = '*chipset*'
                    Versions = @('10.1.2.85') #Add more values if applicable
                },
                @{
                    Class = 'Net'
                    FriendlyName = '*Mellanox*'
                    Versions = @('5.35.12978.0','1.50.15998.0') # CX3,CX4 (Dell Q2 versions) #Add more values if applicable
                }
            )
        },
        @{
            # Individual node information hashtable
            NodeName = 'Node1'
        }
   )
}

Now this metadata inside the configuration file serves as the source of truth for the supported versions in our solution.

Test the node

The above metadata is used by a generic test block written in Pester as below and runs on each node in our solution. Note that $Node variable below is a placeholder for all the information specific to a node in our solution and is generated after reading the above environment configuration data by the framework PSRemotely :
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 
PSRemotely -Path $PSScriptRoot\EnvironmentConfigData.psd1 {
    Node $AllNodes.NodeName {    
        Describe "PnP Device driver version validation" {
            $Node.PnPDeviceMetadata.Foreach({
                Context "PnP Device with class $($PSitem.Class) and Friendlyname $($PSitem.FriendlyName) driver version check" {
                    $PnPDevices =  Get-PnpDevice -Class $PSitem.Class -FriendlyName $PSitem.FriendlyName
                   Foreach ($PnPDevice in $PnPDevices) {
                        $DriverVersion = [version]($PnPDevice | Get-PnpDeviceProperty -KeyName DEVPKEY_Device_DriverVersion | Select-Object -ExpandProperty Data)
                         It "  Should  be running one of the supported driver versions v$($PSitem.versions)" {
                              $Driverversion -in $PSitem.versions | Should Be $True
                        }
                    }
                }
            })
        }
    }
}
Decoupling of the supported driver version and making the PnP device driver version validaiton test a generic Pester test enables us the agile addition of validation new components that are shipped with our solution e.g S2D, CPS etc. We also are working on extending this to validating firmware versions as well. Useful reference:

No comments:

Post a Comment