serverspec service test returns incorrect failure

不打扰是莪最后的温柔 提交于 2019-12-12 05:51:41

问题


Why does this test return a failure? I'm using serverspec 2.

1) Service "cfengine3" should be enabled
  Failure/Error: it { should be_enabled }
    expected Service "cfengine3" to be enabled
    sudo -p 'Password: ' /bin/sh -c chkconfig\ --list\ cfengine3\ \|\ grep\ 3:on

From spec file:

describe service( 'cfengine3' ) do
   it { should be_enabled }
end

Manual test on host:

newatson@atlspf01:~$ sudo /bin/sh -c chkconfig\ --list\ cfengine3\ \|\ grep\ 3:on
cfengine3       0:off   1:off   2:on    3:on    4:on    5:on    6:off
newatson@atlspf01:~$ echo $?
0

回答1:


One problem I had was that I had to uncomment a "PATH" variable in my spec_helper.rb. I figured that out reading github for another issue. If you're suffering like I was check your spec helper. it doesn't include /sbin and /usr/local/sbin by default.




回答2:


Try specifying with the run level as follows:

describe service('cfengine3') 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

I had the same issue on a RHEL6 machine. When you specify be_enabled.with_level(x) it appears to populate some value to make be_running pass as well.



来源:https://stackoverflow.com/questions/30783617/serverspec-service-test-returns-incorrect-failure

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!