Commit 0890e0d1 authored by Klaus Aehlig's avatar Klaus Aehlig
Browse files

Add utility function to recognize upgrade ranges



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: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarJose Lopes <jabolopes@google.com>
parent 8c44d5b3
......@@ -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(target, current=CURRENT_VERSION):
"""Verify whether a version is within the range of automatic upgrades.
@param target: The version to upgrade to as (major, minor, revision)
@type target: tuple
@param current: The version 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 target < FIRST_UPGRADE_VERSION or current < FIRST_UPGRADE_VERSION:
return "automatic upgrades only supported from 2.10 onwards"
if target[0] != current[0]:
return "different major versions"
if target[1] < current[1] - 1:
return "can only downgrade one minor version at a time"
return None
......@@ -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()
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