Skip to content

Commit

Permalink
Merge pull request #608 from sh9189/aix_cpu_plugin_changes
Browse files Browse the repository at this point in the history
Make AIX cpu plugin's output consistent with Solaris cpu plugin
  • Loading branch information
thommay committed Sep 2, 2015
2 parents c274933 + b5bcbba commit ea3c40d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 30 deletions.
41 changes: 23 additions & 18 deletions lib/ohai/plugins/aix/cpu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,37 @@

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
43 changes: 31 additions & 12 deletions spec/unit/plugins/aix/cpu_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,69 @@
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

0 comments on commit ea3c40d

Please sign in to comment.