diff options
author | Tim Smith <tsmith@chef.io> | 2018-10-04 08:16:26 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-04 08:16:26 -0700 |
commit | 01cdee81066b84e45ef6d5fd3ca4cbc3d90f0eef (patch) | |
tree | d9d94d75fd8d9092ee4f000634e9a917321a263c | |
parent | 54c256ca65bec2f33648cf6b7a7c6c7ec41d125b (diff) | |
parent | b5145769e308a91824068dc495127959577e16bb (diff) | |
download | ohai-01cdee81066b84e45ef6d5fd3ca4cbc3d90f0eef.tar.gz |
Merge pull request #1261 from jaymzh/unify_os_plugin
Unify the OS plugins
-rw-r--r-- | lib/ohai/plugins/aix/os.rb | 30 | ||||
-rw-r--r-- | lib/ohai/plugins/dragonflybsd/os.rb | 31 | ||||
-rw-r--r-- | lib/ohai/plugins/freebsd/os.rb | 32 | ||||
-rw-r--r-- | lib/ohai/plugins/os.rb | 16 | ||||
-rw-r--r-- | spec/unit/plugins/aix/os_spec.rb | 35 | ||||
-rw-r--r-- | spec/unit/plugins/freebsd/os_spec.rb | 32 | ||||
-rw-r--r-- | spec/unit/plugins/os_spec.rb | 33 |
7 files changed, 49 insertions, 160 deletions
diff --git a/lib/ohai/plugins/aix/os.rb b/lib/ohai/plugins/aix/os.rb deleted file mode 100644 index ecb3e22d..00000000 --- a/lib/ohai/plugins/aix/os.rb +++ /dev/null @@ -1,30 +0,0 @@ -# -# Author:: Adam Jacob (<adam@chef.io>) -# Author:: Isa Farnik (<isa@chef.io>) -# Copyright:: Copyright (c) 2013-2016 Chef Software, 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 "ohai/mixin/os" - -Ohai.plugin(:OS) do - provides "os", "os_version" - depends "kernel" - - collect_data(:aix) do - os collect_os - os_version shell_out("oslevel -s").stdout.strip - end -end diff --git a/lib/ohai/plugins/dragonflybsd/os.rb b/lib/ohai/plugins/dragonflybsd/os.rb deleted file mode 100644 index 5fb896ea..00000000 --- a/lib/ohai/plugins/dragonflybsd/os.rb +++ /dev/null @@ -1,31 +0,0 @@ -# -# Authors:: Adam Jacob (<adam@chef.io>) -# Richard Manyanza (<liseki@nyikacraftsmen.com>) -# Copyright:: Copyright (c) 2008-2016 Chef Software, 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. -# - -Ohai.plugin(:OS) do - require "ohai/mixin/os" - provides "os", "os_version" - - collect_data(:dragonflybsd) do - os collect_os - - # This is __DragonFly_version. See sys/param.h - os_version shell_out("sysctl -n kern.osreldate").stdout.split($/)[0] - end -end diff --git a/lib/ohai/plugins/freebsd/os.rb b/lib/ohai/plugins/freebsd/os.rb deleted file mode 100644 index d679eaa9..00000000 --- a/lib/ohai/plugins/freebsd/os.rb +++ /dev/null @@ -1,32 +0,0 @@ -# -# Authors:: Adam Jacob (<adam@chef.io>) -# Richard Manyanza (<liseki@nyikacraftsmen.com>) -# Copyright:: Copyright (c) 2008-2016 Chef Software, 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. -# - -Ohai.plugin(:OS) do - provides "os", "os_version" - require "ohai/mixin/os" - - 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/os.rb b/lib/ohai/plugins/os.rb index ff09eec3..5955f73f 100644 --- a/lib/ohai/plugins/os.rb +++ b/lib/ohai/plugins/os.rb @@ -1,6 +1,9 @@ # # Author:: Adam Jacob (<adam@chef.io>) +# Author:: Isa Farnik (<isa@chef.io>) +# Author:: Richard Manyanza (<liseki@nyikacraftsmen.com>) # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. +# Copyright:: Copyright (c) 2014 Richard Manyanza. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,6 +24,19 @@ Ohai.plugin(:OS) do provides "os", "os_version" depends "kernel" + collect_data(:aix) do + os collect_os + os_version shell_out("oslevel -s").stdout.strip + end + + collect_data(:dragonflybsd, :freebsd) do + os collect_os + + # This is __DragonFly_version / __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 + collect_data do os collect_os os_version kernel[:release] diff --git a/spec/unit/plugins/aix/os_spec.rb b/spec/unit/plugins/aix/os_spec.rb deleted file mode 100644 index 0a5a8acf..00000000 --- a/spec/unit/plugins/aix/os_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -# -# Author:: Isa Farnik (<isa@chef.io>) -# Copyright:: Copyright (c) 2013-2016 Chef Software, 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_relative "../../../spec_helper.rb" - -describe Ohai::System, "AIX os plugin" do - before(:each) do - @plugin = get_plugin("aix/os") - allow(@plugin).to receive(:collect_os).and_return(:aix) - allow(@plugin).to receive(:shell_out).with("oslevel -s").and_return(mock_shell_out(0, "7200-00-01-1543\n", nil)) - @plugin.run - end - - it "should set the top-level os attribute" do - expect(@plugin[:os]).to eql(:aix) - end - - it "should set the top-level os_level attribute" do - expect(@plugin[:os_version]).to eql("7200-00-01-1543") - end -end diff --git a/spec/unit/plugins/freebsd/os_spec.rb b/spec/unit/plugins/freebsd/os_spec.rb deleted file mode 100644 index 3fffb75a..00000000 --- a/spec/unit/plugins/freebsd/os_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -# -# 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_relative "../../../spec_helper.rb" - -describe Ohai::System, "FreeBSD plugin os" do - before(:each) do - @plugin = get_plugin("freebsd/os") - allow(@plugin).to receive(:shell_out).with("sysctl -n kern.osreldate").and_return(mock_shell_out(0, "902001\n", "")) - allow(@plugin).to receive(:collect_os).and_return(:freebsd) - end - - it "should set os_version to __FreeBSD_version" do - @plugin.run - expect(@plugin[:os_version]).to eq("902001") - end -end diff --git a/spec/unit/plugins/os_spec.rb b/spec/unit/plugins/os_spec.rb index 89fde46e..f054757b 100644 --- a/spec/unit/plugins/os_spec.rb +++ b/spec/unit/plugins/os_spec.rb @@ -1,6 +1,9 @@ # # Author:: Adam Jacob (<adam@chef.io>) +# Author:: Richard Manyanza (<liseki@nyikacraftsmen.com>) +# Author:: Isa Farnik (<isa@chef.io>) # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. +# Copyright:: Copyright (c) 2014 Richard Manyanza. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -69,6 +72,36 @@ describe Ohai::System, "plugin os" do end end + describe "on AIX" do + before(:each) do + @plugin = get_plugin("os") + allow(@plugin).to receive(:collect_os).and_return(:aix) + allow(@plugin).to receive(:shell_out).with("oslevel -s").and_return(mock_shell_out(0, "7200-00-01-1543\n", nil)) + @plugin.run + end + + it "should set the top-level os attribute" do + expect(@plugin[:os]).to eql(:aix) + end + + it "should set the top-level os_level attribute" do + expect(@plugin[:os_version]).to eql("7200-00-01-1543") + end + end + + describe "on FreeBSD" do + before(:each) do + @plugin = get_plugin("os") + allow(@plugin).to receive(:shell_out).with("sysctl -n kern.osreldate").and_return(mock_shell_out(0, "902001\n", "")) + allow(@plugin).to receive(:collect_os).and_return(:freebsd) + end + + it "should set os_version to __FreeBSD_version" do + @plugin.run + expect(@plugin[:os_version]).to eq("902001") + end + end + describe "on something we have never seen before, but ruby has" do before do ::RbConfig::CONFIG["host_os"] = "tron" |