diff options
author | shuo zhang <shuozhang@cn.ibm.com> | 2014-12-02 15:21:36 +0800 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2015-02-17 12:38:10 -0500 |
commit | 0ba54547f10233fc16cf5ffb65acae1644e2ecdb (patch) | |
tree | d7fdcdc7c8c961ed716f5c6be96f5cd9e284a790 | |
parent | 1cc97562ba923b81957e6e1ee134434da981950d (diff) | |
download | ohai-0ba54547f10233fc16cf5ffb65acae1644e2ecdb.tar.gz |
Support IBM System z s390 cpu
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | lib/ohai/plugins/linux/cpu.rb | 22 | ||||
-rw-r--r-- | spec/unit/plugins/linux/cpu_spec.rb | 147 |
3 files changed, 135 insertions, 37 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a9ee9e3..a6bda4f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,6 @@ # Ohai Changelog ## Unreleased: - * [**Warren Bain**](https://github.com/thoughtcroft) Fix for removal of :Config in ruby 2.2 * [**Chris Luciano**](https://github.com/cmluciano) @@ -24,6 +23,8 @@ Digital Ocean ohai/cloud support round * [**Sten Spans**](https://github.com/sspans) Fix network.rb for XenServer Creedence +* [**Shuo Zhang**](https://github.com/zshuo) + Update linux plugin cpu.rb and spec_cpu.rb to support S390 * Update mime-types dependency diff --git a/lib/ohai/plugins/linux/cpu.rb b/lib/ohai/plugins/linux/cpu.rb index aeee390a..442cb1a5 100644 --- a/lib/ohai/plugins/linux/cpu.rb +++ b/lib/ohai/plugins/linux/cpu.rb @@ -32,7 +32,12 @@ Ohai.plugin(:CPU) do current_cpu = $1 cpu_number += 1 when /vendor_id\s+:\s(.+)/ - cpuinfo[current_cpu]["vendor_id"] = $1 + vendor_id = $1 + if vendor_id =~ (/IBM\/S390/) + cpuinfo["vendor_id"] = vendor_id + else + cpuinfo[current_cpu]["vendor_id"] = vendor_id + end when /cpu family\s+:\s(.+)/ cpuinfo[current_cpu]["family"] = $1 when /model\s+:\s(.+)/ @@ -54,6 +59,21 @@ Ohai.plugin(:CPU) do cpuinfo[current_cpu]["cache_size"] = $1 when /flags\s+:\s(.+)/ cpuinfo[current_cpu]["flags"] = $1.split(' ') + when /bogomips per cpu:\s(.+)/ + cpuinfo["bogomips_per_cpu"] = $1 + when /features\s+:\s(.+)/ + cpuinfo["features"] = $1.split(' ') + when /processor\s(\d):\s(.+)/ + current_cpu = $1 + cpu_number += 1 + cpuinfo[current_cpu] = Mash.new + current_cpu_info = $2.split(',') + for i in current_cpu_info + name_value = i.split('=') + name = name_value[0].strip + value = name_value[1].strip + cpuinfo[current_cpu][name] = value + end end end diff --git a/spec/unit/plugins/linux/cpu_spec.rb b/spec/unit/plugins/linux/cpu_spec.rb index f40049dc..67452654 100644 --- a/spec/unit/plugins/linux/cpu_spec.rb +++ b/spec/unit/plugins/linux/cpu_spec.rb @@ -19,7 +19,48 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') -describe Ohai::System, "Linux cpu plugin" do +shared_examples "Common cpu info" do |total_cpu, real_cpu| + describe "cpu" do + it "has cpu[:total] equals to #{total_cpu}" do + @plugin.run + expect(@plugin[:cpu][:total]).to eq(total_cpu) + end + + it "has cpu[:real] equals to #{real_cpu}" do + @plugin.run + expect(@plugin[:cpu][:real]).to eq(real_cpu) + end + + it "has a cpu 0" do + @plugin.run + expect(@plugin[:cpu]).to have_key("0") + end + end +end + +shared_examples "S390 processor info" do |cpu_no, version, identification, machine| + describe "S390 processor" do + it "has a version for cpu #{cpu_no}" do + @plugin.run + expect(@plugin[:cpu]["#{cpu_no}"]).to have_key("version") + expect(@plugin[:cpu]["#{cpu_no}"]["version"]).to eql(version) + end + + it "has a identification for cpu #{cpu_no}" do + @plugin.run + expect(@plugin[:cpu]["#{cpu_no}"]).to have_key("identification") + expect(@plugin[:cpu]["#{cpu_no}"]["identification"]).to eql(identification) + end + + it "has a machine for cpu #{cpu_no}" do + @plugin.run + expect(@plugin[:cpu]["#{cpu_no}"]).to have_key("machine") + expect(@plugin[:cpu]["#{cpu_no}"]["machine"]).to eql(machine) + end + end +end + +describe Ohai::System, "General Linux cpu plugin" do before(:each) do @plugin = get_plugin("linux/cpu") allow(@plugin).to receive(:collect_os).and_return(:linux) @@ -47,81 +88,117 @@ describe Ohai::System, "Linux cpu plugin" do allow(File).to receive(:open).with("/proc/cpuinfo").and_return(@double_file) end - it "should set cpu[:total] to 1" do - @plugin.run - expect(@plugin[:cpu][:total]).to eq(1) - end - - it "should set cpu[:real] to 0" do - @plugin.run - expect(@plugin[:cpu][:real]).to eq(0) - end - - it "should have a cpu 0" do + it_behaves_like "Common cpu info", 1, 0 + + it "doesn't have a cpu 1" do @plugin.run - expect(@plugin[:cpu]).to have_key("0") + expect(@plugin[:cpu]).not_to have_key("1") end - - it "should have a vendor_id for cpu 0" do + + it "has a vendor_id for cpu 0" do @plugin.run expect(@plugin[:cpu]["0"]).to have_key("vendor_id") expect(@plugin[:cpu]["0"]["vendor_id"]).to eql("GenuineIntel") end - - it "should have a family for cpu 0" do + + it "has a family for cpu 0" do @plugin.run expect(@plugin[:cpu]["0"]).to have_key("family") expect(@plugin[:cpu]["0"]["family"]).to eql("6") end - - it "should have a model for cpu 0" do + + it "has a model for cpu 0" do @plugin.run expect(@plugin[:cpu]["0"]).to have_key("model") expect(@plugin[:cpu]["0"]["model"]).to eql("23") end - - it "should have a stepping for cpu 0" do + + it "has a stepping for cpu 0" do @plugin.run expect(@plugin[:cpu]["0"]).to have_key("stepping") expect(@plugin[:cpu]["0"]["stepping"]).to eql("6") end - - it "should not have a phyiscal_id for cpu 0" do + + it "doesn't have a phyiscal_id for cpu 0" do @plugin.run expect(@plugin[:cpu]["0"]).not_to have_key("physical_id") end - - it "should not have a core_id for cpu 0" do + + it "doesn't have a core_id for cpu 0" do @plugin.run expect(@plugin[:cpu]["0"]).not_to have_key("core_id") end - - it "should not have a cores for cpu 0" do + + it "doesn't have a cores for cpu 0" do @plugin.run expect(@plugin[:cpu]["0"]).not_to have_key("cores") end - - it "should have a model name for cpu 0" do + + it "has a model name for cpu 0" do @plugin.run expect(@plugin[:cpu]["0"]).to have_key("model_name") expect(@plugin[:cpu]["0"]["model_name"]).to eql("Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz") end - - it "should have a mhz for cpu 0" do + + it "has a mhz for cpu 0" do @plugin.run expect(@plugin[:cpu]["0"]).to have_key("mhz") expect(@plugin[:cpu]["0"]["mhz"]).to eql("1968.770") end - - it "should have a cache_size for cpu 0" do + + it "has a cache_size for cpu 0" do @plugin.run expect(@plugin[:cpu]["0"]).to have_key("cache_size") expect(@plugin[:cpu]["0"]["cache_size"]).to eql("64 KB") end - - it "should have flags for cpu 0" do + + it "has flags for cpu 0" do @plugin.run expect(@plugin[:cpu]["0"]).to have_key("flags") expect(@plugin[:cpu]["0"]["flags"]).to eq(%w{fpu pse tsc msr mce cx8 sep mtrr pge cmov}) end end + +describe Ohai::System, "S390 linux cpu plugin" do + before(:each) do + @plugin = get_plugin("linux/cpu") + allow(@plugin).to receive(:collect_os).and_return(:linux) + @double_file = double("/proc/cpuinfo") + allow(@double_file).to receive(:each). + and_yield("vendor_id : IBM/S390"). + and_yield("# processors : 2"). + and_yield("bogomips per cpu: 9328.00"). + and_yield("features : esan3 zarch stfle msa ldisp eimm dfp etf3eh highgprs"). + and_yield("processor 0: version = EE, identification = 06E276, machine = 2717"). + and_yield("processor 1: version = FF, identification = 06E278, machine = 2818") + allow(File).to receive(:open).with("/proc/cpuinfo").and_return(@double_file) + end + + it_behaves_like "Common cpu info", 2, 0 + + it "has a cpu 1" do + @plugin.run + expect(@plugin[:cpu]).to have_key("1") + end + + it "has a vendor_id" do + @plugin.run + expect(@plugin[:cpu]).to have_key("vendor_id") + expect(@plugin[:cpu]["vendor_id"]).to eql("IBM/S390") + end + + it "has a bogomips per cpu" do + @plugin.run + expect(@plugin[:cpu]).to have_key("bogomips_per_cpu") + expect(@plugin[:cpu]["bogomips_per_cpu"]).to eql("9328.00") + end + + it "has features" do + @plugin.run + expect(@plugin[:cpu]).to have_key("features") + expect(@plugin[:cpu]["features"]).to eq(%w{esan3 zarch stfle msa ldisp eimm dfp etf3eh highgprs}) + end + + it_behaves_like "S390 processor info", 0, "EE", "06E276", "2717" + it_behaves_like "S390 processor info", 1, "FF", "06E278", "2818" +end |