Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (2.1 kB)

1 a3a5f850 Iustin Pop
#!/usr/bin/python
2 a3a5f850 Iustin Pop
#
3 a3a5f850 Iustin Pop
4 a3a5f850 Iustin Pop
# Copyright (C) 2010 Google Inc.
5 a3a5f850 Iustin Pop
#
6 a3a5f850 Iustin Pop
# This program is free software; you can redistribute it and/or modify
7 a3a5f850 Iustin Pop
# it under the terms of the GNU General Public License as published by
8 a3a5f850 Iustin Pop
# the Free Software Foundation; either version 2 of the License, or
9 a3a5f850 Iustin Pop
# (at your option) any later version.
10 a3a5f850 Iustin Pop
#
11 a3a5f850 Iustin Pop
# This program is distributed in the hope that it will be useful, but
12 a3a5f850 Iustin Pop
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 a3a5f850 Iustin Pop
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 a3a5f850 Iustin Pop
# General Public License for more details.
15 a3a5f850 Iustin Pop
#
16 a3a5f850 Iustin Pop
# You should have received a copy of the GNU General Public License
17 a3a5f850 Iustin Pop
# along with this program; if not, write to the Free Software
18 a3a5f850 Iustin Pop
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 a3a5f850 Iustin Pop
# 0.0510-1301, USA.
20 a3a5f850 Iustin Pop
21 a3a5f850 Iustin Pop
22 a3a5f850 Iustin Pop
"""Script for unittesting the backend module"""
23 a3a5f850 Iustin Pop
24 a3a5f850 Iustin Pop
25 a3a5f850 Iustin Pop
import os
26 a3a5f850 Iustin Pop
import unittest
27 a3a5f850 Iustin Pop
import time
28 a3a5f850 Iustin Pop
import tempfile
29 a3a5f850 Iustin Pop
import shutil
30 a3a5f850 Iustin Pop
31 a3a5f850 Iustin Pop
from ganeti import backend
32 a3a5f850 Iustin Pop
from ganeti import constants
33 a3a5f850 Iustin Pop
from ganeti import utils
34 a3a5f850 Iustin Pop
35 a3a5f850 Iustin Pop
import testutils
36 a3a5f850 Iustin Pop
37 a3a5f850 Iustin Pop
38 a3a5f850 Iustin Pop
class TestNodeVerify(testutils.GanetiTestCase):
39 a3a5f850 Iustin Pop
  def testMasterIPLocalhost(self):
40 a3a5f850 Iustin Pop
    # this a real functional test, but requires localhost to be reachable
41 a3a5f850 Iustin Pop
    local_data = (utils.HostInfo().name, constants.LOCALHOST_IP_ADDRESS)
42 a3a5f850 Iustin Pop
    result = backend.VerifyNode({constants.NV_MASTERIP: local_data}, None)
43 a3a5f850 Iustin Pop
    self.failUnless(constants.NV_MASTERIP in result,
44 a3a5f850 Iustin Pop
                    "Master IP data not returned")
45 a3a5f850 Iustin Pop
    self.failUnless(result[constants.NV_MASTERIP], "Cannot reach localhost")
46 a3a5f850 Iustin Pop
47 a3a5f850 Iustin Pop
  def testMasterIPUnreachable(self):
48 a3a5f850 Iustin Pop
    # Network 192.0.2.0/24 is reserved for test/documentation as per
49 a3a5f850 Iustin Pop
    # RFC 5735
50 a3a5f850 Iustin Pop
    bad_data =  ("master.example.com", "192.0.2.1")
51 a3a5f850 Iustin Pop
    # we just test that whatever TcpPing returns, VerifyNode returns too
52 a3a5f850 Iustin Pop
    utils.TcpPing = lambda a, b, source=None: False
53 a3a5f850 Iustin Pop
    result = backend.VerifyNode({constants.NV_MASTERIP: bad_data}, None)
54 a3a5f850 Iustin Pop
    self.failUnless(constants.NV_MASTERIP in result,
55 a3a5f850 Iustin Pop
                    "Master IP data not returned")
56 a3a5f850 Iustin Pop
    self.failIf(result[constants.NV_MASTERIP],
57 a3a5f850 Iustin Pop
                "Result from utils.TcpPing corrupted")
58 a3a5f850 Iustin Pop
59 a3a5f850 Iustin Pop
60 a3a5f850 Iustin Pop
if __name__ == "__main__":
61 a3a5f850 Iustin Pop
  testutils.GanetiTestProgram()