With the upcoming changes in 2.12, is it necessary to run 'gnt-cluster renew-crypto --new-node-certificates'. To ensure that our QA runs smoothely, this means that this command needs to be added to the post-upgrade hooks of 2.11. To ensure that it is only run when coming from 2.12.X or from before 2.11, the utility functions are extended by an equal operator for versions.
Note that it is unlikely that 2.11 will get another release, so this is mainly to fix our QA. However, users downgrading to a previous version of 2.11 will get a nagging message to re-run renew-crypto manually. Signed-off-by: Helga Velroyen <[email protected]> --- lib/utils/version.py | 26 ++++++++++++++++++++++++++ test/py/ganeti.utils.version_unittest.py | 10 ++++++++++ tools/post-upgrade | 3 ++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/utils/version.py b/lib/utils/version.py index fb4c303..7983474 100644 --- a/lib/utils/version.py +++ b/lib/utils/version.py @@ -181,3 +181,29 @@ def IsBefore(version, major, minor, revision): return True return version < (major, minor, revision) + + +def IsEqual(version, major, minor, revision): + """Decide if a given version matches the given version. + + If the revision is set to None, only major and minor are compared. + + @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 False + + if revision is None: + current_major, current_minor, _ = version + return (current_major, current_minor) == (major, minor) + + return version == (major, minor, revision) diff --git a/test/py/ganeti.utils.version_unittest.py b/test/py/ganeti.utils.version_unittest.py index 2ca0786..b6d3207 100755 --- a/test/py/ganeti.utils.version_unittest.py +++ b/test/py/ganeti.utils.version_unittest.py @@ -91,6 +91,16 @@ class IsBeforeTest(unittest.TestCase): self.assertTrue(version.IsBefore((2, 10, 1), 2, 11, 0)) self.assertFalse(version.IsBefore((2, 11, 0), 2, 10, 3)) +class IsEqualTest(unittest.Testcase): + def testIsEqual(self): + self.assertTrue(version.IsEqual((2, 10, 0), 2, 10, 0)) + self.assertFalse(version.IsEqual((2, 10, 0), 2, 10, 2)) + self.assertFalse(version.IsEqual((2, 10, 0), 2, 12, 0)) + self.assertFalse(version.IsEqual((2, 10, 0), 3, 10, 0)) + self.assertTrue(version.IsEqual((2, 10, 0), 2, 10, None)) + self.assertTrue(version.IsEqual((2, 10, 5), 2, 10, None)) + self.assertFalse(version.IsEqual((2, 11, 5), 2, 10, None)) + self.assertFalse(version.IsEqual((3, 10, 5), 2, 10, None)) if __name__ == "__main__": testutils.GanetiTestProgram() diff --git a/tools/post-upgrade b/tools/post-upgrade index f3a1132..a660346 100644 --- a/tools/post-upgrade +++ b/tools/post-upgrade @@ -51,7 +51,8 @@ def main(): version = utils.version.ParseVersion(versionstring) - if utils.version.IsBefore(version, 2, 11, 0): + if utils.version.IsBefore(version, 2, 11, 0) or \ + utils.version.IsEqual(version, 2, 12, None): result = utils.RunCmd(["gnt-cluster", "renew-crypto", "--new-node-certificates", "-f"]) if result.failed: -- 2.4.3.573.g4eafbef
