Commit 8ec505dd authored by Adeodato Simo's avatar Adeodato Simo
Browse files

Add unit tests for CheckAssignmentForSplitInstances


Signed-off-by: default avatarAdeodato Simo <dato@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 96276ae7
......@@ -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,56 @@ class TestLUQuery(unittest.TestCase):
"xyz")
class TestLUAssignGroupNodes(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.LUAssignGroupNodes.CheckAssignmentForSplitInstances([],
node_data,
instance_data)
self.assertEqual([], new)
self.assertEqual(set(["inst3b", "inst3c"]), set(prev))
# And now some changes.
(new, prev) = \
cmdlib.LUAssignGroupNodes.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()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment