kitchen verify finishes with 0 examples, 0 failures for serverspec tests while testing ansible role with docker as driver
I am working to test ansible playbook or roles with test-kitchen using kitchen-ansible,serverspec for testing of playbooks with docker driver on a redhat 6.6 server( workstation). I can able to run kitchen convergence successfully.While running kitchen verify, it was unable to find my test cases and returning the below response. i am not sure why it is not picking up my test cases and running. I have playbook default.yml and it calls the role splunk and the main.yml in splunk role will create the directory called splunk in /opt folder of the test server. and the test_spec.rb will check if it is directory or not.
Kitchen converge is running the playbook and created the splunk folder in the docker container. while running kitchen verify below output is coming saying it doesn't find the examples. I am quite sure, I might be missing something related to verifier and suites section in .kitchen.yml. Was trying to fix for couple of days and no luck. can you help me out.
found similar issue https://github.com/neillturner/kitchen-ansible/issues/135 but with older ansible spec plugin.
**_Installing serverspec 2.38.0
Bundle complete! 2 Gemfile dependencies, 15 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
Transferring files to <ansible-ubuntu-1404>
Running Serverspec
Using default pattern /tmp/verifier/suites/serverspec/*_spec.rb
---> RSPEC_CMD variable is: /usr/local/bin/rspec
No examples found.
Finished in 0.00032 seconds (files took 0.04711 seconds to load)
0 examples, 0 failures
Finished verifying <ansible-ubuntu-1404> (0m14.21s)._**
on the kitchen login, i can see my test files test_spec.rb file existing.
kitchen@f5171c3a7133:/tmp/verifier/serverspec$ ll total 16 drwxr-xr-x 2 kitchen kitchen 4096 Mar 31 19:56 ./ drwxr-xr-x 3 kitchen kitchen 4096 Mar 31 19:56 ../ -rwxr-xr-x 1 kitchen kitchen 41 Mar 31 19:56 spec_helper.rb* -rwxr-xr-x 1 kitchen kitchen 162 Mar 31 19:56 test_spec.rb*
My project structure: /opt/ansible/ansible-kitchen - folder
│ default.yml
│ .kitchen
│ .kitchen.yml
│ Gemfile
│ Gemfile.lock
├── roles
│ └── splunk
│ ├── defaults
│ ├── files
│ ├── handlers
│ ├── meta
│ ├── spec
│ ├── tasks
│ └── main.yml
│ ├── templates
│ ├── tests
│ └── vars
├── spec
│ ──spec_helper.rb
├── test
│ └── integration
│ └── default
│ │ ├── serverspec
│ │ ├── spec_helper.rb
│ │ └── test_spec.rb
│ ── default.yml
│
│
│
│
└── vendor
contents of .kitchen.yml
---
driver:
name: docker
use_sudo: false
platforms:
- name: ubuntu-14.04
driver:
image: rndmh3ro/docker-ubuntu1404-ansible:latest
platform: ubuntu
provisioner:
name: ansible_playbook
hosts: test-kitchen
roles_path: roles
ansible_verbose: false
ansible_verbosity: 2
require_ansible_repo: false
require_ansible_omnibus: false
require_chef_for_busser: false
ansible_connection: ssh
verifier:
name: serverspec
use_sudo: yes
sudo_path: true
suites:
- name: default
verifier:
default_pattern: true
bundler_path: '/usr/local/bin'
rspec_path: '/usr/local/bin'
env_vars:
TARGET_HOST: 127.0.0.1
SUDO: true
Contents of Gem file
source 'https://rubygems.org'
gem 'test-kitchen', '~> 1.8.0'
gem 'kitchen-docker'
gem 'kitchen-ansible'
gem 'net-ssh'
gem 'serverspec'
gem 'kitchen-verifier-serverspec'
contents of default.yml
---
- hosts: test-kitchen
roles:
- splunk
contents of /roles/splunk/tasks/main.yml
---
- name: create directory
file: path=/opt/splunk state=directory
contents of spec_helper.rb
require 'serverspec'
set :backend, :exec
contents of test_spec.rb
#require 'spec_helper'
#set :backend, :exec
require '/tmp/kitchen/spec/spec_helper.rb'
describe file ('/opt/splunk') do
it { should be_a_directory
end
Thanks for using my software. If you add -l debug to the kitchen command you run you will get more debug messages which are very helpful in troubleshooting. you can also see my test repository at https://github.com/neillturner/ansible_vagrant_repo using the default option (which where tests are stored when using chef) tests need to be at test/integration/ansible/serverspec/test_spec.rb i think that is the cause of you getting zero tests.
Here is the logs with debug mode. I have the tets in test/integration/default/serverspec/test_spec.rb because my suite name is -default in .kitchen.yml file.
[root@hostname ansible-kitchen]# kitchen verify -l debug
Expected array default value for '--driver'; got "kitchen-vagrant" (string)
-----> Starting Kitchen (v1.8.0)
D [local command] BEGIN (docker >> /dev/null 2>&1)
D [local command] END (0m0.02s)
-----> Creating <default-ubuntu-1404>...
D [kitchen::driver::docker command] BEGIN (docker -H unix:///var/run/docker.sock build -f /opt/ansible/ansible-kitchen/Dockerfile-kitchen20170402-17917-nomrj .)
Sending build context to Docker daemon 14.49 MB57.1 kB
Sending build context to Docker daemon
Step 0 : FROM rndmh3ro/docker-ubuntu1404-ansible:latest
---> afcf55ba22a4
Step 1 : RUN dpkg-divert --local --rename --add /sbin/initctl
---> Using cache
---> 9ebf4b027610
Step 2 : RUN ln -sf /bin/true /sbin/initctl
---> Using cache
---> cc900ac99d86
Step 3 : ENV DEBIAN_FRONTEND noninteractive
---> Using cache
---> e48eb0835dac
Step 4 : ENV container docker
---> Using cache
---> ab40cb30aec7
Step 5 : RUN apt-get update
---> Using cache
---> 0025b7e86b66
Step 6 : RUN apt-get install -y sudo openssh-server curl lsb-release
---> Using cache
---> 20898a625baf
Step 7 : RUN if ! getent passwd kitchen; then useradd -d /home/kitchen -m -s /bin/bash -p '*' kitchen; fi
---> Using cache
---> f24b9931a8a5
Step 8 : RUN echo "kitchen ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
---> Using cache
---> 1183694b41c8
Step 9 : RUN echo "Defaults !requiretty" >> /etc/sudoers
---> Using cache
---> 48e35d80e4c1
Step 10 : RUN mkdir -p /home/kitchen/.ssh
---> Using cache
---> 055c50173ea9
Step 11 : RUN chown -R kitchen /home/kitchen/.ssh
---> Using cache
---> ee655f6c3228
Step 12 : RUN chmod 0700 /home/kitchen/.ssh
---> Using cache
---> 31d0d17becbc
Step 13 : RUN touch /home/kitchen/.ssh/authorized_keys
---> Using cache
---> 73a0d9b5e526
Step 14 : RUN chown kitchen /home/kitchen/.ssh/authorized_keys
---> Using cache
---> e5158b7adf00
Step 15 : RUN chmod 0600 /home/kitchen/.ssh/authorized_keys
---> Using cache
---> 7b5dfdbc8403
Step 16 : RUN echo ssh-rsa\ AAAAB3NzaC1yc2EAAAADAQABAAABAQDPYxr/qv5imN4SzWFnANniDv6PGgWSmuLQgFIxMzpu5JPKOvxnukBTIgjY/IKphE3F3Eq9kKIzYjU97TKdhWbePQOpuyvTR7JGGmAoLrssW\+\+OVlu1aPyEMbqfhFpxXm2f55Fj8i6VMRCOXk1XeMhHeRyWPP3Ctq2Mdl06ML4as001dFFWvL8rEMUpuzOZl4D838RQRthJ5h3G7wXT6whuv2XJ\+P0Sklfjhi5r4ACSH5zyw\+x\+HwjzWdi78iFgvcgesg4lF4rcI74koIci\+75mtkOa0/C8HJinCBtrFL5r8KkLWs/ijS5oXfXo87lPzokmVq7BArU4ke\+qvc14Tlov\ kitchen_docker_key >> /home/kitchen/.ssh/authorized_keys
---> Using cache
---> d165295b5c6c
Successfully built d165295b5c6c
D [kitchen::driver::docker command] END (0m0.58s)
D [kitchen::driver::docker command] BEGIN (docker -H unix:///var/run/docker.sock run -d -p 22 --name defaultubuntu1404-nkotha-led33029-rl2ziu6d d165295b5c6c /usr/sbin/sshd -D -o UseDNS=no -o UsePAM=no -o PasswordAuthentication=yes -o UsePrivilegeSeparation=no -o PidFile=/tmp/sshd.pid)
17f2f5c49ea16158471d8aa130419813d8a78bff240c62742812f521a20e55ee
D [kitchen::driver::docker command] END (0m0.81s)
D [kitchen::driver::docker command] BEGIN (docker -H unix:///var/run/docker.sock port 17f2f5c49ea16158471d8aa130419813d8a78bff240c62742812f521a20e55ee 22/tcp)
0.0.0.0:32774
D [kitchen::driver::docker command] END (0m0.03s)
D [SSH] opening connection to kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32774, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"]}>
D [SSH] kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32774, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"], :user=>"kitchen"}> (echo '[SSH] Established')
[SSH] Established
Finished creating <default-ubuntu-1404> (0m1.88s).
-----> Converging <default-ubuntu-1404>...
Preparing files for transfer
D Creating local sandbox in /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p
D Creating local sandbox in /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p
Preparing playbook
D Copying playbook from /opt/ansible/ansible-kitchen/test/integration/default/default.yml to /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p/default.yml
Preparing inventory
Preparing modules
nothing to do for modules
Preparing roles
D Using roles from roles
Preparing ansible.cfg file
Empty ansible.cfg generated
Preparing group_vars
nothing to do for group_vars
Preparing additional_copy_path
Preparing host_vars
nothing to do for host_vars
Preparing hosts file
D Using host from test-kitchen
Preparing spec
D Using spec from spec
Preparing library plugins
nothing to do for library plugins
Preparing callback plugins
nothing to do for callback plugins
Preparing filter_plugins
nothing to do for filter_plugins
Preparing lookup_plugins
nothing to do for lookup_plugins
Preparing additional_ssh_private_keys
nothing to do for additional_ssh_private_keys
Finished Preparing files for transfer
D [SSH] reusing existing connection kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32774, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"], :user=>"kitchen"}>
D sudo -E rm -rf /tmp/kitchen/modules /tmp/kitchen/roles /tmp/kitchen/group_vars /tmp/kitchen/host_vars; mkdir -p /tmp/kitchen
D [SSH] kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32774, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"], :user=>"kitchen"}> (sudo -E rm -rf /tmp/kitchen/modules /tmp/kitchen/roles /tmp/kitchen/group_vars /tmp/kitchen/host_vars; mkdir -p /tmp/kitchen)
Transferring files to <default-ubuntu-1404>
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p/roles/splunk/defaults/main.yml (36 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p/roles/splunk/README.md (1328 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p/roles/splunk/.travis.yml (539 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p/roles/splunk/handlers/main.yml (36 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p/roles/splunk/meta/main.yml (3900 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p/roles/splunk/vars/main.yml (32 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p/roles/splunk/tests/inventory (9 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p/roles/splunk/tests/test.yml (69 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p/roles/splunk/tasks/main.yml (103 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p/default.yml (234 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p/ansible.cfg (22 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p/hosts (60 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p/spec/spec_helper.rb (41 bytes)
D Transfer complete
D *** COMMAND TO RUN:
D sudo -E sh -c '[ -d /etc/ansible ] || mkdir /etc/ansible' && sudo -E cp /tmp/kitchen/ansible.cfg /etc/ansible && sudo -E cp -r /tmp/kitchen/group_vars /etc/ansible/. && sudo -E cp -r /tmp/kitchen/host_vars /etc/ansible/.
D [SSH] kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32774, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"], :user=>"kitchen"}> (sudo -E sh -c '[ -d /etc/ansible ] || mkdir /etc/ansible' && sudo -E cp /tmp/kitchen/ansible.cfg /etc/ansible && sudo -E cp -r /tmp/kitchen/group_vars /etc/ansible/. && sudo -E cp -r /tmp/kitchen/host_vars /etc/ansible/.)
D Setting roles_path inside VM to /tmp/kitchen/roles
D Setting roles_path inside VM to /tmp/kitchen/roles
D
D Going to invoke ansible-playbook with:
ANSIBLE_ROLES_PATH=/tmp/kitchen/roles sudo -E -s ansible-playbook -i /tmp/kitchen/hosts -c ssh -M /tmp/kitchen/modules /tmp/kitchen/default.yml
D [SSH] kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32774, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"], :user=>"kitchen"}> (
ANSIBLE_ROLES_PATH=/tmp/kitchen/roles sudo -E -s ansible-playbook -i /tmp/kitchen/hosts -c ssh -M /tmp/kitchen/modules /tmp/kitchen/default.yml
)
PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [create directory] ********************************************************
changed: [localhost]
PLAY RECAP *********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0
D Cleaning up local sandbox in /tmp/default-ubuntu-1404-sandbox-20170402-17917-jwbk4p
Finished converging <default-ubuntu-1404> (0m2.03s).
-----> Setting up <default-ubuntu-1404>...
Finished setting up <default-ubuntu-1404> (0m0.00s).
-----> Verifying <default-ubuntu-1404>...
[Serverspec] Verify on instance=#<Kitchen::Instance:0x00000002a489e8> with state={:username=>"kitchen", :ssh_key=>"/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa", :image_id=>"d165295b5c6c", :container_id=>"17f2f5c49ea16158471d8aa130419813d8a78bff240c62742812f521a20e55ee", :hostname=>"localhost", :port=>32774, :last_action=>"setup"}
Environment variable KITCHEN_USERNAME value kitchen
Environment variable KITCHEN_SSH_KEY value /opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa
Environment variable KITCHEN_IMAGE_ID value d165295b5c6c
Environment variable KITCHEN_CONTAINER_ID value 17f2f5c49ea16158471d8aa130419813d8a78bff240c62742812f521a20e55ee
Environment variable KITCHEN_HOSTNAME value localhost
Environment variable KITCHEN_PORT value 32774
Environment variable KITCHEN_LAST_ACTION value setup
Transport Environment variable KITCHEN_USERNAME value root
Transport Environment variable KITCHEN_PORT value 22
D Running Serverspec on remote server
Preparing files for transfer
D Creating local sandbox in /tmp/default-ubuntu-1404-sandbox-20170402-17917-5fxuji
D Creating local sandbox of all test suite files in /opt/ansible/ansible-kitchen/test/integration/default
D [SSH] reusing existing connection kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32774, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"], :user=>"kitchen"}>
Installing ruby, bundler and serverspec remotely on server
D [SSH] kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32774, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"], :user=>"kitchen"}> (
if [ ! $(which ruby) ]; then
echo '-----> Installing ruby, will try to determine platform os'
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
sudo -E -H yum -y install ruby
else
if [ -f /etc/system-release ] && grep -q 'Amazon Linux' /etc/system-release; then
sudo -E -H yum -y install ruby
else
sudo -E -H apt-get -y install ruby
fi
fi
fi
if [ "$(sudo -E -H gem list bundler -i)" = "true" ]; then
echo "Bundler already installed"
else
if [ "$(sudo -E -H gem list bundler -i)" = "false" ]; then
sudo -E -H gem install --no-ri --no-rdoc bundler
else
echo "ERROR: Ruby not installed correctly"
exit 1
fi
fi
if [ -d /tmp/kitchen ]; then
if [ "$(sudo -E -H gem list serverspec -i)" = "false" ]; then
sudo -E -H rm -f /tmp/kitchen/Gemfile
sudo -E -H echo "source 'https://rubygems.org'" >> /tmp/kitchen/Gemfile
sudo -E -H echo "gem 'net-ssh','~> 2.9'" >> /tmp/kitchen/Gemfile
sudo -E -H echo "gem 'serverspec'" >> /tmp/kitchen/Gemfile
BUNDLE_CMD=/usr/local/bin/bundle
echo "---> BUNDLE_CMD variable is: ${BUNDLE_CMD}"
sudo -E -H $BUNDLE_CMD install --gemfile=/tmp/kitchen/Gemfile
fi
else
echo "ERROR: Default path '/tmp/kitchen' does not exist"
exit 1
fi
)
-----> Installing ruby, will try to determine platform os
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libruby1.9.1 ruby1.9.1
Suggested packages:
ri ruby-dev ruby1.9.1-examples ri1.9.1 graphviz ruby1.9.1-dev ruby-switch
The following NEW packages will be installed:
libruby1.9.1 ruby ruby1.9.1
0 upgraded, 3 newly installed, 0 to remove and 10 not upgraded.
Need to get 2686 kB of archives.
After this operation, 12.7 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main ruby all 1:1.9.3.4 [5334 B]
Get:2 http://archive.ubuntu.com/ubuntu/ trusty-updates/main ruby1.9.1 amd64 1.9.3.484-2ubuntu1.2 [35.6 kB]
Get:3 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libruby1.9.1 amd64 1.9.3.484-2ubuntu1.2 [2645 kB]
Fetched 2686 kB in 1s (1396 kB/s)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Selecting previously unselected package ruby.
(Reading database ... 18695 files and directories currently installed.)
Preparing to unpack .../ruby_1%3a1.9.3.4_all.deb ...
Unpacking ruby (1:1.9.3.4) ...
Selecting previously unselected package ruby1.9.1.
Preparing to unpack .../ruby1.9.1_1.9.3.484-2ubuntu1.2_amd64.deb ...
Unpacking ruby1.9.1 (1.9.3.484-2ubuntu1.2) ...
Selecting previously unselected package libruby1.9.1.
Preparing to unpack .../libruby1.9.1_1.9.3.484-2ubuntu1.2_amd64.deb ...
Unpacking libruby1.9.1 (1.9.3.484-2ubuntu1.2) ...
Setting up ruby (1:1.9.3.4) ...
Setting up ruby1.9.1 (1.9.3.484-2ubuntu1.2) ...
Setting up libruby1.9.1 (1.9.3.484-2ubuntu1.2) ...
Processing triggers for libc-bin (2.19-0ubuntu6.9) ...
Fetching: bundler-1.14.6.gem (100%)
Successfully installed bundler-1.14.6
1 gem installed
---> BUNDLE_CMD variable is: /usr/local/bin/bundle
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Fetching gem metadata from https://rubygems.org/......
Fetching version metadata from https://rubygems.org/.
Resolving dependencies...
Rubygems 1.8.23 is not threadsafe, so your gems will be installed one at a time. Upgrade to Rubygems 2.1.0 or higher to enable parallel gem installation.
Installing diff-lcs 1.3
Installing multi_json 1.12.1
Installing net-ssh 2.9.4
Installing net-telnet 0.1.1
Installing rspec-support 3.5.0
Installing sfl 2.3
Using bundler 1.14.6
Installing net-scp 1.2.1
Installing rspec-core 3.5.4
Installing rspec-expectations 3.5.0
Installing rspec-mocks 3.5.0
Installing specinfra 2.67.7
Installing rspec-its 1.2.0
Installing rspec 3.5.0
Installing serverspec 2.38.0
Bundle complete! 2 Gemfile dependencies, 15 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
Transferring files to <default-ubuntu-1404>
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-5fxuji/suites/serverspec/localhost/default_spec.rb (161 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-5fxuji/suites/serverspec/localhost/spec_helper.rb (41 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-5fxuji/suites/serverspec/default_spec.rb (162 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170402-17917-5fxuji/suites/serverspec/spec_helper.rb (41 bytes)
D Transfer complete
Running Serverspec
Using default pattern /tmp/verifier/suites/serverspec/*_spec.rb
D [SSH] kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32774, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"], :user=>"kitchen"}> (
mkdir -p /tmp/kitchen
cd /tmp/kitchen
RSPEC_CMD=/usr/local/bin/rspec
echo "---> RSPEC_CMD variable is: ${RSPEC_CMD}"
sudo -E -H $RSPEC_CMD -c -f documentation --default-path /tmp/kitchen -P /tmp/verifier/suites/serverspec/*_spec.rb
)
---> RSPEC_CMD variable is: /usr/local/bin/rspec
No examples found.
Finished in 0.00036 seconds (files took 0.0512 seconds to load)
0 examples, 0 failures
D Cleaning up local sandbox in /tmp/default-ubuntu-1404-sandbox-20170402-17917-5fxuji
D [Serverspec] Verify completed.
Finished verifying <default-ubuntu-1404> (0m14.01s).
D [SSH] shutting previous connection kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32774, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"], :user=>"kitchen"}>
D [SSH] closing connection to kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32774, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"], :user=>"kitchen"}>
Fixed the issue. I placed the test files into test/integration/default directory. The below entries in the above logs mentions clearly it is looking for the tests in the location "/opt/ansible/ansible-kitchen/test/integration/default" . Not Sure if it is for default behaviour to not to check inside the serverspec directory.
"Creating local sandbox of all test suite files in /opt/ansible/ansible-kitchen/test/integration/default"
Thanks.
I will review this to make sure it the same as chef and document better.
I also found an another issue, I destroyed and ran again and it again throws 0 example and 0 failures. Below is the logs keeping " default_pattern : true " in suites sections.
[root@hostname ansible-kitchen]# kitchen verify
Expected array default value for '--driver'; got "kitchen-vagrant" (string)
-----> Starting Kitchen (v1.8.0)
-----> Creating <default-ubuntu-1404>...
Sending build context to Docker daemon 14.49 MB57.1 kB
Sending build context to Docker daemon
Step 0 : FROM rndmh3ro/docker-ubuntu1404-ansible:latest
---> afcf55ba22a4
Step 1 : RUN dpkg-divert --local --rename --add /sbin/initctl
---> Using cache
---> 9ebf4b027610
Step 2 : RUN ln -sf /bin/true /sbin/initctl
---> Using cache
---> cc900ac99d86
Step 3 : ENV DEBIAN_FRONTEND noninteractive
---> Using cache
---> e48eb0835dac
Step 4 : ENV container docker
---> Using cache
---> ab40cb30aec7
Step 5 : RUN apt-get update
---> Using cache
---> 0025b7e86b66
Step 6 : RUN apt-get install -y sudo openssh-server curl lsb-release
---> Using cache
---> 20898a625baf
Step 7 : RUN if ! getent passwd kitchen; then useradd -d /home/kitchen -m -s /bin/bash -p '*' kitchen; fi
---> Using cache
---> f24b9931a8a5
Step 8 : RUN echo "kitchen ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
---> Using cache
---> 1183694b41c8
Step 9 : RUN echo "Defaults !requiretty" >> /etc/sudoers
---> Using cache
---> 48e35d80e4c1
Step 10 : RUN mkdir -p /home/kitchen/.ssh
---> Using cache
---> 055c50173ea9
Step 11 : RUN chown -R kitchen /home/kitchen/.ssh
---> Using cache
---> ee655f6c3228
Step 12 : RUN chmod 0700 /home/kitchen/.ssh
---> Using cache
---> 31d0d17becbc
Step 13 : RUN touch /home/kitchen/.ssh/authorized_keys
---> Using cache
---> 73a0d9b5e526
Step 14 : RUN chown kitchen /home/kitchen/.ssh/authorized_keys
---> Using cache
---> e5158b7adf00
Step 15 : RUN chmod 0600 /home/kitchen/.ssh/authorized_keys
---> Using cache
---> 7b5dfdbc8403
Step 16 : RUN echo ssh-rsa\ AAAAB3NzaC1yc2EAAAADAQABAAABAQDPYxr/qv5imN4SzWFnANniDv6PGgWSmuLQgFIxMzpu5JPKOvxnukBTIgjY/IKphE3F3Eq9kKIzYjU97TKdhWbePQOpuyvTR7JGGmAoLrssW\+\+OVlu1aPyEMbqfhFpxXm2f55Fj8i6VMRCOXk1XeMhHeRyWPP3Ctq2Mdl06ML4as001dFFWvL8rEMUpuzOZl4D838RQRthJ5h3G7wXT6whuv2XJ\+P0Sklfjhi5r4ACSH5zyw\+x\+HwjzWdi78iFgvcgesg4lF4rcI74koIci\+75mtkOa0/C8HJinCBtrFL5r8KkLWs/ijS5oXfXo87lPzokmVq7BArU4ke\+qvc14Tlov\ kitchen_docker_key >> /home/kitchen/.ssh/authorized_keys
---> Using cache
---> d165295b5c6c
Successfully built d165295b5c6c
7d7f7ba70f574b7d5995cebf3fa30291a4e5e76daf896857c1e18b265cec9b7a
0.0.0.0:32782
[SSH] Established
Finished creating <default-ubuntu-1404> (0m1.36s).
-----> Converging <default-ubuntu-1404>...
Preparing files for transfer
Preparing playbook
Preparing inventory
Preparing modules
nothing to do for modules
Preparing roles
Preparing ansible.cfg file
Empty ansible.cfg generated
Preparing group_vars
nothing to do for group_vars
Preparing additional_copy_path
Preparing host_vars
nothing to do for host_vars
Preparing hosts file
Preparing spec
Preparing library plugins
nothing to do for library plugins
Preparing callback plugins
nothing to do for callback plugins
Preparing filter_plugins
nothing to do for filter_plugins
Preparing lookup_plugins
nothing to do for lookup_plugins
Preparing additional_ssh_private_keys
nothing to do for additional_ssh_private_keys
Finished Preparing files for transfer
Transferring files to <default-ubuntu-1404>
PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [create directory] ********************************************************
changed: [localhost]
PLAY RECAP *********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0
Finished converging <default-ubuntu-1404> (0m1.76s).
-----> Setting up <default-ubuntu-1404>...
Finished setting up <default-ubuntu-1404> (0m0.00s).
-----> Verifying <default-ubuntu-1404>...
[Serverspec] Verify on instance=#<Kitchen::Instance:0x00000002ea0b08> with state={:username=>"kitchen", :ssh_key=>"/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa", :image_id=>"d165295b5c6c", :container_id=>"7d7f7ba70f574b7d5995cebf3fa30291a4e5e76daf896857c1e18b265cec9b7a", :hostname=>"localhost", :port=>32782, :last_action=>"setup"}
Environment variable KITCHEN_USERNAME value kitchen
Environment variable KITCHEN_SSH_KEY value /opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa
Environment variable KITCHEN_IMAGE_ID value d165295b5c6c
Environment variable KITCHEN_CONTAINER_ID value 7d7f7ba70f574b7d5995cebf3fa30291a4e5e76daf896857c1e18b265cec9b7a
Environment variable KITCHEN_HOSTNAME value localhost
Environment variable KITCHEN_PORT value 32782
Environment variable KITCHEN_LAST_ACTION value setup
Transport Environment variable KITCHEN_USERNAME value root
Transport Environment variable KITCHEN_PORT value 22
Preparing files for transfer
Installing ruby, bundler and serverspec remotely on server
-----> Installing ruby, will try to determine platform os
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libruby1.9.1 ruby1.9.1
Suggested packages:
ri ruby-dev ruby1.9.1-examples ri1.9.1 graphviz ruby1.9.1-dev ruby-switch
The following NEW packages will be installed:
libruby1.9.1 ruby ruby1.9.1
0 upgraded, 3 newly installed, 0 to remove and 10 not upgraded.
Need to get 2686 kB of archives.
After this operation, 12.7 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main ruby all 1:1.9.3.4 [5334 B]
Get:2 http://archive.ubuntu.com/ubuntu/ trusty-updates/main ruby1.9.1 amd64 1.9.3.484-2ubuntu1.2 [35.6 kB]
Get:3 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libruby1.9.1 amd64 1.9.3.484-2ubuntu1.2 [2645 kB]
Fetched 2686 kB in 3s (836 kB/s)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Selecting previously unselected package ruby.
(Reading database ... 18695 files and directories currently installed.)
Preparing to unpack .../ruby_1%3a1.9.3.4_all.deb ...
Unpacking ruby (1:1.9.3.4) ...
Selecting previously unselected package ruby1.9.1.
Preparing to unpack .../ruby1.9.1_1.9.3.484-2ubuntu1.2_amd64.deb ...
Unpacking ruby1.9.1 (1.9.3.484-2ubuntu1.2) ...
Selecting previously unselected package libruby1.9.1.
Preparing to unpack .../libruby1.9.1_1.9.3.484-2ubuntu1.2_amd64.deb ...
Unpacking libruby1.9.1 (1.9.3.484-2ubuntu1.2) ...
Setting up ruby (1:1.9.3.4) ...
Setting up ruby1.9.1 (1.9.3.484-2ubuntu1.2) ...
Setting up libruby1.9.1 (1.9.3.484-2ubuntu1.2) ...
Processing triggers for libc-bin (2.19-0ubuntu6.9) ...
Fetching: bundler-1.14.6.gem (100%)
Successfully installed bundler-1.14.6
1 gem installed
---> BUNDLE_CMD variable is: /usr/local/bin/bundle
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Fetching gem metadata from https://rubygems.org/......
Fetching version metadata from https://rubygems.org/.
Resolving dependencies...
Rubygems 1.8.23 is not threadsafe, so your gems will be installed one at a time. Upgrade to Rubygems 2.1.0 or higher to enable parallel gem installation.
Installing diff-lcs 1.3
Installing multi_json 1.12.1
Installing net-ssh 2.9.4
Installing net-telnet 0.1.1
Installing rspec-support 3.5.0
Installing sfl 2.3
Using bundler 1.14.6
Installing net-scp 1.2.1
Installing rspec-core 3.5.4
Installing rspec-expectations 3.5.0
Installing rspec-mocks 3.5.0
Installing specinfra 2.67.7
Installing rspec-its 1.2.0
Installing rspec 3.5.0
Installing serverspec 2.38.0
Bundle complete! 2 Gemfile dependencies, 15 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
Transferring files to <default-ubuntu-1404>
Running Serverspec
Using default pattern /tmp/verifier/suites/serverspec/*_spec.rb
---> RSPEC_CMD variable is: /usr/local/bin/rspec
No examples found.
Finished in 0.00033 seconds (files took 0.04776 seconds to load)
0 examples, 0 failures
Finished verifying <default-ubuntu-1404> (0m15.70s).
I observed
Running Serverspec
Using default pattern /tmp/verifier/suites/serverspec/*_spec.rb
means default_pattern is looking for /tmp/verifier/suites/serverspec/*_spec.rb location, while i logged in my docker conatiner using kitchen login and isee there is no suites directory in the /tmp/verifier location.
[root@hostname ansible-kitchen]# kitchen login
Expected array default value for '--driver'; got "kitchen-vagrant" (string)
Last login: Mon Apr 3 15:54:01 2017 from 172.17.42.1
kitchen@1b5bfb25b432:~$ cd /tmp/verifier/
kitchen@1b5bfb25b432:/tmp/verifier$ ll -al
total 12
drwxr-xr-x 3 kitchen kitchen 4096 Apr 3 15:54 ./
drwxrwxrwt 4 root root 4096 Apr 3 15:54 ../
drwxr-xr-x 3 kitchen kitchen 4096 Apr 3 15:54 serverspec/
After i created a directory suites inside the folder /tmp/verifier and copied the serverspec folder inside and then kitchen verify worked fine. second option i changed the default pattern value to /tmp/verifier/serverspec in .kitchne.yml file and it also worked.
hers is the logs:
[root@hostname ansible-kitchen]# kitchen verify -l debug
Expected array default value for '--driver'; got "kitchen-vagrant" (string)
-----> Starting Kitchen (v1.8.0)
D [local command] BEGIN (docker >> /dev/null 2>&1)
D [local command] END (0m0.02s)
-----> Verifying <default-ubuntu-1404>...
[Serverspec] Verify on instance=#<Kitchen::Instance:0x00000003043168> with state={:username=>"kitchen", :ssh_key=>"/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa", :image_id=>"d165295b5c6c", :container_id=>"238c6114795e059da219a5a21224793b005e092c9c9f6fde35264117dad91742", :hostname=>"localhost", :port=>32785, :last_action=>"verify"}
Environment variable KITCHEN_USERNAME value kitchen
Environment variable KITCHEN_SSH_KEY value /opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa
Environment variable KITCHEN_IMAGE_ID value d165295b5c6c
Environment variable KITCHEN_CONTAINER_ID value 238c6114795e059da219a5a21224793b005e092c9c9f6fde35264117dad91742
Environment variable KITCHEN_HOSTNAME value localhost
Environment variable KITCHEN_PORT value 32785
Environment variable KITCHEN_LAST_ACTION value verify
Transport Environment variable KITCHEN_USERNAME value root
Transport Environment variable KITCHEN_PORT value 22
D Running Serverspec on remote server
Preparing files for transfer
D Creating local sandbox in /tmp/default-ubuntu-1404-sandbox-20170403-27142-q0ugwb
D Creating local sandbox of all test suite files in /opt/ansible/ansible-kitchen/test/integration/default
Installing ruby, bundler and serverspec remotely on server
D [SSH] kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32785, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"]}> (
if [ ! $(which ruby) ]; then
echo '-----> Installing ruby, will try to determine platform os'
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
sudo -E -H yum -y install ruby
else
if [ -f /etc/system-release ] && grep -q 'Amazon Linux' /etc/system-release; then
sudo -E -H yum -y install ruby
else
sudo -E -H apt-get -y install ruby
fi
fi
fi
if [ "$(sudo -E -H gem list bundler -i)" = "true" ]; then
echo "Bundler already installed"
else
if [ "$(sudo -E -H gem list bundler -i)" = "false" ]; then
sudo -E -H gem install --no-ri --no-rdoc bundler
else
echo "ERROR: Ruby not installed correctly"
exit 1
fi
fi
if [ -d /tmp/kitchen ]; then
if [ "$(sudo -E -H gem list serverspec -i)" = "false" ]; then
sudo -E -H rm -f /tmp/kitchen/Gemfile
sudo -E -H echo "source 'https://rubygems.org'" >> /tmp/kitchen/Gemfile
sudo -E -H echo "gem 'net-ssh','~> 2.9'" >> /tmp/kitchen/Gemfile
sudo -E -H echo "gem 'serverspec'" >> /tmp/kitchen/Gemfile
BUNDLE_CMD=/usr/local/bin/bundle
echo "---> BUNDLE_CMD variable is: ${BUNDLE_CMD}"
sudo -E -H $BUNDLE_CMD install --gemfile=/tmp/kitchen/Gemfile
fi
else
echo "ERROR: Default path '/tmp/kitchen' does not exist"
exit 1
fi
)
D [SSH] opening connection to kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32785, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"]}>
Bundler already installed
Transferring files to <default-ubuntu-1404>
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170403-27142-q0ugwb/suites/serverspec/localhost/default_spec.rb (161 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170403-27142-q0ugwb/suites/serverspec/localhost/spec_helper.rb (41 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170403-27142-q0ugwb/suites/serverspec/default_spec.rb (162 bytes)
D Uploaded /tmp/default-ubuntu-1404-sandbox-20170403-27142-q0ugwb/suites/serverspec/spec_helper.rb (41 bytes)
D Transfer complete
Running Serverspec
Using default pattern /tmp/verifier/suites/serverspec/*_spec.rb
D [SSH] kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32785, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"], :user=>"kitchen"}> (
mkdir -p /tmp/kitchen
cd /tmp/kitchen
RSPEC_CMD=/usr/local/bin/rspec
echo "---> RSPEC_CMD variable is: ${RSPEC_CMD}"
sudo -E -H $RSPEC_CMD -c -f documentation --default-path /tmp/kitchen -P /tmp/verifier/suites/serverspec/*_spec.rb
)
---> RSPEC_CMD variable is: /usr/local/bin/rspec
File "/opt/splunk"
should be a directory
Finished in 0.14412 seconds (files took 0.35435 seconds to load)
1 example, 0 failures
D Cleaning up local sandbox in /tmp/default-ubuntu-1404-sandbox-20170403-27142-q0ugwb
D [Serverspec] Verify completed.
Finished verifying <default-ubuntu-1404> (0m1.01s).
D [SSH] shutting previous connection kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32785, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"], :user=>"kitchen"}>
D [SSH] closing connection to kitchen@localhost<{:user_known_hosts_file=>"/dev/null", :paranoid=>false, :port=>32785, :compression=>true, :compression_level=>6, :keepalive=>true, :keepalive_interval=>60, :timeout=>15, :keys_only=>true, :keys=>["/opt/ansible/ansible-kitchen/.kitchen/docker_id_rsa"], :auth_methods=>["publickey"], :user=>"kitchen"}>
-----> Kitchen is finished. (0m1.09s)
ok i will look into it
I got the same error and found 2 issues:
-
First the test file was not on my guest OS and I found that the function chef_data_dir? return nil instead of a boolean. I disabled function in order to have the file transferred to the guest OS.
-
Second, after the transfer the files was on the wrong path when the option "default_pattern" is enabled. The function "call" calls "Dir.glob" with "sandbox_path/*" so the sub-folder "suites" is removed and the function "rspec_commands" doesn't find the tests. I replaced it with the line "sandbox_dirs = [ sandbox_path ]" and the file was transferred in the right path.
thanks for that would you like to create a pull request?
I never did PR on github but it seems I have no right to create a branch and commit.
you just fork the kitchen-verifier-serverspec repo make your changes and then create a pull request