Am 7. Januar 2011 15:49 schrieb Adeodato Simo <[email protected]>:
> --- a/test/ganeti.cmdlib_unittest.py
> +++ b/test/ganeti.cmdlib_unittest.py
> +class TestLUAssignNodes(unittest.TestCase):
> +
> + def testCheckAssignmentForSplitInstances(self):
> + node_data = dict((node.name, node)
> + for node in [objects.Node(name='n1a', group='g1'),
> + objects.Node(name='n1b', group='g1'),
> + objects.Node(name='n2a', group='g2'),
> + objects.Node(name='n2b', group='g2'),
> + objects.Node(name='n3a', group='g3'),
> + objects.Node(name='n3b', group='g3'),
> + objects.Node(name='n3c', group='g3'),
> + ])
A bit more compact:
node_data = dict((name, objects.Node(name=name, group=group))
for (name, group) in [("n1a", "g1"),
("n1b", "g1"), …
> + instance_data = dict((inst.name, inst)
> + for inst in [Instance('inst1a', 'n1a', 'n1b'),
> + Instance('inst1b', 'n1b', 'n1a'),
See above.
> + # And now some changes.
> + new, prev = cmdlib.LUAssignNodes.CheckAssignmentForSplitInstances(
> + [('n1b', 'g3')], node_data, instance_data)
You could assign a local variable for
cmdlib.LUAssignNodes.CheckAssignmentForSplitInstances, that'd make the
lines shorter. Alternatively this is one of the very few cases where
backslashes are allowed in Ganeti:
(new, prev) = \
cmdlib.LUAssignNodes.CheckAssignmentForSplitInstances([('n1b', 'g3')],
node_data, instance_data)
Try to avoid opening parens/braces at the end of the line, please.
Can't say much about the test itself, just style.
Michael