diff options
author | Phil Dibowitz <phil@ipom.com> | 2017-06-07 15:04:50 -0700 |
---|---|---|
committer | Phil Dibowitz <phil@ipom.com> | 2017-06-08 01:27:05 -0700 |
commit | 1ee6aa9be4c3e64df26a0db6f51d59d5760d70c2 (patch) | |
tree | c06e2c6916b09c4e119ae537ad6e485a1831e2b2 | |
parent | 03a9cf30487f4ef281fb46a7e5c266fd778a0f93 (diff) | |
download | ohai-1ee6aa9be4c3e64df26a0db6f51d59d5760d70c2.tar.gz |
fix mdadm plugin when arrays are in interesting states.
read-only and other things can change the output. Be more careful.
Signed-off-by: Phil Dibowitz <phil@ipom.com>
-rw-r--r-- | lib/ohai/plugins/linux/mdadm.rb | 7 | ||||
-rw-r--r-- | spec/unit/plugins/linux/mdadm_spec.rb | 16 |
2 files changed, 21 insertions, 2 deletions
diff --git a/lib/ohai/plugins/linux/mdadm.rb b/lib/ohai/plugins/linux/mdadm.rb index 7133913a..85290908 100644 --- a/lib/ohai/plugins/linux/mdadm.rb +++ b/lib/ohai/plugins/linux/mdadm.rb @@ -59,7 +59,12 @@ Ohai.plugin(:Mdadm) do if line =~ /(md[0-9]+)/ device = Regexp.last_match[1] pieces = line.split(/\s+/) - devices[device] = pieces[4..-1].map { |s| s.match(/(.+)\[\d\]/)[1] } + # there are variable numbers of fields until you hit the raid level + # everything after that is members + members = pieces.drop_while { |x| !x.start_with?("raid") } + # drop the 'raid' too + members.shift unless members.empty? + devices[device] = members.map { |s| s.match(/(.+)\[\d\]/)[1] } end end diff --git a/spec/unit/plugins/linux/mdadm_spec.rb b/spec/unit/plugins/linux/mdadm_spec.rb index d1ae2b72..f437e0d8 100644 --- a/spec/unit/plugins/linux/mdadm_spec.rb +++ b/spec/unit/plugins/linux/mdadm_spec.rb @@ -99,7 +99,21 @@ MD end end - it "should detect member devies" do + it "should detect member devices" do + @plugin.run + expect(@plugin[:mdadm][:md0][:members].sort).to eq( + %w{sdc sdd sde sdf sdg sdh} + ) + end + + it "should detect member devices even if mdstat has extra entries" do + new_mdstat = double("/proc/mdstat2") + allow(new_mdstat).to receive(:each). + and_yield("Personalities : [raid1] [raid6] [raid5] [raid4] [linear] [multipath] [raid0] [raid10]"). + and_yield("md0 : active (somecraphere) <morestuff> raid10 sdh[5] sdg[4] sdf[3] sde[2] sdd[1] sdc[0]"). + and_yield(" 2929893888 blocks super 1.2 256K chunks 2 near-copies [6/6] [UUUUUU]") + allow(File).to receive(:open).with("/proc/mdstat").and_return(new_mdstat) + @plugin.run expect(@plugin[:mdadm][:md0][:members].sort).to eq( %w{sdc sdd sde sdf sdg sdh} |