Revision 9b85ede9

b/lib/utils/version.py
152 152
  """
153 153
  return (configversion[0] == targetversion[0] and
154 154
          configversion[1] == targetversion[1])
155

  
156

  
157
def IsBefore(version, major, minor, revision):
158
  """Decide if a given version is strictly before a given version.
159

  
160
  @param version: (major, minor, revision) or None, with None being
161
      before all versions
162
  @type version: (int, int, int) or None
163
  @param major: major version
164
  @type major: int
165
  @param minor: minor version
166
  @type minor: int
167
  @param revision: revision
168
  @type revision: int
169

  
170
  """
171
  if version is None:
172
    return True
173

  
174
  return version < (major, minor, revision)
b/test/py/ganeti.utils.version_unittest.py
72 72
        self.assertFalse(version.IsCorrectConfigVersion((3,10,0), (2,10,0)))
73 73

  
74 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

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

Also available in: Unified diff