test-kitchen / kitchen-pester

A Test Kitchen driver to execute Pester as a verifier

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Undefined method '/' when using restart_winrm option

nhudacin opened this issue · comments

I'm not sure what's going on here. I'm having trouble running pester tests after installing sql server. They work fine until I install the sql server package, then I get an error saying that the Pester module cannot be found at the "Import-Module Pester" line. Reading the README for this repo, I see there's an option for restart_winrm and it sounds like it would fix my issue not being able to find Pester. Every time I set this option to true I receive the following error message:

>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: Failed to complete #verify action: [undefined method `/' for "schtasks /Create /TN restart_winrm /TR ":String]
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

Here is the usage in my .kitchen.yml file:

verifier:
  name: Pester
  restart_winrm: true

For whatever reason, I'm unable to run the pester tests after I install SQL Server when using the same shell. I can run the steps individually without any issue ==> destroy, create, converge, setup, & destroy. When I run kitchen test however, I ALWAYS get this failure:

$global:ProgressPreference = 'SilentlyContinue'
$TestPath = "$env:TEMP\verifier/suites"
import-module Pester -force; invoke-pester -path $testpath -enableexit
)
$$$$$$ import-module : The specified module 'Pester' was not loaded because no valid
$$$$$$ module file was found in any module directory.
$$$$$$ At line:4 char:1
$$$$$$ + import-module Pester -force; invoke-pester -path $testpath -enableexit
$$$$$$ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
$$$$$$     + CategoryInfo          : ResourceUnavailable: (Pester:String) [Import-Mod
$$$$$$    ule], FileNotFoundException
$$$$$$     + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
$$$$$$    ands.ImportModuleCommand
$$$$$$ 
$$$$$$ invoke-pester : The term 'invoke-pester' is not recognized as the name of a
$$$$$$ cmdlet, function, script file, or operable program. Check the spelling of the
$$$$$$ name, or if a path was included, verify that the path is correct and try again.
$$$$$$ At line:4 char:30
$$$$$$ + import-module Pester -force; invoke-pester -path $testpath -enableexit
$$$$$$ +                              ~~~~~~~~~~~~~
$$$$$$     + CategoryInfo          : ObjectNotFound: (invoke-pester:String) [], Comma
$$$$$$    ndNotFoundException
$$$$$$     + FullyQualifiedErrorId : CommandNotFoundException
D      Cleaning up local sandbox in C:/Users/nhudacin/AppData/Local/Temp/default-Windows-sandbox-20160106-440-krv67e
>>>>>> Verify failed on instance <default-Windows>.
>>>>>> Please see .kitchen/logs/default-Windows.log for more details
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: WinRM exited (1) for command: [
$global:ProgressPreference = 'SilentlyContinue'
$TestPath = "$env:TEMP\verifier/suites"
import-module Pester -force; invoke-pester -path $testpath -enableexit
]
>>>>>> ----------------------

I was hoping to use the restart_winrm option to force it to use a new remote command shell but that's now failing too. Any ideas why this is happening?

Here's the full back trace of the restart_winrm issue:

       Chef Client finished, 25/27 resources updated in 2019.693508 seconds
       [2016-01-06T12:36:38-06:00] DEBUG: Server doesn't support resource history, skipping resource report.
       [2016-01-06T12:36:38-06:00] DEBUG: Audit Reports are disabled. Skipping sending reports.
       [2016-01-06T12:36:38-06:00] DEBUG: Exiting
D      Cleaning up local sandbox in C:/Users/nhudacin/AppData/Local/Temp/default-Windows-sandbox-20160106-8900-8bqk5c
       Finished converging <default-Windows> (34m47.76s).
-----> Setting up <default-Windows>...
       Finished setting up <default-Windows> (0m0.00s).
-----> Verifying <default-Windows>...
       Preparing files for transfer
D      Creating local sandbox in C:/Users/nhudacin/AppData/Local/Temp/default-Windows-sandbox-20160106-8900-1ixtcu8
       Preparing to copy files from C:/_SourceControl/HLGIT/cookbook-sqlserver/test/integration/default to the SUT.
D      Copying C:/_SourceControl/HLGIT/cookbook-sqlserver/test/integration/default/pester/default_spec.tests.ps1 to C:/Users/nhudacin/AppData/Local/Temp/default-Windows-sandbox-20160106-8900-1ixtcu8/suites/pester/default_spec.tests.ps1
D      Copying C:/_SourceControl/HLGIT/cookbook-sqlserver/test/integration/default/pester/instance_spec.tests.ps1 to C:/Users/nhudacin/AppData/Local/Temp/default-Windows-sandbox-20160106-8900-1ixtcu8/suites/pester/instance_spec.tests.ps1
D      [WinRM] reusing existing connection plaintext::http://TESTMACHINE01:5985/wsman<{:disable_sspi=>true, :basic_auth_only=>true, :user=>"user1", :pass=>"password"}>
D      [WinRM] plaintext::http://TESTMACHINE01:5985/wsman<{:disable_sspi=>true, :basic_auth_only=>true, :user=>"user1", :pass=>"password"}> (
set-executionpolicy unrestricted -force
if (-not (get-module -list pester)) {
  if (get-module -list PowerShellGet){
    import-module PowerShellGet -force
    install-module Pester -force
  }
  else {
    if (-not (get-module -list PsGet)){
      iex (new-object Net.WebClient).DownloadString('http://bit.ly/GetPsGet')
    }
    import-module psget -force
    Install-Module Pester
  }
}
)
       Downloading PsGet from https://github.com/psget/psget/raw/master/PsGet/PsGet.psm1
       PsGet is installed and ready to use
       USAGE:
           PS> import-module PsGet
           PS> install-module PsUrl

       For more details:
           get-help install-module
       Or visit http://psget.net
D      Cleaning up local sandbox in C:/Users/nhudacin/AppData/Local/Temp/default-Windows-sandbox-20160106-8900-1ixtcu8
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: Failed to complete #verify action: [undefined method `/' for "schtasks /Create /TN restart_winrm /TR ":String]
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration
D      ------Exception-------
D      Class: Kitchen::ActionFailed
D      Message: Failed to complete #verify action: [undefined method `/' for "schtasks /Create /TN restart_winrm /TR ":String]
D      ---Nested Exception---
D      Class: NoMethodError
D      Message: undefined method `/' for "schtasks /Create /TN restart_winrm /TR ":String
D      ------Backtrace-------
D      C:/Users/nhudacin/AppData/Local/chefdk/gem/ruby/2.1.0/gems/kitchen-pester-0.4.0/lib/kitchen/verifier/Pester.rb:133:in `restart_winrm_service'
D      C:/Users/nhudacin/AppData/Local/chefdk/gem/ruby/2.1.0/gems/kitchen-pester-0.4.0/lib/kitchen/verifier/Pester.rb:101:in `init_command'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/verifier/base.rb:71:in `block in call'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/transport/winrm.rb:468:in `reuse_connection'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/transport/winrm.rb:60:in `connection'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/verifier/base.rb:69:in `call'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:398:in `block in verify_action'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:488:in `call'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:488:in `synchronize_or_call'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:453:in `block in action'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/benchmark.rb:279:in `measure'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:452:in `action'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:394:in `verify_action'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:341:in `block in transition_to'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:340:in `each'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:340:in `transition_to'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:160:in `verify'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:189:in `block in test'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/benchmark.rb:279:in `measure'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:185:in `test'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/command.rb:176:in `public_send'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.4.2/lib/kitchen/command.rb:176:in `block (2 levels) in run_action'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/logging-1.8.2/lib/logging/diagnostic_context.rb:323:in `call'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/logging-1.8.2/lib/logging/diagnostic_context.rb:323:in `block in create_with_logging_context'
D      ----------------------
D      [CommandExecutor] closing remote shell 9F3DDB0A-D5A1-48D6-A470-26CBC5BCE831 on plaintext::http://TESTMACHINE01:5985/wsman<{:disable_sspi=>true, :basic_auth_only=>true, :user=>"user1", :pass=>"password"}>
D      [CommandExecutor] remote shell 9F3DDB0A-D5A1-48D6-A470-26CBC5BCE831 closed

Should the forward slashes on lines 132 & 133 be back slashes instead? https://github.com/test-kitchen/kitchen-pester/blob/master/lib/kitchen/verifier/pester.rb

I reverted back to version 0.3.0 which does NOT include this syntax issue but I'm still getting the following error:

cd "$env:TEMP\verifier/suites/pester/"
$global:ProgressPreference = 'SilentlyContinue'
import-module Pester -force; invoke-pester -enableexit
)
$$$$$$ import-module : The specified module 'Pester' was not loaded because no valid
$$$$$$ module file was found in any module directory.
$$$$$$ At line:4 char:1
$$$$$$ + import-module Pester -force; invoke-pester -enableexit
$$$$$$ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
$$$$$$     + CategoryInfo          : ResourceUnavailable: (Pester:String) [Import-Mod
$$$$$$    ule], FileNotFoundException
$$$$$$     + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
$$$$$$    ands.ImportModuleCommand
$$$$$$ 
$$$$$$ invoke-pester : The term 'invoke-pester' is not recognized as the name of a
$$$$$$ cmdlet, function, script file, or operable program. Check the spelling of the
$$$$$$ name, or if a path was included, verify that the path is correct and try again.
$$$$$$ At line:4 char:30
$$$$$$ + import-module Pester -force; invoke-pester -enableexit
$$$$$$ +                              ~~~~~~~~~~~~~
$$$$$$     + CategoryInfo          : ObjectNotFound: (invoke-pester:String) [], Comma
$$$$$$    ndNotFoundException
$$$$$$     + FullyQualifiedErrorId : CommandNotFoundException
D      Cleaning up local sandbox in C:/Users/nhudacin/AppData/Local/Temp/default-Windows-sandbox-20160106-10348-wwb769

The pull request I made seems to have fixed the syntax issue and this reported issue.. Would you like me to submit another issue for the "Cannot find Pester module"?

I think there's still a problem with the restart_winrm option because of this line:

$$$$$$ WARNING: Task may not run because /ST is earlier than current time.