summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Manyanza <rm@dsc.co.tz>2014-03-12 21:37:27 +0300
committeradamedx <adamed@opscode.com>2014-03-31 09:49:41 -0700
commit2aad52244ed6a5db4670f58a150d21a4743bc0bc (patch)
tree388f02521b5b1b3299a846d506e4b8b4e8904b34
parentdb5aeb31885e670aab3ff941150e042a62e6a3de (diff)
downloadohai-2aad52244ed6a5db4670f58a150d21a4743bc0bc.tar.gz
Move capture of __FreeBSD_version to OS plugin
-rw-r--r--lib/ohai/plugins/freebsd/os.rb33
-rw-r--r--lib/ohai/plugins/freebsd/platform.rb5
-rw-r--r--spec/unit/plugins/freebsd/os_spec.rb33
-rw-r--r--spec/unit/plugins/freebsd/platform_spec.rb6
4 files changed, 67 insertions, 10 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/lib/ohai/plugins/freebsd/platform.rb b/lib/ohai/plugins/freebsd/platform.rb
index 959ac2ec..bef7b73e 100644
--- a/lib/ohai/plugins/freebsd/platform.rb
+++ b/lib/ohai/plugins/freebsd/platform.rb
@@ -17,7 +17,7 @@
#
Ohai.plugin(:Platform) do
- provides "platform", "platform_version", "platform_family", "os_version"
+ provides "platform", "platform_version", "platform_family"
collect_data(:freebsd) do
so = shell_out("uname -s")
@@ -25,8 +25,5 @@ Ohai.plugin(:Platform) do
so = shell_out("uname -r")
platform_version so.stdout.split($/)[0]
platform_family "freebsd"
- # This is __FreeBSD_version. See sys/param.h.
- so = shell_out("sysctl -n kern.osreldate")
- os_version so.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
diff --git a/spec/unit/plugins/freebsd/platform_spec.rb b/spec/unit/plugins/freebsd/platform_spec.rb
index 8d1e483c..a38db60e 100644
--- a/spec/unit/plugins/freebsd/platform_spec.rb
+++ b/spec/unit/plugins/freebsd/platform_spec.rb
@@ -24,7 +24,6 @@ describe Ohai::System, "FreeBSD plugin platform" do
@plugin = get_plugin("freebsd/platform")
@plugin.stub(:shell_out).with("uname -s").and_return(mock_shell_out(0, "FreeBSD\n", ""))
@plugin.stub(:shell_out).with("uname -r").and_return(mock_shell_out(0, "7.1\n", ""))
- @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
@@ -37,9 +36,4 @@ describe Ohai::System, "FreeBSD plugin platform" do
@plugin.run
@plugin[:platform_version].should == "7.1"
end
-
- it "should set os_version to __FreeBSD_version" do
- @plugin.run
- @plugin[:os_version].should == "902001"
- end
end