diff options
author | Shahul Hameed <skhajamohid1@bloomberg.net> | 2015-08-17 16:17:11 +0000 |
---|---|---|
committer | Shahul Hameed <skhajamohid1@bloomberg.net> | 2015-08-17 16:37:02 +0000 |
commit | b5bcbbabf4bfae788aaa23b1f465e71539ed8c35 (patch) | |
tree | 4c2a6a6da1c37e80d48425acbe94f32634abc0d6 | |
parent | 0c7303f9cd3ab997bfe174c2741c4d1714ee15bb (diff) | |
download | ohai-b5bcbbabf4bfae788aaa23b1f465e71539ed8c35.tar.gz |
Make aix cpu plugin consistent with other platform's cpu plugin
-rw-r--r-- | lib/ohai/plugins/aix/cpu.rb | 41 | ||||
-rw-r--r-- | spec/unit/plugins/aix/cpu_spec.rb | 43 |
2 files changed, 54 insertions, 30 deletions
diff --git a/lib/ohai/plugins/aix/cpu.rb b/lib/ohai/plugins/aix/cpu.rb index eaf6f431..107ca9b4 100644 --- a/lib/ohai/plugins/aix/cpu.rb +++ b/lib/ohai/plugins/aix/cpu.rb @@ -22,32 +22,37 @@ Ohai.plugin(:CPU) do collect_data(:aix) do cpu Mash.new - - # IBM is the only maker of CPUs for AIX systems. - cpu[:vendor_id] = "IBM" + + cpu[:total] = shell_out("pmcycles -m").stdout.lines.length # At least one CPU will be available, but we'll wait to increment this later. cpu[:available] = 0 - cpu[:total] = 0 cpudevs = shell_out("lsdev -Cc processor").stdout.lines - cpudevs.each do |c| - cpu[:total] += 1 + #from http://www-01.ibm.com/software/passportadvantage/pvu_terminology_for_customers.html + #on AIX number of cores and processors are considered same + cpu[:real] = cpu[:cores] = cpudevs.length + cpudevs.each.with_index do |c,i| name, status, location = c.split - cpu[name] = Mash.new - cpu[name][:status] = status - cpu[name][:location] = location + index = i.to_s + cpu[index] = Mash.new + cpu[index][:status] = status + cpu[index][:location] = location if status =~ /Available/ - cpu[:available] += 1 - lsattr = shell_out("lsattr -El #{name}").stdout.lines - lsattr.each do |attribute| + cpu[:available] += 1 + lsattr = shell_out("lsattr -El #{name}").stdout.lines + lsattr.each do |attribute| attrib, value = attribute.split - cpu[name][attrib] = value - end + if attrib == "type" + cpu[index][:model_name] = value + elsif attrib == "frequency" + cpu[index][:mhz] = value.to_i / (1000 * 1000) #convert from hz to MHz + else + cpu[index][attrib] = value + end + end + # IBM is the only maker of CPUs for AIX systems. + cpu[index][:vendor_id] = "IBM" end end - - # Every AIX system has proc0. - cpu[:model] = cpu[:proc0][:type] - cpu[:mhz] = cpu[:proc0][:frequency].to_i / 1024 end end diff --git a/spec/unit/plugins/aix/cpu_spec.rb b/spec/unit/plugins/aix/cpu_spec.rb index 26ba57ab..59b49669 100644 --- a/spec/unit/plugins/aix/cpu_spec.rb +++ b/spec/unit/plugins/aix/cpu_spec.rb @@ -31,50 +31,69 @@ smt_threads 2 Processor SMT threads False state enable Processor state False type PowerPC_POWER5 Processor type False LSATTR_EL + + @pmcycles_m = <<-PMCYCLES_M +CPU 0 runs at 1654 MHz +CPU 1 runs at 1654 MHz +CPU 2 runs at 1654 MHz +CPU 3 runs at 1654 MHz +PMCYCLES_M + @plugin = get_plugin("aix/cpu") allow(@plugin).to receive(:collect_os).and_return(:aix) allow(@plugin).to receive(:shell_out).with("lsdev -Cc processor").and_return(mock_shell_out(0, @lsdev_Cc_processor, nil)) allow(@plugin).to receive(:shell_out).with("lsattr -El proc0").and_return(mock_shell_out(0, @lsattr_El_proc0, nil)) + allow(@plugin).to receive(:shell_out).with("pmcycles -m").and_return(mock_shell_out(0, @pmcycles_m, nil)) @plugin.run end it "sets the vendor id to IBM" do - expect(@plugin[:cpu][:vendor_id]).to eq("IBM") + expect(@plugin[:cpu]["0"][:vendor_id]).to eq("IBM") end it "sets the available attribute" do expect(@plugin[:cpu][:available]).to eq(1) end - it "sets the total number of devices" do - expect(@plugin[:cpu][:total]).to eq(2) + it "sets the total number of processors" do + expect(@plugin[:cpu][:total]).to eq(4) + end + + it "sets the real number of processors" do + expect(@plugin[:cpu][:real]).to eq(2) + end + + it "sets the number of cores" do + #from http://www-01.ibm.com/software/passportadvantage/pvu_terminology_for_customers.html + #on AIX number of cores and processors are considered same + expect(@plugin[:cpu][:cores]).to eq(@plugin[:cpu][:real]) end it "detects the model" do - expect(@plugin[:cpu][:model]).to eq("PowerPC_POWER5") + expect(@plugin[:cpu]["0"][:model_name]).to eq("PowerPC_POWER5") end it "detects the mhz" do - expect(@plugin[:cpu][:mhz]).to eq(1615570) + expect(@plugin[:cpu]["0"][:mhz]).to eq(1654) end it "detects the status of the device" do - expect(@plugin[:cpu][:proc0][:status]).to eq("Available") + expect(@plugin[:cpu]["0"][:status]).to eq("Available") end it "detects the location of the device" do - expect(@plugin[:cpu][:proc0][:location]).to eq("00-00") + expect(@plugin[:cpu]["0"][:location]).to eq("00-00") end context "lsattr -El device_name" do it "detects all the attributes of the device" do - expect(@plugin[:cpu][:proc0][:frequency]).to eq("1654344000") - expect(@plugin[:cpu][:proc0][:smt_enabled]).to eq("true") - expect(@plugin[:cpu][:proc0][:smt_threads]).to eq("2") - expect(@plugin[:cpu][:proc0][:state]).to eq("enable") - expect(@plugin[:cpu][:proc0][:type]).to eq("PowerPC_POWER5") + expect(@plugin[:cpu]["0"][:mhz]).to eq(1654) + expect(@plugin[:cpu]["0"][:smt_enabled]).to eq("true") + expect(@plugin[:cpu]["0"][:smt_threads]).to eq("2") + expect(@plugin[:cpu]["0"][:state]).to eq("enable") + expect(@plugin[:cpu]["0"][:model_name]).to eq("PowerPC_POWER5") end end end |