root / test / py / ganeti.hypervisor_unittest.py @ 560ef132
History | View | Annotate | Download (2.6 kB)
1 | e695efbf | Iustin Pop | #!/usr/bin/python
|
---|---|---|---|
2 | e695efbf | Iustin Pop | #
|
3 | e695efbf | Iustin Pop | |
4 | 53fde1ac | Iustin Pop | # Copyright (C) 2010, 2013 Google Inc.
|
5 | e695efbf | Iustin Pop | #
|
6 | e695efbf | Iustin Pop | # This program is free software; you can redistribute it and/or modify
|
7 | e695efbf | Iustin Pop | # it under the terms of the GNU General Public License as published by
|
8 | e695efbf | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or
|
9 | e695efbf | Iustin Pop | # (at your option) any later version.
|
10 | e695efbf | Iustin Pop | #
|
11 | e695efbf | Iustin Pop | # This program is distributed in the hope that it will be useful, but
|
12 | e695efbf | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | e695efbf | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | e695efbf | Iustin Pop | # General Public License for more details.
|
15 | e695efbf | Iustin Pop | #
|
16 | e695efbf | Iustin Pop | # You should have received a copy of the GNU General Public License
|
17 | e695efbf | Iustin Pop | # along with this program; if not, write to the Free Software
|
18 | e695efbf | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | e695efbf | Iustin Pop | # 02110-1301, USA.
|
20 | e695efbf | Iustin Pop | |
21 | e695efbf | Iustin Pop | |
22 | e695efbf | Iustin Pop | """Script for testing hypervisor functionality"""
|
23 | e695efbf | Iustin Pop | |
24 | e695efbf | Iustin Pop | import unittest |
25 | e695efbf | Iustin Pop | |
26 | e695efbf | Iustin Pop | from ganeti import constants |
27 | e695efbf | Iustin Pop | from ganeti import compat |
28 | e695efbf | Iustin Pop | from ganeti import objects |
29 | e695efbf | Iustin Pop | from ganeti import errors |
30 | e695efbf | Iustin Pop | from ganeti import hypervisor |
31 | 53fde1ac | Iustin Pop | from ganeti.hypervisor import hv_base |
32 | e695efbf | Iustin Pop | |
33 | e695efbf | Iustin Pop | import testutils |
34 | e695efbf | Iustin Pop | |
35 | e695efbf | Iustin Pop | |
36 | e695efbf | Iustin Pop | class TestParameters(unittest.TestCase): |
37 | e695efbf | Iustin Pop | def test(self): |
38 | e695efbf | Iustin Pop | for hv, const_params in constants.HVC_DEFAULTS.items(): |
39 | e695efbf | Iustin Pop | hyp = hypervisor.GetHypervisorClass(hv) |
40 | e695efbf | Iustin Pop | for pname in const_params: |
41 | e695efbf | Iustin Pop | self.assertTrue(pname in hyp.PARAMETERS, |
42 | e695efbf | Iustin Pop | "Hypervisor %s: parameter %s defined in constants"
|
43 | e695efbf | Iustin Pop | " but not in the permitted hypervisor parameters" %
|
44 | e695efbf | Iustin Pop | (hv, pname)) |
45 | e695efbf | Iustin Pop | for pname in hyp.PARAMETERS: |
46 | e695efbf | Iustin Pop | self.assertTrue(pname in const_params, |
47 | e695efbf | Iustin Pop | "Hypervisor %s: parameter %s defined in the hypervisor"
|
48 | e695efbf | Iustin Pop | " but missing a default value" %
|
49 | e695efbf | Iustin Pop | (hv, pname)) |
50 | e695efbf | Iustin Pop | |
51 | e695efbf | Iustin Pop | |
52 | 53fde1ac | Iustin Pop | class TestBase(unittest.TestCase): |
53 | 53fde1ac | Iustin Pop | def testVerifyResults(self): |
54 | 53fde1ac | Iustin Pop | fn = hv_base.BaseHypervisor._FormatVerifyResults |
55 | 53fde1ac | Iustin Pop | # FIXME: use assertIsNone when py 2.7 is minimum supported version
|
56 | 53fde1ac | Iustin Pop | self.assertEqual(fn([]), None) |
57 | 53fde1ac | Iustin Pop | self.assertEqual(fn(["a"]), "a") |
58 | 53fde1ac | Iustin Pop | self.assertEqual(fn(["a", "b"]), "a; b") |
59 | 53fde1ac | Iustin Pop | |
60 | 902eb29f | Michele Tartara | def testGetLinuxNodeInfo(self): |
61 | 902eb29f | Michele Tartara | meminfo = testutils.TestDataFilename("proc_meminfo.txt")
|
62 | 902eb29f | Michele Tartara | cpuinfo = testutils.TestDataFilename("proc_cpuinfo.txt")
|
63 | 902eb29f | Michele Tartara | result = hv_base.BaseHypervisor.GetLinuxNodeInfo(meminfo, cpuinfo) |
64 | 902eb29f | Michele Tartara | |
65 | 902eb29f | Michele Tartara | self.assertEqual(result["memory_total"], 7686) |
66 | 902eb29f | Michele Tartara | self.assertEqual(result["memory_free"], 6272) |
67 | 902eb29f | Michele Tartara | self.assertEqual(result["memory_dom0"], 2722) |
68 | 902eb29f | Michele Tartara | self.assertEqual(result["cpu_total"], 4) |
69 | 902eb29f | Michele Tartara | self.assertEqual(result["cpu_nodes"], 1) |
70 | 902eb29f | Michele Tartara | self.assertEqual(result["cpu_sockets"], 1) |
71 | 902eb29f | Michele Tartara | |
72 | 53fde1ac | Iustin Pop | |
73 | e695efbf | Iustin Pop | if __name__ == "__main__": |
74 | e695efbf | Iustin Pop | testutils.GanetiTestProgram() |