0

I'm testing two platforms, cento-7 & ubuntu-1604. Both converge successfully. But fail during verify.

Ubuntu:

  System Package apache2
     ✔  should be installed
  Service apache2
     ×  should be running 
     expected that `Service apache2` is running
  Command curl localhost
     ✔  stdout should match /hello/i
     ✔  exit_status should eq 0
  Port 80
     ✔  should be listening

Test Summary: 4 successful, 1 failure, 0 skipped

Seems strange that it fails on apache2 running but curl localhost succeeds.

I did a kitchen login

$ sudo systemctl status apache2
Failed to connect to bus: No such file or directory

so I tried

$ ps -eo comm,etime,user | grep apache2
apache2            06:34:11 root
apache2            06:34:11 www-data
apache2            06:34:11 www-data

Looks like apache2 is running.

Centos-7

  System Package httpd
     ✔  should be installed
  Service httpd
     ✔  should be running
  Command curl localhost
     ✔  stdout should match /hello/i
     ✔  exit_status should eq 0
  Port 80
     ×  should be listening
     expected `Port 80.listening?` to return true, got false

Test Summary: 4 successful, 1 failure, 0 skipped

Strange that httpd is running and curl works but not listening on port 80?

So I logged in and ran netstat

$ sudo netstat -tulpn | grep :80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      562/httpd

Here are my tests:

package_name =
  service_name =
    case os[:family]
    when 'redhat' then 'httpd'
    when 'debian' then 'apache2'
    end

describe package(package_name) do
  it { should be_installed }
end

describe service(service_name) do
  it { should be_running }
end

describe command('curl localhost') do
  its('stdout') { should match(/hello/i) }
  its('exit_status') { should eq 0 }
end

describe port(80) do
  it { should be_listening }
end

Here is my .kitchen.yml

---
driver:
  name: docker
  privileged: true

provisioner:
  name: chef_zero

verifier:
  name: inspec

platforms:
  - name: ubuntu-16.04
  - name: centos-7
    driver:
      platform: rhel
      run_command: /usr/lib/systemd/systemd

suites:
  - name: default
    run_list:
      - recipe[hello_world_test::default]
      - recipe[hello_world_test::deps]
    verifier:
      inspec_tests:
        - test/integration/default
    attributes:

Any idea why I get the failures when it seems, to me at least, that on the test machines they are working as they should.

Thanks,

Andrew

KingAndrew
  • 1,164
  • 4
  • 21
  • 41

1 Answers1

0

The first one is because systemd is not set up in your Ubuntu platform. By default, kitchen-docker doesn't set up systemd support (as you can see with how you set it up for centos).

The second issue is more likely something funky with ss, which is the modern replacement for netstat. InSpec does have some fallback logic to use netspec but check out https://github.com/inspec/inspec/blob/8683c54510808462c7f3df6d92833aff3b21fe42/lib/resources/port.rb#L385-L421 and compare to your running container.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • thanks coderanger. if kitchen-docker doesn't set up systemd by default is there a setting to tell kitchen-docker to set it up? – KingAndrew Jul 20 '18 at 10:27
  • oops- like I set it up for centos. Thanks again, – KingAndrew Jul 20 '18 at 10:45
  • Actually after unsuccessfully trying to get it working for ubuntu I switched to kitchen-dokken and upgraded from ubuntu 16.04 to 18.04. Like this: https://github.com/test-kitchen/test-kitchen/blob/master/.kitchen.dokken.yml everthing is working now like a charm :-) – KingAndrew Jul 20 '18 at 12:04