root / test / ganeti.hypervisor.hv_kvm_unittest.py @ 7578ab0a
History | View | Annotate | Download (2.6 kB)
1 | 748e4b5a | Michael Hanselmann | #!/usr/bin/python
|
---|---|---|---|
2 | 748e4b5a | Michael Hanselmann | #
|
3 | 748e4b5a | Michael Hanselmann | |
4 | 55cc0a44 | Michael Hanselmann | # Copyright (C) 2010, 2011 Google Inc.
|
5 | 748e4b5a | Michael Hanselmann | #
|
6 | 748e4b5a | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify
|
7 | 748e4b5a | Michael Hanselmann | # it under the terms of the GNU General Public License as published by
|
8 | 748e4b5a | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or
|
9 | 748e4b5a | Michael Hanselmann | # (at your option) any later version.
|
10 | 748e4b5a | Michael Hanselmann | #
|
11 | 748e4b5a | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but
|
12 | 748e4b5a | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 748e4b5a | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 748e4b5a | Michael Hanselmann | # General Public License for more details.
|
15 | 748e4b5a | Michael Hanselmann | #
|
16 | 748e4b5a | Michael Hanselmann | # You should have received a copy of the GNU General Public License
|
17 | 748e4b5a | Michael Hanselmann | # along with this program; if not, write to the Free Software
|
18 | 748e4b5a | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 748e4b5a | Michael Hanselmann | # 02110-1301, USA.
|
20 | 748e4b5a | Michael Hanselmann | |
21 | 748e4b5a | Michael Hanselmann | |
22 | 748e4b5a | Michael Hanselmann | """Script for testing the hypervisor.hv_kvm module"""
|
23 | 748e4b5a | Michael Hanselmann | |
24 | 748e4b5a | Michael Hanselmann | import unittest |
25 | 748e4b5a | Michael Hanselmann | |
26 | 748e4b5a | Michael Hanselmann | from ganeti import constants |
27 | 748e4b5a | Michael Hanselmann | from ganeti import compat |
28 | 748e4b5a | Michael Hanselmann | from ganeti import objects |
29 | 748e4b5a | Michael Hanselmann | from ganeti import errors |
30 | 748e4b5a | Michael Hanselmann | |
31 | 748e4b5a | Michael Hanselmann | from ganeti.hypervisor import hv_kvm |
32 | 748e4b5a | Michael Hanselmann | |
33 | 748e4b5a | Michael Hanselmann | import testutils |
34 | 748e4b5a | Michael Hanselmann | |
35 | 748e4b5a | Michael Hanselmann | |
36 | 55cc0a44 | Michael Hanselmann | class TestConsole(unittest.TestCase): |
37 | 55cc0a44 | Michael Hanselmann | def _Test(self, instance, hvparams): |
38 | 55cc0a44 | Michael Hanselmann | cons = hv_kvm.KVMHypervisor.GetInstanceConsole(instance, hvparams, {}) |
39 | 55cc0a44 | Michael Hanselmann | self.assertTrue(cons.Validate())
|
40 | 55cc0a44 | Michael Hanselmann | return cons
|
41 | 55cc0a44 | Michael Hanselmann | |
42 | 55cc0a44 | Michael Hanselmann | def testSerial(self): |
43 | 55cc0a44 | Michael Hanselmann | instance = objects.Instance(name="kvm.example.com",
|
44 | 55cc0a44 | Michael Hanselmann | primary_node="node6017")
|
45 | 55cc0a44 | Michael Hanselmann | hvparams = { |
46 | 55cc0a44 | Michael Hanselmann | constants.HV_SERIAL_CONSOLE: True,
|
47 | 55cc0a44 | Michael Hanselmann | constants.HV_VNC_BIND_ADDRESS: None,
|
48 | 55cc0a44 | Michael Hanselmann | } |
49 | 55cc0a44 | Michael Hanselmann | cons = self._Test(instance, hvparams)
|
50 | 55cc0a44 | Michael Hanselmann | self.assertEqual(cons.kind, constants.CONS_SSH)
|
51 | 55cc0a44 | Michael Hanselmann | self.assertEqual(cons.host, instance.primary_node)
|
52 | 55cc0a44 | Michael Hanselmann | self.assertEqual(cons.command[0], constants.SOCAT_PATH) |
53 | 55cc0a44 | Michael Hanselmann | |
54 | 55cc0a44 | Michael Hanselmann | def testVnc(self): |
55 | 55cc0a44 | Michael Hanselmann | instance = objects.Instance(name="kvm.example.com",
|
56 | 55cc0a44 | Michael Hanselmann | primary_node="node7235",
|
57 | 55cc0a44 | Michael Hanselmann | network_port=constants.VNC_BASE_PORT + 10)
|
58 | 55cc0a44 | Michael Hanselmann | hvparams = { |
59 | 55cc0a44 | Michael Hanselmann | constants.HV_SERIAL_CONSOLE: False,
|
60 | 55cc0a44 | Michael Hanselmann | constants.HV_VNC_BIND_ADDRESS: "192.0.2.1",
|
61 | 55cc0a44 | Michael Hanselmann | } |
62 | 55cc0a44 | Michael Hanselmann | cons = self._Test(instance, hvparams)
|
63 | 55cc0a44 | Michael Hanselmann | self.assertEqual(cons.kind, constants.CONS_VNC)
|
64 | 55cc0a44 | Michael Hanselmann | self.assertEqual(cons.host, "192.0.2.1") |
65 | 55cc0a44 | Michael Hanselmann | self.assertEqual(cons.port, constants.VNC_BASE_PORT + 10) |
66 | 55cc0a44 | Michael Hanselmann | self.assertEqual(cons.display, 10) |
67 | 55cc0a44 | Michael Hanselmann | |
68 | 55cc0a44 | Michael Hanselmann | def testNoConsole(self): |
69 | 55cc0a44 | Michael Hanselmann | instance = objects.Instance(name="kvm.example.com",
|
70 | 55cc0a44 | Michael Hanselmann | primary_node="node24325",
|
71 | 55cc0a44 | Michael Hanselmann | network_port=0)
|
72 | 55cc0a44 | Michael Hanselmann | hvparams = { |
73 | 55cc0a44 | Michael Hanselmann | constants.HV_SERIAL_CONSOLE: False,
|
74 | 55cc0a44 | Michael Hanselmann | constants.HV_VNC_BIND_ADDRESS: None,
|
75 | 55cc0a44 | Michael Hanselmann | } |
76 | 55cc0a44 | Michael Hanselmann | cons = self._Test(instance, hvparams)
|
77 | 55cc0a44 | Michael Hanselmann | self.assertEqual(cons.kind, constants.CONS_MESSAGE)
|
78 | 55cc0a44 | Michael Hanselmann | |
79 | 55cc0a44 | Michael Hanselmann | |
80 | 748e4b5a | Michael Hanselmann | if __name__ == "__main__": |
81 | 748e4b5a | Michael Hanselmann | testutils.GanetiTestProgram() |