Statistics
| Branch: | Tag: | Revision:

root / test / py / ganeti.utils.version_unittest.py @ 9b85ede9

History | View | Annotate | Download (3.8 kB)

1
#!/usr/bin/python
2
#
3

    
4
# Copyright (C) 2013 Google Inc.
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
# General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
# 02110-1301, USA.
20

    
21

    
22
"""Script for unittesting the version utility functions"""
23

    
24
import unittest
25

    
26
from ganeti.utils import version
27

    
28
import testutils
29

    
30
class ParseVersionTest(unittest.TestCase):
31
    def testParseVersion(self):
32
        self.assertEquals(version.ParseVersion("2.10"), (2, 10, 0))
33
        self.assertEquals(version.ParseVersion("2.10.1"), (2, 10, 1))
34
        self.assertEquals(version.ParseVersion("2.10.1~beta2"), (2, 10, 1))
35
        self.assertEquals(version.ParseVersion("2"), None)
36
        self.assertEquals(version.ParseVersion("pink bunny"), None)
37

    
38
class UpgradeRangeTest(unittest.TestCase):
39
    def testUpgradeRange(self):
40
        self.assertEquals(version.UpgradeRange((2,11,0), current=(2,10,0)),
41
                          None)
42
        self.assertEquals(version.UpgradeRange((2,10,0), current=(2,10,0)),
43
                          None)
44
        self.assertEquals(version.UpgradeRange((2,11,3), current=(2,12,0)),
45
                          None)
46
        self.assertEquals(version.UpgradeRange((2,11,3), current=(2,12,99)),
47
                          None)
48
        self.assertEquals(version.UpgradeRange((3,0,0), current=(2,12,0)),
49
                          "different major versions")
50
        self.assertEquals(version.UpgradeRange((2,12,0), current=(3,0,0)),
51
                          "different major versions")
52
        self.assertEquals(version.UpgradeRange((2,10,0), current=(2,12,0)),
53
                          "can only downgrade one minor version at a time")
54
        self.assertEquals(version.UpgradeRange((2,9,0), current=(2,10,0)),
55
                          "automatic upgrades only supported from 2.10 onwards")
56
        self.assertEquals(version.UpgradeRange((2,10,0), current=(2,9,0)),
57
                          "automatic upgrades only supported from 2.10 onwards")
58

    
59
class ShouldCfgdowngradeTest(unittest.TestCase):
60
    def testShouldCfgDowngrade(self):
61
        self.assertTrue(version.ShouldCfgdowngrade((2,9,3), current=(2,10,0)))
62
        self.assertTrue(version.ShouldCfgdowngrade((2,9,0), current=(2,10,4)))
63
        self.assertFalse(version.ShouldCfgdowngrade((2,9,0), current=(2,11,0)))
64
        self.assertFalse(version.ShouldCfgdowngrade((2,9,0), current=(3,10,0)))
65
        self.assertFalse(version.ShouldCfgdowngrade((2,10,0), current=(3,10,0)))
66

    
67

    
68
class IsCorrectConfigVersionTest(unittest.TestCase):
69
    def testIsCorrectConfigVersion(self):
70
        self.assertTrue(version.IsCorrectConfigVersion((2,10,1), (2,10,0)))
71
        self.assertFalse(version.IsCorrectConfigVersion((2,11,0), (2,10,0)))
72
        self.assertFalse(version.IsCorrectConfigVersion((3,10,0), (2,10,0)))
73

    
74

    
75
class IsBeforeTest(unittest.TestCase):
76
    def testIsBefore(self):
77
        self.assertTrue(version.IsBefore(None, 2, 10, 0))
78
        self.assertFalse(version.IsBefore((2, 10, 0), 2, 10, 0))
79
        self.assertTrue(version.IsBefore((2, 10, 0), 2, 10, 1))
80
        self.assertFalse(version.IsBefore((2, 10, 1), 2, 10, 0))
81
        self.assertTrue(version.IsBefore((2, 10, 1), 2, 11, 0))
82
        self.assertFalse(version.IsBefore((2, 11, 0), 2, 10, 3))
83

    
84

    
85
if __name__ == "__main__":
86
  testutils.GanetiTestProgram()