4 # Copyright (C) 2010, 2011 Google Inc.
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.
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.
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
22 """Script for testing the hypervisor.hv_kvm module"""
26 from ganeti import constants
27 from ganeti import compat
28 from ganeti import objects
29 from ganeti import errors
31 from ganeti.hypervisor import hv_kvm
36 class TestConsole(unittest.TestCase):
37 def _Test(self, instance, hvparams):
38 cons = hv_kvm.KVMHypervisor.GetInstanceConsole(instance, hvparams, {})
39 self.assertTrue(cons.Validate())
43 instance = objects.Instance(name="kvm.example.com",
44 primary_node="node6017")
46 constants.HV_SERIAL_CONSOLE: True,
47 constants.HV_VNC_BIND_ADDRESS: None,
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)
55 instance = objects.Instance(name="kvm.example.com",
56 primary_node="node7235",
57 network_port=constants.VNC_BASE_PORT + 10)
59 constants.HV_SERIAL_CONSOLE: False,
60 constants.HV_VNC_BIND_ADDRESS: "192.0.2.1",
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)
68 def testNoConsole(self):
69 instance = objects.Instance(name="kvm.example.com",
70 primary_node="node24325",
73 constants.HV_SERIAL_CONSOLE: False,
74 constants.HV_VNC_BIND_ADDRESS: None,
76 cons = self._Test(instance, hvparams)
77 self.assertEqual(cons.kind, constants.CONS_MESSAGE)
80 if __name__ == "__main__":
81 testutils.GanetiTestProgram()