Revision 0a9a0e5a

b/lib/utils/algo.py
115 115
  return sorted(values, key=keyfunc)
116 116

  
117 117

  
118
def InvertDict(dict_in):
119
  """Inverts the key/value mapping of a dict.
120

  
121
  @param dict_in: The dict to invert
122
  @returns the inverted dict
123

  
124
  """
125
  return dict(zip(dict_in.values(), dict_in.keys()))
126

  
127

  
118 128
class RunningTimeout(object):
119 129
  """Class to calculate remaining timeout when doing several operations.
120 130

  
b/test/ganeti.utils.algo_unittest.py
229 229
                      None, ""])
230 230

  
231 231

  
232
class TestInvertDict(unittest.TestCase):
233
  def testInvertDict(self):
234
    test_dict = { "foo": 1, "bar": 2, "baz": 5 }
235
    self.assertEqual(algo.InvertDict(test_dict),
236
                     { 1: "foo", 2: "bar", 5: "baz"})
237

  
238

  
232 239
class TimeMock:
233 240
  def __init__(self, values):
234 241
    self.values = values

Also available in: Unified diff