root / test / ganeti.hypervisor.hv_kvm_unittest.py @ 585c8187
History | View | Annotate | Download (3.4 kB)
1 |
#!/usr/bin/python
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2010, 2011 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 the hypervisor.hv_kvm module"""
|
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 utils |
31 |
|
32 |
from ganeti.hypervisor import hv_kvm |
33 |
|
34 |
import testutils |
35 |
|
36 |
|
37 |
class TestConsole(unittest.TestCase): |
38 |
def _Test(self, instance, hvparams): |
39 |
cons = hv_kvm.KVMHypervisor.GetInstanceConsole(instance, hvparams, {}) |
40 |
self.assertTrue(cons.Validate())
|
41 |
return cons
|
42 |
|
43 |
def testSerial(self): |
44 |
instance = objects.Instance(name="kvm.example.com",
|
45 |
primary_node="node6017")
|
46 |
hvparams = { |
47 |
constants.HV_SERIAL_CONSOLE: True,
|
48 |
constants.HV_VNC_BIND_ADDRESS: None,
|
49 |
} |
50 |
cons = self._Test(instance, hvparams)
|
51 |
self.assertEqual(cons.kind, constants.CONS_SSH)
|
52 |
self.assertEqual(cons.host, instance.primary_node)
|
53 |
self.assertEqual(cons.command[0], constants.KVM_CONSOLE_WRAPPER) |
54 |
self.assertEqual(cons.command[1], constants.SOCAT_PATH) |
55 |
|
56 |
def testVnc(self): |
57 |
instance = objects.Instance(name="kvm.example.com",
|
58 |
primary_node="node7235",
|
59 |
network_port=constants.VNC_BASE_PORT + 10)
|
60 |
hvparams = { |
61 |
constants.HV_SERIAL_CONSOLE: False,
|
62 |
constants.HV_VNC_BIND_ADDRESS: "192.0.2.1",
|
63 |
} |
64 |
cons = self._Test(instance, hvparams)
|
65 |
self.assertEqual(cons.kind, constants.CONS_VNC)
|
66 |
self.assertEqual(cons.host, "192.0.2.1") |
67 |
self.assertEqual(cons.port, constants.VNC_BASE_PORT + 10) |
68 |
self.assertEqual(cons.display, 10) |
69 |
|
70 |
def testNoConsole(self): |
71 |
instance = objects.Instance(name="kvm.example.com",
|
72 |
primary_node="node24325",
|
73 |
network_port=0)
|
74 |
hvparams = { |
75 |
constants.HV_SERIAL_CONSOLE: False,
|
76 |
constants.HV_VNC_BIND_ADDRESS: None,
|
77 |
} |
78 |
cons = self._Test(instance, hvparams)
|
79 |
self.assertEqual(cons.kind, constants.CONS_MESSAGE)
|
80 |
|
81 |
|
82 |
class TestVersionChecking(testutils.GanetiTestCase): |
83 |
def testParseVersion(self): |
84 |
parse = hv_kvm.KVMHypervisor._ParseKVMVersion |
85 |
help_10 = utils.ReadFile(self._TestDataFilename("kvm_1.0_help.txt")) |
86 |
help_01590 = utils.ReadFile(self._TestDataFilename("kvm_0.15.90_help.txt")) |
87 |
help_0125 = utils.ReadFile(self._TestDataFilename("kvm_0.12.5_help.txt")) |
88 |
help_091 = utils.ReadFile(self._TestDataFilename("kvm_0.9.1_help.txt")) |
89 |
self.assertEqual(parse(help_10), ("1.0", 1, 0, 0)) |
90 |
self.assertEqual(parse(help_01590), ("0.15.90", 0, 15, 90)) |
91 |
self.assertEqual(parse(help_0125), ("0.12.5", 0, 12, 5)) |
92 |
self.assertEqual(parse(help_091), ("0.9.1", 0, 9, 1)) |
93 |
|
94 |
|
95 |
if __name__ == "__main__": |
96 |
testutils.GanetiTestProgram() |