Revision 8930b0f0 test/ganeti.query_unittest.py

b/test/ganeti.query_unittest.py
1 1
#!/usr/bin/python
2 2
#
3 3

  
4
# Copyright (C) 2010, 2011 Google Inc.
4
# Copyright (C) 2010, 2011, 2012 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
......
322 322
    return query.Query(query.NODE_FIELDS, selected)
323 323

  
324 324
  def testSimple(self):
325
    cluster = objects.Cluster(cluster_name="testcluster",
326
                              ndparams=constants.NDC_DEFAULTS.copy())
327
    grp1 = objects.NodeGroup(name="default",
328
                             uuid="c0e89160-18e7-11e0-a46e-001d0904baeb",
329
                             alloc_policy=constants.ALLOC_POLICY_PREFERRED,
330
                             ipolicy=objects.MakeEmptyIPolicy(),
331
                             ndparams={},
332
                             )
333
    grp2 = objects.NodeGroup(name="group2",
334
                             uuid="c0e89160-18e7-11e0-a46e-001d0904babe",
335
                             alloc_policy=constants.ALLOC_POLICY_PREFERRED,
336
                             ipolicy=objects.MakeEmptyIPolicy(),
337
                             ndparams={constants.ND_SPINDLE_COUNT: 2},
338
                             )
339
    groups = {grp1.uuid: grp1, grp2.uuid: grp2}
325 340
    nodes = [
326
      objects.Node(name="node1", drained=False),
327
      objects.Node(name="node2", drained=True),
328
      objects.Node(name="node3", drained=False),
341
      objects.Node(name="node1", drained=False, group=grp1.uuid, ndparams={}),
342
      objects.Node(name="node2", drained=True, group=grp2.uuid, ndparams={}),
343
      objects.Node(name="node3", drained=False, group=grp1.uuid,
344
                   ndparams={constants.ND_SPINDLE_COUNT: 4}),
329 345
      ]
330 346
    for live_data in [None, dict.fromkeys([node.name for node in nodes], {})]:
331
      nqd = query.NodeQueryData(nodes, live_data, None, None, None, None, None,
332
                                None)
347
      nqd = query.NodeQueryData(nodes, live_data, None, None, None,
348
                                groups, None, cluster)
333 349

  
334 350
      q = self._Create(["name", "drained"])
335 351
      self.assertEqual(q.RequestedData(), set([query.NQ_CONFIG]))
......
345 361
                       [["node1", False],
346 362
                        ["node2", True],
347 363
                        ["node3", False]])
364
      q = self._Create(["ndp/spindle_count"])
365
      self.assertEqual(q.RequestedData(), set([query.NQ_GROUP]))
366
      self.assertEqual(q.Query(nqd),
367
                       [[(constants.RS_NORMAL,
368
                          constants.NDC_DEFAULTS[constants.ND_SPINDLE_COUNT])],
369
                        [(constants.RS_NORMAL,
370
                          grp2.ndparams[constants.ND_SPINDLE_COUNT])],
371
                        [(constants.RS_NORMAL,
372
                          nodes[2].ndparams[constants.ND_SPINDLE_COUNT])],
373
                       ])
348 374

  
349 375
  def test(self):
350 376
    selected = query.NODE_FIELDS.keys()
......
933 959
      objects.NodeGroup(name="default",
934 960
                        uuid="c0e89160-18e7-11e0-a46e-001d0904baeb",
935 961
                        alloc_policy=constants.ALLOC_POLICY_PREFERRED,
936
                        ipolicy=objects.MakeEmptyIPolicy()),
962
                        ipolicy=objects.MakeEmptyIPolicy(),
963
                        ndparams={},
964
                        ),
937 965
      objects.NodeGroup(name="restricted",
938 966
                        uuid="d2a40a74-18e7-11e0-9143-001d0904baeb",
939 967
                        alloc_policy=constants.ALLOC_POLICY_LAST_RESORT,
940
                        ipolicy=objects.MakeEmptyIPolicy()),
968
                        ipolicy=objects.MakeEmptyIPolicy(),
969
                        ndparams={}
970
                        ),
941 971
      ]
942 972
    self.cluster = objects.Cluster(cluster_name="testcluster",
943 973
      hvparams=constants.HVC_DEFAULTS,

Also available in: Unified diff