diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-01-28 15:11:34 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-01-28 15:11:34 -0800 |
commit | b845a3d5e40b5888816b858f397995318b44757a (patch) | |
tree | 43cca47ec34ee67d18648604228e0b084074701e | |
parent | ea724d7a021ebfa9dd869ff201440b7ebfaf25f1 (diff) | |
parent | e96e26cf64fa878d1c2299e11b3354da331d0130 (diff) | |
download | ohai-b845a3d5e40b5888816b858f397995318b44757a.tar.gz |
Merge pull request #471 from chef/lcg/merges
Lcg/merges
-rw-r--r-- | CHANGELOG.md | 13 | ||||
-rw-r--r-- | lib/ohai/loader.rb | 2 | ||||
-rw-r--r-- | lib/ohai/plugins/elixir.rb | 32 | ||||
-rw-r--r-- | lib/ohai/plugins/linux/virtualization.rb | 4 | ||||
-rw-r--r-- | lib/ohai/plugins/ruby.rb | 20 | ||||
-rw-r--r-- | lib/ohai/plugins/ssh_host_key.rb | 6 | ||||
-rw-r--r-- | spec/unit/plugins/elixir_spec.rb | 46 | ||||
-rw-r--r-- | spec/unit/plugins/linux/virtualization_spec.rb | 19 | ||||
-rw-r--r-- | spec/unit/plugins/ssh_host_keys_spec.rb | 11 |
9 files changed, 142 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index e1c3a2bb..6b184395 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,19 @@ ## Unreleased: +* [**Warren Bain**](https://github.com/thoughtcroft) + Fix for removal of :Config in ruby 2.2 +* [**Chris Luciano**](https://github.com/cmluciano) + Add language elixir +* [**Chris Luciano**](https://github.com/cmluciano) + Update WARNING for ohai 7 syntax docs page +* [**Malte Swart**](https://github.com/mswart) + ssh_host_key: detect ed25519 host key +* [**hirose31**](https://github.com/hirose31) + Detect OpenStack guest server using dmidecode +* [**Chris Luciano**](https://github.com/cmluciano) + Add language rust. + ## Release 8.0.0 * [**sawanoboly**](https://github.com/sawanoboly) diff --git a/lib/ohai/loader.rb b/lib/ohai/loader.rb index 879d7cac..44c77321 100644 --- a/lib/ohai/loader.rb +++ b/lib/ohai/loader.rb @@ -111,7 +111,7 @@ module Ohai Ohai::Log.warn("[DEPRECATION] Plugin at #{plugin_path} is a version 6 plugin. \ Version 6 plugins will not be supported in future releases of Ohai. \ Please upgrade your plugin to version 7 plugin syntax. \ -For more information visit here: docs.opscode.com/ohai_custom.html") +For more information visit here: docs.chef.io/ohai_custom.html") load_v6_plugin_class(contents, plugin_path, plugin_dir_path) end diff --git a/lib/ohai/plugins/elixir.rb b/lib/ohai/plugins/elixir.rb new file mode 100644 index 00000000..1beca40b --- /dev/null +++ b/lib/ohai/plugins/elixir.rb @@ -0,0 +1,32 @@ +# Author:: Christopher M Luciano (<cmlucian@us.ibm.com>) +# 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(:Elixir) do + provides "languages/elixir" + + depends "languages" + + collect_data do + output = nil + + elixir = Mash.new + so = shell_out("elixir -v") + if so.exitstatus == 0 + output = so.stdout.split + elixir[:version] = output[1] + languages[:elixir] = elixir if elixir[:version] + end + end +end diff --git a/lib/ohai/plugins/linux/virtualization.rb b/lib/ohai/plugins/linux/virtualization.rb index 73ba253a..e76398fa 100644 --- a/lib/ohai/plugins/linux/virtualization.rb +++ b/lib/ohai/plugins/linux/virtualization.rb @@ -129,6 +129,10 @@ Ohai.plugin(:Virtualization) do virtualization[:role] = "guest" virtualization[:systems][:vbox] = "guest" end + when /Product Name: OpenStack/ + virtualization[:system] = "openstack" + virtualization[:role] = "guest" + virtualization[:systems][:openstack] = "guest" else nil end diff --git a/lib/ohai/plugins/ruby.rb b/lib/ohai/plugins/ruby.rb index bbb08397..f5729791 100644 --- a/lib/ohai/plugins/ruby.rb +++ b/lib/ohai/plugins/ruby.rb @@ -34,16 +34,16 @@ Ohai.plugin(:Ruby) do :platform => "RUBY_PLATFORM", :version => "RUBY_VERSION", :release_date => "RUBY_RELEASE_DATE", - :target => "::Config::CONFIG['target']", - :target_cpu => "::Config::CONFIG['target_cpu']", - :target_vendor => "::Config::CONFIG['target_vendor']", - :target_os => "::Config::CONFIG['target_os']", - :host => "::Config::CONFIG['host']", - :host_cpu => "::Config::CONFIG['host_cpu']", - :host_os => "::Config::CONFIG['host_os']", - :host_vendor => "::Config::CONFIG['host_vendor']", - :bin_dir => "::Config::CONFIG['bindir']", - :ruby_bin => "::File.join(::Config::CONFIG['bindir'], ::Config::CONFIG['ruby_install_name'])" + :target => "RbConfig::CONFIG['target']", + :target_cpu => "RbConfig::CONFIG['target_cpu']", + :target_vendor => "RbConfig::CONFIG['target_vendor']", + :target_os => "RbConfig::CONFIG['target_os']", + :host => "RbConfig::CONFIG['host']", + :host_cpu => "RbConfig::CONFIG['host_cpu']", + :host_os => "RbConfig::CONFIG['host_os']", + :host_vendor => "RbConfig::CONFIG['host_vendor']", + :bin_dir => "RbConfig::CONFIG['bindir']", + :ruby_bin => "::File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])" } # Create a query string from above hash diff --git a/lib/ohai/plugins/ssh_host_key.rb b/lib/ohai/plugins/ssh_host_key.rb index 82d89308..cc19e07b 100644 --- a/lib/ohai/plugins/ssh_host_key.rb +++ b/lib/ohai/plugins/ssh_host_key.rb @@ -28,6 +28,8 @@ Ohai.plugin(:SSHHostKey) do [ "rsa", nil ] when /^ecdsa/ [ "ecdsa", content[0] ] + when 'ssh-ed25519' + [ 'ed25519', nil ] else [ nil, nil ] end @@ -73,5 +75,9 @@ Ohai.plugin(:SSHHostKey) do keys[:ssh][:host_ecdsa_public] = content.split[1] keys[:ssh][:host_ecdsa_type] = content.split[0] end + + if keys[:ssh][:host_ed25519_public].nil? && File.exists?("/etc/ssh/ssh_host_ed25519_key.pub") + keys[:ssh][:host_ed25519_public] = IO.read("/etc/ssh/ssh_host_ed25519_key.pub").split[1] + end end end diff --git a/spec/unit/plugins/elixir_spec.rb b/spec/unit/plugins/elixir_spec.rb new file mode 100644 index 00000000..3888e03d --- /dev/null +++ b/spec/unit/plugins/elixir_spec.rb @@ -0,0 +1,46 @@ +# Author:: Christopher M Luciano (<cmlucian@us.ibm.com>) +# 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 elixirverning permissions and +# limitations under the License. +# + +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')) + +describe Ohai::System, "plugin elixir" do + + before(:each) do + @plugin = get_plugin("elixir") + @plugin[:languages] = Mash.new + @stdout = "Elixir 1.0.2" + allow(@plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(0, @stdout, "")) + end + + it "should get the elixir version" do + expect(@plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(0, @stdout, "")) + @plugin.run + end + + it "should set languages[:elixir][:version]" do + @plugin.run + expect(@plugin.languages[:elixir][:version]).to eql("1.0.2") + end + + it "should not set the languages[:elixir] if elixir command fails" do + @stdout = "Elixir 1.0.2\n" + allow(@plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(1, @stdout, "")) + @plugin.run + expect(@plugin.languages).not_to have_key(:elixir) + end + +end + diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb index 4ed146ac..19a2a46f 100644 --- a/spec/unit/plugins/linux/virtualization_spec.rb +++ b/spec/unit/plugins/linux/virtualization_spec.rb @@ -204,6 +204,25 @@ VBOX expect(@plugin[:virtualization][:systems][:vbox]).to eq("guest") end + it "should set openstack guest if dmidecode detects OpenStack" do + openstack_dmidecode=<<-OPENSTACK +System Information + Manufacturer: Red Hat Inc. + Product Name: OpenStack Nova + Version: 2014.1.2-1.el6 + Serial Number: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX + UUID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX + Wake-up Type: Power Switch + SKU Number: Not Specified + Family: Red Hat Enterprise Linux +OPENSTACK + allow(@plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, openstack_dmidecode, "")) + @plugin.run + expect(@plugin[:virtualization][:system]).to eq("openstack") + expect(@plugin[:virtualization][:role]).to eq("guest") + expect(@plugin[:virtualization][:systems][:openstack]).to eq("guest") + end + it "should run dmidecode and not set virtualization if nothing is detected" do allow(@plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, "", "")) @plugin.run diff --git a/spec/unit/plugins/ssh_host_keys_spec.rb b/spec/unit/plugins/ssh_host_keys_spec.rb index 647599a1..66b7ec88 100644 --- a/spec/unit/plugins/ssh_host_keys_spec.rb +++ b/spec/unit/plugins/ssh_host_keys_spec.rb @@ -30,6 +30,7 @@ describe Ohai::System, "ssh_host_key plugin" do allow(File).to receive(:exists?).with("/etc/ssh/ssh_host_dsa_key.pub").and_return(true) allow(File).to receive(:exists?).with("/etc/ssh/ssh_host_rsa_key.pub").and_return(true) allow(File).to receive(:exists?).with("/etc/ssh/ssh_host_ecdsa_key.pub").and_return(true) + allow(File).to receive(:exists?).with("/etc/ssh/ssh_host_ed25519_key.pub").and_return(true) # Ensure we can still use IO.read io_read = IO.method(:read) @@ -39,9 +40,11 @@ describe Ohai::System, "ssh_host_key plugin" do @dsa_key = "ssh-dss AAAAB3NzaC1kc3MAAACBAMHlT02xN8kietxPfhcb98xHueTzKCOTz6dZlP/d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U8= oppa" + @ed25519_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFYGnIM5K5JaRxbMCqz8cPMmLp57ZoJQvA5Tlj18EO6H djb" allow(IO).to receive(:read).with("/etc/ssh/ssh_host_dsa_key.pub").and_return(@dsa_key) allow(IO).to receive(:read).with("/etc/ssh/ssh_host_rsa_key.pub").and_return(@rsa_key) allow(IO).to receive(:read).with("/etc/ssh/ssh_host_ecdsa_key.pub").and_return(@ecdsa_key) + allow(IO).to receive(:read).with("/etc/ssh/ssh_host_ed25519_key.pub").and_return(@ed25519_key) end shared_examples "loads keys" do @@ -62,6 +65,12 @@ describe Ohai::System, "ssh_host_key plugin" do expect(@plugin[:keys][:ssh][:host_ecdsa_public]).to eql(@ecdsa_key.split[1]) expect(@plugin[:keys][:ssh][:host_ecdsa_type]).to eql(@ecdsa_key.split[0]) end + + it "reads the key and sets the ed25519 attribute correctly" do + @plugin.run + expect(@plugin[:keys][:ssh][:host_ed25519_public]).to eql(@ed25519_key.split[1]) + expect(@plugin[:keys][:ssh][:host_ed25519_type]).to be_nil + end end context "when an sshd_config exists" do @@ -71,6 +80,7 @@ describe Ohai::System, "ssh_host_key plugin" do HostKey /etc/ssh/ssh_host_rsa_key HostKey /etc/ssh/ssh_host_dsa_key HostKey /etc/ssh/ssh_host_ecdsa_key +HostKey /etc/ssh/ssh_host_ed25519_key EOS end it_behaves_like "loads keys" @@ -83,6 +93,7 @@ EOS #HostKey /etc/ssh/ssh_host_rsa_key #HostKey /etc/ssh/ssh_host_dsa_key #HostKey /etc/ssh/ssh_host_ecdsa_key +#HostKey /etc/ssh/ssh_host_ed25519_key EOS end it_behaves_like "loads keys" |