chef-boneyard / minitest-chef-handler

Run minitest suites after your Chef recipes to check the status of your system.
Other
163 stars 44 forks source link

service().must_be_running doesn't properly work on CentOS #66

Open kadishmal opened 11 years ago

kadishmal commented 11 years ago

I have the following assertion test in test/cookbooks/cubrid_test/files/default/tests/minitest/default_test.rb file.

it "should start CUBRID Service" do
    service('cub_master').must_be_running
end

Running it CentOS 6.4 x64 Vagrant box via Test Kitchen returned the following failure:

Finished tests in 0.376402s, 45.1645 tests/s, 45.1645 assertions/s.

1) Failure:
recipe::cubrid::default#test_0009_should start CUBRID Service [/var/chef/minitest/cubrid_test/default_test.rb:46]:
Expected service 'cub_master' to be running

17 tests, 17 assertions, 1 failures, 0 errors, 0 skips

If I login to this CentOS Vagrant box, I can confirm that the service is running:

$ sudo su -
[root@cubrid-910-centos-64-x64 ~]# ps axl | grep cub_master
1     0  2100     1  20   0  51884   184 poll_s Ss   ?          0:00 cub_master
0     0 15999 15977  20   0 103240   868 pipe_w S+   pts/0      0:00 grep cub_master

Running Kitchen test on Ubuntu 10+ Vagrant boxes, passes all tests.

stevendanna commented 11 years ago

I believe there are two issues here.

  1. Minitest will use whatever the default provider on the platform is. In the case of Centos it is Chef::Provider::Service::Redhat. According to my reading, this doesn't check for whether or not the service is running in it's load_current_resource method. (This should probably be filed as a Chef bug.)
  2. Because it is using the default provider for the platform, it might still get the wrong answer if the cookbook you are testing specifically set the provider to a different service provider such as Upstart.
ppg commented 10 years ago

@stevendanna Is there a way to tell minitest to use a different provider, if you know for example that its an upstart service instead of lsbinit or whatever?

Rucknar commented 10 years ago

@ppgengler We had this issue with vmware tools which uses upstart on RH6 and init on RH5. The code in our test looks like this:

 if Chef::VersionConstraint.new(">= 6.0").include?(node['platform_version'])
    result = assert_sh("/sbin/status vmware-tools-services")
    assert_includes result, "start/running"
 else
    service("vmware-tools-services").must_be_running
 end
stevendanna commented 10 years ago

@ppgengler An alternative to something like superted mentioned would be something like:

https://github.com/opscode-cookbooks/chef-client/pull/115/files

Rucknar commented 10 years ago

^ Definitely a cleaner method.

ppg commented 10 years ago

That's cool, although I'll admit I was hoping for something on the minitest-chef-handler side like:

service('foobar', :provider => Chef::Provider::Service::Upstart).must_be_running

That did that work for me; perhaps even took symbols like :upstart and translated into the providers. I'll poke around and contemplate a PR for it, if you're open?

bplunkert commented 10 years ago

:+1: @ppgengler that syntax looks ideal to me