mirror of
https://github.com/saltstack/salt-bootstrap.git
synced 2025-04-16 09:40:21 +00:00
Merge pull request #893 from themalkolm/develop
RFC: Add tests for bootstrap-salt.ps1
This commit is contained in:
commit
0980676391
3 changed files with 143 additions and 0 deletions
|
@ -2,6 +2,8 @@
|
|||
Bootstrapping Salt
|
||||
==================
|
||||
|
||||
|windows_build|
|
||||
|
||||
Before `Salt`_ can be used for provisioning on the desired machine, the binaries need to be
|
||||
installed. Since `Salt`_ supports many different distributions and versions of operating systems,
|
||||
the `Salt`_ installation process is handled by this shell script ``bootstrap-salt.sh``. This
|
||||
|
@ -535,3 +537,7 @@ Salt is ready and working in the Docker container with Minion authenticated on M
|
|||
|
||||
|
||||
.. vim: fenc=utf-8 spell spl=en cc=100 tw=99 fo=want sts=2 sw=2 et
|
||||
|
||||
.. |windows_build| image:: https://ci.appveyor.com/api/projects/status/github/themalkolm/salt-bootstrap?branch=develop&svg=true
|
||||
:target: https://ci.appveyor.com/project/themalkolm/salt-bootstrap
|
||||
:alt: Build status of the develop branch on Windows
|
||||
|
|
32
appveyor.yml
Normal file
32
appveyor.yml
Normal file
|
@ -0,0 +1,32 @@
|
|||
platform: Any CPU
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- bootstrap_args:
|
||||
test_args: -master salt -runservice
|
||||
|
||||
- bootstrap_args: -runservice false
|
||||
test_args: -master salt -noservice
|
||||
|
||||
- bootstrap_args: -minion a-minion
|
||||
test_args: -minion a-minion -master salt -runservice
|
||||
|
||||
- bootstrap_args: -minion a-minion -master a-master
|
||||
test_args: -minion a-minion -master a-master -runservice
|
||||
|
||||
build_script:
|
||||
- ps: |
|
||||
$Path = (Get-Location).Path | Join-Path -ChildPath bootstrap-salt.ps1
|
||||
Invoke-Expression "$Path -verbose $env:bootstrap_args"
|
||||
|
||||
before_test:
|
||||
- SET PATH=%PATH%;C:\salt
|
||||
- salt-call --version
|
||||
|
||||
test_script:
|
||||
- ps: |
|
||||
$Path = (Get-Location).Path | Join-Path -ChildPath tests\runtests.ps1
|
||||
Invoke-Expression "$Path -verbose $env:test_args"
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
105
tests/runtests.ps1
Normal file
105
tests/runtests.ps1
Normal file
|
@ -0,0 +1,105 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
A simple Powershell script to test installed salt minion on windows.
|
||||
|
||||
.PARAMETER version
|
||||
Salt version installed.
|
||||
|
||||
.PARAMETER runservice
|
||||
Boolean flag whenever to test if service is running.
|
||||
|
||||
.PARAMETER noservice
|
||||
Boolean flag whenever to test if service is not running.
|
||||
|
||||
.PARAMETER minion
|
||||
Name of the minion installed on this host.
|
||||
|
||||
.PARAMETER master
|
||||
Name of the master configured on this host.
|
||||
|
||||
.EXAMPLE
|
||||
./runtests.ps1
|
||||
Runs without any parameters. Uses all the default values/settings.
|
||||
#>
|
||||
|
||||
#===============================================================================
|
||||
# Commandlet Binding
|
||||
#===============================================================================
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$False,ValueFromPipeline=$True)]
|
||||
[string]$version = $null,
|
||||
|
||||
[Parameter(Mandatory=$False,ValueFromPipeline=$True)]
|
||||
[switch]$runservice,
|
||||
|
||||
[Parameter(Mandatory=$False,ValueFromPipeline=$True)]
|
||||
[switch]$noservice,
|
||||
|
||||
[Parameter(Mandatory=$False,ValueFromPipeline=$True)]
|
||||
[string]$minion = $null,
|
||||
|
||||
[Parameter(Mandatory=$False,ValueFromPipeline=$True)]
|
||||
[string]$master = $null
|
||||
)
|
||||
|
||||
#===============================================================================
|
||||
# Script Functions
|
||||
#===============================================================================
|
||||
function Get-Grains ([string]$Name) {
|
||||
$Command = "salt-call --local --out json --out-indent -1 grains.get $Name"
|
||||
$Result = iex $Command | Out-String | ConvertFrom-Json
|
||||
|
||||
Write-Verbose "salt-call grains.get ${Name}:`n${Result}"
|
||||
return $Result."local"
|
||||
}
|
||||
|
||||
function Get-Service-Status([string]$Name) {
|
||||
$Service = Get-Service $Name -ErrorAction Stop
|
||||
$Status = $Service.Status
|
||||
|
||||
Write-Verbose "${Name}: ${Status}"
|
||||
return $Status
|
||||
}
|
||||
|
||||
function Assert-Equal {
|
||||
[CmdletBinding()]
|
||||
Param (
|
||||
[Parameter(Mandatory=$True,ValueFromPipeline=$True)]
|
||||
[string]$Actual,
|
||||
|
||||
[Parameter(Mandatory=$True,ValueFromPipeline=$True)]
|
||||
[string]$Expected
|
||||
)
|
||||
|
||||
If ($Actual -ne $Expected) {
|
||||
throw "Assert: $Actual != $Expected"
|
||||
}
|
||||
}
|
||||
|
||||
#===============================================================================
|
||||
# Do enabled checks
|
||||
#===============================================================================
|
||||
if ($True) {
|
||||
Get-Grains -Name os_family | Assert-Equal -Expected "Windows"
|
||||
}
|
||||
|
||||
if ($version) {
|
||||
Get-Grains -Name saltversion | Assert-Equal -Expected $version
|
||||
}
|
||||
|
||||
if ($master) {
|
||||
Get-Grains -Name master | Assert-Equal -Expected $master
|
||||
}
|
||||
|
||||
if ($minion) {
|
||||
Get-Grains -Name id | Assert-Equal -Expected $minion
|
||||
}
|
||||
|
||||
if ($runservice) {
|
||||
Get-Service-Status salt-minion | Assert-Equal -Expected "Running"
|
||||
}
|
||||
|
||||
if ($noservice) {
|
||||
Get-Service-Status salt-minion | Assert-Equal -Expected "Stopped"
|
||||
}
|
Loading…
Add table
Reference in a new issue