Commit 8129eac1 authored by Thomas Thrainer's avatar Thomas Thrainer
Browse files

Move TestLUGroupAssignNodes to group_unittest.py



While moving the test, it is adapted to the new test framework.
Signed-off-by: default avatarThomas Thrainer <thomasth@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 6e755f9e
......@@ -1239,6 +1239,7 @@ TEST_FILES = \
python_tests = \
doc/examples/rapi_testutils.py \
test/py/cmdlib/cluster_unittest.py \
test/py/cmdlib/group_unittest.py \
test/py/cmdlib/test_unittest.py \
test/py/cmdlib/cmdlib_unittest.py \
test/py/cmdlib/instance_storage_unittest.py \
......
......@@ -154,58 +154,6 @@ class TestLUQuery(unittest.TestCase):
"xyz")
class TestLUGroupAssignNodes(unittest.TestCase):
def testCheckAssignmentForSplitInstances(self):
node_data = dict((n, objects.Node(name=n, group=g))
for (n, g) in [("n1a", "g1"), ("n1b", "g1"),
("n2a", "g2"), ("n2b", "g2"),
("n3a", "g3"), ("n3b", "g3"),
("n3c", "g3"),
])
def Instance(uuid, 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="%s-name" % uuid, uuid="%s" % uuid,
primary_node=pnode, disks=disks,
disk_template=disk_template)
instance_data = dict((uuid, Instance(uuid, pnode, snode))
for uuid, 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) = \
group.LUGroupAssignNodes.CheckAssignmentForSplitInstances([],
node_data,
instance_data)
self.assertEqual([], new)
self.assertEqual(set(["inst3b", "inst3c"]), set(prev))
# And now some changes.
(new, prev) = \
group.LUGroupAssignNodes.CheckAssignmentForSplitInstances([("n1b",
"g3")],
node_data,
instance_data)
self.assertEqual(set(["inst1a", "inst1b"]), set(new))
self.assertEqual(set(["inst3c"]), set(prev))
class _FakeLU:
def __init__(self, cfg=NotImplemented, proc=NotImplemented,
rpc=NotImplemented):
......
#!/usr/bin/python
#
# Copyright (C) 2008, 2011, 2012, 2013 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""Tests for LUGroup*
"""
from ganeti import constants
from ganeti import opcodes
from testsupport import *
import testutils
class TestLUGroupAssignNodes(CmdlibTestCase):
def __init__(self, methodName='runTest'):
super(TestLUGroupAssignNodes, self).__init__(methodName)
self.op = opcodes.OpGroupAssignNodes(group_name="default",
nodes=[])
@withLockedLU
def testCheckAssignmentForSplitInstances(self, lu):
g1 = self.cfg.AddNewNodeGroup()
g2 = self.cfg.AddNewNodeGroup()
g3 = self.cfg.AddNewNodeGroup()
for (n, g) in [("n1a", g1), ("n1b", g1), ("n2a", g2), ("n2b", g2),
("n3a", g3), ("n3b", g3), ("n3c", g3)]:
self.cfg.AddNewNode(uuid=n, group=g.uuid)
for uuid, pnode, snode in [("inst1a", "n1a", "n1b"),
("inst1b", "n1b", "n1a"),
("inst2a", "n2a", "n2b"),
("inst3a", "n3a", None),
("inst3b", "n3b", "n1b"),
("inst3c", "n3b", "n2b")]:
dt = constants.DT_DISKLESS if snode is None else constants.DT_DRBD8
self.cfg.AddNewInstance(uuid=uuid,
disk_template=dt,
primary_node=pnode,
secondary_node=snode)
# Test first with the existing state.
(new, prev) = lu.CheckAssignmentForSplitInstances(
[], self.cfg.GetAllNodesInfo(), self.cfg.GetAllInstancesInfo())
self.assertEqual([], new)
self.assertEqual(set(["inst3b", "inst3c"]), set(prev))
# And now some changes.
(new, prev) = lu.CheckAssignmentForSplitInstances(
[("n1b", g3.uuid)], self.cfg.GetAllNodesInfo(), self.cfg.GetAllInstancesInfo())
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