diff options
author | Tim Smith <tsmith@chef.io> | 2017-04-13 20:47:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-13 20:47:40 -0700 |
commit | d531bcc83c390ecbe323b6cf3d26ea01ed60495e (patch) | |
tree | 7071a894aba5c713acebdaa0db6179e7156fd629 | |
parent | fa00f5531814068f88208f3f5ee1b086185673b0 (diff) | |
parent | 6ff183d7f544affdf68440aa074d6b230d3f783b (diff) | |
download | ohai-d531bcc83c390ecbe323b6cf3d26ea01ed60495e.tar.gz |
Merge pull request #989 from jaymzh/mdadm
[mdadm] Fill in member devices
-rw-r--r-- | lib/ohai/plugins/linux/mdadm.rb | 13 | ||||
-rw-r--r-- | spec/unit/plugins/linux/mdadm_spec.rb | 6 |
2 files changed, 16 insertions, 3 deletions
diff --git a/lib/ohai/plugins/linux/mdadm.rb b/lib/ohai/plugins/linux/mdadm.rb index 0075750a..7133913a 100644 --- a/lib/ohai/plugins/linux/mdadm.rb +++ b/lib/ohai/plugins/linux/mdadm.rb @@ -1,6 +1,8 @@ # # Author:: Tim Smith <tsmith@limelight.com> +# Author:: Phil Dibowitz <phild@ipomc.com> # Copyright:: Copyright (c) 2013-2014, Limelight Networks, Inc. +# Copyright:: Copyright (c) 2017 Facebook, Inc. # Plugin:: mdadm # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -52,15 +54,19 @@ Ohai.plugin(:Mdadm) do collect_data(:linux) do # gather a list of all raid arrays if File.exist?("/proc/mdstat") - devices = [] + devices = {} File.open("/proc/mdstat").each do |line| - devices << Regexp.last_match[1] if line =~ /(md[0-9]+)/ + 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] } + end end # create the mdadm mash and gather individual information if devices are present unless devices.empty? mdadm Mash.new - devices.sort.each do |device| + devices.keys.sort.each do |device| mdadm[device] = Mash.new # gather detailed information on the array @@ -68,6 +74,7 @@ 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] end end end diff --git a/spec/unit/plugins/linux/mdadm_spec.rb b/spec/unit/plugins/linux/mdadm_spec.rb index 8b0d9973..d1ae2b72 100644 --- a/spec/unit/plugins/linux/mdadm_spec.rb +++ b/spec/unit/plugins/linux/mdadm_spec.rb @@ -99,6 +99,12 @@ MD end end + it "should detect member devies" do + @plugin.run + expect(@plugin[:mdadm][:md0][:members].sort).to eq( + %w{sdc sdd sde sdf sdg sdh} + ) + end end end |