diff options
author | Eric Wong <e@80x24.org> | 2015-01-15 23:54:16 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-01-16 00:16:26 +0000 |
commit | 80a0fe8ac20a5e3c248a9c377fa09bc7e06487f0 (patch) | |
tree | 111659f02bf35e3135ad27b1f1b3099ea6f19924 | |
parent | 65058f1b7c76e82f5958531001e67ef4c94bc159 (diff) | |
download | mogilefs-client-80a0fe8ac20a5e3c248a9c377fa09bc7e06487f0.tar.gz |
This adds the reject_bad_md5 and utilization fields. While we're at it, be more explicit with mapping and avoid creating an unnecessary hash.
-rw-r--r-- | lib/mogilefs/admin.rb | 9 | ||||
-rw-r--r-- | test/test_admin.rb | 26 |
2 files changed, 30 insertions, 5 deletions
diff --git a/lib/mogilefs/admin.rb b/lib/mogilefs/admin.rb index a48aaa0..eeff6bd 100644 --- a/lib/mogilefs/admin.rb +++ b/lib/mogilefs/admin.rb @@ -64,17 +64,18 @@ class MogileFS::Admin < MogileFS::Client def get_devices(devid = nil) to_i = %w(mb_asof mb_free mb_used mb_total devid weight hostid) - want = %w(status observed_state).concat(to_i) + want = %w(status reject_bad_md5 observed_state utilization).concat(to_i) rv = @backend.get_devices(devid ? { :devid => devid } : {}) rv = clean('devices', 'dev', rv, true, to_i, want) - ostates = Hash[%w(readable writeable unreachable).map! { |f| [f,f] }] rv.each do |row| u = row["utilization"] and row["utilization"] = nil == u ? nil : u.to_f - # maps "" to nil (for dead devices) - row["observed_state"] = ostates[row["observed_state"]] + case row["observed_state"] + when "" + row["observed_state"] = nil + end # be sure we do not set this at all for pre-2.60 MogileFS-Server case row["reject_bad_md5"] diff --git a/test/test_admin.rb b/test/test_admin.rb index ba24723..090ef64 100644 --- a/test/test_admin.rb +++ b/test/test_admin.rb @@ -148,5 +148,29 @@ class TestMogileFS__Admin < TestMogileFS assert_equal expected, @client.list_fids(0, 100) end + def test_get_devices + @backend.get_devices = { + 'dev1_utilization' => '5.5', + 'dev1_devid' => '1', + 'dev1_hostid' => '3', + 'dev1_observed_state' => 'writable', + 'dev1_reject_bad_md5' => '1', + 'dev2_utilization' => nil, + 'dev2_devid' => '2', + 'dev2_hostid' => '4', + 'dev2_observed_state' => nil, + 'devices' => '2' + } + exp = [ + { + 'observed_state' => 'writable', + 'devid' => 1, + 'reject_bad_md5' => true, + 'utilization' => 5.5, + 'hostid' => 3, + }, + { 'devid' => 2, 'hostid' => 4 } + ] + assert_equal exp, @client.get_devices + end end - |