root / test / ganeti.hypervisor.hv_kvm_unittest.py @ 8572f1fe
History | View | Annotate | Download (4.4 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 | 748e4b5a | Michael Hanselmann | class TestWriteNetScript(unittest.TestCase): |
37 | 748e4b5a | Michael Hanselmann | def testBridged(self): |
38 | 748e4b5a | Michael Hanselmann | inst = objects.Instance(name="inst1.example.com", tags=[])
|
39 | 748e4b5a | Michael Hanselmann | nic = objects.NIC(mac="01:23:45:67:89:0A",
|
40 | 748e4b5a | Michael Hanselmann | nicparams={ |
41 | 748e4b5a | Michael Hanselmann | constants.NIC_MODE: constants.NIC_MODE_BRIDGED, |
42 | 748e4b5a | Michael Hanselmann | constants.NIC_LINK: "",
|
43 | 748e4b5a | Michael Hanselmann | }) |
44 | 748e4b5a | Michael Hanselmann | |
45 | 748e4b5a | Michael Hanselmann | script = hv_kvm._WriteNetScript(inst, nic, 0)
|
46 | 748e4b5a | Michael Hanselmann | self.assert_(isinstance(script, basestring)) |
47 | 748e4b5a | Michael Hanselmann | |
48 | 748e4b5a | Michael Hanselmann | def testBridgedWithTags(self): |
49 | 748e4b5a | Michael Hanselmann | inst = objects.Instance(name="inst1.example.com", tags=["Hello", "World"]) |
50 | 748e4b5a | Michael Hanselmann | nic = objects.NIC(mac="01:23:45:67:89:0A",
|
51 | 748e4b5a | Michael Hanselmann | nicparams={ |
52 | 748e4b5a | Michael Hanselmann | constants.NIC_MODE: constants.NIC_MODE_BRIDGED, |
53 | 748e4b5a | Michael Hanselmann | constants.NIC_LINK: "",
|
54 | 748e4b5a | Michael Hanselmann | }) |
55 | 748e4b5a | Michael Hanselmann | |
56 | 748e4b5a | Michael Hanselmann | script = hv_kvm._WriteNetScript(inst, nic, 0)
|
57 | 748e4b5a | Michael Hanselmann | self.assert_(isinstance(script, basestring)) |
58 | 748e4b5a | Michael Hanselmann | |
59 | 748e4b5a | Michael Hanselmann | def testRouted(self): |
60 | 748e4b5a | Michael Hanselmann | inst = objects.Instance(name="inst2.example.com", tags=[])
|
61 | 748e4b5a | Michael Hanselmann | nic = objects.NIC(mac="A0:98:76:54:32:10",
|
62 | 748e4b5a | Michael Hanselmann | ip="192.0.2.4",
|
63 | 748e4b5a | Michael Hanselmann | nicparams={ |
64 | 748e4b5a | Michael Hanselmann | constants.NIC_MODE: constants.NIC_MODE_ROUTED, |
65 | 748e4b5a | Michael Hanselmann | constants.NIC_LINK: "eth0",
|
66 | 748e4b5a | Michael Hanselmann | }) |
67 | 748e4b5a | Michael Hanselmann | |
68 | 748e4b5a | Michael Hanselmann | script = hv_kvm._WriteNetScript(inst, nic, 4)
|
69 | 748e4b5a | Michael Hanselmann | self.assert_(isinstance(script, basestring)) |
70 | 748e4b5a | Michael Hanselmann | |
71 | 748e4b5a | Michael Hanselmann | def testRoutedNoIpAddress(self): |
72 | 748e4b5a | Michael Hanselmann | inst = objects.Instance(name="eiphei1e.example.com", tags=[])
|
73 | 748e4b5a | Michael Hanselmann | nic = objects.NIC(mac="93:28:76:54:32:10",
|
74 | 748e4b5a | Michael Hanselmann | nicparams={ |
75 | 748e4b5a | Michael Hanselmann | constants.NIC_MODE: constants.NIC_MODE_ROUTED, |
76 | 748e4b5a | Michael Hanselmann | constants.NIC_LINK: "",
|
77 | 748e4b5a | Michael Hanselmann | }) |
78 | 748e4b5a | Michael Hanselmann | |
79 | 748e4b5a | Michael Hanselmann | self.assertRaises(errors.HypervisorError, hv_kvm._WriteNetScript,
|
80 | 748e4b5a | Michael Hanselmann | inst, nic, 2)
|
81 | 748e4b5a | Michael Hanselmann | |
82 | 748e4b5a | Michael Hanselmann | |
83 | 55cc0a44 | Michael Hanselmann | class TestConsole(unittest.TestCase): |
84 | 55cc0a44 | Michael Hanselmann | def _Test(self, instance, hvparams): |
85 | 55cc0a44 | Michael Hanselmann | cons = hv_kvm.KVMHypervisor.GetInstanceConsole(instance, hvparams, {}) |
86 | 55cc0a44 | Michael Hanselmann | self.assertTrue(cons.Validate())
|
87 | 55cc0a44 | Michael Hanselmann | return cons
|
88 | 55cc0a44 | Michael Hanselmann | |
89 | 55cc0a44 | Michael Hanselmann | def testSerial(self): |
90 | 55cc0a44 | Michael Hanselmann | instance = objects.Instance(name="kvm.example.com",
|
91 | 55cc0a44 | Michael Hanselmann | primary_node="node6017")
|
92 | 55cc0a44 | Michael Hanselmann | hvparams = { |
93 | 55cc0a44 | Michael Hanselmann | constants.HV_SERIAL_CONSOLE: True,
|
94 | 55cc0a44 | Michael Hanselmann | constants.HV_VNC_BIND_ADDRESS: None,
|
95 | 55cc0a44 | Michael Hanselmann | } |
96 | 55cc0a44 | Michael Hanselmann | cons = self._Test(instance, hvparams)
|
97 | 55cc0a44 | Michael Hanselmann | self.assertEqual(cons.kind, constants.CONS_SSH)
|
98 | 55cc0a44 | Michael Hanselmann | self.assertEqual(cons.host, instance.primary_node)
|
99 | 55cc0a44 | Michael Hanselmann | self.assertEqual(cons.command[0], constants.SOCAT_PATH) |
100 | 55cc0a44 | Michael Hanselmann | |
101 | 55cc0a44 | Michael Hanselmann | def testVnc(self): |
102 | 55cc0a44 | Michael Hanselmann | instance = objects.Instance(name="kvm.example.com",
|
103 | 55cc0a44 | Michael Hanselmann | primary_node="node7235",
|
104 | 55cc0a44 | Michael Hanselmann | network_port=constants.VNC_BASE_PORT + 10)
|
105 | 55cc0a44 | Michael Hanselmann | hvparams = { |
106 | 55cc0a44 | Michael Hanselmann | constants.HV_SERIAL_CONSOLE: False,
|
107 | 55cc0a44 | Michael Hanselmann | constants.HV_VNC_BIND_ADDRESS: "192.0.2.1",
|
108 | 55cc0a44 | Michael Hanselmann | } |
109 | 55cc0a44 | Michael Hanselmann | cons = self._Test(instance, hvparams)
|
110 | 55cc0a44 | Michael Hanselmann | self.assertEqual(cons.kind, constants.CONS_VNC)
|
111 | 55cc0a44 | Michael Hanselmann | self.assertEqual(cons.host, "192.0.2.1") |
112 | 55cc0a44 | Michael Hanselmann | self.assertEqual(cons.port, constants.VNC_BASE_PORT + 10) |
113 | 55cc0a44 | Michael Hanselmann | self.assertEqual(cons.display, 10) |
114 | 55cc0a44 | Michael Hanselmann | |
115 | 55cc0a44 | Michael Hanselmann | def testNoConsole(self): |
116 | 55cc0a44 | Michael Hanselmann | instance = objects.Instance(name="kvm.example.com",
|
117 | 55cc0a44 | Michael Hanselmann | primary_node="node24325",
|
118 | 55cc0a44 | Michael Hanselmann | network_port=0)
|
119 | 55cc0a44 | Michael Hanselmann | hvparams = { |
120 | 55cc0a44 | Michael Hanselmann | constants.HV_SERIAL_CONSOLE: False,
|
121 | 55cc0a44 | Michael Hanselmann | constants.HV_VNC_BIND_ADDRESS: None,
|
122 | 55cc0a44 | Michael Hanselmann | } |
123 | 55cc0a44 | Michael Hanselmann | cons = self._Test(instance, hvparams)
|
124 | 55cc0a44 | Michael Hanselmann | self.assertEqual(cons.kind, constants.CONS_MESSAGE)
|
125 | 55cc0a44 | Michael Hanselmann | |
126 | 55cc0a44 | Michael Hanselmann | |
127 | 748e4b5a | Michael Hanselmann | if __name__ == "__main__": |
128 | 748e4b5a | Michael Hanselmann | testutils.GanetiTestProgram() |