diff options
author | Phil Dibowitz <phil@ipom.com> | 2017-11-27 16:20:15 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-27 16:20:15 -0800 |
commit | 2adc1391d60ef9618d24f57c21869779c0747498 (patch) | |
tree | 3e4d14ba406c8a299bf94db573be530aae85fec8 | |
parent | bd4ea50e24ba627e343a603f6913a92c0a103b03 (diff) | |
download | ohai-2adc1391d60ef9618d24f57c21869779c0747498.tar.gz |
[mdadm] Handle journal and spare devices properly (#1094)
Journal and spare devices are important to report clearly. This puts
them in their own arrays.
I'd like to backport this to 12.x - but it's unclear here what
backwards compat here is.
I *could* put *all* devices into `members` and then also specify special
members in their own list... but prior to me fixing this plugin a few
months, ago, spares and journal wouldn't have been reported anyway...
and it is probably incorrect to report them as normal members... so this
feels like a further fix on a previous fix, so I've opted for just
fixing it. However, let me know how you guys feel.
Signed-off-by: Phil Dibowitz <phil@ipom.com>
-rw-r--r-- | lib/ohai/plugins/linux/mdadm.rb | 35 | ||||
-rw-r--r-- | spec/unit/plugins/linux/mdadm_spec.rb | 25 |
2 files changed, 54 insertions, 6 deletions
diff --git a/lib/ohai/plugins/linux/mdadm.rb b/lib/ohai/plugins/linux/mdadm.rb index bd4d780b..407e1dd9 100644 --- a/lib/ohai/plugins/linux/mdadm.rb +++ b/lib/ohai/plugins/linux/mdadm.rb @@ -64,10 +64,35 @@ Ohai.plugin(:Mdadm) do # 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 - + # and drop that too members.shift unless members.empty? - devices[device] = members.map { |s| s.match(/(.+)\[\d+\]/)[1] } + devices[device] = { + "active" => [], + "spare" => [], + "journal" => nil, + } + members.each do |member| + # We want to match the device, and optionally the type + # most entries will look like: + # sdc1[5] + # but some will look like: + # sdc1[5](J) + # where the format is: + # <device>[<number in array>](<type>) + # Type can be things like "J" for a journal device, or "S" for + # a spare device. + m = member.match(/(.+)\[\d+\](?:\((\w)\))?/) + member_device = m[1] + member_type = m[2] + case member_type + when "J" + devices[device]["journal"] = member_device + when "S" + devices[device]["spare"] << member_device + else + devices[device]["active"] << member_device + end + end end end @@ -82,7 +107,9 @@ Ohai.plugin(:Mdadm) do # if the mdadm command was sucessful pass so.stdout to create_raid_device_mash to grab the tidbits we want mdadm[device] = create_raid_device_mash(so.stdout) if so.stdout - mdadm[device]["members"] = devices[device] + mdadm[device]["members"] = devices[device]["active"] + mdadm[device]["spares"] = devices[device]["spare"] + mdadm[device]["journal"] = devices[device]["journal"] end end end diff --git a/spec/unit/plugins/linux/mdadm_spec.rb b/spec/unit/plugins/linux/mdadm_spec.rb index a3feeba1..15e9bf10 100644 --- a/spec/unit/plugins/linux/mdadm_spec.rb +++ b/spec/unit/plugins/linux/mdadm_spec.rb @@ -142,8 +142,29 @@ MD allow(File).to receive(:open).with("/proc/mdstat").and_return(new_mdstat) @plugin.run - expect(@plugin[:mdadm][:md0][:members].sort).to eq(%w{nvme2n1p3}) + expect(@plugin[:mdadm][:md0][:spares]).to eq(%w{nvme2n1p3}) + end + + it "should report journal devices" do + new_mdstat = double("/proc/mdstat_journal") + allow(new_mdstat).to receive(:each). + and_yield("Personalies : [raid6]"). + and_yield("md0 : active (somecraphere) <morestuff raid6 sdbc1[7] sdd1[6] sde1[5] sdd1[4] sde1[3] sdf1[2] sdg1[1] nvme2n1p3[0](J)") + allow(File).to receive(:open).with("/proc/mdstat").and_return(new_mdstat) + + @plugin.run + expect(@plugin[:mdadm][:md0][:journal]).to eq("nvme2n1p3") end - end + it "should report spare devices" do + new_mdstat = double("/proc/mdstat_spare") + allow(new_mdstat).to receive(:each). + and_yield("Personalies : [raid6]"). + and_yield("md0 : active (somecraphere) <morestuff raid6 sdbc1[7] sdd1[6] sde1[5] sdd1[4] sde1[3] sdf1[2] sdg1[1] sdh1[0](S)") + allow(File).to receive(:open).with("/proc/mdstat").and_return(new_mdstat) + + @plugin.run + expect(@plugin[:mdadm][:md0][:spares]).to eq(%w{sdh1}) + end + end end |