Statistics
| Branch: | Tag: | Revision:

root / test / py / ganeti.hypervisor_unittest.py @ 560ef132

History | View | Annotate | Download (2.6 kB)

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

    
4
# Copyright (C) 2010, 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 testing hypervisor functionality"""
23

    
24
import unittest
25

    
26
from ganeti import constants
27
from ganeti import compat
28
from ganeti import objects
29
from ganeti import errors
30
from ganeti import hypervisor
31
from ganeti.hypervisor import hv_base
32

    
33
import testutils
34

    
35

    
36
class TestParameters(unittest.TestCase):
37
  def test(self):
38
    for hv, const_params in constants.HVC_DEFAULTS.items():
39
      hyp = hypervisor.GetHypervisorClass(hv)
40
      for pname in const_params:
41
        self.assertTrue(pname in hyp.PARAMETERS,
42
                        "Hypervisor %s: parameter %s defined in constants"
43
                        " but not in the permitted hypervisor parameters" %
44
                        (hv, pname))
45
      for pname in hyp.PARAMETERS:
46
        self.assertTrue(pname in const_params,
47
                        "Hypervisor %s: parameter %s defined in the hypervisor"
48
                        " but missing a default value" %
49
                        (hv, pname))
50

    
51

    
52
class TestBase(unittest.TestCase):
53
  def testVerifyResults(self):
54
    fn = hv_base.BaseHypervisor._FormatVerifyResults
55
    # FIXME: use assertIsNone when py 2.7 is minimum supported version
56
    self.assertEqual(fn([]), None)
57
    self.assertEqual(fn(["a"]), "a")
58
    self.assertEqual(fn(["a", "b"]), "a; b")
59

    
60
  def testGetLinuxNodeInfo(self):
61
    meminfo = testutils.TestDataFilename("proc_meminfo.txt")
62
    cpuinfo = testutils.TestDataFilename("proc_cpuinfo.txt")
63
    result = hv_base.BaseHypervisor.GetLinuxNodeInfo(meminfo, cpuinfo)
64

    
65
    self.assertEqual(result["memory_total"], 7686)
66
    self.assertEqual(result["memory_free"], 6272)
67
    self.assertEqual(result["memory_dom0"], 2722)
68
    self.assertEqual(result["cpu_total"], 4)
69
    self.assertEqual(result["cpu_nodes"], 1)
70
    self.assertEqual(result["cpu_sockets"], 1)
71

    
72

    
73
if __name__ == "__main__":
74
  testutils.GanetiTestProgram()