厨师的厨房测试失败,但当地检查证明情况相反

时间:2018-07-19 14:09:26

标签: docker chef test-kitchen

我正在测试两个平台,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次

奇怪的是,它在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次

奇怪的是,httpd正在运行并且可以卷曲,但是没有在端口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:

至少在我看来,为什么在测试计算机上它们按预期方式工作时我会失败?

谢谢

安德鲁

1 个答案:

答案 0 :(得分:0)

第一个是因为未在Ubuntu平台中设置systemd。默认情况下,kitchen-docker不设置systemd支持(如您所见,如何为centos设置)。

第二个问题很可能是ss的时髦之处,它是netstat的现代替代品。 InSpec确实具有使用netspec的一些后备逻辑,但请检出Scatter plot with colours per group并与正在运行的容器进行比较。