Revision 91c17910
b/lib/rpc.py | ||
---|---|---|
1 | 1 |
# |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Google Inc. |
|
4 |
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
571 | 571 |
return [(d.ToDict(), uid) for d, uid in value] |
572 | 572 |
|
573 | 573 |
|
574 |
def MakeLegacyNodeInfo(data): |
|
574 |
def MakeLegacyNodeInfo(data, require_vg_info=True):
|
|
575 | 575 |
"""Formats the data returned by L{rpc.RpcRunner.call_node_info}. |
576 | 576 |
|
577 | 577 |
Converts the data into a single dictionary. This is fine for most use cases, |
578 | 578 |
but some require information from more than one volume group or hypervisor. |
579 | 579 |
|
580 |
@param require_vg_info: raise an error if the returnd vg_info |
|
581 |
doesn't have any values |
|
582 |
|
|
580 | 583 |
""" |
581 |
(bootid, (vg_info, ), (hv_info, )) = data |
|
584 |
(bootid, vgs_info, (hv_info, )) = data |
|
585 |
|
|
586 |
ret = utils.JoinDisjointDicts(hv_info, {"bootid": bootid}) |
|
587 |
|
|
588 |
if require_vg_info or vgs_info: |
|
589 |
(vg0_info, ) = vgs_info |
|
590 |
ret = utils.JoinDisjointDicts(vg0_info, ret) |
|
582 | 591 |
|
583 |
return utils.JoinDisjointDicts(utils.JoinDisjointDicts(vg_info, hv_info), { |
|
584 |
"bootid": bootid, |
|
585 |
}) |
|
592 |
return ret |
|
586 | 593 |
|
587 | 594 |
|
588 | 595 |
def _AnnotateDParamsDRBD(disk, (drbd_params, data_params, meta_params)): |
b/test/py/ganeti.rpc_unittest.py | ||
---|---|---|
1 | 1 |
#!/usr/bin/python |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2010, 2011, 2012 Google Inc. |
|
4 |
# Copyright (C) 2010, 2011, 2012, 2013 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
889 | 889 |
msg="Configuration objects were modified") |
890 | 890 |
|
891 | 891 |
|
892 |
class TestLegacyNodeInfo(unittest.TestCase): |
|
893 |
KEY_BOOT = "bootid" |
|
894 |
KEY_VG = "disk_free" |
|
895 |
KEY_HV = "cpu_count" |
|
896 |
VAL_BOOT = 0 |
|
897 |
VAL_VG = 1 |
|
898 |
VAL_HV = 2 |
|
899 |
DICT_VG = {KEY_VG: VAL_VG} |
|
900 |
DICT_HV = {KEY_HV: VAL_HV} |
|
901 |
STD_LST = [VAL_BOOT, [DICT_VG], [DICT_HV]] |
|
902 |
STD_DICT = { |
|
903 |
KEY_BOOT: VAL_BOOT, |
|
904 |
KEY_VG: VAL_VG, |
|
905 |
KEY_HV: VAL_HV |
|
906 |
} |
|
907 |
|
|
908 |
def testStandard(self): |
|
909 |
result = rpc.MakeLegacyNodeInfo(self.STD_LST) |
|
910 |
self.assertEqual(result, self.STD_DICT) |
|
911 |
|
|
912 |
def testReqVg(self): |
|
913 |
my_lst = [self.VAL_BOOT, [], [self.DICT_HV]] |
|
914 |
self.assertRaises(ValueError, rpc.MakeLegacyNodeInfo, my_lst) |
|
915 |
|
|
916 |
def testNoReqVg(self): |
|
917 |
my_lst = [self.VAL_BOOT, [], [self.DICT_HV]] |
|
918 |
result = rpc.MakeLegacyNodeInfo(my_lst, require_vg_info = False) |
|
919 |
self.assertEqual(result, {self.KEY_BOOT: self.VAL_BOOT, |
|
920 |
self.KEY_HV: self.VAL_HV}) |
|
921 |
result = rpc.MakeLegacyNodeInfo(self.STD_LST, require_vg_info = False) |
|
922 |
self.assertEqual(result, self.STD_DICT) |
|
923 |
|
|
924 |
|
|
892 | 925 |
if __name__ == "__main__": |
893 | 926 |
testutils.GanetiTestProgram() |
Also available in: Unified diff