Revision 45f62156 test/py/ganeti.config_unittest.py
b/test/py/ganeti.config_unittest.py | ||
---|---|---|
174 | 174 |
self.failUnlessRaises(errors.ConfigurationError, cfg.Update, fake_instance, |
175 | 175 |
None) |
176 | 176 |
|
177 |
def testUpgradeSave(self): |
|
178 |
"""Test that any modification done during upgrading is saved back""" |
|
179 |
cfg = self._get_object() |
|
180 |
|
|
181 |
# Remove an element, run upgrade, and check if the element is |
|
182 |
# back and the file upgraded |
|
183 |
node = cfg.GetNodeInfo(cfg.GetNodeList()[0]) |
|
184 |
# For a ConfigObject, None is the same as a missing field |
|
185 |
node.ndparams = None |
|
186 |
oldsaved = utils.ReadFile(self.cfg_file) |
|
187 |
cfg._UpgradeConfig() |
|
188 |
self.assertTrue(node.ndparams is not None) |
|
189 |
newsaved = utils.ReadFile(self.cfg_file) |
|
190 |
# We rely on the fact that at least the serial number changes |
|
191 |
self.assertNotEqual(oldsaved, newsaved) |
|
192 |
|
|
193 |
# Add something that should not be there this time |
|
194 |
key = list(constants.NDC_GLOBALS)[0] |
|
195 |
node.ndparams[key] = constants.NDC_DEFAULTS[key] |
|
196 |
cfg._WriteConfig(None) |
|
197 |
oldsaved = utils.ReadFile(self.cfg_file) |
|
198 |
cfg._UpgradeConfig() |
|
199 |
self.assertTrue(node.ndparams.get(key) is None) |
|
200 |
newsaved = utils.ReadFile(self.cfg_file) |
|
201 |
self.assertNotEqual(oldsaved, newsaved) |
|
202 |
|
|
203 |
# Do the upgrade again, this time there should be no update |
|
204 |
oldsaved = newsaved |
|
205 |
cfg._UpgradeConfig() |
|
206 |
newsaved = utils.ReadFile(self.cfg_file) |
|
207 |
self.assertEqual(oldsaved, newsaved) |
|
208 |
|
|
209 |
# Reload the configuration again: it shouldn't change the file |
|
210 |
oldsaved = newsaved |
|
211 |
self._get_object() |
|
212 |
newsaved = utils.ReadFile(self.cfg_file) |
|
213 |
self.assertEqual(oldsaved, newsaved) |
|
214 |
|
|
177 | 215 |
def testNICParameterSyntaxCheck(self): |
178 | 216 |
"""Test the NIC's CheckParameterSyntax function""" |
179 | 217 |
mode = constants.NIC_MODE |
Also available in: Unified diff