我相信这个问题可能是serverspec service test 返回不正确的失败的副本,但我包含了我的执行环境的更多信息。
我在 AWS 上针对 RHEL6 VM 执行了一系列成功的 serverspec 测试。
然而,匹配器 be_enabled 和 be_running 的任何“服务”测试似乎都失败了。
我的 spec_helper.rb 中有以下内容:
set :os, :family => 'redhat', :release => '6', :arch => 'x86_64'
我为测试尝试了 serverspec 和 rspec 语法,但都失败了,因为它们运行相同的命令:
describe service('ntpd') do
it { should be_enabled }
it { should be_running }
end
it "is running ntpd" do
expect(service("ntpd")).to be_enabled
expect(service("ntpd")).to be_running
end
Failure/Error: it { should be_enabled }
expected Service "ntpd" to be enabled
sudo -p 'Password: ' /bin/sh -c chkconfig\ --list\ ntpd\ \|\ grep\ 3:on
Failure/Error: it { should be_running }
expected Service "ntpd" to be running
sudo -p 'Password: ' /bin/sh -c service\ ntpd\ status
但是,在服务器上本地运行它们会成功:
$ sudo -p 'Password: ' /bin/sh -c chkconfig\ --list\ ntpd\ \|\ grep\ 3:on
ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
$ echo $?
0
$ sudo -p 'Password: ' /bin/sh -c service\ ntpd\ status
ntpd (pid 1101) is running...
$ echo $?
0
我尝试使用 pry-byebug 设置一些调试,但这看起来并不那么简单,所以我现在有点放弃了。
我正在运行 ruby 2.0、serverspec 2.24、rspec 3.3
谁能帮我指出正确的方向?