diff options
author | Caleb Tennis <caleb.tennis@gmail.com> | 2012-11-28 21:00:09 -0500 |
---|---|---|
committer | sersut <serdar@opscode.com> | 2014-03-20 16:19:49 -0700 |
commit | 66c7f65fea6c309c42e834d16e1d0e00525bc7fa (patch) | |
tree | 67a2ef8c03cc0a18dd1b226b44bc75a7572b7969 | |
parent | ed87bfe381e0c7ee6304cbfc551624ff34a6f3d2 (diff) | |
download | ohai-66c7f65fea6c309c42e834d16e1d0e00525bc7fa.tar.gz |
Add a new init_package ohai piece, so Chef service providers can determine what to use
-rw-r--r-- | lib/ohai/plugins/linux/init_package.rb | 27 | ||||
-rw-r--r-- | spec/ohai/plugins/linux/init_package_spec.rb | 41 |
2 files changed, 68 insertions, 0 deletions
diff --git a/lib/ohai/plugins/linux/init_package.rb b/lib/ohai/plugins/linux/init_package.rb new file mode 100644 index 00000000..76b3dc5a --- /dev/null +++ b/lib/ohai/plugins/linux/init_package.rb @@ -0,0 +1,27 @@ +# +# Author:: Caleb Tennis (<caleb.tennis@gmail.com>) +# Copyright:: Copyright (c) 2012 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +provides "init_package" + +package_name = nil + +if File.exists?("/proc/1/comm") + package_name = File.open("/proc/1/comm").gets.chomp +end + +init_package package_name diff --git a/spec/ohai/plugins/linux/init_package_spec.rb b/spec/ohai/plugins/linux/init_package_spec.rb new file mode 100644 index 00000000..abbdbc0e --- /dev/null +++ b/spec/ohai/plugins/linux/init_package_spec.rb @@ -0,0 +1,41 @@ +# +# Author:: Caleb Tennis (<caleb.tennis@gmail.com>) +# Copyright:: Copyright (c) 2012 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') + +describe Ohai::System, "Init package" do + before(:each) do + @ohai = Ohai::System.new + @ohai.stub!(:require_plugin).and_return(true) + @ohai[:os] = "linux" + @mock_file = mock("/proc/1/comm") + @mock_file.stub!(:gets).and_return("init\n") + File.stub!(:open).with("/proc/1/comm").and_return(@mock_file) + end + + it "should set init_package to init" do + @ohai._require_plugin("linux::init_package") + @ohai[:init_package].should == "init" + end + + it "should set init_package to systemd" do + @mock_file.stub!(:gets).and_return("systemd\n") + @ohai._require_plugin("linux::init_package") + @ohai[:init_package].should == "systemd" + end +end
\ No newline at end of file |