Search code examples
apachechef-infracentos7test-kitcheninspec

How check the httpd is enabled and running using InSpec with Kitchen-docker on CentOS?


Running my test with InSpec I am unable to test if the httpd is enabled and running.

InSpec test

describe package 'httpd' do
  it { should be_installed }
end

describe service 'httpd' do
  it { should be_enabled }
  it { should be_running }
end

describe port 80 do
  it { should be_listening }
end

The output for kitchen verify is:

  System Package
     ✔  httpd should be installed
  Service httpd
     ✖  should be enabled
     expected that `Service httpd` is enabled
     ✖  should be running
     expected that `Service httpd` is running
  Port 80
     ✖  should be listening
     expected `Port 80.listening?` to return true, got false

Test Summary: 1 successful, 3 failures, 0 skipped

Recipe for httpd installation:

if node['platform'] == 'centos'
  # do centos installation
  package 'httpd' do
    action :install
  end

  execute "chkconfig httpd on" do
    command "chkconfig httpd on"
  end

  execute 'apache start' do
    command '/usr/sbin/httpd -DFOREGROUND &'
    action :run
  end

I do not know what I am doing wrong.

More info

CentOS version on docker instance

kitchen exec --command 'cat /etc/centos-release'
-----> Execute command on default-centos-72.
       CentOS Linux release 7.2.1511 (Core)

Chef version installed in my host

Chef Development Kit Version: 1.0.3
chef-client version: 12.16.42
delivery version: master (83358fb62c0f711c70ad5a81030a6cae4017f103)
berks version: 5.2.0
kitchen version: 1.13.2

UPDATE 1: Kitchen yml with driver attributes

The platform has the configuration recommended by coderanger :

---
driver:
  name: docker
  use_sudo: false

provisioner:
  name: chef_zero

verifier: inspec

platforms:
  - name: centos-7.2
    driver:
      platform: rhel
      run_command: /usr/lib/systemd/systemd
      provision_command:
        - /bin/yum install -y iniscripts net-tools wget
suites:
  - name: default
    run_list:
      - recipe[apache::default]
    verifier:
      inspec_tests:
        - test/integration
    attributes:

And it is the output when run kitchen test:

... some docker steps...

Step 16 : RUN echo ssh-rsa\ AAAAB3NzaC1yc2EAAAADAQABAAABAQDIp1HE9Zbtl3zAH2KKL1mVzb7BU1WxK7mi5xpIxNRBar7EZAAzxi1pVb1JwUXFSCVoAmUyfn/lBsKlgXnUD49pKrqkeLQQW7NoG3uCFiXBUTof8nFVuLYtw4CTiAudplyMvu5J7HQIP1Hve1caY27tFs/kpkQaXHCEuIkqgrM2rreMKK0n8im9b36L2SwWyM/GwqcIS1z9mMttid7ux0\+HOWWHqZ\+7gumOauh6tLRbtjrm3YYoaIAMyv945MIX8BFPXSQixThBVOlXGA9iTwUZWjU6WvZThxVFkKPR9KZtUTuTCT7Y8\+wFtQ/9XCHpPR00YDQvS0Vgdb/LhZUDoNqV\ kitchen_docker_key >> /home/kitchen/.ssh/authorized_keys
        ---> Using cache
        ---> c0e6b9e98d6a
       Successfully built c0e6b9e98d6a
       d486d7ebfe000a3138db06b1424c943a0a1ee7b2a00e8a396cb8c09f9527fb4b
       0.0.0.0:32841
       Waiting for SSH service on localhost:32841, retrying in 3 seconds
       Waiting for SSH service on localhost:32841, retrying in 3 seconds
       Waiting for SSH service on localhost:32841, retrying in 3 seconds
       Waiting for SSH service on localhost:32841, retrying in 3 seconds
       .....

Solution

  • You cannot, at least not out of the box. This is one area where kitchen-docker shows its edges. We try to pretend that a container is like a tiny VM but in reality it isn't, and one notable place where the pretending breaks down is init systems. With CentOS 7, it uses systemd. It is possible to get systemd to run inside the container (see https://github.com/poise/yolover-example/blob/master/.kitchen.yml#L17-L33) but not all features are supported and it can generally be a bit odd :-/ That example should be enough to make your tests work though. For completeness, CentOS 6 uses Upstart which just flat out won't run inside Docker so no love there either.