Commit 9b85ede9 authored by Klaus Aehlig's avatar Klaus Aehlig
Browse files

Add utility to compare versions



This will be needed, e.g., for post-upgrade task, as they
have to decide whether a feature was not yet present at
the version started from.
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarHrvoje Ribicic <riba@google.com>
parent 74289509
......@@ -152,3 +152,23 @@ def IsCorrectConfigVersion(targetversion, configversion):
"""
return (configversion[0] == targetversion[0] and
configversion[1] == targetversion[1])
def IsBefore(version, major, minor, revision):
"""Decide if a given version is strictly before a given version.
@param version: (major, minor, revision) or None, with None being
before all versions
@type version: (int, int, int) or None
@param major: major version
@type major: int
@param minor: minor version
@type minor: int
@param revision: revision
@type revision: int
"""
if version is None:
return True
return version < (major, minor, revision)
......@@ -72,5 +72,15 @@ class IsCorrectConfigVersionTest(unittest.TestCase):
self.assertFalse(version.IsCorrectConfigVersion((3,10,0), (2,10,0)))
class IsBeforeTest(unittest.TestCase):
def testIsBefore(self):
self.assertTrue(version.IsBefore(None, 2, 10, 0))
self.assertFalse(version.IsBefore((2, 10, 0), 2, 10, 0))
self.assertTrue(version.IsBefore((2, 10, 0), 2, 10, 1))
self.assertFalse(version.IsBefore((2, 10, 1), 2, 10, 0))
self.assertTrue(version.IsBefore((2, 10, 1), 2, 11, 0))
self.assertFalse(version.IsBefore((2, 11, 0), 2, 10, 3))
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