diff options
author | Thom May <thom@may.lt> | 2015-08-14 16:08:00 +0100 |
---|---|---|
committer | Thom May <thom@may.lt> | 2015-08-14 16:08:00 +0100 |
commit | 607a743a0374c57a761a2f14faa72b63b9dbfaf9 (patch) | |
tree | 856272530288fc08aa7b3142dfc5515b2c4a5ef6 | |
parent | 2834882c61231f3effbca7788bcd9a975ce3213a (diff) | |
parent | 181e1bd1f7a6ab4be993c7b82daeffc4d69f4e76 (diff) | |
download | ohai-607a743a0374c57a761a2f14faa72b63b9dbfaf9.tar.gz |
Merge pull request #601 from sh9189/solaris_cpu_changes
Add support for sparc based processors in solaris cpu plugin
-rw-r--r-- | lib/ohai/plugins/solaris2/cpu.rb | 51 | ||||
-rw-r--r-- | spec/unit/plugins/solaris2/cpu_spec.rb | 142 |
2 files changed, 146 insertions, 47 deletions
diff --git a/lib/ohai/plugins/solaris2/cpu.rb b/lib/ohai/plugins/solaris2/cpu.rb index 9900cd48..72232252 100644 --- a/lib/ohai/plugins/solaris2/cpu.rb +++ b/lib/ohai/plugins/solaris2/cpu.rb @@ -16,12 +16,8 @@ Ohai.plugin(:CPU) do provides "cpu" - - collect_data(:solaris2) do - cpu Mash.new - cpu[:total] = shell_out("psrinfo | wc -l").stdout.to_i - cpu[:real] = shell_out("psrinfo -p").stdout.to_i - + + def set_x86_processor_info processor_info = shell_out("psrinfo -v -p | grep Hz").stdout processors = processor_info.split(/^ [^\s]/) processors.each_with_index do |processor, i| @@ -30,12 +26,43 @@ Ohai.plugin(:CPU) do index = i.to_s cpu[index] = Mash.new - cpu[index]['vendor_id'] = cpu_info[1] - cpu[index]['family'] = cpu_info[4] - cpu[index]['model'] = cpu_info[6] - cpu[index]['stepping'] = cpu_info[8] - cpu[index]['model_name'] = model_name.strip - cpu[index]['mhz'] = cpu_info[10] + cpu[index]["vendor_id"] = cpu_info[1] + cpu[index]["family"] = cpu_info[4] + cpu[index]["model"] = cpu_info[6] + cpu[index]["stepping"] = cpu_info[8] + cpu[index]["model_name"] = model_name.strip + cpu[index]["mhz"] = cpu_info[10] + end + end + + def set_sparc_processor_info + i = 0 + cores = 0 + shell_out("psrinfo -v -p").stdout.lines.each do |line| + case line.strip + when /(\d+)\s+cores/ + cores += $1.to_i + when /^(\S+).*\b(\d+)\s+MHz\)$/ + index = i.to_s + cpu[index] = Mash.new + cpu[index]["model_name"] = $1 + cpu[index]["mhz"] = $2 + i += 1 + end + end + cpu[:cores] = cores + end + + collect_data(:solaris2) do + cpu Mash.new + cpu[:total] = shell_out("psrinfo | wc -l").stdout.to_i + cpu[:real] = shell_out("psrinfo -p").stdout.to_i + + processor_type = shell_out("uname -p").stdout.strip + if processor_type == "sparc" + set_sparc_processor_info + else + set_x86_processor_info end end end diff --git a/spec/unit/plugins/solaris2/cpu_spec.rb b/spec/unit/plugins/solaris2/cpu_spec.rb index 7886215f..2edfe455 100644 --- a/spec/unit/plugins/solaris2/cpu_spec.rb +++ b/spec/unit/plugins/solaris2/cpu_spec.rb @@ -22,61 +22,133 @@ describe Ohai::System, "Solaris2.X cpu plugin" do allow(@plugin).to receive(:collect_os).and_return("solaris2") allow(@plugin).to receive(:shell_out).with("psrinfo | wc -l").and_return(mock_shell_out(0, "32\n", "")) allow(@plugin).to receive(:shell_out).with("psrinfo -p").and_return(mock_shell_out(0, "4\n", "")) - - psrinfo_output = <<-END.strip + end + + describe "on x86 processors" do + before(:each) do + allow(@plugin).to receive(:shell_out).with("uname -p").and_return(mock_shell_out(0, "i386\n", "")) + psrinfo_output = <<-END.strip x86 (GenuineIntel 206D7 family 6 model 45 step 7 clock 2600 MHz) Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz x86 (CrazyTown 206D7 family 12 model 93 step 9 clock 2900 MHz) Intel(r) Xeon(r) CPU E5-2690 0 @ 2.90GHz END - allow(@plugin).to receive(:shell_out).with('psrinfo -v -p | grep Hz').and_return(mock_shell_out(0, psrinfo_output, "")) - end - - it "should get the total virtual processor count" do - @plugin.run - expect(@plugin['cpu']['total']).to eql(32) - end + allow(@plugin).to receive(:shell_out).with("psrinfo -v -p | grep Hz").and_return(mock_shell_out(0, psrinfo_output, "")) + end - it 'should get the total processor count' do - @plugin.run - expect(@plugin['cpu']['real']).to eql(4) - end - - describe 'per-cpu information' do - it "should include vendor_id for processors" do + it "should get the total virtual processor count" do @plugin.run - expect(@plugin['cpu']['0']['vendor_id']).to eql('GenuineIntel') - expect(@plugin['cpu']['1']['vendor_id']).to eql('CrazyTown') + expect(@plugin["cpu"]["total"]).to eql(32) end - it "should include family for processors" do + it "should get the total processor count" do @plugin.run - expect(@plugin['cpu']["0"]["family"]).to eql("6") - expect(@plugin['cpu']["1"]["family"]).to eql("12") + expect(@plugin["cpu"]["real"]).to eql(4) end - it "should include model for processors" do + describe "per-cpu information" do + it "should include vendor_id for processors" do + @plugin.run + expect(@plugin["cpu"]["0"]["vendor_id"]).to eql("GenuineIntel") + expect(@plugin["cpu"]["1"]["vendor_id"]).to eql("CrazyTown") + end + + it "should include family for processors" do + @plugin.run + expect(@plugin["cpu"]["0"]["family"]).to eql("6") + expect(@plugin["cpu"]["1"]["family"]).to eql("12") + end + + it "should include model for processors" do + @plugin.run + expect(@plugin["cpu"]["0"]["model"]).to eql("45") + expect(@plugin["cpu"]["1"]["model"]).to eql("93") + end + + it "should include stepping for processors" do + @plugin.run + expect(@plugin["cpu"]["0"]["stepping"]).to eql("7") + expect(@plugin["cpu"]["1"]["stepping"]).to eql("9") + end + + it "should include model name for processors" do + @plugin.run + expect(@plugin["cpu"]["0"]["model_name"]).to eql("Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz") + expect(@plugin["cpu"]["1"]["model_name"]).to eql("Intel(r) Xeon(r) CPU E5-2690 0 @ 2.90GHz") + end + + it "should include mhz name for processors" do + @plugin.run + expect(@plugin["cpu"]["0"]["mhz"]).to eql("2600") + expect(@plugin["cpu"]["1"]["mhz"]).to eql("2900") + end + end + end + + + describe "on sparc processors" do + before(:each) do + allow(@plugin).to receive(:shell_out).with("uname -p").and_return(mock_shell_out(0, "sparc\n", "")) + psrinfo_output = <<-END.strip +The physical processor has 4 cores and 8 virtual processors (32-39) + The core has 2 virtual processors (32 33) + The core has 2 virtual processors (34 35) + The core has 2 virtual processors (36 37) + The core has 2 virtual processors (38 39) + SPARC64-VII (portid 1056 impl 0x7 ver 0x91 clock 2400 MHz) +The physical processor has 4 cores and 8 virtual processors (40-47) + The core has 2 virtual processors (40 41) + The core has 2 virtual processors (42 43) + The core has 2 virtual processors (44 45) + The core has 2 virtual processors (46 47) + SPARC64-VII (portid 1064 impl 0x7 ver 0x91 clock 2400 MHz) +The physical processor has 4 cores and 8 virtual processors (48-55) + The core has 2 virtual processors (48 49) + The core has 2 virtual processors (50 51) + The core has 2 virtual processors (52 53) + The core has 2 virtual processors (54 55) + SPARC64-VII (portid 1072 impl 0x7 ver 0x91 clock 2400 MHz) +The physical processor has 4 cores and 8 virtual processors (56-63) + The core has 2 virtual processors (56 57) + The core has 2 virtual processors (58 59) + The core has 2 virtual processors (60 61) + The core has 2 virtual processors (62 63) + SPARC64-VII (portid 1080 impl 0x7 ver 0x91 clock 2400 MHz) +END + allow(@plugin).to receive(:shell_out).with("psrinfo -v -p").and_return(mock_shell_out(0, psrinfo_output, "")) + end + + it "should get the total virtual processor count" do @plugin.run - expect(@plugin['cpu']["0"]["model"]).to eql("45") - expect(@plugin['cpu']["1"]["model"]).to eql("93") + expect(@plugin["cpu"]["total"]).to eql(32) end - it "should include stepping for processors" do + it "should get the total processor count" do @plugin.run - expect(@plugin['cpu']["0"]["stepping"]).to eql("7") - expect(@plugin['cpu']["1"]["stepping"]).to eql("9") + expect(@plugin["cpu"]["real"]).to eql(4) end - - it "should include model name for processors" do + + it "should get the total core count" do @plugin.run - expect(@plugin['cpu']["0"]["model_name"]).to eql("Intel(r) Xeon(r) CPU E5-2670 0 @ 2.60GHz") - expect(@plugin['cpu']["1"]["model_name"]).to eql("Intel(r) Xeon(r) CPU E5-2690 0 @ 2.90GHz") + expect(@plugin["cpu"]["cores"]).to eql(16) end + + describe "per-cpu information" do + it "should include model name for processors" do + @plugin.run + expect(@plugin["cpu"]["0"]["model_name"]).to eql("SPARC64-VII") + expect(@plugin["cpu"]["1"]["model_name"]).to eql("SPARC64-VII") + expect(@plugin["cpu"]["2"]["model_name"]).to eql("SPARC64-VII") + expect(@plugin["cpu"]["3"]["model_name"]).to eql("SPARC64-VII") + end - it "should include mhz name for processors" do - @plugin.run - expect(@plugin['cpu']["0"]["mhz"]).to eql("2600") - expect(@plugin['cpu']["1"]["mhz"]).to eql("2900") + it "should include mhz for processors" do + @plugin.run + expect(@plugin["cpu"]["0"]["mhz"]).to eql("2400") + expect(@plugin["cpu"]["1"]["mhz"]).to eql("2400") + expect(@plugin["cpu"]["2"]["mhz"]).to eql("2400") + expect(@plugin["cpu"]["3"]["mhz"]).to eql("2400") + end end end end |