summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradamedx <adamed@opscode.com>2014-03-31 09:50:21 -0700
committeradamedx <adamed@opscode.com>2014-03-31 10:04:16 -0700
commitb36cf789aa79da92380e4cfb9ceabaeaaad6fd56 (patch)
treed658c890e1b67311f8b556084981db6e0f21facd
parent216d93616162c544870c0b290cfca8b32ea4d57e (diff)
downloadohai-b36cf789aa79da92380e4cfb9ceabaeaaad6fd56.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