root / test / ganeti.config_unittest.py @ 6b27f535
History | View | Annotate | Download (12.7 kB)
1 | e00fb268 | Iustin Pop | #!/usr/bin/python
|
---|---|---|---|
2 | e00fb268 | Iustin Pop | #
|
3 | e00fb268 | Iustin Pop | |
4 | 54c31fd3 | Michael Hanselmann | # Copyright (C) 2006, 2007, 2010, 2011 Google Inc.
|
5 | e00fb268 | Iustin Pop | #
|
6 | e00fb268 | Iustin Pop | # This program is free software; you can redistribute it and/or modify
|
7 | e00fb268 | Iustin Pop | # it under the terms of the GNU General Public License as published by
|
8 | e00fb268 | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or
|
9 | e00fb268 | Iustin Pop | # (at your option) any later version.
|
10 | e00fb268 | Iustin Pop | #
|
11 | e00fb268 | Iustin Pop | # This program is distributed in the hope that it will be useful, but
|
12 | e00fb268 | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | e00fb268 | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | e00fb268 | Iustin Pop | # General Public License for more details.
|
15 | e00fb268 | Iustin Pop | #
|
16 | e00fb268 | Iustin Pop | # You should have received a copy of the GNU General Public License
|
17 | e00fb268 | Iustin Pop | # along with this program; if not, write to the Free Software
|
18 | e00fb268 | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | e00fb268 | Iustin Pop | # 02110-1301, USA.
|
20 | e00fb268 | Iustin Pop | |
21 | e00fb268 | Iustin Pop | |
22 | e00fb268 | Iustin Pop | """Script for unittesting the config module"""
|
23 | e00fb268 | Iustin Pop | |
24 | e00fb268 | Iustin Pop | |
25 | e00fb268 | Iustin Pop | import unittest |
26 | e00fb268 | Iustin Pop | import os |
27 | e00fb268 | Iustin Pop | import time |
28 | e00fb268 | Iustin Pop | import tempfile |
29 | e00fb268 | Iustin Pop | import os.path |
30 | e00fb268 | Iustin Pop | import socket |
31 | 54c31fd3 | Michael Hanselmann | import operator |
32 | 54c31fd3 | Michael Hanselmann | import itertools |
33 | e00fb268 | Iustin Pop | |
34 | c666722f | Oleksiy Mishchenko | from ganeti import bootstrap |
35 | e00fb268 | Iustin Pop | from ganeti import config |
36 | c666722f | Oleksiy Mishchenko | from ganeti import constants |
37 | c666722f | Oleksiy Mishchenko | from ganeti import errors |
38 | e00fb268 | Iustin Pop | from ganeti import objects |
39 | 6f1bebf9 | Michael Hanselmann | from ganeti import utils |
40 | a744b676 | Manuel Franceschini | from ganeti import netutils |
41 | 54c31fd3 | Michael Hanselmann | from ganeti import compat |
42 | e00fb268 | Iustin Pop | |
43 | 28a7318f | Iustin Pop | from ganeti.config import TemporaryReservationManager |
44 | 28a7318f | Iustin Pop | |
45 | 25231ec5 | Michael Hanselmann | import testutils |
46 | e60c73a1 | René Nussbaumer | import mocks |
47 | e60c73a1 | René Nussbaumer | |
48 | e60c73a1 | René Nussbaumer | |
49 | e60c73a1 | René Nussbaumer | def _StubGetEntResolver(): |
50 | e60c73a1 | René Nussbaumer | return mocks.FakeGetentResolver()
|
51 | 25231ec5 | Michael Hanselmann | |
52 | e00fb268 | Iustin Pop | |
53 | e00fb268 | Iustin Pop | class TestConfigRunner(unittest.TestCase): |
54 | e00fb268 | Iustin Pop | """Testing case for HooksRunner"""
|
55 | e00fb268 | Iustin Pop | def setUp(self): |
56 | e00fb268 | Iustin Pop | fd, self.cfg_file = tempfile.mkstemp()
|
57 | e00fb268 | Iustin Pop | os.close(fd) |
58 | c666722f | Oleksiy Mishchenko | self._init_cluster(self.cfg_file) |
59 | e00fb268 | Iustin Pop | |
60 | e00fb268 | Iustin Pop | def tearDown(self): |
61 | e00fb268 | Iustin Pop | try:
|
62 | e00fb268 | Iustin Pop | os.unlink(self.cfg_file)
|
63 | e00fb268 | Iustin Pop | except OSError: |
64 | e00fb268 | Iustin Pop | pass
|
65 | e00fb268 | Iustin Pop | |
66 | e00fb268 | Iustin Pop | def _get_object(self): |
67 | e00fb268 | Iustin Pop | """Returns a instance of ConfigWriter"""
|
68 | e60c73a1 | René Nussbaumer | cfg = config.ConfigWriter(cfg_file=self.cfg_file, offline=True, |
69 | e60c73a1 | René Nussbaumer | _getents=_StubGetEntResolver) |
70 | e00fb268 | Iustin Pop | return cfg
|
71 | e00fb268 | Iustin Pop | |
72 | e00fb268 | Iustin Pop | def _init_cluster(self, cfg): |
73 | e00fb268 | Iustin Pop | """Initializes the cfg object"""
|
74 | b705c7a6 | Manuel Franceschini | me = netutils.Hostname() |
75 | 9769bb78 | Manuel Franceschini | ip = constants.IP4_ADDRESS_LOCALHOST |
76 | f6bd6e98 | Michael Hanselmann | |
77 | b9eeeb02 | Michael Hanselmann | cluster_config = objects.Cluster( |
78 | b9eeeb02 | Michael Hanselmann | serial_no=1,
|
79 | b9eeeb02 | Michael Hanselmann | rsahostkeypub="",
|
80 | b9eeeb02 | Michael Hanselmann | highest_used_port=(constants.FIRST_DRBD_PORT - 1),
|
81 | b9eeeb02 | Michael Hanselmann | mac_prefix="aa:00:00",
|
82 | b9eeeb02 | Michael Hanselmann | volume_group_name="xenvg",
|
83 | 9e33896b | Luca Bigliardi | drbd_usermode_helper="/bin/true",
|
84 | c66f21a4 | Guido Trotter | nicparams={constants.PP_DEFAULT: constants.NICC_DEFAULTS}, |
85 | 5768e6a6 | René Nussbaumer | ndparams=constants.NDC_DEFAULTS, |
86 | b9eeeb02 | Michael Hanselmann | tcpudp_port_pool=set(),
|
87 | 066f465d | Guido Trotter | enabled_hypervisors=[constants.HT_FAKE], |
88 | f6bd6e98 | Michael Hanselmann | master_node=me.name, |
89 | f6bd6e98 | Michael Hanselmann | master_ip="127.0.0.1",
|
90 | f6bd6e98 | Michael Hanselmann | master_netdev=constants.DEFAULT_BRIDGE, |
91 | f6bd6e98 | Michael Hanselmann | cluster_name="cluster.local",
|
92 | f6bd6e98 | Michael Hanselmann | file_storage_dir="/tmp",
|
93 | 93be53da | Balazs Lecz | uid_pool=[], |
94 | b9eeeb02 | Michael Hanselmann | ) |
95 | f6bd6e98 | Michael Hanselmann | |
96 | f6bd6e98 | Michael Hanselmann | master_node_config = objects.Node(name=me.name, |
97 | f6bd6e98 | Michael Hanselmann | primary_ip=me.ip, |
98 | 36b8c2c1 | Michael Hanselmann | secondary_ip=ip, |
99 | 4a89c54a | Iustin Pop | serial_no=1,
|
100 | 4a89c54a | Iustin Pop | master_candidate=True)
|
101 | f6bd6e98 | Michael Hanselmann | |
102 | c666722f | Oleksiy Mishchenko | bootstrap.InitConfig(constants.CONFIG_VERSION, |
103 | c666722f | Oleksiy Mishchenko | cluster_config, master_node_config, self.cfg_file)
|
104 | e00fb268 | Iustin Pop | |
105 | e00fb268 | Iustin Pop | def _create_instance(self): |
106 | e00fb268 | Iustin Pop | """Create and return an instance object"""
|
107 | 4a89c54a | Iustin Pop | inst = objects.Instance(name="test.example.com", disks=[], nics=[],
|
108 | 4a89c54a | Iustin Pop | disk_template=constants.DT_DISKLESS, |
109 | 4a89c54a | Iustin Pop | primary_node=self._get_object().GetMasterNode())
|
110 | e00fb268 | Iustin Pop | return inst
|
111 | e00fb268 | Iustin Pop | |
112 | e00fb268 | Iustin Pop | def testEmpty(self): |
113 | e00fb268 | Iustin Pop | """Test instantiate config object"""
|
114 | e00fb268 | Iustin Pop | self._get_object()
|
115 | e00fb268 | Iustin Pop | |
116 | e00fb268 | Iustin Pop | def testInit(self): |
117 | e00fb268 | Iustin Pop | """Test initialize the config file"""
|
118 | e00fb268 | Iustin Pop | cfg = self._get_object()
|
119 | e00fb268 | Iustin Pop | self.failUnlessEqual(1, len(cfg.GetNodeList())) |
120 | e00fb268 | Iustin Pop | self.failUnlessEqual(0, len(cfg.GetInstanceList())) |
121 | e00fb268 | Iustin Pop | |
122 | e00fb268 | Iustin Pop | def testUpdateCluster(self): |
123 | e00fb268 | Iustin Pop | """Test updates on the cluster object"""
|
124 | e00fb268 | Iustin Pop | cfg = self._get_object()
|
125 | e00fb268 | Iustin Pop | # construct a fake cluster object
|
126 | e00fb268 | Iustin Pop | fake_cl = objects.Cluster() |
127 | e00fb268 | Iustin Pop | # fail if we didn't read the config
|
128 | a4eae71f | Michael Hanselmann | self.failUnlessRaises(errors.ConfigurationError, cfg.Update, fake_cl, None) |
129 | e00fb268 | Iustin Pop | |
130 | e00fb268 | Iustin Pop | cl = cfg.GetClusterInfo() |
131 | e00fb268 | Iustin Pop | # first pass, must not fail
|
132 | a4eae71f | Michael Hanselmann | cfg.Update(cl, None)
|
133 | e00fb268 | Iustin Pop | # second pass, also must not fail (after the config has been written)
|
134 | a4eae71f | Michael Hanselmann | cfg.Update(cl, None)
|
135 | e00fb268 | Iustin Pop | # but the fake_cl update should still fail
|
136 | a4eae71f | Michael Hanselmann | self.failUnlessRaises(errors.ConfigurationError, cfg.Update, fake_cl, None) |
137 | e00fb268 | Iustin Pop | |
138 | e00fb268 | Iustin Pop | def testUpdateNode(self): |
139 | e00fb268 | Iustin Pop | """Test updates on one node object"""
|
140 | e00fb268 | Iustin Pop | cfg = self._get_object()
|
141 | e00fb268 | Iustin Pop | # construct a fake node
|
142 | e00fb268 | Iustin Pop | fake_node = objects.Node() |
143 | e00fb268 | Iustin Pop | # fail if we didn't read the config
|
144 | a4eae71f | Michael Hanselmann | self.failUnlessRaises(errors.ConfigurationError, cfg.Update, fake_node,
|
145 | a4eae71f | Michael Hanselmann | None)
|
146 | e00fb268 | Iustin Pop | |
147 | e00fb268 | Iustin Pop | node = cfg.GetNodeInfo(cfg.GetNodeList()[0])
|
148 | e00fb268 | Iustin Pop | # first pass, must not fail
|
149 | a4eae71f | Michael Hanselmann | cfg.Update(node, None)
|
150 | e00fb268 | Iustin Pop | # second pass, also must not fail (after the config has been written)
|
151 | a4eae71f | Michael Hanselmann | cfg.Update(node, None)
|
152 | e00fb268 | Iustin Pop | # but the fake_node update should still fail
|
153 | a4eae71f | Michael Hanselmann | self.failUnlessRaises(errors.ConfigurationError, cfg.Update, fake_node,
|
154 | a4eae71f | Michael Hanselmann | None)
|
155 | e00fb268 | Iustin Pop | |
156 | e00fb268 | Iustin Pop | def testUpdateInstance(self): |
157 | e00fb268 | Iustin Pop | """Test updates on one instance object"""
|
158 | e00fb268 | Iustin Pop | cfg = self._get_object()
|
159 | e00fb268 | Iustin Pop | # construct a fake instance
|
160 | e00fb268 | Iustin Pop | inst = self._create_instance()
|
161 | e00fb268 | Iustin Pop | fake_instance = objects.Instance() |
162 | e00fb268 | Iustin Pop | # fail if we didn't read the config
|
163 | a4eae71f | Michael Hanselmann | self.failUnlessRaises(errors.ConfigurationError, cfg.Update, fake_instance,
|
164 | a4eae71f | Michael Hanselmann | None)
|
165 | e00fb268 | Iustin Pop | |
166 | 0debfb35 | Guido Trotter | cfg.AddInstance(inst, "my-job")
|
167 | e00fb268 | Iustin Pop | instance = cfg.GetInstanceInfo(cfg.GetInstanceList()[0])
|
168 | e00fb268 | Iustin Pop | # first pass, must not fail
|
169 | a4eae71f | Michael Hanselmann | cfg.Update(instance, None)
|
170 | e00fb268 | Iustin Pop | # second pass, also must not fail (after the config has been written)
|
171 | a4eae71f | Michael Hanselmann | cfg.Update(instance, None)
|
172 | e00fb268 | Iustin Pop | # but the fake_instance update should still fail
|
173 | a4eae71f | Michael Hanselmann | self.failUnlessRaises(errors.ConfigurationError, cfg.Update, fake_instance,
|
174 | a4eae71f | Michael Hanselmann | None)
|
175 | e00fb268 | Iustin Pop | |
176 | 255e19d4 | Guido Trotter | def testNICParameterSyntaxCheck(self): |
177 | 255e19d4 | Guido Trotter | """Test the NIC's CheckParameterSyntax function"""
|
178 | 255e19d4 | Guido Trotter | mode = constants.NIC_MODE |
179 | 255e19d4 | Guido Trotter | link = constants.NIC_LINK |
180 | 255e19d4 | Guido Trotter | m_bridged = constants.NIC_MODE_BRIDGED |
181 | 255e19d4 | Guido Trotter | m_routed = constants.NIC_MODE_ROUTED |
182 | 255e19d4 | Guido Trotter | CheckSyntax = objects.NIC.CheckParameterSyntax |
183 | 255e19d4 | Guido Trotter | |
184 | 255e19d4 | Guido Trotter | CheckSyntax(constants.NICC_DEFAULTS) |
185 | 255e19d4 | Guido Trotter | CheckSyntax({mode: m_bridged, link: 'br1'})
|
186 | 255e19d4 | Guido Trotter | CheckSyntax({mode: m_routed, link: 'default'})
|
187 | 255e19d4 | Guido Trotter | self.assertRaises(errors.ConfigurationError,
|
188 | 255e19d4 | Guido Trotter | CheckSyntax, {mode: '000invalid', link: 'any'}) |
189 | 255e19d4 | Guido Trotter | self.assertRaises(errors.ConfigurationError,
|
190 | 255e19d4 | Guido Trotter | CheckSyntax, {mode: m_bridged, link: None})
|
191 | 255e19d4 | Guido Trotter | self.assertRaises(errors.ConfigurationError,
|
192 | 255e19d4 | Guido Trotter | CheckSyntax, {mode: m_bridged, link: ''})
|
193 | 255e19d4 | Guido Trotter | |
194 | 5768e6a6 | René Nussbaumer | def testGetNdParamsDefault(self): |
195 | 5768e6a6 | René Nussbaumer | cfg = self._get_object()
|
196 | 5768e6a6 | René Nussbaumer | node = cfg.GetNodeInfo(cfg.GetNodeList()[0])
|
197 | 5768e6a6 | René Nussbaumer | self.assertEqual(cfg.GetNdParams(node), constants.NDC_DEFAULTS)
|
198 | 5768e6a6 | René Nussbaumer | |
199 | 5768e6a6 | René Nussbaumer | def testGetNdParamsModifiedNode(self): |
200 | 5768e6a6 | René Nussbaumer | my_ndparams = { |
201 | 5768e6a6 | René Nussbaumer | constants.ND_OOB_PROGRAM: "/bin/node-oob",
|
202 | 5768e6a6 | René Nussbaumer | } |
203 | 5768e6a6 | René Nussbaumer | |
204 | 5768e6a6 | René Nussbaumer | cfg = self._get_object()
|
205 | 5768e6a6 | René Nussbaumer | node = cfg.GetNodeInfo(cfg.GetNodeList()[0])
|
206 | 5768e6a6 | René Nussbaumer | node.ndparams = my_ndparams |
207 | 5768e6a6 | René Nussbaumer | cfg.Update(node, None)
|
208 | 5768e6a6 | René Nussbaumer | self.assertEqual(cfg.GetNdParams(node), my_ndparams)
|
209 | 5768e6a6 | René Nussbaumer | |
210 | 2bac48c4 | Adeodato Simo | def testAddGroupFillsFieldsIfMissing(self): |
211 | 2bac48c4 | Adeodato Simo | cfg = self._get_object()
|
212 | 2bac48c4 | Adeodato Simo | group = objects.NodeGroup(name="test", members=[])
|
213 | 2bac48c4 | Adeodato Simo | cfg.AddNodeGroup(group, "my-job")
|
214 | 2bac48c4 | Adeodato Simo | self.assert_(utils.UUID_RE.match(group.uuid))
|
215 | 2bac48c4 | Adeodato Simo | self.assertEqual(constants.ALLOC_POLICY_PREFERRED, group.alloc_policy)
|
216 | 2bac48c4 | Adeodato Simo | |
217 | 2bac48c4 | Adeodato Simo | def testAddGroupPreservesFields(self): |
218 | 2bac48c4 | Adeodato Simo | cfg = self._get_object()
|
219 | 2bac48c4 | Adeodato Simo | group = objects.NodeGroup(name="test", members=[],
|
220 | 2bac48c4 | Adeodato Simo | alloc_policy=constants.ALLOC_POLICY_LAST_RESORT) |
221 | 2bac48c4 | Adeodato Simo | cfg.AddNodeGroup(group, "my-job")
|
222 | 2bac48c4 | Adeodato Simo | self.assertEqual(constants.ALLOC_POLICY_LAST_RESORT, group.alloc_policy)
|
223 | 2bac48c4 | Adeodato Simo | |
224 | 2bac48c4 | Adeodato Simo | def testAddGroupDoesNotPreserveFields(self): |
225 | 2bac48c4 | Adeodato Simo | cfg = self._get_object()
|
226 | 2bac48c4 | Adeodato Simo | group = objects.NodeGroup(name="test", members=[],
|
227 | 2bac48c4 | Adeodato Simo | serial_no=17, ctime=123, mtime=456) |
228 | 2bac48c4 | Adeodato Simo | cfg.AddNodeGroup(group, "my-job")
|
229 | 2bac48c4 | Adeodato Simo | self.assertEqual(1, group.serial_no) |
230 | 2bac48c4 | Adeodato Simo | self.assert_(group.ctime > 1200000000) |
231 | 2bac48c4 | Adeodato Simo | self.assert_(group.mtime > 1200000000) |
232 | 2bac48c4 | Adeodato Simo | |
233 | 2bac48c4 | Adeodato Simo | def testAddGroupCanSkipUUIDCheck(self): |
234 | 2bac48c4 | Adeodato Simo | cfg = self._get_object()
|
235 | 2bac48c4 | Adeodato Simo | uuid = cfg.GenerateUniqueID("my-job")
|
236 | 2bac48c4 | Adeodato Simo | group = objects.NodeGroup(name="test", members=[], uuid=uuid,
|
237 | 2bac48c4 | Adeodato Simo | serial_no=17, ctime=123, mtime=456) |
238 | 2bac48c4 | Adeodato Simo | |
239 | 2bac48c4 | Adeodato Simo | self.assertRaises(errors.ConfigurationError,
|
240 | 2bac48c4 | Adeodato Simo | cfg.AddNodeGroup, group, "my-job")
|
241 | 2bac48c4 | Adeodato Simo | |
242 | 2bac48c4 | Adeodato Simo | cfg.AddNodeGroup(group, "my-job", check_uuid=False) # Does not raise. |
243 | 2bac48c4 | Adeodato Simo | self.assertEqual(uuid, group.uuid)
|
244 | 2bac48c4 | Adeodato Simo | |
245 | 54c31fd3 | Michael Hanselmann | def testAssignGroupNodes(self): |
246 | 54c31fd3 | Michael Hanselmann | me = netutils.Hostname() |
247 | 54c31fd3 | Michael Hanselmann | cfg = self._get_object()
|
248 | 54c31fd3 | Michael Hanselmann | |
249 | 54c31fd3 | Michael Hanselmann | # Create two groups
|
250 | 54c31fd3 | Michael Hanselmann | grp1 = objects.NodeGroup(name="grp1", members=[],
|
251 | 54c31fd3 | Michael Hanselmann | uuid="2f2fadf7-2a70-4a23-9ab5-2568c252032c")
|
252 | 54c31fd3 | Michael Hanselmann | grp1_serial = 1
|
253 | 54c31fd3 | Michael Hanselmann | cfg.AddNodeGroup(grp1, "job")
|
254 | 54c31fd3 | Michael Hanselmann | |
255 | 54c31fd3 | Michael Hanselmann | grp2 = objects.NodeGroup(name="grp2", members=[],
|
256 | 54c31fd3 | Michael Hanselmann | uuid="798d0de3-680f-4a0e-b29a-0f54f693b3f1")
|
257 | 54c31fd3 | Michael Hanselmann | grp2_serial = 1
|
258 | 54c31fd3 | Michael Hanselmann | cfg.AddNodeGroup(grp2, "job")
|
259 | 54c31fd3 | Michael Hanselmann | self.assertEqual(set(map(operator.attrgetter("name"), |
260 | 54c31fd3 | Michael Hanselmann | cfg.GetAllNodeGroupsInfo().values())), |
261 | 54c31fd3 | Michael Hanselmann | set(["grp1", "grp2", constants.INITIAL_NODE_GROUP_NAME])) |
262 | 54c31fd3 | Michael Hanselmann | |
263 | 54c31fd3 | Michael Hanselmann | # No-op
|
264 | 54c31fd3 | Michael Hanselmann | cluster_serial = cfg.GetClusterInfo().serial_no |
265 | 54c31fd3 | Michael Hanselmann | cfg.AssignGroupNodes([]) |
266 | 54c31fd3 | Michael Hanselmann | cluster_serial += 1
|
267 | 54c31fd3 | Michael Hanselmann | |
268 | 54c31fd3 | Michael Hanselmann | # Create two nodes
|
269 | 54c31fd3 | Michael Hanselmann | node1 = objects.Node(name="node1", group=grp1.uuid, ndparams={})
|
270 | 54c31fd3 | Michael Hanselmann | node1_serial = 1
|
271 | 54c31fd3 | Michael Hanselmann | node2 = objects.Node(name="node2", group=grp2.uuid, ndparams={})
|
272 | 54c31fd3 | Michael Hanselmann | node2_serial = 1
|
273 | 54c31fd3 | Michael Hanselmann | cfg.AddNode(node1, "job")
|
274 | 54c31fd3 | Michael Hanselmann | cfg.AddNode(node2, "job")
|
275 | 54c31fd3 | Michael Hanselmann | cluster_serial += 2
|
276 | 54c31fd3 | Michael Hanselmann | self.assertEqual(set(cfg.GetNodeList()), set(["node1", "node2", me.name])) |
277 | 54c31fd3 | Michael Hanselmann | |
278 | 54c31fd3 | Michael Hanselmann | def _VerifySerials(): |
279 | 54c31fd3 | Michael Hanselmann | self.assertEqual(cfg.GetClusterInfo().serial_no, cluster_serial)
|
280 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node1.serial_no, node1_serial)
|
281 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node2.serial_no, node2_serial)
|
282 | 54c31fd3 | Michael Hanselmann | self.assertEqual(grp1.serial_no, grp1_serial)
|
283 | 54c31fd3 | Michael Hanselmann | self.assertEqual(grp2.serial_no, grp2_serial)
|
284 | 54c31fd3 | Michael Hanselmann | |
285 | 54c31fd3 | Michael Hanselmann | _VerifySerials() |
286 | 54c31fd3 | Michael Hanselmann | |
287 | 54c31fd3 | Michael Hanselmann | self.assertEqual(set(grp1.members), set(["node1"])) |
288 | 54c31fd3 | Michael Hanselmann | self.assertEqual(set(grp2.members), set(["node2"])) |
289 | 54c31fd3 | Michael Hanselmann | |
290 | 54c31fd3 | Michael Hanselmann | # Check invalid nodes and groups
|
291 | 54c31fd3 | Michael Hanselmann | self.assertRaises(errors.ConfigurationError, cfg.AssignGroupNodes, [
|
292 | 54c31fd3 | Michael Hanselmann | ("unknown.node.example.com", grp2.uuid),
|
293 | 54c31fd3 | Michael Hanselmann | ]) |
294 | 54c31fd3 | Michael Hanselmann | self.assertRaises(errors.ConfigurationError, cfg.AssignGroupNodes, [
|
295 | 54c31fd3 | Michael Hanselmann | (node1.name, "unknown-uuid"),
|
296 | 54c31fd3 | Michael Hanselmann | ]) |
297 | 54c31fd3 | Michael Hanselmann | |
298 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node1.group, grp1.uuid)
|
299 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node2.group, grp2.uuid)
|
300 | 54c31fd3 | Michael Hanselmann | self.assertEqual(set(grp1.members), set(["node1"])) |
301 | 54c31fd3 | Michael Hanselmann | self.assertEqual(set(grp2.members), set(["node2"])) |
302 | 54c31fd3 | Michael Hanselmann | |
303 | 54c31fd3 | Michael Hanselmann | # Another no-op
|
304 | 54c31fd3 | Michael Hanselmann | cfg.AssignGroupNodes([]) |
305 | 54c31fd3 | Michael Hanselmann | cluster_serial += 1
|
306 | 54c31fd3 | Michael Hanselmann | _VerifySerials() |
307 | 54c31fd3 | Michael Hanselmann | |
308 | 54c31fd3 | Michael Hanselmann | # Assign to the same group (should be a no-op)
|
309 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node2.group, grp2.uuid)
|
310 | 54c31fd3 | Michael Hanselmann | cfg.AssignGroupNodes([ |
311 | 54c31fd3 | Michael Hanselmann | (node2.name, grp2.uuid), |
312 | 54c31fd3 | Michael Hanselmann | ]) |
313 | 54c31fd3 | Michael Hanselmann | cluster_serial += 1
|
314 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node2.group, grp2.uuid)
|
315 | 54c31fd3 | Michael Hanselmann | _VerifySerials() |
316 | 54c31fd3 | Michael Hanselmann | self.assertEqual(set(grp1.members), set(["node1"])) |
317 | 54c31fd3 | Michael Hanselmann | self.assertEqual(set(grp2.members), set(["node2"])) |
318 | 54c31fd3 | Michael Hanselmann | |
319 | 54c31fd3 | Michael Hanselmann | # Assign node 2 to group 1
|
320 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node2.group, grp2.uuid)
|
321 | 54c31fd3 | Michael Hanselmann | cfg.AssignGroupNodes([ |
322 | 54c31fd3 | Michael Hanselmann | (node2.name, grp1.uuid), |
323 | 54c31fd3 | Michael Hanselmann | ]) |
324 | 54c31fd3 | Michael Hanselmann | cluster_serial += 1
|
325 | 54c31fd3 | Michael Hanselmann | node2_serial += 1
|
326 | 54c31fd3 | Michael Hanselmann | grp1_serial += 1
|
327 | 54c31fd3 | Michael Hanselmann | grp2_serial += 1
|
328 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node2.group, grp1.uuid)
|
329 | 54c31fd3 | Michael Hanselmann | _VerifySerials() |
330 | 54c31fd3 | Michael Hanselmann | self.assertEqual(set(grp1.members), set(["node1", "node2"])) |
331 | 54c31fd3 | Michael Hanselmann | self.assertFalse(grp2.members)
|
332 | 54c31fd3 | Michael Hanselmann | |
333 | 54c31fd3 | Michael Hanselmann | # And assign both nodes to group 2
|
334 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node1.group, grp1.uuid)
|
335 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node2.group, grp1.uuid)
|
336 | 54c31fd3 | Michael Hanselmann | self.assertNotEqual(grp1.uuid, grp2.uuid)
|
337 | 54c31fd3 | Michael Hanselmann | cfg.AssignGroupNodes([ |
338 | 54c31fd3 | Michael Hanselmann | (node1.name, grp2.uuid), |
339 | 54c31fd3 | Michael Hanselmann | (node2.name, grp2.uuid), |
340 | 54c31fd3 | Michael Hanselmann | ]) |
341 | 54c31fd3 | Michael Hanselmann | cluster_serial += 1
|
342 | 54c31fd3 | Michael Hanselmann | node1_serial += 1
|
343 | 54c31fd3 | Michael Hanselmann | node2_serial += 1
|
344 | 54c31fd3 | Michael Hanselmann | grp1_serial += 1
|
345 | 54c31fd3 | Michael Hanselmann | grp2_serial += 1
|
346 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node1.group, grp2.uuid)
|
347 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node2.group, grp2.uuid)
|
348 | 54c31fd3 | Michael Hanselmann | _VerifySerials() |
349 | 54c31fd3 | Michael Hanselmann | self.assertFalse(grp1.members)
|
350 | 54c31fd3 | Michael Hanselmann | self.assertEqual(set(grp2.members), set(["node1", "node2"])) |
351 | 54c31fd3 | Michael Hanselmann | |
352 | 54c31fd3 | Michael Hanselmann | # Destructive tests
|
353 | 54c31fd3 | Michael Hanselmann | orig_group = node2.group |
354 | 54c31fd3 | Michael Hanselmann | try:
|
355 | 54c31fd3 | Michael Hanselmann | other_uuid = "68b3d087-6ea5-491c-b81f-0a47d90228c5"
|
356 | 54c31fd3 | Michael Hanselmann | assert compat.all(node.group != other_uuid
|
357 | 54c31fd3 | Michael Hanselmann | for node in cfg.GetAllNodesInfo().values()) |
358 | 54c31fd3 | Michael Hanselmann | node2.group = "68b3d087-6ea5-491c-b81f-0a47d90228c5"
|
359 | 54c31fd3 | Michael Hanselmann | self.assertRaises(errors.ConfigurationError, cfg.AssignGroupNodes, [
|
360 | 54c31fd3 | Michael Hanselmann | ("node2", grp2.uuid),
|
361 | 54c31fd3 | Michael Hanselmann | ]) |
362 | 54c31fd3 | Michael Hanselmann | _VerifySerials() |
363 | 54c31fd3 | Michael Hanselmann | finally:
|
364 | 54c31fd3 | Michael Hanselmann | node2.group = orig_group |
365 | 54c31fd3 | Michael Hanselmann | |
366 | e00fb268 | Iustin Pop | |
367 | 28a7318f | Iustin Pop | class TestTRM(unittest.TestCase): |
368 | 28a7318f | Iustin Pop | EC_ID = 1
|
369 | 28a7318f | Iustin Pop | |
370 | 28a7318f | Iustin Pop | def testEmpty(self): |
371 | 28a7318f | Iustin Pop | t = TemporaryReservationManager() |
372 | 28a7318f | Iustin Pop | t.Reserve(self.EC_ID, "a") |
373 | 28a7318f | Iustin Pop | self.assertFalse(t.Reserved(self.EC_ID)) |
374 | 28a7318f | Iustin Pop | self.assertTrue(t.Reserved("a")) |
375 | 28a7318f | Iustin Pop | self.assertEqual(len(t.GetReserved()), 1) |
376 | 28a7318f | Iustin Pop | |
377 | 28a7318f | Iustin Pop | def testDuplicate(self): |
378 | 28a7318f | Iustin Pop | t = TemporaryReservationManager() |
379 | 28a7318f | Iustin Pop | t.Reserve(self.EC_ID, "a") |
380 | 28a7318f | Iustin Pop | self.assertRaises(errors.ReservationError, t.Reserve, 2, "a") |
381 | 28a7318f | Iustin Pop | t.DropECReservations(self.EC_ID)
|
382 | 28a7318f | Iustin Pop | self.assertFalse(t.Reserved("a")) |
383 | 28a7318f | Iustin Pop | |
384 | 28a7318f | Iustin Pop | |
385 | e00fb268 | Iustin Pop | if __name__ == '__main__': |
386 | 25231ec5 | Michael Hanselmann | testutils.GanetiTestProgram() |