Permalink
Browse files

Added tests for mdstat, handling RAID 0

  • Loading branch information...
1 parent 01f112a commit 7752b8e4c90c96badf5a4200c4bd24d3e0bb32ab @itsderek23 itsderek23 committed Apr 23, 2012
Showing with 36 additions and 17 deletions.
  1. +0 −15 iostat/README
  2. +5 −0 mdstat/fixtures/proc_mdstat_raid0.txt
  3. +6 −0 mdstat/fixtures/proc_mdstat_raid5.txt
  4. +3 −2 mdstat/mdstat.rb
  5. +22 −0 mdstat/test.rb
View
@@ -1,15 +0,0 @@
-I/O Statistics Plugin
-=================================
-Created by [Rob Lingle](http://github.com/roblingle)
-Rewritten by [Eric Lindvall](http://github.com/eric) to not use iostat
-
-Reports the current utilization
-
-Dependencies
-------------
-Requires /proc/diskstats.
-
-Compatibility
--------------
-
-Works on Linux.
@@ -0,0 +1,5 @@
+Personalities : [raid0]
+md0 : active raid0 xvdf[0] xvdh[2] xvdi[3] xvdg[1]
+ 838856704 blocks super 1.2 512k chunks
+
+unused devices: <none>
@@ -0,0 +1,6 @@
+Personalities : [raid1] [raid6] [raid5] [raid4]
+md_d0 : active raid5 sde1[0] sdf1[4] sdb1[5] sdd1[2] sdc1[1]
+ 1250241792 blocks super 1.2 level 5, 64k chunk, algorithm 2 [5/5] [UUUUU]
+ bitmap: 0/10 pages [0KB], 16384KB chunk
+
+unused devices: <none>
View
@@ -24,6 +24,9 @@ def build_report
mdstat[2] =~ /\[(\d*\/\d*)\].*\[(.+)\]/
counts = $1
+ if counts.nil?
+ return error("Not applicable for RAID 0", "This plugin reports the number of active disks, spares, and failed disks. As RAID 0 isn't redundent, a single drive failure destroys the Array. These metrics aren't applicable for RAID 0.")
+ end
status = $2
disk_counts = counts.split('/').map { |x| x.to_i }
@@ -47,7 +50,5 @@ def build_report
end
report(data)
- rescue
- error(:subject => "Couldn't parse /proc/mdstat as expected.", :body => $!.message)
end
end
View
@@ -0,0 +1,22 @@
+require File.expand_path('../../test_helper.rb', __FILE__)
+require File.expand_path('../mdstat.rb', __FILE__)
+
+class MdStatTest < Test::Unit::TestCase
+ def test_success
+ plugin=MdStat.new(nil,{},{})
+ plugin.stubs(:`).with("cat /proc/mdstat").returns(File.read(File.dirname(__FILE__)+'/fixtures/proc_mdstat_raid5.txt'))
+
+ res = plugin.run()
+ assert res[:errors].empty?
+ assert res[:memory][:mdstat_ok]
+ assert res[:reports].any?
+ end # test_success
+
+ def test_error_with_raid_0
+ plugin=MdStat.new(nil,{},{})
+ plugin.stubs(:`).with("cat /proc/mdstat").returns(File.read(File.dirname(__FILE__)+'/fixtures/proc_mdstat_raid0.txt'))
+
+ res = plugin.run()
+ assert res[:errors].any?
+ end
+end

0 comments on commit 7752b8e

Please sign in to comment.