Last active
March 7, 2016 17:20
-
-
Save glennsarti/6a7f4f6ad80dfabb89f5 to your computer and use it in GitHub Desktop.
Automated testing for MSIs on VM Pooler for PA-231
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
SETLOCAL | |
SET COMP=<poolername>.delivery.puppetlabs.net | |
SET UNAME=administrator | |
SET PWD=<password> | |
NET USE \\%COMP%\c$ /user:%UNAME% %PWD% | |
ECHO Copying data... | |
robocopy /mir /s /e /Copy:DAT /R:1 /w:1 "%~dp0." "\\%COMP%\C$\TEST-5769" | |
ECHO -------------------------------------------------- | |
psexec \\%COMP% -u %UNAME% -p %PWD% powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin | |
psexec \\%COMP% -u %UNAME% -p %PWD% choco install pester -y | |
psexec \\%COMP% -u %UNAME% -p %PWD% powershell "& { Import-Module Pester; Invoke-Pester -Strict -EnableExit -Path C:\TEST-5769\tests }" | |
REM NET USE \\%COMP%\c$ /d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$DebugPreference = "SilentlyContinue" | |
$here = Split-Path -Parent $MyInvocation.MyCommand.Definition | |
$src = Resolve-Path -Path "$($here)\.." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$here = Split-Path -Parent $MyInvocation.MyCommand.Path | |
$common = Join-Path -Path $here 'Common.ps1' | |
. $common | |
$oldMSI = "$src\puppet-agent-1.3.1-x64.msi" | |
$newMSI = "$src\puppet-agent-1.3.5.286.g1ff143b-x64.msi" | |
function Install-MSI($msiPath,$cmdArgs = @()) { | |
if ($msiPath -eq $oldMSI) { Write-Host "Installing Old MSI" -ForegroundColor Yellow } | |
if ($msiPath -eq $newMSI) { Write-Host "Installing New MSI" -ForegroundColor Yellow } | |
$result = Start-Process -FilePath 'C:\Windows\System32\msiexec.exe' -Wait -NoNewWindow -PassThru ` | |
-ArgumentList ( @('/i',$msiPath,'/qn','REBOOT=ReallySuppress','ALLUSERS=1','/l*v','C:\Test-5769\install-msi.log','PUPPET_AGENT_STARTUP_MODE=Manual') + $cmdArgs) | |
Write-Host "Exit Code $($result.ExitCode)" -ForegroundColor Yellow | |
Write-Output $result.ExitCode | |
} | |
function Uninstall-MSI($msiPath,$nocleanup=$false, $cmdArgs = @()) { | |
if ($msiPath -eq $oldMSI) { Write-Host "Uninstalling Old MSI" -ForegroundColor Yellow } | |
if ($msiPath -eq $newMSI) { Write-Host "Uninstalling New MSI" -ForegroundColor Yellow } | |
$result = Start-Process -FilePath 'C:\Windows\System32\msiexec.exe' -Wait -NoNewWindow -PassThru ` | |
-ArgumentList ( @('/x',$msiPath,'/qn','REBOOT=ReallySuppress','ALLUSERS=1','/l*v','C:\Test-5769\uninstall-msi.log') + $cmdArgs) | |
Write-Host "Exit Code $($result.ExitCode)" -ForegroundColor Yellow | |
if (-not $nocleanup) { | |
Write-Host "Cleaning up after the pup install" -ForegroundColor Yellow | |
& cmd.exe /c RD "C:\ProgramData\PuppetLabs" /s /q | |
& cmd.exe /c RD "C:\Program Files\Puppet Labs" /s /q | |
Remove-Item -Path 'HKLM:\Software\Wow6432Node\Puppet Labs' -Recurse -ErrorAction 'SilentlyContinue' | out-Null | |
Write-Host "Cleaning completed" -ForegroundColor Yellow | |
} | |
Write-Output $result.ExitCode | |
} | |
function Invoke-CleanEverything { | |
Get-Service -Name 'puppet' -ErrorAction 'SilentlyContinue' | % { & cmd.exe /c sc stop puppet } | |
$result = Uninstall-MSI -MSIPath $newMSI $true | |
$result = Uninstall-MSI -MSIPath $oldMSI | |
} | |
function Get-PuppetConfig { | |
$hash = @{} | |
Get-Content "C:\ProgramData\PuppetLabs\puppet\etc\puppet.conf" | % { | |
if ($matches -ne $null) { $matches.Clear() } | |
if ($_ -match '(.+)=(.+)') { | |
$hash."$($matches[1])" = "$($matches[2])" | |
} | |
} | |
Write-Output $hash | |
} | |
Describe "Plain Install - New MSI" { | |
It "Uses defaults if nothing specified" { | |
Invoke-CleanEverything | |
$result = Install-MSI -MSIPath $newMSI | |
$result | Should Be 0 | |
(Get-PuppetConfig).server | Should Be 'puppet' | |
} | |
It "Uses specified MSI exec properties" { | |
Invoke-CleanEverything | |
$result = Install-MSI -MSIPath $newMSI -cmdArgs @('PUPPET_MASTER_SERVER=beforeserver','PUPPET_CA_SERVER=beforecaserver','PUPPET_AGENT_CERTNAME=beforecertname','PUPPET_AGENT_ENVIRONMENT=beforeenv') | |
$result | Should Be 0 | |
(Get-PuppetConfig).server | Should Be 'beforeserver' | |
(Get-PuppetConfig).ca_server | Should Be 'beforecaserver' | |
(Get-PuppetConfig).certname | Should Be 'beforecertname' | |
(Get-PuppetConfig).environment | Should Be 'beforeenv' | |
} | |
} | |
Describe "Upgrade" { | |
It "Uses specified MSI exec properties in old MSI as part of the upgrade" { | |
Invoke-CleanEverything | |
$result = Install-MSI -MSIPath $oldMSI -cmdArgs @('PUPPET_MASTER_SERVER=beforeserver','PUPPET_CA_SERVER=beforecaserver','PUPPET_AGENT_CERTNAME=beforecertname','PUPPET_AGENT_ENVIRONMENT=beforeenv') | |
$result | Should Be 0 | |
$result = Uninstall-MSI -MSIPath $oldMSI -nocleanup $true | |
$result | Should Be 0 | |
$result = Install-MSI -MSIPath $newMSI | |
$result | Should Be 0 | |
(Get-PuppetConfig).server | Should Be 'beforeserver' | |
(Get-PuppetConfig).ca_server | Should Be 'beforecaserver' | |
(Get-PuppetConfig).certname | Should Be 'beforecertname' | |
(Get-PuppetConfig).environment | Should Be 'beforeenv' | |
} | |
It "Supports msi upgrade" { | |
Invoke-CleanEverything | |
$result = Install-MSI -MSIPath $oldMSI -cmdArgs @('PUPPET_MASTER_SERVER=beforeserver','PUPPET_CA_SERVER=beforecaserver','PUPPET_AGENT_CERTNAME=beforecertname','PUPPET_AGENT_ENVIRONMENT=beforeenv') | |
$result | Should Be 0 | |
$result = Install-MSI -MSIPath $newMSI | |
$result | Should Be 0 | |
(Get-PuppetConfig).server | Should Be 'beforeserver' | |
(Get-PuppetConfig).ca_server | Should Be 'beforecaserver' | |
(Get-PuppetConfig).certname | Should Be 'beforecertname' | |
(Get-PuppetConfig).environment | Should Be 'beforeenv' | |
} | |
It "Uses specified settings in puppet.conf" { | |
Invoke-CleanEverything | |
$result = Install-MSI -MSIPath $oldMSI -cmdArgs @('PUPPET_MASTER_SERVER=beforeserver','PUPPET_CA_SERVER=beforecaserver','PUPPET_AGENT_CERTNAME=beforecertname','PUPPET_AGENT_ENVIRONMENT=beforeenv') | |
$result | Should Be 0 | |
@" | |
[main] | |
server=confserver | |
pluginsync=true | |
autoflush=true | |
environment=confenv | |
certname=confcertname | |
ca_server=confcaserver | |
"@ | Out-File "C:\ProgramData\PuppetLabs\puppet\etc\puppet.conf" -Encoding 'ASCII' | Out-Null | |
$result = Install-MSI -MSIPath $newMSI | |
$result | Should Be 0 | |
(Get-PuppetConfig).server | Should Be 'confserver' | |
(Get-PuppetConfig).ca_server | Should Be 'confcaserver' | |
(Get-PuppetConfig).certname | Should Be 'confcertname' | |
(Get-PuppetConfig).environment | Should Be 'confenv' | |
} | |
It "Ignores previous settings if specified in the new MSI" { | |
Invoke-CleanEverything | |
$result = Install-MSI -MSIPath $oldMSI -cmdArgs @('PUPPET_MASTER_SERVER=beforeserver','PUPPET_CA_SERVER=beforecaserver','PUPPET_AGENT_CERTNAME=beforecertname','PUPPET_AGENT_ENVIRONMENT=beforeenv') | |
$result | Should Be 0 | |
$result = Uninstall-MSI -MSIPath $oldMSI -nocleanup $true | |
$result | Should Be 0 | |
$result = Install-MSI -MSIPath $newMSI -cmdArgs @('PUPPET_MASTER_SERVER=newserver','PUPPET_CA_SERVER=newcaserver','PUPPET_AGENT_CERTNAME=newcertname','PUPPET_AGENT_ENVIRONMENT=newenv') | |
$result | Should Be 0 | |
(Get-PuppetConfig).server | Should Be 'newserver' | |
(Get-PuppetConfig).ca_server | Should Be 'newcaserver' | |
(Get-PuppetConfig).certname | Should Be 'newcertname' | |
(Get-PuppetConfig).environment | Should Be 'newenv' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment