【问题标题】:Chef's Kitchen tests fail but local examination prove otherwise厨师厨房测试失败,但当地考试证明并非如此
【发布时间】:2018-07-20 09:29:05
【问题描述】:

我正在测试两个平台,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 正在运行并且 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:

知道为什么我会遇到失败,至少在我看来,在测试机器上它们正在按应有的方式工作。

谢谢,

安德鲁

【问题讨论】:

    标签: docker chef-infra test-kitchen


    【解决方案1】:

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

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

    【讨论】:

    • 感谢 coderanger。如果 kitchen-docker 默认没有设置 systemd 是否有设置告诉 kitchen-docker 设置它?
    • 哎呀——就像我为 centos 设置的一样。再次感谢,
    • 实际上在尝试让它为 ubuntu 工作失败后,我切换到 kitchen-dokken 并从 ubuntu 16.04 升级到 18.04。像这样:github.com/test-kitchen/test-kitchen/blob/master/… 现在一切都像魅力一样工作:-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 2021-04-21
    相关资源
    最近更新 更多