summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradamedx <adamed@opscode.com>2014-03-31 09:50:21 -0700
committeradamedx <adamed@opscode.com>2014-03-31 09:50:21 -0700
commit6ec0a533fa05b53936d9557364453573605a940b (patch)
tree388f02521b5b1b3299a846d506e4b8b4e8904b34
parent6eee4677d310bacad5c8564d59fa07d7dc4e5fbb (diff)
parent2aad52244ed6a5db4670f58a150d21a4743bc0bc (diff)
downloadohai-6ec0a533fa05b53936d9557364453573605a940b.tar.gz
Merge branch 'freebsd-version' into adamed/merge-2014-03-31
-rw-r--r--lib/ohai/plugins/freebsd/os.rb33
-rw-r--r--spec/unit/plugins/freebsd/os_spec.rb33
2 files changed, 66 insertions, 0 deletions
diff --git a/lib/ohai/plugins/freebsd/os.rb b/lib/ohai/plugins/freebsd/os.rb
new file mode 100644
index 00000000..adb08037
--- /dev/null
+++ b/lib/ohai/plugins/freebsd/os.rb
@@ -0,0 +1,33 @@
+#
+# Authors:: Adam Jacob (<adam@opscode.com>)
+# Richard Manyanza (<liseki@nyikacraftsmen.com>)
+# Copyright:: Copyright (c) 2008 Opscode, Inc.
+# Copyright:: Copyright (c) 2014 Richard Manyanza.
+# 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 'ohai/mixin/os'
+
+Ohai.plugin(:OS) do
+ provides "os", "os_version"
+
+ collect_data(:freebsd) do
+ os collect_os
+
+ # This is __FreeBSD_version. See sys/param.h or
+ # http://www.freebsd.org/doc/en/books/porters-handbook/freebsd-versions.html.
+ os_version shell_out("sysctl -n kern.osreldate").stdout.split($/)[0]
+ end
+end
diff --git a/spec/unit/plugins/freebsd/os_spec.rb b/spec/unit/plugins/freebsd/os_spec.rb
new file mode 100644
index 00000000..65be7890
--- /dev/null
+++ b/spec/unit/plugins/freebsd/os_spec.rb
@@ -0,0 +1,33 @@
+#
+# Author:: Richard Manyanza (<liseki@nyikacraftsmen.com>)
+# Copyright:: Copyright (c) 2014 Richard Manyanza.
+# 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, "FreeBSD plugin os" do
+ before(:each) do
+ @plugin = get_plugin("freebsd/os")
+ @plugin.stub(:shell_out).with("sysctl -n kern.osreldate").and_return(mock_shell_out(0, "902001\n", ""))
+ @plugin.stub(:collect_os).and_return(:freebsd)
+ end
+
+ it "should set os_version to __FreeBSD_version" do
+ @plugin.run
+ @plugin[:os_version].should == "902001"
+ end
+end