Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor driver to include Windows support (includes new transport for all supported platforms) #340

Merged
merged 15 commits into from
Jul 30, 2019

Conversation

jeffreycoe
Copy link
Contributor

@jeffreycoe jeffreycoe commented Jun 6, 2019

This pull request adds Windows support to the Kitchen driver. It also includes a new transport which supports all supported Linux platforms and Windows. We decided to add a new transport to leverage a lot of the same code the driver uses in the same code base so we can continue to build support for both Windows and Linux in one location within this gem.

I’m requesting feedback (and a code review) from the community on this approach and some help with additional testing.

This update fixes issues #259, #318, #338

@stuartpreston
Copy link

@jeffreycoe This looks like a great effort. I have also been looking into this recently and as you have probablly seen, InSpec's Train docker transport doesn't understand how to detect Docker on Windows. As you probably found out, the docker-api gem used needs a bit of modernization in order to use the right Docker API version too when on Windows. I have also been playing with this in a separate standalone driver that offers a 'dockercli' transport (name required by kitchen-inspec I believe).

Feel free to rescue any of the bits out of there you need. The driver with all my bits and monkeypatched DockerAPI and Train transport is at: https://github.com/stuartpreston/kitchen-dockerwin/

@jeffreycoe
Copy link
Contributor Author

@stuartpreston Appreciate the feedback. I’ll take a look at merging the code you referenced to see if we can get these updates working with InSpec. Thanks!

@lmayorga1980
Copy link

I have tested this PR in the following environment:

OS: Windows 2019 Core Server
Ruby: ruby 2.6.3p62 (2019-04-16 revision 67580) [x64-mingw32]
MingGW: msys2 20180531.0.0

I had to install the Ruby Development Kit when installing the ruby gem from source code in order to compile the dependencies that require low level libraries.

gem list --local

PS C:\Users\vagrant\test-kitchen-poc> gem list --local

*** LOCAL GEMS ***

bcrypt_pbkdf (1.0.1 x64-mingw32)
bigdecimal (default: 1.4.1)
builder (3.2.3)
bundler (default: 1.17.2)
cmath (default: 1.0.0)
csv (default: 3.0.9)
date (default: 2.0.0)
dbm (default: 1.0.0)
did_you_mean (1.3.0)
e2mmap (default: 0.1.0)
ed25519 (1.2.4)
equatable (0.5.0)
erubis (2.7.0)
etc (default: 1.0.1)
fcntl (default: 1.0.0)
ffi (1.11.1 x64-mingw32)
fiddle (default: 1.0.0)
fileutils (default: 1.1.0)
forwardable (default: 1.2.0)
gdbm (default: 2.0.0)
gssapi (1.3.0)
gyoku (1.3.1)
httpclient (2.8.3)
io-console (default: 0.4.7)
ipaddr (default: 1.2.2)
irb (default: 1.0.0)
json (default: 2.1.0)
kitchen-docker (2.9.0)
license-acceptance (1.0.13)
little-plugger (1.1.4)
logger (default: 1.3.0)
logging (2.2.2)
matrix (default: 0.1.0)
minitest (5.11.3)
mixlib-install (3.11.18)
mixlib-shellout (2.4.4 universal-mingw32)
mixlib-versioning (1.2.7)
multi_json (1.13.1)
mutex_m (default: 0.1.0)
necromancer (0.5.0)
net-scp (2.0.0)
net-ssh (5.2.0)
net-ssh-gateway (2.0.0)
net-telnet (0.2.0)
nori (2.6.0)
openssl (default: 2.1.2)
ostruct (default: 0.1.0)
pastel (0.7.2)
power_assert (1.1.3)
prime (default: 0.1.0)
psych (default: 3.1.0)
rake (12.3.2)
rdoc (default: 6.1.0)
rexml (default: 3.1.9)
rss (default: 0.2.7)
rubyntlm (0.6.2)
rubyzip (1.2.3)
scanf (default: 1.0.0)
sdbm (default: 1.0.0)
shell (default: 0.7)
stringio (default: 0.0.2)
strings (0.1.5)
strings-ansi (0.1.0)
strscan (default: 1.0.0)
sync (default: 0.5.0)
test-kitchen (2.2.5)
test-unit (3.2.9)
thor (0.20.3)
thwait (default: 0.1.0)
tomlrb (1.2.8)
tracer (default: 0.1.0)
tty-box (0.4.0)
tty-color (0.4.3)
tty-cursor (0.7.0)
tty-prompt (0.19.0)
tty-reader (0.6.0)
tty-screen (0.7.0)
unicode-display_width (1.6.0)
unicode_utils (1.4.0)
webrick (default: 1.4.2)
win32-process (0.8.3)
winrm (2.3.2)
winrm-elevated (1.1.1)
winrm-fs (1.3.2)
wisper (2.0.0)
wmi-lite (1.0.2)
xmlrpc (0.3.0)
zlib (default: 1.0.0)

kitchen.yml

---
driver:
  name: docker

platforms:
- name: windows
  driver_config:
    image: mcr.microsoft.com/windows/servercore:ltsc2019
    platform: windows

provisioner:
  name: shell

transport:
  name: docker
  env_variables:
    TEST_KEY: TEST_VALUE
    
suites:
  - name: default
    verifier:
      inspec_tests:
        - test/integration/default
      attributes:

output

PS C:\Users\vagrant\test-kitchen-poc> kitchen test
-----> Starting Kitchen (v2.2.5)
-----> Cleaning up any prior instances of <default-windows>
-----> Destroying <default-windows>...
       Finished destroying <default-windows> (0m0.00s).
-----> Testing <default-windows>
-----> Creating <default-windows>...
       Sending build context to Docker daemon  9.728kB
       Step 1/1 : FROM mcr.microsoft.com/windows/servercore:ltsc2019
        ---> 3e9dc86c64a9
       Successfully built 3e9dc86c64a9
       21a58d6a8e64333bbaa14f37c772bdb699cd0f0d5fca0b29eae5f5b54456009a
       Finished creating <default-windows> (0m1.72s).
-----> Converging <default-windows>...
       Preparing files for transfer
       Preparing script
       No provisioner script file specified, skipping
       [Docker] Executing command on container
       Transferring files to <default-windows>
       Downloading files from <default-windows>
       Finished converging <default-windows> (0m16.73s).
-----> Setting up <default-windows>...
       Finished setting up <default-windows> (0m0.00s).
-----> Verifying <default-windows>...
       Preparing files for transfer
       Transferring files to <default-windows>
       Finished verifying <default-windows> (0m0.02s).
-----> Destroying <default-windows>...
       [Docker] Destroying Docker container 21a58d6a8e64333bbaa14f37c772bdb699cd0f0d5fca0b29eae5f5b54456009a
       Name                PID                 CPU                 Private Working Set
       smss.exe            2904                00:00:00.109        278.5kB
       csrss.exe           3192                00:00:00.171        1.098MB
       wininit.exe         836                 00:00:00.062        1.118MB
       services.exe        844                 00:00:00.421        1.831MB
       lsass.exe           3340                00:00:00.218        3.453MB
       svchost.exe         3960                00:00:00.234        1.937MB
       fontdrvhost.exe     1924                00:00:00.000        577.5kB
       svchost.exe         2228                00:00:00.140        2.2MB
       svchost.exe         2868                00:00:00.359        4.841MB
       svchost.exe         1508                00:00:00.062        2.441MB
       CExecSvc.exe        2768                00:00:00.078        983kB
       svchost.exe         2608                00:00:00.437        5.882MB
       PING.EXE            3708                00:00:00.046        598kB
       svchost.exe         784                 00:00:02.375        4.059MB
       svchost.exe         3232                00:00:00.015        892.9kB
       svchost.exe         2052                00:00:00.390        6.963MB
       svchost.exe         2720                00:00:00.031        1.118MB
       21a58d6a8e64333bbaa14f37c772bdb699cd0f0d5fca0b29eae5f5b54456009a
       21a58d6a8e64333bbaa14f37c772bdb699cd0f0d5fca0b29eae5f5b54456009a
       Finished destroying <default-windows> (0m1.38s).
       Finished testing <default-windows> (0m20.09s).
-----> Kitchen is finished. (0m20.38s)
PS C:\Users\vagrant\test-kitchen-poc>

It created the container and destroys it but seems that is not executing my test yet.

Will add a few tests and get back.

@lmayorga1980
Copy link

lmayorga1980 commented Jun 14, 2019

@jeffreycoe

I did another test using the verifier section pointing to inspec and I got the following results...

https://gist.github.com/lmayorga1980/8c3922f6133d16dfc9025938bd2b3049

@jeffreycoe
Copy link
Contributor Author

@lmayorga1980 Thanks for testing and glad to see the create, converge, and destroy phases worked so far. I'm still looking into the InSpec verifier to see what needs to be updated to support Windows.

@lmayorga1980
Copy link

I see, I guess change beed to through kitchen-inspec first since its crashing on the Transport piece

@lmayorga1980
Copy link

@jeffreycoe

Using the last commit of the PR.

...
Using net-ssh-gateway 2.0.0
Using winrm-elevated 1.1.1
Using test-kitchen 2.2.5
Using kitchen-docker 2.9.0 from git://github.com/jeffreycoe/kitchen-docker.git (at windows-support@9ceb39d)
Using kitchen-inspec 1.1.0
Bundle updated!
PS C:\users\vagrant\test-kitchen-poc> bundle exec kitchen test
-----> Starting Kitchen (v2.2.5)
-----> Cleaning up any prior instances of <default-windows>
-----> Destroying <default-windows>...
       [Docker] Destroying Docker container 91e5b7503de0acc7c95ca966adc5afab26cd910d47468eca8882cab155676450
       Error response from daemon: No such container: 91e5b7503de0acc7c95ca966adc5afab26cd910d47468eca8882cab155676450
       Finished destroying <default-windows> (0m0.17s).
-----> Testing <default-windows>
-----> Creating <default-windows>...
       Sending build context to Docker daemon  24.58kB
       Step 1/1 : FROM mcr.microsoft.com/windows/servercore:ltsc2019
        ---> 3e9dc86c64a9
       Successfully built 3e9dc86c64a9
       932e38f4674f1de22cfe9d151bbc77db17717157d60c2f864b98b717459cbfd5
       Finished creating <default-windows> (0m1.52s).
-----> Converging <default-windows>...
       Preparing files for transfer
       Preparing script
       No provisioner script file specified, skipping
       [Docker] Executing command on container
       Transferring files to <default-windows>
       Downloading files from <default-windows>
       Finished converging <default-windows> (0m14.24s).
-----> Setting up <default-windows>...
       Finished setting up <default-windows> (0m0.00s).
-----> Verifying <default-windows>...
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Failed to complete #verify action: [Verifier Inspec does not support the Docker Transport] on default-windows
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

---
driver:
  name: docker

provisioner:
  name: shell
  
verifier:
  name: inspec
  
platforms:
- name: windows
  driver_config:
    image: mcr.microsoft.com/windows/servercore:ltsc2019
    platform: windows

transport:
  name: docker
  env_variables:
    TEST_KEY: TEST_VALUE
    
suites:
  - name: default
    verifier:
      inspec_tests:
        - test/integration/default/default_spec.rb
      attributes:

stacktrace

I, [2019-06-16T05:58:48.479991 #5072]  INFO -- Kitchen: -----> Starting Kitchen (v2.2.5)
I, [2019-06-16T05:58:53.320514 #5072]  INFO -- Kitchen: -----> Cleaning up any prior instances of <default-windows>
I, [2019-06-16T05:58:53.325610 #5072]  INFO -- Kitchen: -----> Destroying <default-windows>...
I, [2019-06-16T05:58:53.328524 #5072]  INFO -- Kitchen: [Docker] Destroying Docker container 932e38f4674f1de22cfe9d151bbc77db17717157d60c2f864b98b717459cbfd5
I, [2019-06-16T05:58:53.490884 #5072]  INFO -- Kitchen: Name                PID                 CPU                 Private Working Set
I, [2019-06-16T05:58:53.491155 #5072]  INFO -- Kitchen: smss.exe            1096                00:00:00.093        266.2kB
I, [2019-06-16T05:58:53.492582 #5072]  INFO -- Kitchen: csrss.exe           3372                00:00:00.093        1.032MB
I, [2019-06-16T05:58:53.493158 #5072]  INFO -- Kitchen: wininit.exe         3460                00:00:00.093        1.024MB
I, [2019-06-16T05:58:53.493564 #5072]  INFO -- Kitchen: services.exe        4392                00:00:00.312        1.679MB
I, [2019-06-16T05:58:53.494854 #5072]  INFO -- Kitchen: lsass.exe           4336                00:00:00.406        3.33MB
I, [2019-06-16T05:58:53.495058 #5072]  INFO -- Kitchen: svchost.exe         4272                00:00:00.250        1.376MB
I, [2019-06-16T05:58:53.495256 #5072]  INFO -- Kitchen: fontdrvhost.exe     3800                00:00:00.000        528.4kB
I, [2019-06-16T05:58:53.495520 #5072]  INFO -- Kitchen: svchost.exe         4480                00:00:00.109        1.364MB
I, [2019-06-16T05:58:53.495702 #5072]  INFO -- Kitchen: svchost.exe         728                 00:00:05.703        12.03MB
I, [2019-06-16T05:58:53.495890 #5072]  INFO -- Kitchen: svchost.exe         5016                00:00:00.046        1.819MB
I, [2019-06-16T05:58:53.496082 #5072]  INFO -- Kitchen: CExecSvc.exe        4928                00:00:00.031        921.6kB
I, [2019-06-16T05:58:53.496268 #5072]  INFO -- Kitchen: svchost.exe         2488                00:00:00.250        4.6MB
I, [2019-06-16T05:58:53.496478 #5072]  INFO -- Kitchen: PING.EXE            1352                00:00:00.078        589.8kB
I, [2019-06-16T05:58:53.496669 #5072]  INFO -- Kitchen: svchost.exe         4676                00:00:02.281        2.949MB
I, [2019-06-16T05:58:53.496899 #5072]  INFO -- Kitchen: svchost.exe         4560                00:00:00.031        454.7kB
I, [2019-06-16T05:58:53.497104 #5072]  INFO -- Kitchen: svchost.exe         2056                00:00:00.531        7.012MB
I, [2019-06-16T05:58:53.497283 #5072]  INFO -- Kitchen: msdtc.exe           4428                00:00:00.125        2.13MB
I, [2019-06-16T05:58:53.497478 #5072]  INFO -- Kitchen: WmiPrvSE.exe        6096                00:00:01.843        5.214MB
I, [2019-06-16T05:58:54.584546 #5072]  INFO -- Kitchen: 932e38f4674f1de22cfe9d151bbc77db17717157d60c2f864b98b717459cbfd5
I, [2019-06-16T05:58:54.785204 #5072]  INFO -- Kitchen: 932e38f4674f1de22cfe9d151bbc77db17717157d60c2f864b98b717459cbfd5
I, [2019-06-16T05:58:54.796122 #5072]  INFO -- Kitchen: -----> Testing <default-windows>
I, [2019-06-16T05:58:54.798780 #5072]  INFO -- Kitchen: -----> Creating <default-windows>...
I, [2019-06-16T05:58:54.971480 #5072]  INFO -- Kitchen: Sending build context to Docker daemon  27.14kB
I, [2019-06-16T05:58:54.982985 #5072]  INFO -- Kitchen: Step 1/1 : FROM mcr.microsoft.com/windows/servercore:ltsc2019
I, [2019-06-16T05:58:54.983134 #5072]  INFO -- Kitchen:  ---> 3e9dc86c64a9
I, [2019-06-16T05:58:54.987040 #5072]  INFO -- Kitchen: Successfully built 3e9dc86c64a9
I, [2019-06-16T05:58:55.177957 #5072]  INFO -- Kitchen: d94c425d4b9ee60b57903d99f44739e9979c1e9e5a02dcae33731ac1dd1c05e7
I, [2019-06-16T05:58:56.257466 #5072]  INFO -- Kitchen: -----> Converging <default-windows>...
I, [2019-06-16T05:58:56.460254 #5072]  INFO -- Kitchen: [Docker] Executing command on container
I, [2019-06-16T05:59:11.349503 #5072]  INFO -- Kitchen: -----> Setting up <default-windows>...
I, [2019-06-16T05:59:11.355550 #5072]  INFO -- Kitchen: -----> Verifying <default-windows>...
E, [2019-06-16T05:59:11.409389 #5072] ERROR -- Kitchen: ------Exception-------
E, [2019-06-16T05:59:11.410628 #5072] ERROR -- Kitchen: Class: Kitchen::ActionFailed
E, [2019-06-16T05:59:11.410853 #5072] ERROR -- Kitchen: Message: 1 actions failed.
>>>>>>     Failed to complete #verify action: [Verifier Inspec does not support the Docker Transport] on default-windows
E, [2019-06-16T05:59:11.411501 #5072] ERROR -- Kitchen: ----------------------
E, [2019-06-16T05:59:11.418105 #5072] ERROR -- Kitchen: ------Backtrace-------
E, [2019-06-16T05:59:11.418601 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/command.rb:183:in `report_errors'
E, [2019-06-16T05:59:11.418904 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/command.rb:174:in `run_action'
E, [2019-06-16T05:59:11.419154 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/command/test.rb:42:in `block in call'
E, [2019-06-16T05:59:11.419809 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/2.6.0/benchmark.rb:293:in `measure'
E, [2019-06-16T05:59:11.420131 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/command/test.rb:38:in `call'
E, [2019-06-16T05:59:11.420833 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/cli.rb:52:in `perform'
E, [2019-06-16T05:59:11.421107 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/cli.rb:245:in `test'
E, [2019-06-16T05:59:11.421430 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
E, [2019-06-16T05:59:11.422457 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
E, [2019-06-16T05:59:11.422746 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
E, [2019-06-16T05:59:11.423060 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
E, [2019-06-16T05:59:11.423378 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/bin/kitchen:13:in `block in <top (required)>'
E, [2019-06-16T05:59:11.423697 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/errors.rb:171:in `with_friendly_errors'
E, [2019-06-16T05:59:11.423947 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/bin/kitchen:13:in `<top (required)>'
E, [2019-06-16T05:59:11.424222 #5072] ERROR -- Kitchen: C:/tools/ruby26/bin/kitchen:23:in `load'
E, [2019-06-16T05:59:11.424447 #5072] ERROR -- Kitchen: C:/tools/ruby26/bin/kitchen:23:in `<main>'
E, [2019-06-16T05:59:11.424682 #5072] ERROR -- Kitchen: ----End Backtrace-----
E, [2019-06-16T05:59:11.424928 #5072] ERROR -- Kitchen: -Composite Exception--
E, [2019-06-16T05:59:11.425204 #5072] ERROR -- Kitchen: Class: Kitchen::ActionFailed
E, [2019-06-16T05:59:11.425449 #5072] ERROR -- Kitchen: Message: Failed to complete #verify action: [Verifier Inspec does not support the Docker Transport] on default-windows
E, [2019-06-16T05:59:11.425732 #5072] ERROR -- Kitchen: ----------------------
E, [2019-06-16T05:59:11.425979 #5072] ERROR -- Kitchen: ------Backtrace-------
E, [2019-06-16T05:59:11.426299 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/kitchen-inspec-1.1.0/lib/kitchen/verifier/inspec.rb:198:in `runner_options'
E, [2019-06-16T05:59:11.426479 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/kitchen-inspec-1.1.0/lib/kitchen/verifier/inspec.rb:69:in `call'
E, [2019-06-16T05:59:11.426761 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:459:in `block in verify_action'
E, [2019-06-16T05:59:11.426967 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:552:in `synchronize_or_call'
E, [2019-06-16T05:59:11.427274 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:514:in `block in action'
E, [2019-06-16T05:59:11.427455 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/2.6.0/benchmark.rb:293:in `measure'
E, [2019-06-16T05:59:11.428139 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:513:in `action'
E, [2019-06-16T05:59:11.428374 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:451:in `verify_action'
E, [2019-06-16T05:59:11.428630 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:382:in `block (2 levels) in transition_to'
E, [2019-06-16T05:59:11.428834 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/lifecycle_hooks.rb:45:in `run_with_hooks'
E, [2019-06-16T05:59:11.429071 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:381:in `block in transition_to'
E, [2019-06-16T05:59:11.429408 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:380:in `each'
E, [2019-06-16T05:59:11.429649 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:380:in `transition_to'
E, [2019-06-16T05:59:11.429864 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:162:in `verify'
E, [2019-06-16T05:59:11.430097 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:191:in `block in test'
E, [2019-06-16T05:59:11.430302 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/2.6.0/benchmark.rb:293:in `measure'
E, [2019-06-16T05:59:11.430499 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:187:in `test'
E, [2019-06-16T05:59:11.430725 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/command.rb:197:in `public_send'
E, [2019-06-16T05:59:11.431014 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/command.rb:197:in `run_action_in_thread'
E, [2019-06-16T05:59:11.431219 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/command.rb:169:in `block (2 levels) in run_action'
E, [2019-06-16T05:59:11.431467 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/logging-2.2.2/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
E, [2019-06-16T05:59:11.431679 #5072] ERROR -- Kitchen: ----End Backtrace-----
E, [2019-06-16T05:59:11.431831 #5072] ERROR -- Kitchen: ---Nested Exception---
E, [2019-06-16T05:59:11.432040 #5072] ERROR -- Kitchen: Class: Kitchen::ActionFailed
E, [2019-06-16T05:59:11.432237 #5072] ERROR -- Kitchen: Message: Failed to complete #verify action: [Verifier Inspec does not support the Docker Transport]
E, [2019-06-16T05:59:11.432484 #5072] ERROR -- Kitchen: ----------------------
E, [2019-06-16T05:59:11.432673 #5072] ERROR -- Kitchen: ------Backtrace-------
E, [2019-06-16T05:59:11.432826 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/kitchen-inspec-1.1.0/lib/kitchen/verifier/inspec.rb:198:in `runner_options'
E, [2019-06-16T05:59:11.433049 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/kitchen-inspec-1.1.0/lib/kitchen/verifier/inspec.rb:69:in `call'
E, [2019-06-16T05:59:11.433246 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:459:in `block in verify_action'
E, [2019-06-16T05:59:11.433464 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:552:in `synchronize_or_call'
E, [2019-06-16T05:59:11.433656 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:514:in `block in action'
E, [2019-06-16T05:59:11.433803 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/2.6.0/benchmark.rb:293:in `measure'
E, [2019-06-16T05:59:11.434455 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:513:in `action'
E, [2019-06-16T05:59:11.434660 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:451:in `verify_action'
E, [2019-06-16T05:59:11.434872 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:382:in `block (2 levels) in transition_to'
E, [2019-06-16T05:59:11.435045 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/lifecycle_hooks.rb:45:in `run_with_hooks'
E, [2019-06-16T05:59:11.435247 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:381:in `block in transition_to'
E, [2019-06-16T05:59:11.435470 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:380:in `each'
E, [2019-06-16T05:59:11.435680 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:380:in `transition_to'
E, [2019-06-16T05:59:11.435940 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:162:in `verify'
E, [2019-06-16T05:59:11.436116 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:191:in `block in test'
E, [2019-06-16T05:59:11.436352 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/2.6.0/benchmark.rb:293:in `measure'
E, [2019-06-16T05:59:11.436518 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:187:in `test'
E, [2019-06-16T05:59:11.436727 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/command.rb:197:in `public_send'
E, [2019-06-16T05:59:11.436896 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/command.rb:197:in `run_action_in_thread'
E, [2019-06-16T05:59:11.437090 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/test-kitchen-2.2.5/lib/kitchen/command.rb:169:in `block (2 levels) in run_action'
E, [2019-06-16T05:59:11.437221 #5072] ERROR -- Kitchen: C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/logging-2.2.2/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
E, [2019-06-16T05:59:11.437424 #5072] ERROR -- Kitchen: ----End Backtrace-----

@jeffreycoe jeffreycoe changed the title Refactor driver to include Windows support (includes new transport for all supported platforms) WIP: Refactor driver to include Windows support (includes new transport for all supported platforms) Jun 17, 2019
@jeffreycoe
Copy link
Contributor Author

@stuartpreston @lmayorga1980 These commits include a bunch of monkey patches to get InSpec working with Windows. (Thanks @stuartpreston for the code). So far, it seems to be working. I haven't encountered any issues.

Looking for some feedback and some additional testing with these latest commits. Thanks.

@jeffreycoe
Copy link
Contributor Author

Also, I was testing with an older version of the ChefDK (v3.10.1), but I found there have been updates to the Train gem (starting in version 2.1.0) which help with detecting the Windows platform. I upgraded to the latest Chef Workstation 0.4.1 and it has been working with no issues.

@lmayorga1980
Copy link

Platform: Windows 2019 Core
Docker Version:

Client: Docker Engine - Enterprise
 Version:           18.09.6
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        1578dcadd2
 Built:             05/04/2019 02:34:11
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Enterprise
 Engine:
  Version:          18.09.6
  API version:      1.39 (minimum version 1.24)
  Go version:       go1.10.8
  Git commit:       1578dcadd2
  Built:            05/04/2019 02:32:24
  OS/Arch:          windows/amd64
  Experimental:     false

Ruby: ruby 2.6.3p62 (2019-04-16 revision 67580) [x64-mingw32]

Results: https://gist.github.com/lmayorga1980/436d1a9011d6681267ee6ccc3410404a

I am not using ChefDK and using just the gems coming from rubygems.org

@jeffreycoe
Copy link
Contributor Author

jeffreycoe commented Jun 18, 2019

@lmayorga1980 Forgot to mention it doesn't support named pipes yet, so by default the transport has to be configured to use a TCP socket so the InSpec verifier works.

Can you configure the Docker engine to listen on a TCP port and try again? I updated the readme to include this info now.

You'll need to update the C:\ProgramData\docker\config\daemon.json file and add the following value (and recycle the Docker services):

"hosts": ["tcp://0.0.0.0:2375"]

Example configuration is shown below:

{
  "registry-mirrors": [],
  "insecure-registries": [],
  "debug": true,
  "experimental": false,
  "hosts": ["tcp://0.0.0.0:2375"]
}

Then update your .kitchen.yml file to include the socket option in the transport section:

transport:
  name: docker
  socket: tcp://localhost:2375

@lmayorga1980
Copy link

lmayorga1980 commented Jun 18, 2019

@jeffreycoe ,

It worked 👍 🎉 🎈

PS C:\Users\vagrant> $env:DOCKER_HOST="tcp://localhost:2375"
PS C:\Users\vagrant\test-kitchen-poc> bundle exec kitchen test
-----> Starting Kitchen (v2.2.5)
C:/tools/ruby26/lib/ruby/gems/2.6.0/bundler/gems/kitchen-docker-ba58e25f34a3/lib/kitchen/docker/helpers/inspec_helper.rb:27: warning: already initialized constant Docker::API_VERSION
C:/tools/ruby26/lib/ruby/gems/2.6.0/gems/docker-api-1.34.2/lib/docker/version.rb:6: warning: previous definition of API_VERSION was here
-----> Cleaning up any prior instances of <default-windows>
-----> Destroying <default-windows>...
       [Docker] Destroying Docker container 06e6f383d15a83f6416857a68c0bc0424d14c1661133588764735e04bd909c46
       Error response from daemon: No such container: 06e6f383d15a83f6416857a68c0bc0424d14c1661133588764735e04bd909c46
       Finished destroying <default-windows> (0m0.18s).
-----> Testing <default-windows>
-----> Creating <default-windows>...
       Sending build context to Docker daemon  2.048kB
       Step 1/1 : FROM mcr.microsoft.com/windows/servercore:ltsc2019
        ---> 3e9dc86c64a9
       Successfully built 3e9dc86c64a9
       ef03a05e94064b1ee075702eea92e4e63a1c37baf21cb0da2348ceded648b1a6
       Finished creating <default-windows> (0m1.61s).
-----> Converging <default-windows>...
       Preparing files for transfer
       Preparing script
       No provisioner script file specified, skipping
       Transferring files to <default-windows>
       [Docker] Executing command on container


       Name             : ConsoleHost
       Version          : 5.1.17763.503
       InstanceId       : 0620a69a-d5d7-45f3-93b1-fc946c0b6a55
       UI               : System.Management.Automation.Internal.Host.InternalHostUserI
                   nterface
       CurrentCulture   : en-US
       CurrentUICulture : en-US
       PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
       DebuggerEnabled  : True
       IsRunspacePushed : False
       Runspace         : System.Management.Automation.Runspaces.LocalRunspace



       Downloading files from <default-windows>
       Finished converging <default-windows> (0m17.83s).
-----> Setting up <default-windows>...
       Finished setting up <default-windows> (0m0.00s).
-----> Verifying <default-windows>...
[2019-06-17T18:56:39-07:00] WARN: DEPRECATION: InSpec Attributes are being renamed to InSpec Inputs to avoid confusion with Chef Attributes. Use --input-file on the command line instead of --attrs.
       Loaded tests from {:path=>"C:.Users.vagrant.test-kitchen-poc.test.integration.default"}
       Loaded tests from {:path=>"C:.Users.vagrant.test-kitchen-poc.test.integration.default.default_spec.rb"}

Profile: tests from {:path=>"C:/Users/vagrant/test-kitchen-poc/test/integration/default"} (tests from {:path=>"C:.Users.vagrant.test-kitchen-poc.test.integration.default"})
Version: (not specified)
Target:  docker://ef03a05e94064b1ee075702eea92e4e63a1c37baf21cb0da2348ceded648b1a6

  File c:\
     [PASS]  should exist

Profile: tests from {:path=>"C:/Users/vagrant/test-kitchen-poc/test/integration/default/default_spec.rb"} (tests from {:path=>"C:.Users.vagrant.test-kitchen-poc.test.integration.default.default_spec.rb"})
Version: (not specified)
Target:  docker://ef03a05e94064b1ee075702eea92e4e63a1c37baf21cb0da2348ceded648b1a6

  File c:\
     [PASS]  should exist

Test Summary: 2 successful, 0 failures, 0 skipped
       Finished verifying <default-windows> (0m7.31s).
-----> Destroying <default-windows>...
       [Docker] Destroying Docker container ef03a05e94064b1ee075702eea92e4e63a1c37baf21cb0da2348ceded648b1a6
       Name                PID                 CPU                 Private Working Set
       smss.exe            4916                00:00:00.093        282.6kB
       csrss.exe           4940                00:00:00.171        1.122MB
       wininit.exe         4980                00:00:00.078        1.126MB
       services.exe        5024                00:00:00.281        1.929MB
       lsass.exe           5032                00:00:00.328        3.445MB
       svchost.exe         552                 00:00:00.109        2.159MB
       fontdrvhost.exe     4168                00:00:00.015        573.4kB
       svchost.exe         3904                00:00:00.062        1.942MB
       svchost.exe         4116                00:00:00.546        8.454MB
       svchost.exe         2848                00:00:00.046        2.408MB
       CExecSvc.exe        3080                00:00:00.140        958.5kB
       svchost.exe         1048                00:00:00.312        5.943MB
       PING.EXE            4132                00:00:00.031        606.2kB
       svchost.exe         4276                00:00:02.109        4.141MB
       svchost.exe         3364                00:00:00.031        892.9kB
       svchost.exe         1764                00:00:00.484        7.172MB
       svchost.exe         712                 00:00:00.015        1.118MB
       WmiPrvSE.exe        648                 00:00:00.078        2.535MB
       ef03a05e94064b1ee075702eea92e4e63a1c37baf21cb0da2348ceded648b1a6
       ef03a05e94064b1ee075702eea92e4e63a1c37baf21cb0da2348ceded648b1a6
       Finished destroying <default-windows> (0m1.44s).
       Finished testing <default-windows> (0m28.49s).
-----> Kitchen is finished. (0m35.74s)

I added a repo to reproduce the behavior when future changes are introduced.

https://github.com/LM3CORP/test-kitchen-docker-windows/tree/master/win2019core

@lmayorga1980
Copy link

Please Merge this. Looks good.

@jeffreycoe
Copy link
Contributor Author

@lmayorga1980 I made some minor updates to organize things a little better for the overridden classes to support the InSpec verifier on Windows. CI tests have been updated for Windows, too.

As long as the tests complete successfully, and no one has any issues with the code, we should be able to merge now.

@jeffreycoe jeffreycoe changed the title WIP: Refactor driver to include Windows support (includes new transport for all supported platforms) Refactor driver to include Windows support (includes new transport for all supported platforms) Jun 23, 2019
@lmayorga1980
Copy link

@jeffreycoe 👍 I will be running some specific tests this week but everything in the PR looks good.

Thanks for including this desired feature...

@jeffreycoe
Copy link
Contributor Author

@lmayorga1980 Thanks for all of your help with testing.

Looks like my testing completed successfully, and the CI tests passed with the last commit. This PR is ready to be merged.

@lmayorga1980
Copy link

@jeffreycoe no problem. Let me know if there is something I could do.

@jeffreycoe
Copy link
Contributor Author

@stuartpreston Thanks for approving. Would we be able to merge the code at this point?

Let us know if you need anything else from us. Thanks.

@lmayorga1980
Copy link

@stuartpreston Can you merge this PR?

@stuartpreston stuartpreston merged commit c43a4af into test-kitchen:master Jul 30, 2019
@stuartpreston
Copy link

Happy to merge the PR but we need someone with the relevant org access to push the gem, etc. I'll see if I can find someone with the correct permissions.

@lmayorga1980
Copy link

Much appreciated 👍

@jeffreycoe
Copy link
Contributor Author

@stuartpreston Thank you!

@yeoldegrove
Copy link

@stuartpreston Would you mind creating a new release with this code included?

@jeffreycoe
Copy link
Contributor Author

Hi @yeoldegrove - @stuartpreston isn't able to release the gem, but only merge code into this repo. I've reached out to someone who is working on getting the right individuals involved who can release this gem. It should be available soon, hopefully.

@rshad
Copy link

rshad commented Feb 4, 2020

Hi @jeffreycoe !

Thank you for the rework.

Unfortunately when destroying the instances, however, the docker images are automatically removed, but then it produces an exception:

>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Failed to complete #destroy action: [Expected process to exit with [0], but received '1'
---- Begin output of docker -H unix:///var/run/docker.sock rmi 29d6ee71040d ----
STDOUT:
STDERR: Error response from daemon: conflict: unable to delete 29d6ee71040d (cannot be forced) - image is being used by running container a980e8f5cefc
---- End output of docker -H unix:///var/run/docker.sock rmi 29d6ee71040d ----
Ran docker -H unix:///var/run/docker.sock rmi 29d6ee71040d returned 1] on manager-amazonlinux-latest-kitchen-chef
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

This image ID does not exist at all in my image list!

anyone is facing the same issue?

Kr,

Rshad

@jeffreycoe
Copy link
Contributor Author

Hi @rshad - Could you open a new issue with the steps to reproduce? Are you using the code from the master branch? I have been running this code on macOS, Linux, and Windows machines and have not encountered this error yet.

@rshad
Copy link

rshad commented Feb 5, 2020

Hi @jeffreycoe !

Yes, I first took the master branch, to solve the issue commented in #338, but I got an error when creating the container for each Kitchen instance, which was reported here #355 and solved here #356.

Message: Error getting internal IP of Docker container

So I then took the Fork branch of #356 and got such error.

Kr,

Rshad

@rshad
Copy link

rshad commented Feb 5, 2020

Hi @jeffreycoe !

I created an issue #360 and the corresponding PR with the fix #361.

Kr,

Rshad

This was referenced Jun 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants