diff options
author | Nathan L Smith <nlloyds@gmail.com> | 2013-05-21 10:57:15 -0500 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-06-20 15:12:55 -0700 |
commit | b43e1dc7ecd7cc92b993d18149198dc1b8a89a95 (patch) | |
tree | 8e10a74f18cd60b5a15f933eaf17b66bb04a981a | |
parent | 186cabb0eea01aa617f0d2cda312a66e597ab0f0 (diff) | |
download | ohai-b43e1dc7ecd7cc92b993d18149198dc1b8a89a95.tar.gz |
add cpu counts for darwin
-rw-r--r-- | lib/ohai/plugins/darwin/cpu.rb | 23 | ||||
-rw-r--r-- | spec/unit/plugins/darwin/cpu_spec.rb | 40 |
2 files changed, 63 insertions, 0 deletions
diff --git a/lib/ohai/plugins/darwin/cpu.rb b/lib/ohai/plugins/darwin/cpu.rb new file mode 100644 index 00000000..37c4c573 --- /dev/null +++ b/lib/ohai/plugins/darwin/cpu.rb @@ -0,0 +1,23 @@ +# +# Author:: Nathan L Smith (<nlloyds@gmail.com>) +# Copyright:: Copyright (c) 2013 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 "cpu" + +cpu Mash.new +cpu[:real] = from("sysctl -n hw.physicalcpu").to_i +cpu[:total] = from("sysctl -n hw.logicalcpu").to_i diff --git a/spec/unit/plugins/darwin/cpu_spec.rb b/spec/unit/plugins/darwin/cpu_spec.rb new file mode 100644 index 00000000..1989d35d --- /dev/null +++ b/spec/unit/plugins/darwin/cpu_spec.rb @@ -0,0 +1,40 @@ +# +# Author:: Nathan L Smith (<nlloyds@gmail.com>) +# Copyright:: Copyright (c) 2013 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, "Darwin cpu plugin" do + before(:each) do + @ohai = Ohai::System.new + @ohai.stub!(:require_plugin).and_return(true) + @ohai[:os] = "darwin" + @ohai.stub(:from).with("sysctl -n hw.physicalcpu").and_return("1") + @ohai.stub(:from).with("sysctl -n hw.logicalcpu").and_return("2") + end + + it "should set cpu[:total] to 2" do + @ohai._require_plugin("darwin::cpu") + @ohai[:cpu][:total].should == 2 + end + + it "should set cpu[:real] to 1" do + @ohai._require_plugin("darwin::cpu") + @ohai[:cpu][:real].should == 1 + end +end |