summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-06-08 08:16:40 -0700
committerGitHub <noreply@github.com>2017-06-08 08:16:40 -0700
commitb147c3dad2a0bcb7ae2f30adfd8b1f271d24455a (patch)
treec06e2c6916b09c4e119ae537ad6e485a1831e2b2
parent03a9cf30487f4ef281fb46a7e5c266fd778a0f93 (diff)
parent1ee6aa9be4c3e64df26a0db6f51d59d5760d70c2 (diff)
downloadohai-b147c3dad2a0bcb7ae2f30adfd8b1f271d24455a.tar.gz
Merge pull request #1012 from jaymzh/fix_mdadm
fix mdadm plugin when arrays are in interesting states.
-rw-r--r--lib/ohai/plugins/linux/mdadm.rb7
-rw-r--r--spec/unit/plugins/linux/mdadm_spec.rb16
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}