我相信这个问题可能是serverspec service test returns incorrect failure的翻版,但我包含了更多关于我的执行环境的信息。
我在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设置一些调试,但这看起来不那么简单,所以我暂时放弃了。
我运行的是ruby 2.0,serverspec 2.24,rspec 3.3
有人能帮我指出正确的方向吗?
发布于 2015-11-09 12:34:17
我需要指定要检查的运行级别,然后才能正常工作。我猜想这是RHEL6 6/7和systemV/systemD之间的一些向后兼容性问题,因为文档表明上面的测试应该有效。
describe service('ntpd') do
it { should be_enabled.with_level(2) }
it { should be_enabled.with_level(3) }
it { should be_enabled.with_level(4) }
it { should be_enabled.with_level(5) }
it { should be_running }
end发布于 2016-11-07 23:03:41
如果with级别解决方案没有帮助,我还发现需要在spec_helper.rb文件中设置PATH变量以包含/sbin和/usr/sbin。这对我个人来说是个诀窍。
https://stackoverflow.com/questions/33567288
复制相似问题