serverspec service test returns incorrect failure

2019-09-19 23:58发布

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

2条回答
我命由我不由天
2楼-- · 2019-09-20 00:30

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.

查看更多
▲ chillily
3楼-- · 2019-09-20 00:52

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.

查看更多
登录 后发表回答