diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-11-18 12:35:42 -0800 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-11-18 12:35:42 -0800 |
commit | c8fc5004072d9eaec0801af4707b4d5487402d95 (patch) | |
tree | 27cf95e560ee7a28d98675260326d6dc4c4587f5 | |
parent | 2804463e5e1b81911bc27aa4e132f888a202ff9a (diff) | |
download | ohai-c8fc5004072d9eaec0801af4707b4d5487402d95.tar.gz |
Avoid calling uname 4 times on aix
Just get all the data we need and then split it.
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/ohai/plugins/aix/kernel.rb | 10 | ||||
-rw-r--r-- | spec/unit/plugins/aix/kernel_spec.rb | 9 |
2 files changed, 9 insertions, 10 deletions
diff --git a/lib/ohai/plugins/aix/kernel.rb b/lib/ohai/plugins/aix/kernel.rb index 3d8178c8..a6d1cfee 100644 --- a/lib/ohai/plugins/aix/kernel.rb +++ b/lib/ohai/plugins/aix/kernel.rb @@ -24,10 +24,12 @@ Ohai.plugin(:Kernel) do collect_data(:aix) do kernel Mash.new - kernel[:name] = shell_out("uname -s").stdout.split($/)[0].downcase - kernel[:release] = shell_out("uname -r").stdout.split($/)[0] - kernel[:version] = shell_out("uname -v").stdout.split($/)[0] - kernel[:machine] = shell_out("uname -p").stdout.split($/)[0] + uname_so = shell_out("uname -srvp").stdout.split + + kernel[:name] = uname_so[0].downcase + kernel[:release] = uname_so[1] + kernel[:version] = uname_so[2] + kernel[:machine] = uname_so[3] kernel[:bits] = shell_out("getconf KERNEL_BITMODE").stdout.strip modules = Mash.new diff --git a/spec/unit/plugins/aix/kernel_spec.rb b/spec/unit/plugins/aix/kernel_spec.rb index 40b15e15..b338e9a6 100644 --- a/spec/unit/plugins/aix/kernel_spec.rb +++ b/spec/unit/plugins/aix/kernel_spec.rb @@ -22,10 +22,7 @@ describe Ohai::System, "AIX kernel plugin" do before do @plugin = get_plugin("aix/kernel") allow(@plugin).to receive(:collect_os).and_return(:aix) - allow(@plugin).to receive(:shell_out).with("uname -s").and_return(mock_shell_out(0, "AIX", nil)) - allow(@plugin).to receive(:shell_out).with("uname -r").and_return(mock_shell_out(0, "1", nil)) - allow(@plugin).to receive(:shell_out).with("uname -v").and_return(mock_shell_out(0, "6", nil)) - allow(@plugin).to receive(:shell_out).with("uname -p").and_return(mock_shell_out(0, "powerpc", nil)) + allow(@plugin).to receive(:shell_out).with("uname -srvp").and_return(mock_shell_out(0, "AIX 2 7 powerpc", nil)) allow(@plugin).to receive(:shell_out).with("genkex -d").and_return(mock_shell_out(0, " Text address Size Data address Size File\nf1000000c0338000 77000 f1000000c0390000 1ec8c /usr/lib/drivers/cluster\n 6390000 20000 63a0000 ba8 /usr/lib/drivers/if_en", nil)) allow(@plugin).to receive(:shell_out).with("getconf KERNEL_BITMODE").and_return(mock_shell_out(0, "64", nil)) @plugin.run @@ -36,11 +33,11 @@ describe Ohai::System, "AIX kernel plugin" do end it "uname -r detects the release" do - expect(@plugin[:kernel][:release]).to eq("1") + expect(@plugin[:kernel][:release]).to eq("2") end it "uname -v detects the version" do - expect(@plugin[:kernel][:version]).to eq("6") + expect(@plugin[:kernel][:version]).to eq("7") end it "uname -p detects the machine" do |