Skip to content
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

added dev badge #1

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DSCResource.Tests
.vscode/
8 changes: 5 additions & 3 deletions AutoPatchDSC/AutoPatchDSC.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Get-ChildItem (Join-Path $PSScriptRoot *.ps1) | ForEach-Object { . $_.FullName}
#requires -version 5.0

Get-ChildItem (Join-Path $PSScriptRoot *.ps1) | ForEach-Object { . $_.FullName}

#region AutoPatchInstall Class
<#
Expand Down Expand Up @@ -158,10 +160,10 @@
[void] initialize(){
if (-not (Get-Module PSWindowsUpdate)) {Import-Module PSWindowsUpdate}

$this.LastBootUpTime = $(Get-CimInstance -ClassName win32_OperatingSystem).lastbootuptime #Note: this is producing extra output; could be improved by supressing it becuase it's not helpful. Try: -Verbose 4>&1 | Out-Null
$this.LastBootUpTime = $(Get-CimInstance -ClassName win32_OperatingSystem).lastbootuptime
$this.inPreFlightWindow = ($this.RunTime -ge $this.preflightStart) -and ($this.RunTime -lt $this.patchWindowStart)
$this.inMaintenanceWindow = ($this.RunTime -ge $this.patchWindowStart) -and ($this.RunTime -lt $this.patchWindowEnd)
$this.wuList = Get-WUList -NotCategory 'Definition Updates' # this produces extra output, but it's helpful, so I'm leaving it for now.
$this.wuList = Get-WUList -NotCategory 'Definition Updates'
$this.UpdatesPendingInstall = [String]$(($this.wuList).kb)
$this.PendingRebootRequired = $(Get-WURebootStatus -Silent)
$this.WsusInstallerStatus = Get-WUInstallerStatus
Expand Down
30 changes: 15 additions & 15 deletions AutoPatchDSC/Examples/Sample_AutoPatchDSC_Complete.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Configuration PatchOneServer {
#Install patches during maintenance window 2am - 4am
AutoPatchInstall InstallOSPatches {
Name = 'InstallOSPatches'
PatchWindowStart = 'January 1st, 2017 2am'
PatchWindowEnd = 'January 1st, 2017 4am'
PatchWindowStart = Get-Date 'January 1 2017 2am'
PatchWindowEnd = Get-Date 'January 1 2017 4am'
}

# A start-service call wiill be executed for all services listed (if the service isn't running).
Expand All @@ -38,8 +38,8 @@ Configuration PatchOneServer {
#Reboot server on completion of patch installation
AutoPatchReboot LocalReboot {
Name = 'LocalReboot'
PatchWindowStart = 'January 1st, 2017 2am'
PatchWindowEnd = 'January 1st, 2017 4am'
PatchWindowStart = Get-Date 'January 1 2017 2am'
PatchWindowEnd = Get-Date 'January 1 2017 4am'
RebootMode = 'MaintenanceWindowAutomaticReboot'
}
}
Expand All @@ -57,9 +57,9 @@ Configuration PatchTwoServers {
#Install patches during the preflight window 1am - 2am or during the maintenance window 2am - 3am
AutoPatchInstall InstallOSPatches {
Name = 'InstallOSPatches'
PreflightWindowStart = 'January 1st, 2017 1am'
PatchWindowStart = 'January 1st, 2017 2am'
PatchWindowEnd = 'January 1st, 2017 3am'
PreflightWindowStart = Get-Date 'January 1 2017 1am'
PatchWindowStart = Get-Date 'January 1 2017 2am'
PatchWindowEnd = Get-Date 'January 1 2017 3am'
InstallPatchesDuringPreflight = $True
}

Expand All @@ -73,9 +73,9 @@ Configuration PatchTwoServers {
#Reboot server on completion of patch installation during the preflight window only, 1am - 2am
AutoPatchReboot LocalReboot {
Name = 'LocalReboot'
PreflightWindowStart = 'January 1st, 2017 1am'
PatchWindowStart = 'January 1st, 2017 2am'
PatchWindowEnd = 'January 1st, 2017 3am'
PreflightWindowStart = Get-Date 'January 1 2017 1am'
PatchWindowStart = Get-Date 'January 1 2017 2am'
PatchWindowEnd = Get-Date 'January 1 2017 3am'
RebootMode = 'PreFlightWindowAutomaticReboot'
}
}
Expand All @@ -84,10 +84,10 @@ Configuration PatchTwoServers {
#Install patches during the preflight window 1am - 2am or during the maintenance window 3am - 4am
AutoPatchInstall InstallOSPatches {
Name = 'InstallOSPatches'
PatchWindowStart = 'January 1st, 2017 3am'
PatchWindowEnd = 'January 1st, 2017 4am'
PreflightWindowStart = Get-Date 'January 1 2017 1am'
PatchWindowStart = Get-Date 'January 1 2017 3am'
PatchWindowEnd = Get-Date 'January 1 2017 4am'
InstallPatchesDuringPreflight = $True
PreflightWindowStart = 'January 1st, 2017 1am'
}

# A start-service call wiill be executed for all services listed (if the service isn't running).
Expand Down Expand Up @@ -119,8 +119,8 @@ Configuration PatchTwoServers {
# for example from 2-3am Server1 can reboot, from 3-4am Server2 can reboot.
AutoPatchReboot LocalReboot {
Name = 'LocalReboot'
PatchWindowStart = 'January 1st, 2017 3am'
PatchWindowEnd = 'January 1st, 2017 4am'
PatchWindowStart = Get-Date 'January 1 2017 3am'
PatchWindowEnd = Get-Date 'January 1 2017 4am'
DependsOn = '[WaitForAll]SqlServer01LocalReboot'
RebootMode = 'MaintenanceWindowAutomaticReboot'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Configuration OnlyPatchServerNoReboot {
#Install patches during maintenance window
AutoPatchInstall InstallOSPatches {
Name = 'InstallOSPatches'
PreflightWindowStart = 'January 1st, 2017 1am'
PatchWindowStart = 'January 1st, 2017 2am'
PatchWindowEnd = 'January 1st, 2017 4am'
PreflightWindowStart = Get-Date 'January 1 2017 1am'
PatchWindowStart = Get-Date 'January 1 2017 2am'
PatchWindowEnd = Get-Date 'January 1 2017 4am'
InstallPatchesDuringPreflight = $false
LogFile = 'c:\locallogs\AutoPatchInstall.log'
}
Expand Down
14 changes: 14 additions & 0 deletions AutoPatchDsc/Tests/Integration/AutoPatchDsc.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$script:DSCModuleName = 'AutoPatchDsc'

#region Pester Tests
Describe "$script:DSCModuleName Unit Tests" {
Context 'Module Validation' {
It "$script:DSCModuleName is valid PowerShell code" {
$psFile = Get-Content -Path "$PSScriptRoot\..\..\$script:DSCModuleName.psm1"
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($psFile, [ref]$errors)
$errors.Count | Should Be 0
}
}
}
#endregion
60 changes: 60 additions & 0 deletions AutoPatchDsc/Tests/Unit/AutoPatchInstall.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
$script:DSCModuleName = 'AutoPatchDsc'
$script:DSCResourceName = 'AutoPatchInstall'

Import-module AutoPatchDsc

<#
#region HEADER
[String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $script:MyInvocation.MyCommand.Path))
if ( (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
{
& git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\'))
}
else
{
& git @('-C',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\'),'pull')
}
Import-Module (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force
$TestEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:DSCModuleName `
-DSCResourceName $script:DSCResourceName `
-TestType Unit
#endregion
#>

# Begin Testing
try {
#region Pester Tests

#create sample parameter sets
$script:propertySets = @(
@{ Name = 'InstallOSPatches'
PatchWindowStart = Get-Date '1/1/2017 2am'
PatchWindowEnd = Get-Date '1/1/2017 4am'
}
@{ Name = 'InstallOSPatches'
PreflightWindowStart = Get-Date '1/1/2017 1am'
PatchWindowStart = Get-Date '1/1/2017 2am'
PatchWindowEnd = Get-Date '1/1/2017 4am'
InstallPatchesDuringPreflight = $True
}
)

#test each Property Set Individually
$parameterSetNumber = 1
Foreach ($script:properties in $script:propertySets) {
Describe "$script:DSCResourceName.Get() - Testing Parameter Set #$parameterSetNumber" {
It 'Should not throw an exception' {
{ $get = Invoke-DscResource -Name AutoPatchInstall -Method Get -Property $script:properties -ModuleName AutoPatchDSC } |
Should Not Throw
}
}

$parameterSetNumber++
}
} finally {
#region FOOTER
#Restore-TestEnvironment -TestEnvironment $TestEnvironment
#endregion
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[![Build status](https://ci.appveyor.com/api/projects/status/k6d7snrsx1neqjcm/branch/master?svg=true)](https://ci.appveyor.com/project/chmadole/autopatchdsc/branch/master)
| master | dev |
|---|---|
| [![Build status](https://ci.appveyor.com/api/projects/status/k6d7snrsx1neqjcm/branch/master?svg=true)](https://ci.appveyor.com/project/chmadole/autopatchdsc/branch/master) | [![Build status](https://ci.appveyor.com/api/projects/status/k6d7snrsx1neqjcm/branch/dev?svg=true)](https://ci.appveyor.com/project/chmadole/autopatchdsc/branch/dev) |

# AutoPatchDSC

Expand Down
12 changes: 10 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ install:
Import-Module -Name .\DscResource.Tests\TestHelper.psm1 -Force
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module -Name Pester -Repository PSGallery -Force

Install-Module -Name AutoPatchDsc -Repository PSGallery -Force
Import-module AutoPatchDsc
#---------------------------------#
# build configuration #
#---------------------------------#
Expand All @@ -20,4 +21,11 @@ build: off
# test configuration #
#---------------------------------#

# testing moved to dev branch
test_script:
- ps: |
$testResultsFile = ".\TestsResults.xml"
$res = Invoke-Pester -OutputFormat NUnitXml -OutputFile $testResultsFile -PassThru
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $testResultsFile))
if ($res.FailedCount -gt 0) {
throw "$($res.FailedCount) tests failed."
}