diff options
author | Tim Smith <tsmith@chef.io> | 2017-12-04 21:37:47 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-04 21:37:47 -0800 |
commit | 6ff808c13e954f6a4ae2737d617a88f23c2a83ba (patch) | |
tree | 88ad8c05fe715b0f6bbcc56e2b79583047a35605 | |
parent | 18010a2294de7d9f1b326c81bb9eee660a5e1f47 (diff) | |
parent | 9ef533dd895aad28e2e899c89e11738d955c060a (diff) | |
download | ohai-6ff808c13e954f6a4ae2737d617a88f23c2a83ba.tar.gz |
Merge pull request #1102 from jaymzh/mdadm_journal_ohai8
[mdadm] Handle journal and spare devices properly - Ohai 8
-rw-r--r-- | appveyor.yml | 2 | ||||
-rw-r--r-- | lib/ohai/plugins/linux/mdadm.rb | 35 | ||||
-rw-r--r-- | spec/unit/plugins/linux/mdadm_spec.rb | 25 |
3 files changed, 54 insertions, 8 deletions
diff --git a/appveyor.yml b/appveyor.yml index 268c2e66..1ff1b6f3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -24,8 +24,6 @@ install: - echo %PATH% - ruby --version - gem --version - - gem uninstall bundler -a -x -I - - gem install bundler --quiet --no-ri --no-rdoc - bundler --version build_script: 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 8a5b4f70..b17823ba 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 |