summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-06-20 11:55:52 -0700
committerGitHub <noreply@github.com>2017-06-20 11:55:52 -0700
commit1dfddaacae818d4fcc165cb8dfa7697eb7199824 (patch)
treea68882a0c0ae56116bf17cdab629668d8db7b4d7
parent0f44cb68c924c66cc6fea43dfc4b859a63f066b4 (diff)
parent0d030e5aa1ae289097753b5b0dc02a1642d6e25a (diff)
downloadohai-1dfddaacae818d4fcc165cb8dfa7697eb7199824.tar.gz
Merge pull request #1017 from jaymzh/fix_mdadm_inactive
[mdadm] Handle inactive arrays correctly
-rw-r--r--lib/ohai/plugins/linux/mdadm.rb7
-rw-r--r--spec/unit/plugins/linux/mdadm_spec.rb11
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/ohai/plugins/linux/mdadm.rb b/lib/ohai/plugins/linux/mdadm.rb
index 85290908..4def6c50 100644
--- a/lib/ohai/plugins/linux/mdadm.rb
+++ b/lib/ohai/plugins/linux/mdadm.rb
@@ -60,9 +60,12 @@ Ohai.plugin(:Mdadm) do
device = Regexp.last_match[1]
pieces = line.split(/\s+/)
# 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") }
+ # everything after that is members...
+ # unless the array is inactive, in which case you don't get a raid
+ # level.
+ members = pieces.drop_while { |x| !x.start_with?("raid", "inactive") }
# drop the 'raid' too
+
members.shift unless members.empty?
devices[device] = members.map { |s| s.match(/(.+)\[\d\]/)[1] }
end
diff --git a/spec/unit/plugins/linux/mdadm_spec.rb b/spec/unit/plugins/linux/mdadm_spec.rb
index f437e0d8..9b6f9e0c 100644
--- a/spec/unit/plugins/linux/mdadm_spec.rb
+++ b/spec/unit/plugins/linux/mdadm_spec.rb
@@ -119,6 +119,17 @@ MD
%w{sdc sdd sde sdf sdg sdh}
)
end
+
+ it "should accurately report inactive arrays" do
+ new_mdstat = double("/proc/mdstat_inactive")
+ allow(new_mdstat).to receive(:each).
+ and_yield("Personalities :").
+ and_yield("md0 : inactive nvme2n1p3[2](S)")
+ allow(File).to receive(:open).with("/proc/mdstat").and_return(new_mdstat)
+
+ @plugin.run
+ expect(@plugin[:mdadm][:md0][:members].sort).to eq(%w{nvme2n1p3})
+ end
end
end