Commit 78521495 authored by Klaus Aehlig's avatar Klaus Aehlig
Browse files

Add predicate whether to call cfgupgrade --downgrade



Provide a predicate that, given the current version and the
version to go to, tells whether it is appropriate to call
cfgupgrade --downgrade.
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarJose Lopes <jabolopes@google.com>
parent 0890e0d1
......@@ -119,3 +119,21 @@ def UpgradeRange(target, current=CURRENT_VERSION):
return "can only downgrade one minor version at a time"
return None
def ShouldCfgdowngrade(version, current=CURRENT_VERSION):
"""Decide whether cfgupgrade --downgrade should be called.
Given the current version and the version to change to, decide
if in the transition process cfgupgrade --downgrade should
be called
@param version: The version to upgrade to as (major, minor, revision)
@type version: tuple
@param current: The versino to upgrade from as (major, minor, revision)
@type current: tuple
@rtype: bool
@return: True, if cfgupgrade --downgrade should be called.
"""
return version[0] == current[0] and version[1] == current[1] - 1
......@@ -56,6 +56,14 @@ class UpgradeRangeTest(unittest.TestCase):
self.assertEquals(version.UpgradeRange((2,10,0), current=(2,9,0)),
"automatic upgrades only supported from 2.10 onwards")
class ShouldCfgdowngradeTest(unittest.TestCase):
def testShouldCfgDowngrade(self):
self.assertTrue(version.ShouldCfgdowngrade((2,9,3), current=(2,10,0)))
self.assertTrue(version.ShouldCfgdowngrade((2,9,0), current=(2,10,4)))
self.assertFalse(version.ShouldCfgdowngrade((2,9,0), current=(2,11,0)))
self.assertFalse(version.ShouldCfgdowngrade((2,9,0), current=(3,10,0)))
self.assertFalse(version.ShouldCfgdowngrade((2,10,0), current=(3,10,0)))
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