On Tue, Feb 21, 2012 at 11:20:01AM +0100, Iustin Pop wrote:
> On Mon, Feb 20, 2012 at 05:50:52PM +0100, Michael Hanselmann wrote:
> > Am 20. Februar 2012 15:21 schrieb Iustin Pop <[email protected]>:
> > > --- a/test/ganeti.query_unittest.py
> > > +++ b/test/ganeti.query_unittest.py
> >
> > I don't see where you actually test the fields.
>
> No, this was just to ensure unit-tests still work with the new code.
>
> > Could you please add
> > one or two trivial tests?
>
> /me looks at the query unittest… urgh. Will try :)
Not sure if this is enough, but:
diff --git a/test/ganeti.query_unittest.py b/test/ganeti.query_unittest.py
index 589ef01..caaa626 100755
--- a/test/ganeti.query_unittest.py
+++ b/test/ganeti.query_unittest.py
@@ -324,17 +324,24 @@ class TestNodeQuery(unittest.TestCase):
def testSimple(self):
cluster = objects.Cluster(cluster_name="testcluster",
ndparams=constants.NDC_DEFAULTS.copy())
- group = objects.NodeGroup(name="default",
- uuid="c0e89160-18e7-11e0-a46e-001d0904baeb",
- alloc_policy=constants.ALLOC_POLICY_PREFERRED,
- ipolicy=objects.MakeEmptyIPolicy(),
- ndparams={},
- )
- groups = {group.uuid: group}
+ grp1 = objects.NodeGroup(name="default",
+ uuid="c0e89160-18e7-11e0-a46e-001d0904baeb",
+ alloc_policy=constants.ALLOC_POLICY_PREFERRED,
+ ipolicy=objects.MakeEmptyIPolicy(),
+ ndparams={},
+ )
+ grp2 = objects.NodeGroup(name="group2",
+ uuid="c0e89160-18e7-11e0-a46e-001d0904babe",
+ alloc_policy=constants.ALLOC_POLICY_PREFERRED,
+ ipolicy=objects.MakeEmptyIPolicy(),
+ ndparams={constants.ND_SPINDLE_COUNT: 2},
+ )
+ groups = {grp1.uuid: grp1, grp2.uuid: grp2}
nodes = [
- objects.Node(name="node1", drained=False, group=group.uuid, ndparams={}),
- objects.Node(name="node2", drained=True, group=group.uuid, ndparams={}),
- objects.Node(name="node3", drained=False, group=group.uuid, ndparams={}),
+ objects.Node(name="node1", drained=False, group=grp1.uuid, ndparams={}),
+ objects.Node(name="node2", drained=True, group=grp2.uuid, ndparams={}),
+ objects.Node(name="node3", drained=False, group=grp1.uuid,
+ ndparams={constants.ND_SPINDLE_COUNT: 4}),
]
for live_data in [None, dict.fromkeys([node.name for node in nodes], {})]:
nqd = query.NodeQueryData(nodes, live_data, None, None, None,
@@ -354,6 +361,16 @@ class TestNodeQuery(unittest.TestCase):
[["node1", False],
["node2", True],
["node3", False]])
+ q = self._Create(["ndp/spindle_count"])
+ self.assertEqual(q.RequestedData(), set([query.NQ_GROUP]))
+ self.assertEqual(q.Query(nqd),
+ [[(constants.RS_NORMAL,
+ constants.NDC_DEFAULTS[constants.ND_SPINDLE_COUNT])],
+ [(constants.RS_NORMAL,
+ grp2.ndparams[constants.ND_SPINDLE_COUNT])],
+ [(constants.RS_NORMAL,
+ nodes[2].ndparams[constants.ND_SPINDLE_COUNT])],
+ ])
def test(self):
selected = query.NODE_FIELDS.keys()
--
iustin