root / test / ganeti.hypervisor.hv_kvm_unittest.py @ 7578ab0a
History | View | Annotate | Download (2.6 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 |
|
31 |
from ganeti.hypervisor import hv_kvm |
32 |
|
33 |
import testutils |
34 |
|
35 |
|
36 |
class TestConsole(unittest.TestCase): |
37 |
def _Test(self, instance, hvparams): |
38 |
cons = hv_kvm.KVMHypervisor.GetInstanceConsole(instance, hvparams, {}) |
39 |
self.assertTrue(cons.Validate())
|
40 |
return cons
|
41 |
|
42 |
def testSerial(self): |
43 |
instance = objects.Instance(name="kvm.example.com",
|
44 |
primary_node="node6017")
|
45 |
hvparams = { |
46 |
constants.HV_SERIAL_CONSOLE: True,
|
47 |
constants.HV_VNC_BIND_ADDRESS: None,
|
48 |
} |
49 |
cons = self._Test(instance, hvparams)
|
50 |
self.assertEqual(cons.kind, constants.CONS_SSH)
|
51 |
self.assertEqual(cons.host, instance.primary_node)
|
52 |
self.assertEqual(cons.command[0], constants.SOCAT_PATH) |
53 |
|
54 |
def testVnc(self): |
55 |
instance = objects.Instance(name="kvm.example.com",
|
56 |
primary_node="node7235",
|
57 |
network_port=constants.VNC_BASE_PORT + 10)
|
58 |
hvparams = { |
59 |
constants.HV_SERIAL_CONSOLE: False,
|
60 |
constants.HV_VNC_BIND_ADDRESS: "192.0.2.1",
|
61 |
} |
62 |
cons = self._Test(instance, hvparams)
|
63 |
self.assertEqual(cons.kind, constants.CONS_VNC)
|
64 |
self.assertEqual(cons.host, "192.0.2.1") |
65 |
self.assertEqual(cons.port, constants.VNC_BASE_PORT + 10) |
66 |
self.assertEqual(cons.display, 10) |
67 |
|
68 |
def testNoConsole(self): |
69 |
instance = objects.Instance(name="kvm.example.com",
|
70 |
primary_node="node24325",
|
71 |
network_port=0)
|
72 |
hvparams = { |
73 |
constants.HV_SERIAL_CONSOLE: False,
|
74 |
constants.HV_VNC_BIND_ADDRESS: None,
|
75 |
} |
76 |
cons = self._Test(instance, hvparams)
|
77 |
self.assertEqual(cons.kind, constants.CONS_MESSAGE)
|
78 |
|
79 |
|
80 |
if __name__ == "__main__": |
81 |
testutils.GanetiTestProgram() |