我正在测试两个平台,cento-7和ubuntu-1604。两者都成功收敛。但是在验证过程中失败。
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
奇怪的是,它在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正在运行。
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
奇怪的是,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:
至少在我看来,为什么在测试计算机上它们按预期方式工作时我会失败?
谢谢
安德鲁