Skip to content

Instantly share code, notes, and snippets.

@mattstratton
Created August 19, 2014 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattstratton/a0944e0dddacdbe9abce to your computer and use it in GitHub Desktop.
Save mattstratton/a0944e0dddacdbe9abce to your computer and use it in GitHub Desktop.
Windows feature "TelnetClient"
should be installed (FAILED - 1)
Failures:
1) Windows feature "TelnetClient" should be installed
On host ``
Failure/Error: it{should be_installed}
$exitCode = 1
$ProgressPreference = "SilentlyContinue"
try {
function ListWindowsFeatures
{
param(
[string]$feature,
[string]$provider="dism"
)
$cachepath = "${env:temp}/ListWindowsFeatures-${provider}.xml"
$maxAge = 2
$cache = Get-Item $cachepath -erroraction SilentlyContinue
if($cache -ne $null -and ((get-date) - $cache.LastWriteTime).minutes -lt $maxage){
$features = Import-Clixml $cachepath | Select *| Where-Object {(($_.name -like $feature) -or ($_.displayName -like $feature)) -and (($_.installed -eq $true) -or ($_.state -
eq "Enabled"))}
return $features
}
else{
switch($provider)
{
"dism" { return features_dism | Select * | Where-Object {($_.name -eq $feature) -and ($_.state -eq "Enabled")} }
"powershell" { return features_powershell | Select * | Where-Object {(($_.name -like $feature) -or ($_.displayName -like $feature)) -and ($_.installed -eq $true)} }
default {throw "Unsupported provider"}
}
}
}
function features_dism{
try
{
$out = DISM /Online /Get-Features /Format:List | Where-Object {$_}
if($LASTEXITCODE -ne 0)
{
Write-Error $out
Break
}
$f = $out[4..($out.length-2)]
$features = for($i=0; $i -lt $f.length;$i+=2)
{
$tmp = $f[$i],$f[$i+1] -replace '^([^:]+:\s)'
New-Object PSObject -Property @{
Name = $tmp[0]
State = $tmp[1]
}
}
$features | Export-Clixml $cachepath
return $features
}
catch
{
Throw
}
}
function features_powershell{
$ProgressPreference = "SilentlyContinue"
import-module servermanager
$features = Get-WindowsFeature
$features | Export-Clixml $cachepath
return Get-WindowsFeature
}
$success = (@(ListWindowsFeatures -feature TelnetClient).count -gt 0)
if ($success -is [Boolean] -and $success) { $exitCode = 0 }
} catch {
Write-Output $_.Exception.Message
}
Write-Output "Exiting with code: $exitCode"
exit $exitCode
Exiting with code: 1
expected Windows feature "TelnetClient" to be installed
# C:/tmp/busser/suites/serverspec/localhost/default_spec.rb:8:in `block (2 levels) in <top (required)>'
Finished in 3.97 seconds
2 examples, 1 failure
Failed examples:
rspec C:/tmp/busser/suites/serverspec/localhost/default_spec.rb:8 # Windows feature "TelnetClient" should be installed
C:/opscode/chef/embedded/bin/ruby.exe -IC:/tmp/busser/suites/serverspec -S rspec C:/tmp/busser/suites/serverspec/localhost/default_spec.rb --color --format documentation
>>>>>> Verify failed on instance <default-windows2012r2-cloud>.
>>>>>> Please see .kitchen/logs/default-windows2012r2-cloud.log for more details
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: WinRM exited (1) using shell [powershell] for command: [$env:BUSSER_ROOT="/tmp/busser"; $env:GEM_HOME="/tmp/busser/gems"; $env:GEM_PATH="/tmp/busser/gems"; $env:PATH
="$env:PATH;$env:GEM_PATH/bin"; $env:GEM_CACHE="/tmp/busser/gems/cache"; busser test]
ERROR:
>>>>>> ----------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment