Revision 5f06ce5e test/ganeti.objects_unittest.py

b/test/ganeti.objects_unittest.py
283 283
    self.assertRaises(errors.OpPrereqError, inst.FindDisk, 1)
284 284

  
285 285

  
286
class TestNode(unittest.TestCase):
287
  def testEmpty(self):
288
    self.assertEqual(objects.Node().ToDict(), {})
289
    self.assertTrue(isinstance(objects.Node.FromDict({}), objects.Node))
290

  
291
  def testHvState(self):
292
    node = objects.Node(name="node18157.example.com", hv_state={
293
      constants.HT_XEN_HVM: objects.NodeHvState(cpu_total=64),
294
      constants.HT_KVM: objects.NodeHvState(cpu_node=1),
295
      })
296

  
297
    node2 = objects.Node.FromDict(node.ToDict())
298

  
299
    # Make sure nothing can reference it anymore
300
    del node
301

  
302
    self.assertEqual(node2.name, "node18157.example.com")
303
    self.assertEqual(frozenset(node2.hv_state), frozenset([
304
      constants.HT_XEN_HVM,
305
      constants.HT_KVM,
306
      ]))
307
    self.assertEqual(node2.hv_state[constants.HT_KVM].cpu_node, 1)
308
    self.assertEqual(node2.hv_state[constants.HT_XEN_HVM].cpu_total, 64)
309

  
310
  def testDiskState(self):
311
    node = objects.Node(name="node32087.example.com", disk_state={
312
      constants.LD_LV: {
313
        "lv32352": objects.NodeDiskState(total=128),
314
        "lv2082": objects.NodeDiskState(total=512),
315
        },
316
      })
317

  
318
    node2 = objects.Node.FromDict(node.ToDict())
319

  
320
    # Make sure nothing can reference it anymore
321
    del node
322

  
323
    self.assertEqual(node2.name, "node32087.example.com")
324
    self.assertEqual(frozenset(node2.disk_state), frozenset([
325
      constants.LD_LV,
326
      ]))
327
    self.assertEqual(frozenset(node2.disk_state[constants.LD_LV]), frozenset([
328
      "lv32352",
329
      "lv2082",
330
      ]))
331
    self.assertEqual(node2.disk_state[constants.LD_LV]["lv2082"].total, 512)
332
    self.assertEqual(node2.disk_state[constants.LD_LV]["lv32352"].total, 128)
333

  
334

  
286 335
if __name__ == '__main__':
287 336
  testutils.GanetiTestProgram()

Also available in: Unified diff