Chef's Kitchen 测试失败,但当地考试证明并非如此

Chef's Kitchen tests fail but local examination prove otherwise

我正在测试两个平台,cento-7 和 ubuntu-1604。两者都成功收敛。但是验证失败。

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

测试总结:4 次成功,1 次失败,0 次跳过

似乎 st运行ge 它在 apache2 上失败 运行 但 curl localhost 成功。

我登录了厨房

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

所以我试过了

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

看起来 apache2 是 运行。

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

测试总结:4 次成功,1 次失败,0 次跳过

St运行ge httpd 是 运行 和 curl 工作但不侦听端口 80?

所以我登录并 运行 netstat

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

这是我的测试:

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

这是我的。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:

知道为什么我会遇到失败,至少对我来说,它们在测试机器上正常工作。

谢谢,

安德鲁

第一个是因为您的 Ubuntu 平台中没有设置 systemd。默认情况下,kitchen-docker 不设置 systemd 支持(正如您在为 centos 设置时看到的那样)。

第二个问题更可能是 ss 的时髦问题,它是 netstat 的现代替代品。 InSpec 确实有一些使用 netspec 的后备逻辑,但请查看 https://github.com/inspec/inspec/blob/8683c54510808462c7f3df6d92833aff3b21fe42/lib/resources/port.rb#L385-L421 并与您的 运行 容器进行比较。