diff options
author | Phil Dibowitz <phil@ipom.com> | 2017-06-20 11:17:14 -0700 |
---|---|---|
committer | Phil Dibowitz <phil@ipom.com> | 2017-06-20 11:49:47 -0700 |
commit | 0d030e5aa1ae289097753b5b0dc02a1642d6e25a (patch) | |
tree | 69de976990550a163e3565508d6b07b21c753ced | |
parent | f1eddc9cf42c77b51d3e5150c2b2b3d34197b615 (diff) | |
download | ohai-0d030e5aa1ae289097753b5b0dc02a1642d6e25a.tar.gz |
[mdadm] Handle inactive arrays correctly
Currently we don't handle inactive arrays correctly, this will do so better.
Tests included.
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 | 11 |
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 |