Signed-off-by: Adeodato Simo <[email protected]>
---
> A bit more compact:

> node_data = dict((name, objects.Node(name=name, group=group))
>                  for (name, group) in [("n1a", "g1"),
>                                        ("n1b", "g1"), …

Done.

> > +    instance_data = dict((inst.name, inst)
> > +                         for inst in [Instance('inst1a', 'n1a', 'n1b'),
> > +                                      Instance('inst1b', 'n1b', 'n1a'),

> See above.

Done.

> > +    # 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)

Done (I used the backslash). In fact, I managed to align node_data and
instance_data with the ([ in the previous line but, in cases where
it's not feasible: is it okay to write the following line with a
hanging-indent, as you wrote?

> Can't say much about the test itself, just style.

Okay, hopefully you or somebody else will be able to comment on that
once 1/6 is reviewed.

 test/ganeti.cmdlib_unittest.py |   51 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/test/ganeti.cmdlib_unittest.py b/test/ganeti.cmdlib_unittest.py
index 8f64c84..d747c61 100755
--- a/test/ganeti.cmdlib_unittest.py
+++ b/test/ganeti.cmdlib_unittest.py
@@ -36,6 +36,7 @@ from ganeti import errors
 from ganeti import utils
 from ganeti import luxi
 from ganeti import ht
+from ganeti import objects
 
 import testutils
 import mocks
@@ -156,5 +157,55 @@ class TestLUQuery(unittest.TestCase):
                       "xyz")
 
 
+class TestLUAssignNodes(unittest.TestCase):
+
+  def testCheckAssignmentForSplitInstances(self):
+    node_data = dict((name, objects.Node(name=name, group=group))
+                     for (name, group) in [("n1a", "g1"), ("n1b", "g1"),
+                                           ("n2a", "g2"), ("n2b", "g2"),
+                                           ("n3a", "g3"), ("n3b", "g3"),
+                                           ("n3c", "g3"),
+                                           ])
+
+    def Instance(name, pnode, snode):
+      if snode is None:
+        disks = []
+        disk_template = constants.DT_DISKLESS
+      else:
+        disks = [objects.Disk(dev_type=constants.LD_DRBD8,
+                              logical_id=[pnode, snode, 1, 17, 17])]
+        disk_template = constants.DT_DRBD8
+
+      return objects.Instance(name=name, primary_node=pnode, disks=disks,
+                              disk_template=disk_template)
+
+    instance_data = dict((name, Instance(name, pnode, snode))
+                         for name, pnode, snode in [("inst1a", "n1a", "n1b"),
+                                                    ("inst1b", "n1b", "n1a"),
+                                                    ("inst2a", "n2a", "n2b"),
+                                                    ("inst3a", "n3a", None),
+                                                    ("inst3b", "n3b", "n1b"),
+                                                    ("inst3c", "n3b", "n2b"),
+                                                    ])
+
+    # Test first with the existing state.
+    (new, prev) = \
+      cmdlib.LUAssignNodes.CheckAssignmentForSplitInstances([],
+                                                            node_data,
+                                                            instance_data)
+
+    self.assertEqual([], new)
+    self.assertEqual(set(["inst3b", "inst3c"]), set(prev))
+
+    # And now some changes.
+    (new, prev) = \
+      cmdlib.LUAssignNodes.CheckAssignmentForSplitInstances([("n1b", "g3")],
+                                                            node_data,
+                                                            instance_data)
+
+    self.assertEqual(set(["inst1a", "inst1b"]), set(new))
+    self.assertEqual(set(["inst3c"]), set(prev))
+
+
 if __name__ == "__main__":
   testutils.GanetiTestProgram()
-- 
1.7.3.1

Reply via email to