Statistics
| Branch: | Tag: | Revision:

root / test / ganeti.backend_unittest.py @ 49f986e7

History | View | Annotate | Download (2.1 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
# 0.0510-1301, USA.
20

    
21

    
22
"""Script for unittesting the backend module"""
23

    
24

    
25
import os
26
import unittest
27
import time
28
import tempfile
29
import shutil
30

    
31
from ganeti import backend
32
from ganeti import constants
33
from ganeti import utils
34

    
35
import testutils
36

    
37

    
38
class TestNodeVerify(testutils.GanetiTestCase):
39
  def testMasterIPLocalhost(self):
40
    # this a real functional test, but requires localhost to be reachable
41
    local_data = (utils.HostInfo().name, constants.LOCALHOST_IP_ADDRESS)
42
    result = backend.VerifyNode({constants.NV_MASTERIP: local_data}, None)
43
    self.failUnless(constants.NV_MASTERIP in result,
44
                    "Master IP data not returned")
45
    self.failUnless(result[constants.NV_MASTERIP], "Cannot reach localhost")
46

    
47
  def testMasterIPUnreachable(self):
48
    # Network 192.0.2.0/24 is reserved for test/documentation as per
49
    # RFC 5735
50
    bad_data =  ("master.example.com", "192.0.2.1")
51
    # we just test that whatever TcpPing returns, VerifyNode returns too
52
    utils.TcpPing = lambda a, b, source=None: False
53
    result = backend.VerifyNode({constants.NV_MASTERIP: bad_data}, None)
54
    self.failUnless(constants.NV_MASTERIP in result,
55
                    "Master IP data not returned")
56
    self.failIf(result[constants.NV_MASTERIP],
57
                "Result from utils.TcpPing corrupted")
58

    
59

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