Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Proposal to modify Invoke-OperationValidation to support passing parameters to a Pester script inside an OVF module. #6

Closed
devblackops opened this issue Jun 9, 2016 · 3 comments

Comments

@devblackops
Copy link
Contributor

This is to improve the flexibility of the Operation Validation Framework by adding the capability to override parameters used in Pester tests with user provided values. This would allow generic OVF modules that test core Infrastructure technologies to be tailored to a user's environment.

Example

With a properly written test script, it is possible to define sane or best practice defaults for monitoring inside the OVF module. This Pester script mimics the free volume space monitors within the Windows Server management pack in SCOM. In SCOM there are separate thresholds for system and non-system drives.

Storage.Capacity.Tests.ps1
param(
    $SystemDrive = $env:SystemDrive.Substring(0,1),
    $FreeSystemDriveThreshold = 200,
    $FreeNonSystemDriveThreshold = 1000,
    $FreeNonSystemDriveThresholdPct = .05,
)

Describe 'Storage Capacity' {

    Context 'Volumes' {

        $volumes = Get-Volume | where DriveType -eq 'Fixed'
        $sysDrive = $volumes | where DriveLetter -eq $SystemDrive
        $nonSysDrives = $volumes | where DriveLetter -ne $SystemDrive

        it "System drive [$SystemDrive] has $FreeSystemDriveThreshold MB free" {
            ($sysDrive.SizeRemaining / 1MB) -ge $FreeSystemDriveThreshold | should be $true
        }

        foreach ($volume in $nonSysDrives) {
            $driveLetter = $volume.DriveLetter
            it "Non-System drive [$driveLetter] has greater than $FreeNonSystemDriveThreshold MB free" {
                ($volume.SizeRemaining / 1MB) -ge $FreeNonSystemDriveThreshold | should be $true
            }

            it "Non-System drive [$driveLetter] has greater than $FreeNonSystemDriveThresholdPct% free" {
                ($volume.SizeRemaining / $volume.Size) -ge $FreeNonSystemDriveThresholdPct | should be $true
            }
        }
    }
}

With Pester, you can pass parameters to the test script. The thresholds from the test script above will be overridden by executing the following:

Invoke-Pester -Script @{ Path = '.\Storage.Capacity.Tests.ps1'; Parameters = @{FreeSystemDriveThreshold = 40000} }

Proposal

Add new [hashtable] parameter to Invoke-OperationValidation Called Parameters. If this parameter is supplied, the hashtable of "overrides" will be passed to the Pester script.

If others agree with this approach. I'll submit a PR implementing the changes.

-Brandon

@timker
Copy link

timker commented Jun 16, 2016

for the sake of consistancy
I think the paramter be -Script and work exactly like the Pester param.

@devblackops
Copy link
Contributor Author

Actually what about two parameters? A [hashtable] for Parameters and an [array] for Arguments. That follows how Pester uses them internally. Invoke-OperationValidation already figures out the file path so no need to include it again inside a -Script parameter.

This would basically be how OVF would execute the Pester test.

# Base params
$pesterParams = @{
    TestName = $tName    
    Quiet = $quiet
    PassThru = $true
}

 # Script path with or without parameters / arguments
if ($parameters -or $arguments) {
    $pesterParams.Script = @{
        Path = $ti.FilePath
        Parameters = $parameters
        Arguments = $arguments
    }
} else {
    $pesterParams.Script = $ti.FilePath
}

$testResult = Invoke-pester @pesterParams

@devblackops
Copy link
Contributor Author

Implemented in PR #12.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants