root / test / py / ganeti.config_unittest.py @ 5470b894
History | View | Annotate | Download (24.3 kB)
1 | e00fb268 | Iustin Pop | #!/usr/bin/python
|
---|---|---|---|
2 | e00fb268 | Iustin Pop | #
|
3 | e00fb268 | Iustin Pop | |
4 | 64760879 | Bernardo Dal Seno | # Copyright (C) 2006, 2007, 2010, 2011, 2012, 2013 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 tempfile |
28 | 54c31fd3 | Michael Hanselmann | import operator |
29 | e00fb268 | Iustin Pop | |
30 | c666722f | Oleksiy Mishchenko | from ganeti import bootstrap |
31 | e00fb268 | Iustin Pop | from ganeti import config |
32 | c666722f | Oleksiy Mishchenko | from ganeti import constants |
33 | c666722f | Oleksiy Mishchenko | from ganeti import errors |
34 | e00fb268 | Iustin Pop | from ganeti import objects |
35 | 6f1bebf9 | Michael Hanselmann | from ganeti import utils |
36 | a744b676 | Manuel Franceschini | from ganeti import netutils |
37 | 54c31fd3 | Michael Hanselmann | from ganeti import compat |
38 | a5efec93 | Santi Raffa | from ganeti import serializer |
39 | 22b7f6f8 | Thomas Thrainer | from ganeti.cmdlib import instance |
40 | e00fb268 | Iustin Pop | |
41 | 28a7318f | Iustin Pop | from ganeti.config import TemporaryReservationManager |
42 | 28a7318f | Iustin Pop | |
43 | 25231ec5 | Michael Hanselmann | import testutils |
44 | e60c73a1 | René Nussbaumer | import mocks |
45 | def6577f | Helga Velroyen | import mock |
46 | e60c73a1 | René Nussbaumer | |
47 | e60c73a1 | René Nussbaumer | |
48 | e60c73a1 | René Nussbaumer | def _StubGetEntResolver(): |
49 | e60c73a1 | René Nussbaumer | return mocks.FakeGetentResolver()
|
50 | 25231ec5 | Michael Hanselmann | |
51 | e00fb268 | Iustin Pop | |
52 | e00fb268 | Iustin Pop | class TestConfigRunner(unittest.TestCase): |
53 | e00fb268 | Iustin Pop | """Testing case for HooksRunner"""
|
54 | e00fb268 | Iustin Pop | def setUp(self): |
55 | e00fb268 | Iustin Pop | fd, self.cfg_file = tempfile.mkstemp()
|
56 | e00fb268 | Iustin Pop | os.close(fd) |
57 | c666722f | Oleksiy Mishchenko | self._init_cluster(self.cfg_file) |
58 | e00fb268 | Iustin Pop | |
59 | e00fb268 | Iustin Pop | def tearDown(self): |
60 | e00fb268 | Iustin Pop | try:
|
61 | e00fb268 | Iustin Pop | os.unlink(self.cfg_file)
|
62 | e00fb268 | Iustin Pop | except OSError: |
63 | e00fb268 | Iustin Pop | pass
|
64 | e00fb268 | Iustin Pop | |
65 | e00fb268 | Iustin Pop | def _get_object(self): |
66 | 64760879 | Bernardo Dal Seno | """Returns an instance of ConfigWriter"""
|
67 | e60c73a1 | René Nussbaumer | cfg = config.ConfigWriter(cfg_file=self.cfg_file, offline=True, |
68 | e60c73a1 | René Nussbaumer | _getents=_StubGetEntResolver) |
69 | e00fb268 | Iustin Pop | return cfg
|
70 | e00fb268 | Iustin Pop | |
71 | e00fb268 | Iustin Pop | def _init_cluster(self, cfg): |
72 | e00fb268 | Iustin Pop | """Initializes the cfg object"""
|
73 | b705c7a6 | Manuel Franceschini | me = netutils.Hostname() |
74 | 9769bb78 | Manuel Franceschini | ip = constants.IP4_ADDRESS_LOCALHOST |
75 | 3697def0 | Bernardo Dal Seno | # master_ip must not conflict with the node ip address
|
76 | 3697def0 | Bernardo Dal Seno | master_ip = "127.0.0.2"
|
77 | f6bd6e98 | Michael Hanselmann | |
78 | b9eeeb02 | Michael Hanselmann | cluster_config = objects.Cluster( |
79 | b9eeeb02 | Michael Hanselmann | serial_no=1,
|
80 | b9eeeb02 | Michael Hanselmann | rsahostkeypub="",
|
81 | a9542a4f | Thomas Thrainer | dsahostkeypub="",
|
82 | b9eeeb02 | Michael Hanselmann | highest_used_port=(constants.FIRST_DRBD_PORT - 1),
|
83 | b9eeeb02 | Michael Hanselmann | mac_prefix="aa:00:00",
|
84 | b9eeeb02 | Michael Hanselmann | volume_group_name="xenvg",
|
85 | 9e33896b | Luca Bigliardi | drbd_usermode_helper="/bin/true",
|
86 | c66f21a4 | Guido Trotter | nicparams={constants.PP_DEFAULT: constants.NICC_DEFAULTS}, |
87 | 5768e6a6 | René Nussbaumer | ndparams=constants.NDC_DEFAULTS, |
88 | b9eeeb02 | Michael Hanselmann | tcpudp_port_pool=set(),
|
89 | 066f465d | Guido Trotter | enabled_hypervisors=[constants.HT_FAKE], |
90 | f6bd6e98 | Michael Hanselmann | master_node=me.name, |
91 | 3697def0 | Bernardo Dal Seno | master_ip=master_ip, |
92 | f6bd6e98 | Michael Hanselmann | master_netdev=constants.DEFAULT_BRIDGE, |
93 | f6bd6e98 | Michael Hanselmann | cluster_name="cluster.local",
|
94 | f6bd6e98 | Michael Hanselmann | file_storage_dir="/tmp",
|
95 | 93be53da | Balazs Lecz | uid_pool=[], |
96 | b9eeeb02 | Michael Hanselmann | ) |
97 | f6bd6e98 | Michael Hanselmann | |
98 | f6bd6e98 | Michael Hanselmann | master_node_config = objects.Node(name=me.name, |
99 | f6bd6e98 | Michael Hanselmann | primary_ip=me.ip, |
100 | 36b8c2c1 | Michael Hanselmann | secondary_ip=ip, |
101 | 4a89c54a | Iustin Pop | serial_no=1,
|
102 | 4a89c54a | Iustin Pop | master_candidate=True)
|
103 | f6bd6e98 | Michael Hanselmann | |
104 | c666722f | Oleksiy Mishchenko | bootstrap.InitConfig(constants.CONFIG_VERSION, |
105 | c666722f | Oleksiy Mishchenko | cluster_config, master_node_config, self.cfg_file)
|
106 | e00fb268 | Iustin Pop | |
107 | 5470b894 | Ilias Tsitsimpis | def _create_instance(self, cfg): |
108 | e00fb268 | Iustin Pop | """Create and return an instance object"""
|
109 | da4a52a3 | Thomas Thrainer | inst = objects.Instance(name="test.example.com",
|
110 | da4a52a3 | Thomas Thrainer | uuid="test-uuid",
|
111 | da4a52a3 | Thomas Thrainer | disks=[], nics=[], |
112 | 4a89c54a | Iustin Pop | disk_template=constants.DT_DISKLESS, |
113 | 5470b894 | Ilias Tsitsimpis | primary_node=cfg.GetMasterNode(), |
114 | a5efec93 | Santi Raffa | osparams_private=serializer.PrivateDict()) |
115 | e00fb268 | Iustin Pop | return inst
|
116 | e00fb268 | Iustin Pop | |
117 | e00fb268 | Iustin Pop | def testEmpty(self): |
118 | e00fb268 | Iustin Pop | """Test instantiate config object"""
|
119 | e00fb268 | Iustin Pop | self._get_object()
|
120 | e00fb268 | Iustin Pop | |
121 | e00fb268 | Iustin Pop | def testInit(self): |
122 | e00fb268 | Iustin Pop | """Test initialize the config file"""
|
123 | e00fb268 | Iustin Pop | cfg = self._get_object()
|
124 | e00fb268 | Iustin Pop | self.failUnlessEqual(1, len(cfg.GetNodeList())) |
125 | e00fb268 | Iustin Pop | self.failUnlessEqual(0, len(cfg.GetInstanceList())) |
126 | e00fb268 | Iustin Pop | |
127 | e00fb268 | Iustin Pop | def testUpdateCluster(self): |
128 | e00fb268 | Iustin Pop | """Test updates on the cluster object"""
|
129 | e00fb268 | Iustin Pop | cfg = self._get_object()
|
130 | e00fb268 | Iustin Pop | # construct a fake cluster object
|
131 | e00fb268 | Iustin Pop | fake_cl = objects.Cluster() |
132 | e00fb268 | Iustin Pop | # fail if we didn't read the config
|
133 | a4eae71f | Michael Hanselmann | self.failUnlessRaises(errors.ConfigurationError, cfg.Update, fake_cl, None) |
134 | e00fb268 | Iustin Pop | |
135 | e00fb268 | Iustin Pop | cl = cfg.GetClusterInfo() |
136 | e00fb268 | Iustin Pop | # first pass, must not fail
|
137 | a4eae71f | Michael Hanselmann | cfg.Update(cl, None)
|
138 | e00fb268 | Iustin Pop | # second pass, also must not fail (after the config has been written)
|
139 | a4eae71f | Michael Hanselmann | cfg.Update(cl, None)
|
140 | e00fb268 | Iustin Pop | # but the fake_cl update should still fail
|
141 | a4eae71f | Michael Hanselmann | self.failUnlessRaises(errors.ConfigurationError, cfg.Update, fake_cl, None) |
142 | e00fb268 | Iustin Pop | |
143 | e00fb268 | Iustin Pop | def testUpdateNode(self): |
144 | e00fb268 | Iustin Pop | """Test updates on one node object"""
|
145 | e00fb268 | Iustin Pop | cfg = self._get_object()
|
146 | e00fb268 | Iustin Pop | # construct a fake node
|
147 | e00fb268 | Iustin Pop | fake_node = objects.Node() |
148 | e00fb268 | Iustin Pop | # fail if we didn't read the config
|
149 | a4eae71f | Michael Hanselmann | self.failUnlessRaises(errors.ConfigurationError, cfg.Update, fake_node,
|
150 | a4eae71f | Michael Hanselmann | None)
|
151 | e00fb268 | Iustin Pop | |
152 | e00fb268 | Iustin Pop | node = cfg.GetNodeInfo(cfg.GetNodeList()[0])
|
153 | e00fb268 | Iustin Pop | # first pass, must not fail
|
154 | a4eae71f | Michael Hanselmann | cfg.Update(node, None)
|
155 | e00fb268 | Iustin Pop | # second pass, also must not fail (after the config has been written)
|
156 | a4eae71f | Michael Hanselmann | cfg.Update(node, None)
|
157 | e00fb268 | Iustin Pop | # but the fake_node update should still fail
|
158 | a4eae71f | Michael Hanselmann | self.failUnlessRaises(errors.ConfigurationError, cfg.Update, fake_node,
|
159 | a4eae71f | Michael Hanselmann | None)
|
160 | e00fb268 | Iustin Pop | |
161 | e00fb268 | Iustin Pop | def testUpdateInstance(self): |
162 | e00fb268 | Iustin Pop | """Test updates on one instance object"""
|
163 | e00fb268 | Iustin Pop | cfg = self._get_object()
|
164 | e00fb268 | Iustin Pop | # construct a fake instance
|
165 | 5470b894 | Ilias Tsitsimpis | inst = self._create_instance(cfg)
|
166 | e00fb268 | Iustin Pop | fake_instance = objects.Instance() |
167 | e00fb268 | Iustin Pop | # fail if we didn't read the config
|
168 | a4eae71f | Michael Hanselmann | self.failUnlessRaises(errors.ConfigurationError, cfg.Update, fake_instance,
|
169 | a4eae71f | Michael Hanselmann | None)
|
170 | e00fb268 | Iustin Pop | |
171 | 0debfb35 | Guido Trotter | cfg.AddInstance(inst, "my-job")
|
172 | e00fb268 | Iustin Pop | instance = cfg.GetInstanceInfo(cfg.GetInstanceList()[0])
|
173 | e00fb268 | Iustin Pop | # first pass, must not fail
|
174 | a4eae71f | Michael Hanselmann | cfg.Update(instance, None)
|
175 | e00fb268 | Iustin Pop | # second pass, also must not fail (after the config has been written)
|
176 | a4eae71f | Michael Hanselmann | cfg.Update(instance, None)
|
177 | e00fb268 | Iustin Pop | # but the fake_instance update should still fail
|
178 | a4eae71f | Michael Hanselmann | self.failUnlessRaises(errors.ConfigurationError, cfg.Update, fake_instance,
|
179 | a4eae71f | Michael Hanselmann | None)
|
180 | e00fb268 | Iustin Pop | |
181 | 45f62156 | Bernardo Dal Seno | def testUpgradeSave(self): |
182 | 45f62156 | Bernardo Dal Seno | """Test that any modification done during upgrading is saved back"""
|
183 | 45f62156 | Bernardo Dal Seno | cfg = self._get_object()
|
184 | 45f62156 | Bernardo Dal Seno | |
185 | 45f62156 | Bernardo Dal Seno | # Remove an element, run upgrade, and check if the element is
|
186 | 45f62156 | Bernardo Dal Seno | # back and the file upgraded
|
187 | 45f62156 | Bernardo Dal Seno | node = cfg.GetNodeInfo(cfg.GetNodeList()[0])
|
188 | 45f62156 | Bernardo Dal Seno | # For a ConfigObject, None is the same as a missing field
|
189 | 45f62156 | Bernardo Dal Seno | node.ndparams = None
|
190 | 45f62156 | Bernardo Dal Seno | oldsaved = utils.ReadFile(self.cfg_file)
|
191 | 45f62156 | Bernardo Dal Seno | cfg._UpgradeConfig() |
192 | 45f62156 | Bernardo Dal Seno | self.assertTrue(node.ndparams is not None) |
193 | 45f62156 | Bernardo Dal Seno | newsaved = utils.ReadFile(self.cfg_file)
|
194 | 45f62156 | Bernardo Dal Seno | # We rely on the fact that at least the serial number changes
|
195 | 45f62156 | Bernardo Dal Seno | self.assertNotEqual(oldsaved, newsaved)
|
196 | 45f62156 | Bernardo Dal Seno | |
197 | 45f62156 | Bernardo Dal Seno | # Add something that should not be there this time
|
198 | 45f62156 | Bernardo Dal Seno | key = list(constants.NDC_GLOBALS)[0] |
199 | 45f62156 | Bernardo Dal Seno | node.ndparams[key] = constants.NDC_DEFAULTS[key] |
200 | 45f62156 | Bernardo Dal Seno | cfg._WriteConfig(None)
|
201 | 45f62156 | Bernardo Dal Seno | oldsaved = utils.ReadFile(self.cfg_file)
|
202 | 45f62156 | Bernardo Dal Seno | cfg._UpgradeConfig() |
203 | 45f62156 | Bernardo Dal Seno | self.assertTrue(node.ndparams.get(key) is None) |
204 | 45f62156 | Bernardo Dal Seno | newsaved = utils.ReadFile(self.cfg_file)
|
205 | 45f62156 | Bernardo Dal Seno | self.assertNotEqual(oldsaved, newsaved)
|
206 | 45f62156 | Bernardo Dal Seno | |
207 | 45f62156 | Bernardo Dal Seno | # Do the upgrade again, this time there should be no update
|
208 | 45f62156 | Bernardo Dal Seno | oldsaved = newsaved |
209 | 45f62156 | Bernardo Dal Seno | cfg._UpgradeConfig() |
210 | 45f62156 | Bernardo Dal Seno | newsaved = utils.ReadFile(self.cfg_file)
|
211 | 45f62156 | Bernardo Dal Seno | self.assertEqual(oldsaved, newsaved)
|
212 | 45f62156 | Bernardo Dal Seno | |
213 | 45f62156 | Bernardo Dal Seno | # Reload the configuration again: it shouldn't change the file
|
214 | 45f62156 | Bernardo Dal Seno | oldsaved = newsaved |
215 | 45f62156 | Bernardo Dal Seno | self._get_object()
|
216 | 45f62156 | Bernardo Dal Seno | newsaved = utils.ReadFile(self.cfg_file)
|
217 | 45f62156 | Bernardo Dal Seno | self.assertEqual(oldsaved, newsaved)
|
218 | 45f62156 | Bernardo Dal Seno | |
219 | 255e19d4 | Guido Trotter | def testNICParameterSyntaxCheck(self): |
220 | 255e19d4 | Guido Trotter | """Test the NIC's CheckParameterSyntax function"""
|
221 | 255e19d4 | Guido Trotter | mode = constants.NIC_MODE |
222 | 255e19d4 | Guido Trotter | link = constants.NIC_LINK |
223 | 255e19d4 | Guido Trotter | m_bridged = constants.NIC_MODE_BRIDGED |
224 | 255e19d4 | Guido Trotter | m_routed = constants.NIC_MODE_ROUTED |
225 | 255e19d4 | Guido Trotter | CheckSyntax = objects.NIC.CheckParameterSyntax |
226 | 255e19d4 | Guido Trotter | |
227 | 255e19d4 | Guido Trotter | CheckSyntax(constants.NICC_DEFAULTS) |
228 | 8c114acd | Michael Hanselmann | CheckSyntax({mode: m_bridged, link: "br1"})
|
229 | 8c114acd | Michael Hanselmann | CheckSyntax({mode: m_routed, link: "default"})
|
230 | 255e19d4 | Guido Trotter | self.assertRaises(errors.ConfigurationError,
|
231 | 8c114acd | Michael Hanselmann | CheckSyntax, {mode: "000invalid", link: "any"}) |
232 | 255e19d4 | Guido Trotter | self.assertRaises(errors.ConfigurationError,
|
233 | 255e19d4 | Guido Trotter | CheckSyntax, {mode: m_bridged, link: None})
|
234 | 255e19d4 | Guido Trotter | self.assertRaises(errors.ConfigurationError,
|
235 | 8c114acd | Michael Hanselmann | CheckSyntax, {mode: m_bridged, link: ""})
|
236 | 255e19d4 | Guido Trotter | |
237 | 5768e6a6 | René Nussbaumer | def testGetNdParamsDefault(self): |
238 | 5768e6a6 | René Nussbaumer | cfg = self._get_object()
|
239 | 5768e6a6 | René Nussbaumer | node = cfg.GetNodeInfo(cfg.GetNodeList()[0])
|
240 | 5768e6a6 | René Nussbaumer | self.assertEqual(cfg.GetNdParams(node), constants.NDC_DEFAULTS)
|
241 | 5768e6a6 | René Nussbaumer | |
242 | 5768e6a6 | René Nussbaumer | def testGetNdParamsModifiedNode(self): |
243 | 5768e6a6 | René Nussbaumer | my_ndparams = { |
244 | 5768e6a6 | René Nussbaumer | constants.ND_OOB_PROGRAM: "/bin/node-oob",
|
245 | 432e8e2f | Iustin Pop | constants.ND_SPINDLE_COUNT: 1,
|
246 | 0ea11dcb | Bernardo Dal Seno | constants.ND_EXCLUSIVE_STORAGE: False,
|
247 | 807d8853 | Sebastian Gebhard | constants.ND_OVS: True,
|
248 | 807d8853 | Sebastian Gebhard | constants.ND_OVS_NAME: "openvswitch",
|
249 | 33ffda6c | Petr Pudlak | constants.ND_OVS_LINK: "eth1",
|
250 | 33ffda6c | Petr Pudlak | constants.ND_SSH_PORT: 22,
|
251 | 5768e6a6 | René Nussbaumer | } |
252 | 5768e6a6 | René Nussbaumer | |
253 | 5768e6a6 | René Nussbaumer | cfg = self._get_object()
|
254 | 5768e6a6 | René Nussbaumer | node = cfg.GetNodeInfo(cfg.GetNodeList()[0])
|
255 | 5768e6a6 | René Nussbaumer | node.ndparams = my_ndparams |
256 | 5768e6a6 | René Nussbaumer | cfg.Update(node, None)
|
257 | 5768e6a6 | René Nussbaumer | self.assertEqual(cfg.GetNdParams(node), my_ndparams)
|
258 | 5768e6a6 | René Nussbaumer | |
259 | 0ea11dcb | Bernardo Dal Seno | def testGetNdParamsInheritance(self): |
260 | 0ea11dcb | Bernardo Dal Seno | node_ndparams = { |
261 | 0ea11dcb | Bernardo Dal Seno | constants.ND_OOB_PROGRAM: "/bin/node-oob",
|
262 | 807d8853 | Sebastian Gebhard | constants.ND_OVS_LINK: "eth3"
|
263 | 0ea11dcb | Bernardo Dal Seno | } |
264 | 0ea11dcb | Bernardo Dal Seno | group_ndparams = { |
265 | 0ea11dcb | Bernardo Dal Seno | constants.ND_SPINDLE_COUNT: 10,
|
266 | 807d8853 | Sebastian Gebhard | constants.ND_OVS: True,
|
267 | 807d8853 | Sebastian Gebhard | constants.ND_OVS_NAME: "openvswitch",
|
268 | 33ffda6c | Petr Pudlak | constants.ND_SSH_PORT: 222,
|
269 | 0ea11dcb | Bernardo Dal Seno | } |
270 | 0ea11dcb | Bernardo Dal Seno | expected_ndparams = { |
271 | 0ea11dcb | Bernardo Dal Seno | constants.ND_OOB_PROGRAM: "/bin/node-oob",
|
272 | 0ea11dcb | Bernardo Dal Seno | constants.ND_SPINDLE_COUNT: 10,
|
273 | 0ea11dcb | Bernardo Dal Seno | constants.ND_EXCLUSIVE_STORAGE: |
274 | 0ea11dcb | Bernardo Dal Seno | constants.NDC_DEFAULTS[constants.ND_EXCLUSIVE_STORAGE], |
275 | 807d8853 | Sebastian Gebhard | constants.ND_OVS: True,
|
276 | 807d8853 | Sebastian Gebhard | constants.ND_OVS_NAME: "openvswitch",
|
277 | 33ffda6c | Petr Pudlak | constants.ND_OVS_LINK: "eth3",
|
278 | 33ffda6c | Petr Pudlak | constants.ND_SSH_PORT: 222,
|
279 | 0ea11dcb | Bernardo Dal Seno | } |
280 | 0ea11dcb | Bernardo Dal Seno | cfg = self._get_object()
|
281 | 0ea11dcb | Bernardo Dal Seno | node = cfg.GetNodeInfo(cfg.GetNodeList()[0])
|
282 | 0ea11dcb | Bernardo Dal Seno | node.ndparams = node_ndparams |
283 | 0ea11dcb | Bernardo Dal Seno | cfg.Update(node, None)
|
284 | 0ea11dcb | Bernardo Dal Seno | group = cfg.GetNodeGroup(node.group) |
285 | 0ea11dcb | Bernardo Dal Seno | group.ndparams = group_ndparams |
286 | 0ea11dcb | Bernardo Dal Seno | cfg.Update(group, None)
|
287 | 0ea11dcb | Bernardo Dal Seno | self.assertEqual(cfg.GetNdParams(node), expected_ndparams)
|
288 | 0ea11dcb | Bernardo Dal Seno | |
289 | 2bac48c4 | Adeodato Simo | def testAddGroupFillsFieldsIfMissing(self): |
290 | 2bac48c4 | Adeodato Simo | cfg = self._get_object()
|
291 | 2bac48c4 | Adeodato Simo | group = objects.NodeGroup(name="test", members=[])
|
292 | 2bac48c4 | Adeodato Simo | cfg.AddNodeGroup(group, "my-job")
|
293 | 2bac48c4 | Adeodato Simo | self.assert_(utils.UUID_RE.match(group.uuid))
|
294 | 2bac48c4 | Adeodato Simo | self.assertEqual(constants.ALLOC_POLICY_PREFERRED, group.alloc_policy)
|
295 | 2bac48c4 | Adeodato Simo | |
296 | 2bac48c4 | Adeodato Simo | def testAddGroupPreservesFields(self): |
297 | 2bac48c4 | Adeodato Simo | cfg = self._get_object()
|
298 | 2bac48c4 | Adeodato Simo | group = objects.NodeGroup(name="test", members=[],
|
299 | 2bac48c4 | Adeodato Simo | alloc_policy=constants.ALLOC_POLICY_LAST_RESORT) |
300 | 2bac48c4 | Adeodato Simo | cfg.AddNodeGroup(group, "my-job")
|
301 | 2bac48c4 | Adeodato Simo | self.assertEqual(constants.ALLOC_POLICY_LAST_RESORT, group.alloc_policy)
|
302 | 2bac48c4 | Adeodato Simo | |
303 | 2bac48c4 | Adeodato Simo | def testAddGroupDoesNotPreserveFields(self): |
304 | 2bac48c4 | Adeodato Simo | cfg = self._get_object()
|
305 | 2bac48c4 | Adeodato Simo | group = objects.NodeGroup(name="test", members=[],
|
306 | 2bac48c4 | Adeodato Simo | serial_no=17, ctime=123, mtime=456) |
307 | 2bac48c4 | Adeodato Simo | cfg.AddNodeGroup(group, "my-job")
|
308 | 2bac48c4 | Adeodato Simo | self.assertEqual(1, group.serial_no) |
309 | 2bac48c4 | Adeodato Simo | self.assert_(group.ctime > 1200000000) |
310 | 2bac48c4 | Adeodato Simo | self.assert_(group.mtime > 1200000000) |
311 | 2bac48c4 | Adeodato Simo | |
312 | 2bac48c4 | Adeodato Simo | def testAddGroupCanSkipUUIDCheck(self): |
313 | 2bac48c4 | Adeodato Simo | cfg = self._get_object()
|
314 | 2bac48c4 | Adeodato Simo | uuid = cfg.GenerateUniqueID("my-job")
|
315 | 2bac48c4 | Adeodato Simo | group = objects.NodeGroup(name="test", members=[], uuid=uuid,
|
316 | 2bac48c4 | Adeodato Simo | serial_no=17, ctime=123, mtime=456) |
317 | 2bac48c4 | Adeodato Simo | |
318 | 2bac48c4 | Adeodato Simo | self.assertRaises(errors.ConfigurationError,
|
319 | 2bac48c4 | Adeodato Simo | cfg.AddNodeGroup, group, "my-job")
|
320 | 2bac48c4 | Adeodato Simo | |
321 | 2bac48c4 | Adeodato Simo | cfg.AddNodeGroup(group, "my-job", check_uuid=False) # Does not raise. |
322 | 2bac48c4 | Adeodato Simo | self.assertEqual(uuid, group.uuid)
|
323 | 2bac48c4 | Adeodato Simo | |
324 | 54c31fd3 | Michael Hanselmann | def testAssignGroupNodes(self): |
325 | 54c31fd3 | Michael Hanselmann | me = netutils.Hostname() |
326 | 54c31fd3 | Michael Hanselmann | cfg = self._get_object()
|
327 | 54c31fd3 | Michael Hanselmann | |
328 | 54c31fd3 | Michael Hanselmann | # Create two groups
|
329 | 54c31fd3 | Michael Hanselmann | grp1 = objects.NodeGroup(name="grp1", members=[],
|
330 | 54c31fd3 | Michael Hanselmann | uuid="2f2fadf7-2a70-4a23-9ab5-2568c252032c")
|
331 | 54c31fd3 | Michael Hanselmann | grp1_serial = 1
|
332 | 54c31fd3 | Michael Hanselmann | cfg.AddNodeGroup(grp1, "job")
|
333 | 54c31fd3 | Michael Hanselmann | |
334 | 54c31fd3 | Michael Hanselmann | grp2 = objects.NodeGroup(name="grp2", members=[],
|
335 | 54c31fd3 | Michael Hanselmann | uuid="798d0de3-680f-4a0e-b29a-0f54f693b3f1")
|
336 | 54c31fd3 | Michael Hanselmann | grp2_serial = 1
|
337 | 54c31fd3 | Michael Hanselmann | cfg.AddNodeGroup(grp2, "job")
|
338 | 54c31fd3 | Michael Hanselmann | self.assertEqual(set(map(operator.attrgetter("name"), |
339 | 54c31fd3 | Michael Hanselmann | cfg.GetAllNodeGroupsInfo().values())), |
340 | 54c31fd3 | Michael Hanselmann | set(["grp1", "grp2", constants.INITIAL_NODE_GROUP_NAME])) |
341 | 54c31fd3 | Michael Hanselmann | |
342 | 54c31fd3 | Michael Hanselmann | # No-op
|
343 | 54c31fd3 | Michael Hanselmann | cluster_serial = cfg.GetClusterInfo().serial_no |
344 | 54c31fd3 | Michael Hanselmann | cfg.AssignGroupNodes([]) |
345 | 54c31fd3 | Michael Hanselmann | cluster_serial += 1
|
346 | 54c31fd3 | Michael Hanselmann | |
347 | 54c31fd3 | Michael Hanselmann | # Create two nodes
|
348 | 1c3231aa | Thomas Thrainer | node1 = objects.Node(name="node1", group=grp1.uuid, ndparams={},
|
349 | 1c3231aa | Thomas Thrainer | uuid="node1-uuid")
|
350 | 54c31fd3 | Michael Hanselmann | node1_serial = 1
|
351 | 1c3231aa | Thomas Thrainer | node2 = objects.Node(name="node2", group=grp2.uuid, ndparams={},
|
352 | 1c3231aa | Thomas Thrainer | uuid="node2-uuid")
|
353 | 54c31fd3 | Michael Hanselmann | node2_serial = 1
|
354 | 54c31fd3 | Michael Hanselmann | cfg.AddNode(node1, "job")
|
355 | 54c31fd3 | Michael Hanselmann | cfg.AddNode(node2, "job")
|
356 | 54c31fd3 | Michael Hanselmann | cluster_serial += 2
|
357 | 1c3231aa | Thomas Thrainer | self.assertEqual(set(cfg.GetNodeList()), |
358 | 1c3231aa | Thomas Thrainer | set(["node1-uuid", "node2-uuid", |
359 | 1c3231aa | Thomas Thrainer | cfg.GetNodeInfoByName(me.name).uuid])) |
360 | 54c31fd3 | Michael Hanselmann | |
361 | 54c31fd3 | Michael Hanselmann | def _VerifySerials(): |
362 | 54c31fd3 | Michael Hanselmann | self.assertEqual(cfg.GetClusterInfo().serial_no, cluster_serial)
|
363 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node1.serial_no, node1_serial)
|
364 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node2.serial_no, node2_serial)
|
365 | 54c31fd3 | Michael Hanselmann | self.assertEqual(grp1.serial_no, grp1_serial)
|
366 | 54c31fd3 | Michael Hanselmann | self.assertEqual(grp2.serial_no, grp2_serial)
|
367 | 54c31fd3 | Michael Hanselmann | |
368 | 54c31fd3 | Michael Hanselmann | _VerifySerials() |
369 | 54c31fd3 | Michael Hanselmann | |
370 | 1c3231aa | Thomas Thrainer | self.assertEqual(set(grp1.members), set(["node1-uuid"])) |
371 | 1c3231aa | Thomas Thrainer | self.assertEqual(set(grp2.members), set(["node2-uuid"])) |
372 | 54c31fd3 | Michael Hanselmann | |
373 | 54c31fd3 | Michael Hanselmann | # Check invalid nodes and groups
|
374 | 54c31fd3 | Michael Hanselmann | self.assertRaises(errors.ConfigurationError, cfg.AssignGroupNodes, [
|
375 | 54c31fd3 | Michael Hanselmann | ("unknown.node.example.com", grp2.uuid),
|
376 | 54c31fd3 | Michael Hanselmann | ]) |
377 | 54c31fd3 | Michael Hanselmann | self.assertRaises(errors.ConfigurationError, cfg.AssignGroupNodes, [
|
378 | 54c31fd3 | Michael Hanselmann | (node1.name, "unknown-uuid"),
|
379 | 54c31fd3 | Michael Hanselmann | ]) |
380 | 54c31fd3 | Michael Hanselmann | |
381 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node1.group, grp1.uuid)
|
382 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node2.group, grp2.uuid)
|
383 | 1c3231aa | Thomas Thrainer | self.assertEqual(set(grp1.members), set(["node1-uuid"])) |
384 | 1c3231aa | Thomas Thrainer | self.assertEqual(set(grp2.members), set(["node2-uuid"])) |
385 | 54c31fd3 | Michael Hanselmann | |
386 | 54c31fd3 | Michael Hanselmann | # Another no-op
|
387 | 54c31fd3 | Michael Hanselmann | cfg.AssignGroupNodes([]) |
388 | 54c31fd3 | Michael Hanselmann | cluster_serial += 1
|
389 | 54c31fd3 | Michael Hanselmann | _VerifySerials() |
390 | 54c31fd3 | Michael Hanselmann | |
391 | 54c31fd3 | Michael Hanselmann | # Assign to the same group (should be a no-op)
|
392 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node2.group, grp2.uuid)
|
393 | 54c31fd3 | Michael Hanselmann | cfg.AssignGroupNodes([ |
394 | 1c3231aa | Thomas Thrainer | (node2.uuid, grp2.uuid), |
395 | 54c31fd3 | Michael Hanselmann | ]) |
396 | 54c31fd3 | Michael Hanselmann | cluster_serial += 1
|
397 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node2.group, grp2.uuid)
|
398 | 54c31fd3 | Michael Hanselmann | _VerifySerials() |
399 | 1c3231aa | Thomas Thrainer | self.assertEqual(set(grp1.members), set(["node1-uuid"])) |
400 | 1c3231aa | Thomas Thrainer | self.assertEqual(set(grp2.members), set(["node2-uuid"])) |
401 | 54c31fd3 | Michael Hanselmann | |
402 | 54c31fd3 | Michael Hanselmann | # Assign node 2 to group 1
|
403 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node2.group, grp2.uuid)
|
404 | 54c31fd3 | Michael Hanselmann | cfg.AssignGroupNodes([ |
405 | 1c3231aa | Thomas Thrainer | (node2.uuid, grp1.uuid), |
406 | 54c31fd3 | Michael Hanselmann | ]) |
407 | 54c31fd3 | Michael Hanselmann | cluster_serial += 1
|
408 | 54c31fd3 | Michael Hanselmann | node2_serial += 1
|
409 | 54c31fd3 | Michael Hanselmann | grp1_serial += 1
|
410 | 54c31fd3 | Michael Hanselmann | grp2_serial += 1
|
411 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node2.group, grp1.uuid)
|
412 | 54c31fd3 | Michael Hanselmann | _VerifySerials() |
413 | 1c3231aa | Thomas Thrainer | self.assertEqual(set(grp1.members), set(["node1-uuid", "node2-uuid"])) |
414 | 54c31fd3 | Michael Hanselmann | self.assertFalse(grp2.members)
|
415 | 54c31fd3 | Michael Hanselmann | |
416 | 54c31fd3 | Michael Hanselmann | # And assign both nodes to group 2
|
417 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node1.group, grp1.uuid)
|
418 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node2.group, grp1.uuid)
|
419 | 54c31fd3 | Michael Hanselmann | self.assertNotEqual(grp1.uuid, grp2.uuid)
|
420 | 54c31fd3 | Michael Hanselmann | cfg.AssignGroupNodes([ |
421 | 1c3231aa | Thomas Thrainer | (node1.uuid, grp2.uuid), |
422 | 1c3231aa | Thomas Thrainer | (node2.uuid, grp2.uuid), |
423 | 54c31fd3 | Michael Hanselmann | ]) |
424 | 54c31fd3 | Michael Hanselmann | cluster_serial += 1
|
425 | 54c31fd3 | Michael Hanselmann | node1_serial += 1
|
426 | 54c31fd3 | Michael Hanselmann | node2_serial += 1
|
427 | 54c31fd3 | Michael Hanselmann | grp1_serial += 1
|
428 | 54c31fd3 | Michael Hanselmann | grp2_serial += 1
|
429 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node1.group, grp2.uuid)
|
430 | 54c31fd3 | Michael Hanselmann | self.assertEqual(node2.group, grp2.uuid)
|
431 | 54c31fd3 | Michael Hanselmann | _VerifySerials() |
432 | 54c31fd3 | Michael Hanselmann | self.assertFalse(grp1.members)
|
433 | 1c3231aa | Thomas Thrainer | self.assertEqual(set(grp2.members), set(["node1-uuid", "node2-uuid"])) |
434 | 54c31fd3 | Michael Hanselmann | |
435 | 54c31fd3 | Michael Hanselmann | # Destructive tests
|
436 | 54c31fd3 | Michael Hanselmann | orig_group = node2.group |
437 | 54c31fd3 | Michael Hanselmann | try:
|
438 | 54c31fd3 | Michael Hanselmann | other_uuid = "68b3d087-6ea5-491c-b81f-0a47d90228c5"
|
439 | 54c31fd3 | Michael Hanselmann | assert compat.all(node.group != other_uuid
|
440 | 54c31fd3 | Michael Hanselmann | for node in cfg.GetAllNodesInfo().values()) |
441 | 54c31fd3 | Michael Hanselmann | node2.group = "68b3d087-6ea5-491c-b81f-0a47d90228c5"
|
442 | 54c31fd3 | Michael Hanselmann | self.assertRaises(errors.ConfigurationError, cfg.AssignGroupNodes, [
|
443 | 1c3231aa | Thomas Thrainer | (node2.uuid, grp2.uuid), |
444 | 54c31fd3 | Michael Hanselmann | ]) |
445 | 54c31fd3 | Michael Hanselmann | _VerifySerials() |
446 | 54c31fd3 | Michael Hanselmann | finally:
|
447 | 54c31fd3 | Michael Hanselmann | node2.group = orig_group |
448 | 54c31fd3 | Michael Hanselmann | |
449 | 64760879 | Bernardo Dal Seno | def _TestVerifyConfigIPolicy(self, ipolicy, ipowner, cfg, isgroup): |
450 | 64760879 | Bernardo Dal Seno | INVALID_KEY = "this_key_cannot_exist"
|
451 | 64760879 | Bernardo Dal Seno | |
452 | 64760879 | Bernardo Dal Seno | ipolicy[INVALID_KEY] = None
|
453 | 64760879 | Bernardo Dal Seno | # A call to cluster.SimpleFillIPolicy causes different kinds of error
|
454 | 64760879 | Bernardo Dal Seno | # depending on the owner (cluster or group)
|
455 | 64760879 | Bernardo Dal Seno | if isgroup:
|
456 | 64760879 | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
457 | 0f511c8a | Bernardo Dal Seno | self.assertTrue(len(errs) >= 1) |
458 | 64760879 | Bernardo Dal Seno | errstr = "%s has invalid instance policy" % ipowner
|
459 | 0f511c8a | Bernardo Dal Seno | self.assertTrue(_IsErrorInList(errstr, errs))
|
460 | 64760879 | Bernardo Dal Seno | else:
|
461 | 64760879 | Bernardo Dal Seno | self.assertRaises(AssertionError, cfg.VerifyConfig) |
462 | 64760879 | Bernardo Dal Seno | del ipolicy[INVALID_KEY]
|
463 | 64760879 | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
464 | 64760879 | Bernardo Dal Seno | self.assertFalse(errs)
|
465 | 64760879 | Bernardo Dal Seno | |
466 | 64760879 | Bernardo Dal Seno | key = list(constants.IPOLICY_PARAMETERS)[0] |
467 | 64760879 | Bernardo Dal Seno | hasoldv = (key in ipolicy)
|
468 | 64760879 | Bernardo Dal Seno | if hasoldv:
|
469 | 64760879 | Bernardo Dal Seno | oldv = ipolicy[key] |
470 | 64760879 | Bernardo Dal Seno | ipolicy[key] = "blah"
|
471 | 64760879 | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
472 | 64760879 | Bernardo Dal Seno | self.assertTrue(len(errs) >= 1) |
473 | 64760879 | Bernardo Dal Seno | self.assertTrue(_IsErrorInList("%s has invalid instance policy" % ipowner, |
474 | 64760879 | Bernardo Dal Seno | errs)) |
475 | 64760879 | Bernardo Dal Seno | if hasoldv:
|
476 | 64760879 | Bernardo Dal Seno | ipolicy[key] = oldv |
477 | 64760879 | Bernardo Dal Seno | else:
|
478 | 64760879 | Bernardo Dal Seno | del ipolicy[key]
|
479 | 64760879 | Bernardo Dal Seno | |
480 | 0f511c8a | Bernardo Dal Seno | ispeclist = [] |
481 | 0f511c8a | Bernardo Dal Seno | if constants.ISPECS_MINMAX in ipolicy: |
482 | 41044e04 | Bernardo Dal Seno | for k in range(len(ipolicy[constants.ISPECS_MINMAX])): |
483 | 41044e04 | Bernardo Dal Seno | ispeclist.extend([ |
484 | 41044e04 | Bernardo Dal Seno | (ipolicy[constants.ISPECS_MINMAX][k][constants.ISPECS_MIN], |
485 | 41044e04 | Bernardo Dal Seno | "%s[%s]/%s" % (constants.ISPECS_MINMAX, k, constants.ISPECS_MIN)),
|
486 | 41044e04 | Bernardo Dal Seno | (ipolicy[constants.ISPECS_MINMAX][k][constants.ISPECS_MAX], |
487 | 41044e04 | Bernardo Dal Seno | "%s[%s]/%s" % (constants.ISPECS_MINMAX, k, constants.ISPECS_MAX)),
|
488 | 41044e04 | Bernardo Dal Seno | ]) |
489 | 0f511c8a | Bernardo Dal Seno | if constants.ISPECS_STD in ipolicy: |
490 | 0f511c8a | Bernardo Dal Seno | ispeclist.append((ipolicy[constants.ISPECS_STD], constants.ISPECS_STD)) |
491 | 0f511c8a | Bernardo Dal Seno | |
492 | 64760879 | Bernardo Dal Seno | for (ispec, ispecpath) in ispeclist: |
493 | 64760879 | Bernardo Dal Seno | ispec[INVALID_KEY] = None
|
494 | 64760879 | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
495 | 64760879 | Bernardo Dal Seno | self.assertTrue(len(errs) >= 1) |
496 | 64760879 | Bernardo Dal Seno | self.assertTrue(_IsErrorInList(("%s has invalid ipolicy/%s" % |
497 | 64760879 | Bernardo Dal Seno | (ipowner, ispecpath)), errs)) |
498 | 64760879 | Bernardo Dal Seno | del ispec[INVALID_KEY]
|
499 | 64760879 | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
500 | 64760879 | Bernardo Dal Seno | self.assertFalse(errs)
|
501 | 64760879 | Bernardo Dal Seno | |
502 | 64760879 | Bernardo Dal Seno | for par in constants.ISPECS_PARAMETERS: |
503 | 64760879 | Bernardo Dal Seno | hasoldv = par in ispec
|
504 | 64760879 | Bernardo Dal Seno | if hasoldv:
|
505 | 64760879 | Bernardo Dal Seno | oldv = ispec[par] |
506 | 64760879 | Bernardo Dal Seno | ispec[par] = "blah"
|
507 | 64760879 | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
508 | 64760879 | Bernardo Dal Seno | self.assertTrue(len(errs) >= 1) |
509 | 64760879 | Bernardo Dal Seno | self.assertTrue(_IsErrorInList(("%s has invalid ipolicy/%s" % |
510 | 64760879 | Bernardo Dal Seno | (ipowner, ispecpath)), errs)) |
511 | 64760879 | Bernardo Dal Seno | if hasoldv:
|
512 | 64760879 | Bernardo Dal Seno | ispec[par] = oldv |
513 | 64760879 | Bernardo Dal Seno | else:
|
514 | 64760879 | Bernardo Dal Seno | del ispec[par]
|
515 | 64760879 | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
516 | 64760879 | Bernardo Dal Seno | self.assertFalse(errs)
|
517 | 64760879 | Bernardo Dal Seno | |
518 | 0f511c8a | Bernardo Dal Seno | if constants.ISPECS_MINMAX in ipolicy: |
519 | 0f511c8a | Bernardo Dal Seno | # Test partial minmax specs
|
520 | 41044e04 | Bernardo Dal Seno | for minmax in ipolicy[constants.ISPECS_MINMAX]: |
521 | 41044e04 | Bernardo Dal Seno | for key in constants.ISPECS_MINMAX_KEYS: |
522 | 41044e04 | Bernardo Dal Seno | self.assertTrue(key in minmax) |
523 | 41044e04 | Bernardo Dal Seno | ispec = minmax[key] |
524 | 41044e04 | Bernardo Dal Seno | del minmax[key]
|
525 | 0f511c8a | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
526 | 0f511c8a | Bernardo Dal Seno | self.assertTrue(len(errs) >= 1) |
527 | 41044e04 | Bernardo Dal Seno | self.assertTrue(_IsErrorInList("Missing instance specification", |
528 | 0f511c8a | Bernardo Dal Seno | errs)) |
529 | 41044e04 | Bernardo Dal Seno | minmax[key] = ispec |
530 | 41044e04 | Bernardo Dal Seno | for par in constants.ISPECS_PARAMETERS: |
531 | 41044e04 | Bernardo Dal Seno | oldv = ispec[par] |
532 | 41044e04 | Bernardo Dal Seno | del ispec[par]
|
533 | 41044e04 | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
534 | 41044e04 | Bernardo Dal Seno | self.assertTrue(len(errs) >= 1) |
535 | 41044e04 | Bernardo Dal Seno | self.assertTrue(_IsErrorInList("Missing instance specs parameters", |
536 | 41044e04 | Bernardo Dal Seno | errs)) |
537 | 41044e04 | Bernardo Dal Seno | ispec[par] = oldv |
538 | 0f511c8a | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
539 | 0f511c8a | Bernardo Dal Seno | self.assertFalse(errs)
|
540 | 0f511c8a | Bernardo Dal Seno | |
541 | 64760879 | Bernardo Dal Seno | def _TestVerifyConfigGroupIPolicy(self, groupinfo, cfg): |
542 | 64760879 | Bernardo Dal Seno | old_ipolicy = groupinfo.ipolicy |
543 | 64760879 | Bernardo Dal Seno | ipolicy = cfg.GetClusterInfo().SimpleFillIPolicy({}) |
544 | 64760879 | Bernardo Dal Seno | groupinfo.ipolicy = ipolicy |
545 | 64760879 | Bernardo Dal Seno | # Test partial policies
|
546 | 64760879 | Bernardo Dal Seno | for key in constants.IPOLICY_ALL_KEYS: |
547 | 64760879 | Bernardo Dal Seno | self.assertTrue(key in ipolicy) |
548 | 64760879 | Bernardo Dal Seno | oldv = ipolicy[key] |
549 | 64760879 | Bernardo Dal Seno | del ipolicy[key]
|
550 | 64760879 | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
551 | 64760879 | Bernardo Dal Seno | self.assertFalse(errs)
|
552 | 64760879 | Bernardo Dal Seno | ipolicy[key] = oldv |
553 | 64760879 | Bernardo Dal Seno | groupinfo.ipolicy = old_ipolicy |
554 | 64760879 | Bernardo Dal Seno | |
555 | 64760879 | Bernardo Dal Seno | def _TestVerifyConfigClusterIPolicy(self, ipolicy, cfg): |
556 | 64760879 | Bernardo Dal Seno | # Test partial policies
|
557 | 64760879 | Bernardo Dal Seno | for key in constants.IPOLICY_ALL_KEYS: |
558 | 64760879 | Bernardo Dal Seno | self.assertTrue(key in ipolicy) |
559 | 64760879 | Bernardo Dal Seno | oldv = ipolicy[key] |
560 | 64760879 | Bernardo Dal Seno | del ipolicy[key]
|
561 | 64760879 | Bernardo Dal Seno | self.assertRaises(AssertionError, cfg.VerifyConfig) |
562 | 64760879 | Bernardo Dal Seno | ipolicy[key] = oldv |
563 | 0f511c8a | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
564 | 0f511c8a | Bernardo Dal Seno | self.assertFalse(errs)
|
565 | 0f511c8a | Bernardo Dal Seno | # Partial standard specs
|
566 | 0f511c8a | Bernardo Dal Seno | ispec = ipolicy[constants.ISPECS_STD] |
567 | 0f511c8a | Bernardo Dal Seno | for par in constants.ISPECS_PARAMETERS: |
568 | 0f511c8a | Bernardo Dal Seno | oldv = ispec[par] |
569 | 0f511c8a | Bernardo Dal Seno | del ispec[par]
|
570 | 0f511c8a | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
571 | 0f511c8a | Bernardo Dal Seno | self.assertTrue(len(errs) >= 1) |
572 | 0f511c8a | Bernardo Dal Seno | self.assertTrue(_IsErrorInList("Missing instance specs parameters", |
573 | 0f511c8a | Bernardo Dal Seno | errs)) |
574 | 0f511c8a | Bernardo Dal Seno | ispec[par] = oldv |
575 | 64760879 | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
576 | 64760879 | Bernardo Dal Seno | self.assertFalse(errs)
|
577 | 64760879 | Bernardo Dal Seno | |
578 | 3697def0 | Bernardo Dal Seno | def testVerifyConfig(self): |
579 | 3697def0 | Bernardo Dal Seno | cfg = self._get_object()
|
580 | 3697def0 | Bernardo Dal Seno | |
581 | 3697def0 | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
582 | 3697def0 | Bernardo Dal Seno | self.assertFalse(errs)
|
583 | 3697def0 | Bernardo Dal Seno | |
584 | 3697def0 | Bernardo Dal Seno | node = cfg.GetNodeInfo(cfg.GetNodeList()[0])
|
585 | 3697def0 | Bernardo Dal Seno | key = list(constants.NDC_GLOBALS)[0] |
586 | 3697def0 | Bernardo Dal Seno | node.ndparams[key] = constants.NDC_DEFAULTS[key] |
587 | 3697def0 | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
588 | 3697def0 | Bernardo Dal Seno | self.assertTrue(len(errs) >= 1) |
589 | 3697def0 | Bernardo Dal Seno | self.assertTrue(_IsErrorInList("has some global parameters set", errs)) |
590 | 3697def0 | Bernardo Dal Seno | |
591 | 3697def0 | Bernardo Dal Seno | del node.ndparams[key]
|
592 | 3697def0 | Bernardo Dal Seno | errs = cfg.VerifyConfig() |
593 | 3697def0 | Bernardo Dal Seno | self.assertFalse(errs)
|
594 | 3697def0 | Bernardo Dal Seno | |
595 | 64760879 | Bernardo Dal Seno | cluster = cfg.GetClusterInfo() |
596 | 64760879 | Bernardo Dal Seno | nodegroup = cfg.GetNodeGroup(cfg.GetNodeGroupList()[0])
|
597 | 64760879 | Bernardo Dal Seno | self._TestVerifyConfigIPolicy(cluster.ipolicy, "cluster", cfg, False) |
598 | 64760879 | Bernardo Dal Seno | self._TestVerifyConfigClusterIPolicy(cluster.ipolicy, cfg)
|
599 | 64760879 | Bernardo Dal Seno | self._TestVerifyConfigIPolicy(nodegroup.ipolicy, nodegroup.name, cfg, True) |
600 | 64760879 | Bernardo Dal Seno | self._TestVerifyConfigGroupIPolicy(nodegroup, cfg)
|
601 | 64760879 | Bernardo Dal Seno | nodegroup.ipolicy = cluster.SimpleFillIPolicy(nodegroup.ipolicy) |
602 | 64760879 | Bernardo Dal Seno | self._TestVerifyConfigIPolicy(nodegroup.ipolicy, nodegroup.name, cfg, True) |
603 | 64760879 | Bernardo Dal Seno | |
604 | def6577f | Helga Velroyen | # Tests for Ssconf helper functions
|
605 | def6577f | Helga Velroyen | def testUnlockedGetHvparamsString(self): |
606 | def6577f | Helga Velroyen | hvparams = {"a": "A", "b": "B", "c": "C"} |
607 | def6577f | Helga Velroyen | hvname = "myhv"
|
608 | def6577f | Helga Velroyen | cfg_writer = self._get_object()
|
609 | def6577f | Helga Velroyen | cfg_writer._config_data = mock.Mock() |
610 | def6577f | Helga Velroyen | cfg_writer._config_data.cluster = mock.Mock() |
611 | def6577f | Helga Velroyen | cfg_writer._config_data.cluster.hvparams = {hvname: hvparams} |
612 | def6577f | Helga Velroyen | |
613 | def6577f | Helga Velroyen | result = cfg_writer._UnlockedGetHvparamsString(hvname) |
614 | def6577f | Helga Velroyen | |
615 | def6577f | Helga Velroyen | self.assertTrue("a=A" in result) |
616 | def6577f | Helga Velroyen | lines = [line for line in result.split('\n') if line != ''] |
617 | def6577f | Helga Velroyen | self.assertEqual(len(hvparams.keys()), len(lines)) |
618 | def6577f | Helga Velroyen | |
619 | def6577f | Helga Velroyen | def testExtendByAllHvparamsStrings(self): |
620 | def6577f | Helga Velroyen | all_hvparams = {constants.HT_XEN_PVM: "foo"}
|
621 | def6577f | Helga Velroyen | ssconf_values = {} |
622 | def6577f | Helga Velroyen | cfg_writer = self._get_object()
|
623 | def6577f | Helga Velroyen | |
624 | def6577f | Helga Velroyen | cfg_writer._ExtendByAllHvparamsStrings(ssconf_values, all_hvparams) |
625 | def6577f | Helga Velroyen | |
626 | def6577f | Helga Velroyen | expected_key = constants.SS_HVPARAMS_PREF + constants.HT_XEN_PVM |
627 | def6577f | Helga Velroyen | self.assertTrue(expected_key in ssconf_values) |
628 | def6577f | Helga Velroyen | |
629 | cc0c1197 | Petr Pudlak | def testAddAndRemoveCerts(self): |
630 | cc0c1197 | Petr Pudlak | cfg = self._get_object()
|
631 | cc0c1197 | Petr Pudlak | self.assertEqual(0, len(cfg.GetCandidateCerts())) |
632 | cc0c1197 | Petr Pudlak | |
633 | cc0c1197 | Petr Pudlak | node_uuid = "1234"
|
634 | cc0c1197 | Petr Pudlak | cert_digest = "foobar"
|
635 | cc0c1197 | Petr Pudlak | cfg.AddNodeToCandidateCerts(node_uuid, cert_digest, |
636 | cc0c1197 | Petr Pudlak | warn_fn=None, info_fn=None) |
637 | cc0c1197 | Petr Pudlak | self.assertEqual(1, len(cfg.GetCandidateCerts())) |
638 | cc0c1197 | Petr Pudlak | |
639 | cc0c1197 | Petr Pudlak | # Try adding the same cert again
|
640 | cc0c1197 | Petr Pudlak | cfg.AddNodeToCandidateCerts(node_uuid, cert_digest, |
641 | cc0c1197 | Petr Pudlak | warn_fn=None, info_fn=None) |
642 | cc0c1197 | Petr Pudlak | self.assertEqual(1, len(cfg.GetCandidateCerts())) |
643 | cc0c1197 | Petr Pudlak | self.assertTrue(cfg.GetCandidateCerts()[node_uuid] == cert_digest)
|
644 | cc0c1197 | Petr Pudlak | |
645 | cc0c1197 | Petr Pudlak | # Overriding cert
|
646 | cc0c1197 | Petr Pudlak | other_digest = "barfoo"
|
647 | cc0c1197 | Petr Pudlak | cfg.AddNodeToCandidateCerts(node_uuid, other_digest, |
648 | cc0c1197 | Petr Pudlak | warn_fn=None, info_fn=None) |
649 | cc0c1197 | Petr Pudlak | self.assertEqual(1, len(cfg.GetCandidateCerts())) |
650 | cc0c1197 | Petr Pudlak | self.assertTrue(cfg.GetCandidateCerts()[node_uuid] == other_digest)
|
651 | cc0c1197 | Petr Pudlak | |
652 | cc0c1197 | Petr Pudlak | # Try removing a certificate from a node that is not in the list
|
653 | cc0c1197 | Petr Pudlak | other_node_uuid = "5678"
|
654 | cc0c1197 | Petr Pudlak | cfg.RemoveNodeFromCandidateCerts(other_node_uuid, warn_fn=None)
|
655 | cc0c1197 | Petr Pudlak | self.assertEqual(1, len(cfg.GetCandidateCerts())) |
656 | cc0c1197 | Petr Pudlak | |
657 | cc0c1197 | Petr Pudlak | # Remove a certificate from a node that is in the list
|
658 | cc0c1197 | Petr Pudlak | cfg.RemoveNodeFromCandidateCerts(node_uuid, warn_fn=None)
|
659 | cc0c1197 | Petr Pudlak | self.assertEqual(0, len(cfg.GetCandidateCerts())) |
660 | cc0c1197 | Petr Pudlak | |
661 | 3697def0 | Bernardo Dal Seno | |
662 | 3697def0 | Bernardo Dal Seno | def _IsErrorInList(err_str, err_list): |
663 | 3697def0 | Bernardo Dal Seno | return any(map(lambda e: err_str in e, err_list)) |
664 | 3697def0 | Bernardo Dal Seno | |
665 | e00fb268 | Iustin Pop | |
666 | 28a7318f | Iustin Pop | class TestTRM(unittest.TestCase): |
667 | 28a7318f | Iustin Pop | EC_ID = 1
|
668 | 28a7318f | Iustin Pop | |
669 | 28a7318f | Iustin Pop | def testEmpty(self): |
670 | 28a7318f | Iustin Pop | t = TemporaryReservationManager() |
671 | 28a7318f | Iustin Pop | t.Reserve(self.EC_ID, "a") |
672 | 28a7318f | Iustin Pop | self.assertFalse(t.Reserved(self.EC_ID)) |
673 | 28a7318f | Iustin Pop | self.assertTrue(t.Reserved("a")) |
674 | 28a7318f | Iustin Pop | self.assertEqual(len(t.GetReserved()), 1) |
675 | 28a7318f | Iustin Pop | |
676 | 28a7318f | Iustin Pop | def testDuplicate(self): |
677 | 28a7318f | Iustin Pop | t = TemporaryReservationManager() |
678 | 28a7318f | Iustin Pop | t.Reserve(self.EC_ID, "a") |
679 | 28a7318f | Iustin Pop | self.assertRaises(errors.ReservationError, t.Reserve, 2, "a") |
680 | 28a7318f | Iustin Pop | t.DropECReservations(self.EC_ID)
|
681 | 28a7318f | Iustin Pop | self.assertFalse(t.Reserved("a")) |
682 | 28a7318f | Iustin Pop | |
683 | 28a7318f | Iustin Pop | |
684 | 82c54b5b | Michael Hanselmann | class TestCheckInstanceDiskIvNames(unittest.TestCase): |
685 | 82c54b5b | Michael Hanselmann | @staticmethod
|
686 | 82c54b5b | Michael Hanselmann | def _MakeDisks(names): |
687 | 82c54b5b | Michael Hanselmann | return [objects.Disk(iv_name=name) for name in names] |
688 | 82c54b5b | Michael Hanselmann | |
689 | 82c54b5b | Michael Hanselmann | def testNoError(self): |
690 | 82c54b5b | Michael Hanselmann | disks = self._MakeDisks(["disk/0", "disk/1"]) |
691 | 82c54b5b | Michael Hanselmann | self.assertEqual(config._CheckInstanceDiskIvNames(disks), [])
|
692 | 22b7f6f8 | Thomas Thrainer | instance._UpdateIvNames(0, disks)
|
693 | 82c54b5b | Michael Hanselmann | self.assertEqual(config._CheckInstanceDiskIvNames(disks), [])
|
694 | 82c54b5b | Michael Hanselmann | |
695 | 82c54b5b | Michael Hanselmann | def testWrongNames(self): |
696 | 82c54b5b | Michael Hanselmann | disks = self._MakeDisks(["disk/1", "disk/3", "disk/2"]) |
697 | 82c54b5b | Michael Hanselmann | self.assertEqual(config._CheckInstanceDiskIvNames(disks), [
|
698 | 82c54b5b | Michael Hanselmann | (0, "disk/0", "disk/1"), |
699 | 82c54b5b | Michael Hanselmann | (1, "disk/1", "disk/3"), |
700 | 82c54b5b | Michael Hanselmann | ]) |
701 | 82c54b5b | Michael Hanselmann | |
702 | 82c54b5b | Michael Hanselmann | # Fix names
|
703 | 22b7f6f8 | Thomas Thrainer | instance._UpdateIvNames(0, disks)
|
704 | 82c54b5b | Michael Hanselmann | self.assertEqual(config._CheckInstanceDiskIvNames(disks), [])
|
705 | 82c54b5b | Michael Hanselmann | |
706 | 82c54b5b | Michael Hanselmann | |
707 | 2f96c43c | Michael Hanselmann | if __name__ == "__main__": |
708 | 25231ec5 | Michael Hanselmann | testutils.GanetiTestProgram() |