On Tue, Oct 7, 2014 at 11:04 AM, 'Klaus Aehlig' via ganeti-devel < [email protected]> wrote:
> The hypervisor-compatibility test we used was specific to > Xen, so move it to the hv_xen instead of having it in util. > > Signed-off-by: Klaus Aehlig <[email protected]> > --- > lib/hypervisor/hv_xen.py | 21 +++++++++++++++++++++ > lib/utils/version.py | 21 --------------------- > test/py/ganeti.hypervisor.hv_xen_unittest.py | 12 ++++++++++++ > test/py/ganeti.utils.version_unittest.py | 18 ------------------ > 4 files changed, 33 insertions(+), 39 deletions(-) > > diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py > index 07464bb..f434f79 100644 > --- a/lib/hypervisor/hv_xen.py > +++ b/lib/hypervisor/hv_xen.py > @@ -548,6 +548,27 @@ class XenHypervisor(hv_base.BaseHypervisor): > raise errors.HypervisorError("Cannot write Xen instance > configuration" > " file %s: %s" % (cfg_file, err)) > > + @staticmethod > + def VersionsSafeForMigration(src, target): > + """Decide if migration is likely to suceed for hypervisor versions. > + > + Given two versions of a hypervisor, give a guess whether live > migration > + from the one version to the other version is likely to succeed. For > Xen, > + the heuristics is, that an increase by one on the second digit is OK. > This > + fits with the current numbering scheme. > + > + @type src: list or tuple > + @type target: list or tuple > + @rtype: bool > + """ > + if src == target: > + return True > + > + if len(src) < 2 or len(target) < 2: > + return False > + > + return src[0] == target[0] and target[1] in [src[1], src[1] + 1] > + > @classmethod > def _InstanceNICDir(cls, instance_name): > """Returns the directory holding the tap device files for a given > instance. > diff --git a/lib/utils/version.py b/lib/utils/version.py > index c67bbb5..fb4c303 100644 > --- a/lib/utils/version.py > +++ b/lib/utils/version.py > @@ -181,24 +181,3 @@ def IsBefore(version, major, minor, revision): > return True > > return version < (major, minor, revision) > - > - > -def HVVersionsLikelySafeForMigration(src, target): > - """Decide if migration is likely to suceed for hypervisor versions. > - > - Given two versions of a hypervisor, give a guess whether live migration > - from the one version to the other version is likely to succeed. The > current > - heuristics is, that an increase by one on the second digit is OK. This > is > - in line with the current numbering of Xen. > - > - @type src: list or tuple > - @type target: list or tuple > - @rtype: bool > - """ > - if src == target: > - return True > - > - if len(src) < 2 or len(target) < 2: > - return False > - > - return src[0] == target[0] and target[1] in [src[1], src[1] + 1] > diff --git a/test/py/ganeti.hypervisor.hv_xen_unittest.py b/test/py/ > ganeti.hypervisor.hv_xen_unittest.py > index a2f14c7..73b40cb 100755 > --- a/test/py/ganeti.hypervisor.hv_xen_unittest.py > +++ b/test/py/ganeti.hypervisor.hv_xen_unittest.py > @@ -971,6 +971,18 @@ class _TestXenHypervisor(object): > self.assertTrue(hv.GetNodeInfo() is None) > > > +class TestXenVersionsSafeForMigration(unittest.TestCase): > + def testHVVersionsLikelySafeForMigration(self): > + hv = hv_xen.XenHypervisor() > + self.assertTrue(hv.VersionsSafeForMigration([4, 0], [4, 1])) > + self.assertFalse(hv.VersionsSafeForMigration([4, 1], [4, 0])) > + self.assertFalse(hv.VersionsSafeForMigration([4, 0], [4, 2])) > + self.assertTrue(hv.VersionsSafeForMigration([4, 2, 7], [4, 2, 9])) > + self.assertTrue(hv.VersionsSafeForMigration([4, 2, 9], [4, 2, 7])) > + self.assertTrue(hv.VersionsSafeForMigration([4], [4])) > + self.assertFalse(hv.VersionsSafeForMigration([4], [5])) > + > + > def _MakeTestClass(cls, cmd): > """Makes a class for testing. > > diff --git a/test/py/ganeti.utils.version_unittest.py b/test/py/ > ganeti.utils.version_unittest.py > index a5c91ba..2ca0786 100755 > --- a/test/py/ganeti.utils.version_unittest.py > +++ b/test/py/ganeti.utils.version_unittest.py > @@ -92,23 +92,5 @@ class IsBeforeTest(unittest.TestCase): > self.assertFalse(version.IsBefore((2, 11, 0), 2, 10, 3)) > > > -class HVVersionsLikelySafeForMigrationTest(unittest.TestCase): > - def testHVVersionsLikelySafeForMigration(self): > - self.assertTrue( > - version.HVVersionsLikelySafeForMigration([4, 0], [4, 1])) > - self.assertFalse( > - version.HVVersionsLikelySafeForMigration([4, 1], [4, 0])) > - self.assertFalse( > - version.HVVersionsLikelySafeForMigration([4, 0], [4, 2])) > - self.assertTrue( > - version.HVVersionsLikelySafeForMigration([4, 2, 7], [4, 2, > 9])) > - self.assertTrue( > - version.HVVersionsLikelySafeForMigration([4, 2, 9], [4, 2, > 7])) > - self.assertTrue( > - version.HVVersionsLikelySafeForMigration([4], [4])) > - self.assertFalse( > - version.HVVersionsLikelySafeForMigration([4], [5])) > - > - > if __name__ == "__main__": > testutils.GanetiTestProgram() > -- > 2.1.0.rc2.206.gedb03e5 > > LGTM, thanks -- Helga Velroyen | Software Engineer | [email protected] | 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
