Skip to content

Commit

Permalink
Run health check before each tentacle test
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-richardson committed Jan 16, 2017
1 parent 76f1112 commit 6319da2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Tests/trigger-and-wait-for-healthcheck.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# If for whatever reason this doesn't work, check this file:
Start-Transcript -path "C:\Octopus\Logs\trigger-and-wait-for-healthcheck.txt" -append

$OFS = "`r`n"
$OctopusURI = "http://localhost:81"
$OctopusAPIKey=$env:OctopusApiKey

try
{
Add-Type -Path "${env:ProgramFiles}\Octopus Deploy\Octopus\Newtonsoft.Json.dll"
Add-Type -Path "${env:ProgramFiles}\Octopus Deploy\Octopus\Octopus.Client.dll"

$endpoint = new-object Octopus.Client.OctopusServerEndpoint $OctopusURI, $OctopusAPIKey
$repository = new-object Octopus.Client.OctopusRepository $endpoint
$environments = $repository.Environments.FindAll()

foreach($environment in $environments)
{
$header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey }
Write-Output "Creating healthcheck task for environment '$($environment.Name)'"
$body = @{
Name = "Health"
Description = "Checking health of all machines in environment '$($environment.Name)'"
Arguments = @{
Timeout= "00:05:00"
EnvironmentId = $environment.Id
}
} | ConvertTo-Json

$result = Invoke-RestMethod $OctopusURI/api/tasks -Method Post -Body $body -Headers $header
while (($result.State -ne "Success") -and ($result.State -ne "Failed") -and ($result.State -ne "Canceled") -and ($result.State -ne "TimedOut")) {
Write-Output "Polling for healthcheck completion. Status is '$($result.State)'"
Start-Sleep -Seconds 5
$result = Invoke-RestMethod "$OctopusURI$($result.Links.Self)" -Headers $header
}
Write-Output "Healthcheck completed with status '$($result.State)'"
}
}
catch
{
Write-Output $_
exit 1
}

4 changes: 4 additions & 0 deletions vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
end

#run tests for tentacle scenario 1 (initial install)
config.vm.provision "shell", inline: "& c:\\temp\\Tests\\trigger-and-wait-for-healthcheck.ps1; exit $LASTEXITCODE"
config.vm.provision "shell", inline: $run_test_scenario_script.gsub('{scenario_name}', 'tentacle_scenario_01_install')

# Run DSC for tentacle scenario 2 (uninstall)
Expand All @@ -148,6 +149,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
end

#run tests for tentacle scenario 2 (initial install)
config.vm.provision "shell", inline: "& c:\\temp\\Tests\\trigger-and-wait-for-healthcheck.ps1; exit $LASTEXITCODE"
config.vm.provision "shell", inline: $run_test_scenario_script.gsub('{scenario_name}', 'tentacle_scenario_02_remove')

# Run DSC for tentacle scenario 3 (subsequent re-install)
Expand All @@ -166,6 +168,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
end

#run tests for tentacle scenario 3 (subsequent re-install)
config.vm.provision "shell", inline: "& c:\\temp\\Tests\\trigger-and-wait-for-healthcheck.ps1; exit $LASTEXITCODE"
config.vm.provision "shell", inline: $run_test_scenario_script.gsub('{scenario_name}', 'tentacle_scenario_03_reinstall')

# Run DSC for tentacle scenario 4 (upgrade)
Expand All @@ -184,6 +187,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
end

#run tests for tentacle scenario 4 (upgrade)
config.vm.provision "shell", inline: "& c:\\temp\\Tests\\trigger-and-wait-for-healthcheck.ps1; exit $LASTEXITCODE"
config.vm.provision "shell", inline: $run_test_scenario_script.gsub('{scenario_name}', 'tentacle_scenario_04_upgrade')

end

0 comments on commit 6319da2

Please sign in to comment.