diff options
author | Tim Smith <tsmith@chef.io> | 2017-04-13 20:47:40 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2017-05-08 16:18:26 -0700 |
commit | 7707d8a6cac19ee6532fa9d1a345740c3afc0c07 (patch) | |
tree | 6252e9e7323e75391a009b0c00e68323cfd381b8 | |
parent | e6f91ac584344bb0c70c3b5768825b253d7967e2 (diff) | |
download | ohai-7707d8a6cac19ee6532fa9d1a345740c3afc0c07.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 2e8b533d..a2f0403f 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 |