Statistics
| Branch: | Tag: | Revision:

root / test / ganeti.masterd.instance_unittest.py @ 033a1d00

History | View | Annotate | Download (2 kB)

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

    
4
# Copyright (C) 2010 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 testing ganeti.masterd.instance"""
23

    
24
import os
25
import sys
26
import unittest
27

    
28
from ganeti import utils
29
from ganeti import masterd
30

    
31
from ganeti.masterd.instance import \
32
  ImportExportTimeouts, _TimeoutExpired, _DiskImportExportBase
33

    
34
import testutils
35

    
36

    
37
class TestMisc(unittest.TestCase):
38
  def testTimeouts(self):
39
    tmo = ImportExportTimeouts(0)
40
    self.assertEqual(tmo.connect, 0)
41
    self.assertEqual(tmo.listen, ImportExportTimeouts.DEFAULT_LISTEN_TIMEOUT)
42
    self.assertEqual(tmo.ready, ImportExportTimeouts.DEFAULT_READY_TIMEOUT)
43
    self.assertEqual(tmo.error, ImportExportTimeouts.DEFAULT_ERROR_TIMEOUT)
44

    
45
    tmo = ImportExportTimeouts(999)
46
    self.assertEqual(tmo.connect, 999)
47

    
48
  def testTimeoutExpired(self):
49
    self.assert_(_TimeoutExpired(100, 300, _time_fn=lambda: 500))
50
    self.assertFalse(_TimeoutExpired(100, 300, _time_fn=lambda: 0))
51
    self.assertFalse(_TimeoutExpired(100, 300, _time_fn=lambda: 100))
52
    self.assertFalse(_TimeoutExpired(100, 300, _time_fn=lambda: 400))
53

    
54
  def testDiskImportExportBaseDirect(self):
55
    self.assertRaises(AssertionError, _DiskImportExportBase,
56
                      None, None, None, None, None, None, None)
57

    
58

    
59
if __name__ == "__main__":
60
  testutils.GanetiTestProgram()