Revision 1709435e test/py/cfgupgrade_unittest.py

b/test/py/cfgupgrade_unittest.py
1 1
#!/usr/bin/python
2 2
#
3 3

  
4
# Copyright (C) 2010, 2012 Google Inc.
4
# Copyright (C) 2010, 2012, 2013 Google Inc.
5 5
#
6 6
# This program is free software; you can redistribute it and/or modify
7 7
# it under the terms of the GNU General Public License as published by
......
37 37
import testutils
38 38

  
39 39

  
40
def _RunUpgrade(path, dry_run, no_verify, ignore_hostname=True):
40
def _RunUpgrade(path, dry_run, no_verify, ignore_hostname=True,
41
                downgrade=False):
41 42
  cmd = [sys.executable, "%s/tools/cfgupgrade" % testutils.GetSourceDir(),
42 43
         "--debug", "--force", "--path=%s" % path, "--confdir=%s" % path]
43 44

  
......
47 48
    cmd.append("--dry-run")
48 49
  if no_verify:
49 50
    cmd.append("--no-verify")
51
  if downgrade:
52
    cmd.append("--downgrade")
50 53

  
51 54
  result = utils.RunCmd(cmd, cwd=os.getcwd())
52 55
  if result.failed:
......
347 350
  def testUpgradeCurrent(self):
348 351
    self._TestSimpleUpgrade(constants.CONFIG_VERSION, False)
349 352

  
353
  def testDowngrade(self):
354
    self._TestSimpleUpgrade(constants.CONFIG_VERSION, False)
355
    oldconf = self._LoadConfig()
356
    _RunUpgrade(self.tmpdir, False, True, downgrade=True)
357
    _RunUpgrade(self.tmpdir, False, True)
358
    newconf = self._LoadConfig()
359
    self.assertEqual(oldconf, newconf)
360

  
361
  def testDowngradeTwice(self):
362
    self._TestSimpleUpgrade(constants.CONFIG_VERSION, False)
363
    _RunUpgrade(self.tmpdir, False, True, downgrade=True)
364
    oldconf = self._LoadConfig()
365
    _RunUpgrade(self.tmpdir, False, True, downgrade=True)
366
    newconf = self._LoadConfig()
367
    self.assertEqual(oldconf, newconf)
368

  
350 369
  def testUpgradeDryRunFrom_2_0(self):
351 370
    self._TestSimpleUpgrade(constants.BuildVersion(2, 0, 0), True)
352 371

  
......
371 390
  def testUpgradeCurrentDryRun(self):
372 391
    self._TestSimpleUpgrade(constants.CONFIG_VERSION, True)
373 392

  
393
  def testDowngradeDryRun(self):
394
    self._TestSimpleUpgrade(constants.CONFIG_VERSION, False)
395
    oldconf = self._LoadConfig()
396
    _RunUpgrade(self.tmpdir, True, True, downgrade=True)
397
    newconf = self._LoadConfig()
398
    self.assertEqual(oldconf["version"], newconf["version"])
374 399

  
375 400
if __name__ == "__main__":
376 401
  testutils.GanetiTestProgram()

Also available in: Unified diff