Search code examples
macosdockertest-kitchenchefdk

Class: Kitchen::ActionFailed - Test Kitchen + Docker + Remote API


I am trying to create a docker instance on a remote server using test kitchen (That came with ChefDK and with docker-api driver installed) on my Mac (OS X Mavericks) and I seem to failing almost at the last step:

stardust:test_kitchen rilindo$ kitchen create
-----> Starting Kitchen (v1.2.1)
-----> Creating <default-centos-64>...
       Step 0 : FROM centos:centos6
       ---> 68edf809afe7
       Step 1 : RUN yum clean all
       ---> Using cache
       ---> 79fd0e4588de
       Step 2 : RUN yum install -y sudo openssh-server openssh-clients curl
       ---> Using cache
       ---> 131f54051dc4
       Step 3 : RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
       ---> Using cache
       ---> d05a99414427
       Step 4 : RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
       ---> Using cache
       ---> 53636accc8b7
       Step 5 : RUN mkdir -p /var/run/sshd
       ---> Using cache
       ---> fa875c2e9f1a
       Step 6 : RUN useradd -d /home/kitchen -m -s /bin/bash kitchen
       ---> Using cache
       ---> 962000c5929d
       Step 7 : RUN echo kitchen:kitchen | chpasswd
       ---> Using cache
       ---> f22dcbca6292
       Step 8 : RUN echo 'kitchen ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
       ---> Using cache
       ---> cb9d8b95eb33
       Successfully built cb9d8b95eb33
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: Failed to complete #create action: [undefined method `[]' for nil:NilClass]
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

It seems to failing at the part when it attempts to create the container port:

stardust:test_kitchen rilindo$ tail -30 .kitchen/logs/kitchen.log 
I, [2014-10-09T23:46:59.460656 #1112]  INFO -- Kitchen: -----> Starting Kitchen (v1.2.1)
I, [2014-10-09T23:46:59.525462 #1112]  INFO -- Kitchen: -----> Destroying <default-centos-64>...
I, [2014-10-09T23:47:02.720005 #1112]  INFO -- Kitchen: -----> Kitchen is finished. (0m3.26s)
I, [2014-10-09T23:48:49.778602 #1118]  INFO -- Kitchen: -----> Starting Kitchen (v1.2.1)
I, [2014-10-09T23:48:49.842909 #1118]  INFO -- Kitchen: -----> Creating <default-centos-64>...
E, [2014-10-09T23:48:52.826223 #1118] ERROR -- Kitchen: ------Exception-------
E, [2014-10-09T23:48:52.826280 #1118] ERROR -- Kitchen: Class: Kitchen::ActionFailed
E, [2014-10-09T23:48:52.826322 #1118] ERROR -- Kitchen: Message: Failed to complete #create action: [undefined method `[]' for nil:NilClass]
E, [2014-10-09T23:48:52.826363 #1118] ERROR -- Kitchen: ---Nested Exception---
E, [2014-10-09T23:48:52.826403 #1118] ERROR -- Kitchen: Class: NoMethodError
E, [2014-10-09T23:48:52.826442 #1118] ERROR -- Kitchen: Message: undefined method `[]' for nil:NilClass
E, [2014-10-09T23:48:52.826481 #1118] ERROR -- Kitchen: ------Backtrace-------
E, [2014-10-09T23:48:52.826520 #1118] ERROR -- Kitchen: /Users/rilindo/.chefdk/gem/ruby/2.1.0/gems/kitchen-docker-api-0.4.0/lib/kitchen/driver/docker.rb:228:in `container_ssh_port'
E, [2014-10-09T23:48:52.826560 #1118] ERROR -- Kitchen: /Users/rilindo/.chefdk/gem/ruby/2.1.0/gems/kitchen-docker-api-0.4.0/lib/kitchen/driver/docker.rb:82:in `create'
E, [2014-10-09T23:48:52.826600 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:273:in `public_send'
E, [2014-10-09T23:48:52.826641 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:273:in `block in perform_action'
E, [2014-10-09T23:48:52.826681 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:308:in `call'
E, [2014-10-09T23:48:52.826760 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:308:in `synchronize_or_call'
E, [2014-10-09T23:48:52.826802 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:283:in `block in action'
E, [2014-10-09T23:48:52.826842 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/lib/ruby/2.1.0/benchmark.rb:279:in `measure'
E, [2014-10-09T23:48:52.826882 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:282:in `action'
E, [2014-10-09T23:48:52.826921 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:273:in `perform_action'
E, [2014-10-09T23:48:52.826961 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:252:in `create_action'
E, [2014-10-09T23:48:52.827001 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:246:in `block in transition_to'
E, [2014-10-09T23:48:52.827041 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:245:in `each'
E, [2014-10-09T23:48:52.827081 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:245:in `transition_to'
E, [2014-10-09T23:48:52.827149 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:108:in `create'
E, [2014-10-09T23:48:52.827189 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/command.rb:109:in `public_send'
E, [2014-10-09T23:48:52.827229 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/command.rb:109:in `block (2 levels) in run_action'
E, [2014-10-09T23:48:52.827269 #1118] ERROR -- Kitchen: ----------------------

I am not sure if the issue is that ports is being forward correctly or not in my .kitchen.yaml. It may, of course, be a completely different problem:

---
driver:
  name: docker
  socket: tcp://111.222.333.444:4243

provisioner:
  name: chef_solo

platforms:
  - name: centos-6.4
    driver_config:
      image: centos:centos6
      platform: centos
    forward:
    -  22:2222

suites:
  - name: default
    run_list:
    attributes:

I am sing adnichols/kitchen-docker-api driver, BTW.


Solution

  • As it turns out, it was failing because docker could not allocate the port:

    Oct 10 22:05:04 traeger docker: [error] server.go:1013 Error: Cannot start container e92342347ce6e372ffcada89724067bc2878f00d5679e26ea849d4f49f275e1e: port has already been allocated
    Oct 10 22:05:04 traeger docker: [error] server.go:90 HTTP Error: statusCode=500 Cannot start container e92342347ce6e372ffcada89724067bc2878f00d5679e26ea849d4f49f275e1e: port has already been allocated
    

    The forward parameter was not necessary in my case. Here is my correct config now:

    ---
    driver:
      name: docker
      socket: tcp://111.222.333.444:4243
    
    provisioner:
      name: chef_solo
    
    platforms:
      - name: ubuntu-12.04
        driver_config:
          privileged: true
          container_name: ubuntu_test_1204
          image: ubuntu:12.04
          platform: ubuntu
      - name: centos-6.4
        driver_config:
          privileged: true
          container_name: centos_test_6
          image: centos:centos6
          platform: centos
    
    suites:
      - name: default
        run_list:
        attributes:
    

    And I could connect to my instance now:

    mylaptop:test_kit rilindo$ kitchen create default-centos-64
    -----> Starting Kitchen (v1.2.1)
    -----> Creating <default-centos-64>...
           Step 0 : FROM centos:centos6
           ---> 68edf809afe7
           Step 1 : RUN yum clean all
           ---> Using cache
           ---> 79fd0e4588de
           Step 2 : RUN yum install -y sudo openssh-server openssh-clients curl
           ---> Using cache
           ---> 131f54051dc4
           Step 3 : RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
           ---> Using cache
           ---> d05a99414427
           Step 4 : RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
           ---> Using cache
           ---> 53636accc8b7
           Step 5 : RUN mkdir -p /var/run/sshd
           ---> Using cache
           ---> fa875c2e9f1a
           Step 6 : RUN useradd -d /home/kitchen -m -s /bin/bash kitchen
           ---> Using cache
           ---> 962000c5929d
           Step 7 : RUN echo kitchen:kitchen | chpasswd
           ---> Using cache
           ---> f22dcbca6292
           Step 8 : RUN echo 'kitchen ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
           ---> Using cache
           ---> cb9d8b95eb33
           Successfully built cb9d8b95eb33
           Finished creating <default-centos-64> (0m3.70s).
    -----> Kitchen is finished. (0m3.77s)
    my laptop:test_kit rilindo$ kitchen login default-centos-64
    [email protected]'s password: 
    [kitchen@2bdd84c99337 ~]$ exit