如何在 CentOS 上使用 InSpec 和 Kitchen-docker 检查 httpd 是否已启用和 运行?

How check the httpd is enabled and running using InSpec with Kitchen-docker on CentOS?

运行 我使用 InSpec 进行的测试 我无法测试 httpd 是否已启用并且 运行ning.

InSpec 测试

describe package 'httpd' do
  it { should be_installed }
end

describe service 'httpd' do
  it { should be_enabled }
  it { should be_running }
end

describe port 80 do
  it { should be_listening }
end

kitchen verify 的输出是:

  System Package
     ✔  httpd should be installed
  Service httpd
     ✖  should be enabled
     expected that `Service httpd` is enabled
     ✖  should be running
     expected that `Service httpd` is running
  Port 80
     ✖  should be listening
     expected `Port 80.listening?` to return true, got false

Test Summary: 1 successful, 3 failures, 0 skipped

httpd 安装方法:

if node['platform'] == 'centos'
  # do centos installation
  package 'httpd' do
    action :install
  end

  execute "chkconfig httpd on" do
    command "chkconfig httpd on"
  end

  execute 'apache start' do
    command '/usr/sbin/httpd -DFOREGROUND &'
    action :run
  end

我不知道我做错了什么。

更多信息

docker 实例上的 CentOS 版本

kitchen exec --command 'cat /etc/centos-release'
-----> Execute command on default-centos-72.
       CentOS Linux release 7.2.1511 (Core)

我的主机安装了 Chef 版本

Chef Development Kit Version: 1.0.3
chef-client version: 12.16.42
delivery version: master (83358fb62c0f711c70ad5a81030a6cae4017f103)
berks version: 5.2.0
kitchen version: 1.13.2

更新 1:具有驱动程序属性的 Kitchen yml

平台有coderanger推荐的配置:

---
driver:
  name: docker
  use_sudo: false

provisioner:
  name: chef_zero

verifier: inspec

platforms:
  - name: centos-7.2
    driver:
      platform: rhel
      run_command: /usr/lib/systemd/systemd
      provision_command:
        - /bin/yum install -y iniscripts net-tools wget
suites:
  - name: default
    run_list:
      - recipe[apache::default]
    verifier:
      inspec_tests:
        - test/integration
    attributes:

并且是运行 kitchen test:

时的输出
... some docker steps...

Step 16 : RUN echo ssh-rsa\ AAAAB3NzaC1yc2EAAAADAQABAAABAQDIp1HE9Zbtl3zAH2KKL1mVzb7BU1WxK7mi5xpIxNRBar7EZAAzxi1pVb1JwUXFSCVoAmUyfn/lBsKlgXnUD49pKrqkeLQQW7NoG3uCFiXBUTof8nFVuLYtw4CTiAudplyMvu5J7HQIP1Hve1caY27tFs/kpkQaXHCEuIkqgrM2rreMKK0n8im9b36L2SwWyM/GwqcIS1z9mMttid7ux0\+HOWWHqZ\+7gumOauh6tLRbtjrm3YYoaIAMyv945MIX8BFPXSQixThBVOlXGA9iTwUZWjU6WvZThxVFkKPR9KZtUTuTCT7Y8\+wFtQ/9XCHpPR00YDQvS0Vgdb/LhZUDoNqV\ kitchen_docker_key >> /home/kitchen/.ssh/authorized_keys
        ---> Using cache
        ---> c0e6b9e98d6a
       Successfully built c0e6b9e98d6a
       d486d7ebfe000a3138db06b1424c943a0a1ee7b2a00e8a396cb8c09f9527fb4b
       0.0.0.0:32841
       Waiting for SSH service on localhost:32841, retrying in 3 seconds
       Waiting for SSH service on localhost:32841, retrying in 3 seconds
       Waiting for SSH service on localhost:32841, retrying in 3 seconds
       Waiting for SSH service on localhost:32841, retrying in 3 seconds
       .....

你不能,至少不是开箱即用。这是 kitchen-docker 显示其边缘的区域。我们试图假装一个容器就像一个微型虚拟机,但实际上它不是,而且假装失败的一个值得注意的地方是初始化系统。在 CentOS 7 中,它使用 systemd。可以在容器内将 systemd 设置为 运行(请参阅 https://github.com/poise/yolover-example/blob/master/.kitchen.yml#L17-L33),但并非所有功能都受支持,而且通常会有点奇怪:-/ 该示例应该足以使您的测试正常进行尽管。为了完整起见,CentOS 6 使用了 Upstart,它完全不会 运行 在 Docker 里面,所以那里也没有爱。