LGTM. Thanks, Jose On Wed, Oct 02, 2013 at 02:33:02PM +0200, Klaus Aehlig wrote: > Upgrading is possible within the same major version to any equal > or higher minor version. Downgrading is possible within the same > major version to the previous minor version. Moreover, automatic > upgrades are only supported from version 2.10 onwards. Add a utility > function implementing this logic. > > Signed-off-by: Klaus Aehlig <[email protected]> > --- > lib/utils/version.py | 32 > ++++++++++++++++++++++++++++++++ > test/py/ganeti.utils.version_unittest.py | 21 +++++++++++++++++++++ > 2 files changed, 53 insertions(+) > > diff --git a/lib/utils/version.py b/lib/utils/version.py > index 20381b7..ef9aa27 100644 > --- a/lib/utils/version.py > +++ b/lib/utils/version.py > @@ -23,9 +23,17 @@ > > import re > > +from ganeti import constants > + > _FULL_VERSION_RE = re.compile(r"(\d+)\.(\d+)\.(\d+)") > _SHORT_VERSION_RE = re.compile(r"(\d+)\.(\d+)") > > +# The first Ganeti version that supports automatic upgrades > +FIRST_UPGRADE_VERSION = (2, 10, 0) > + > +CURRENT_VERSION = (constants.VERSION_MAJOR, constants.VERSION_MINOR, > + constants.VERSION_REVISION) > + > # Format for CONFIG_VERSION: > # 01 03 0123 = 01030123 > # ^^ ^^ ^^^^ > @@ -87,3 +95,27 @@ def ParseVersion(versionstring): > return (int(m.group(1)), int(m.group(2)), 0) > > return None > + > + > +def UpgradeRange(version, current=CURRENT_VERSION): > + """Verify whether a version is within the range of automatic upgrades. > + > + @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: string or None > + @return: None, if within the range, and a human-readable error message > + otherwise > + > + """ > + if version < FIRST_UPGRADE_VERSION or current < FIRST_UPGRADE_VERSION: > + return "automatic upgrades only supported from 2.10 onwards" > + > + if version[0] != current[0]: > + return "different major versions" > + > + if version[1] < current[1] - 1: > + return "can only downgrade one minor version at a time" > + > + return None > diff --git a/test/py/ganeti.utils.version_unittest.py > b/test/py/ganeti.utils.version_unittest.py > index 7df0c62..8e175b1 100755 > --- a/test/py/ganeti.utils.version_unittest.py > +++ b/test/py/ganeti.utils.version_unittest.py > @@ -35,6 +35,27 @@ class ParseVersionTest(unittest.TestCase): > self.assertEquals(version.ParseVersion("2"), None) > self.assertEquals(version.ParseVersion("pink bunny"), None) > > +class UpgradeRangeTest(unittest.TestCase): > + def testUpgradeRange(self): > + self.assertEquals(version.UpgradeRange((2,11,0), current=(2,10,0)), > + None) > + self.assertEquals(version.UpgradeRange((2,10,0), current=(2,10,0)), > + None) > + self.assertEquals(version.UpgradeRange((2,11,3), current=(2,12,0)), > + None) > + self.assertEquals(version.UpgradeRange((2,11,3), current=(2,12,99)), > + None) > + self.assertEquals(version.UpgradeRange((3,0,0), current=(2,12,0)), > + "different major versions") > + self.assertEquals(version.UpgradeRange((2,12,0), current=(3,0,0)), > + "different major versions") > + self.assertEquals(version.UpgradeRange((2,10,0), current=(2,12,0)), > + "can only downgrade one minor version at a time") > + self.assertEquals(version.UpgradeRange((2,9,0), current=(2,10,0)), > + "automatic upgrades only supported from 2.10 > onwards") > + self.assertEquals(version.UpgradeRange((2,10,0), current=(2,9,0)), > + "automatic upgrades only supported from 2.10 > onwards") > + > > if __name__ == "__main__": > testutils.GanetiTestProgram() > -- > 1.8.4 >
-- Jose Antonio Lopes Ganeti Engineering Google Germany GmbH Dienerstr. 12, 80331, München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores Steuernummer: 48/725/00206 Umsatzsteueridentifikationsnummer: DE813741370
