4 # Copyright (C) 2010 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 TestWriteNetScript(unittest.TestCase):
37 def testBridged(self):
38 inst = objects.Instance(name="inst1.example.com", tags=[])
39 nic = objects.NIC(mac="01:23:45:67:89:0A",
41 constants.NIC_MODE: constants.NIC_MODE_BRIDGED,
42 constants.NIC_LINK: "",
45 script = hv_kvm._WriteNetScript(inst, nic, 0)
46 self.assert_(isinstance(script, basestring))
48 def testBridgedWithTags(self):
49 inst = objects.Instance(name="inst1.example.com", tags=["Hello", "World"])
50 nic = objects.NIC(mac="01:23:45:67:89:0A",
52 constants.NIC_MODE: constants.NIC_MODE_BRIDGED,
53 constants.NIC_LINK: "",
56 script = hv_kvm._WriteNetScript(inst, nic, 0)
57 self.assert_(isinstance(script, basestring))
60 inst = objects.Instance(name="inst2.example.com", tags=[])
61 nic = objects.NIC(mac="A0:98:76:54:32:10",
64 constants.NIC_MODE: constants.NIC_MODE_ROUTED,
65 constants.NIC_LINK: "eth0",
68 script = hv_kvm._WriteNetScript(inst, nic, 4)
69 self.assert_(isinstance(script, basestring))
71 def testRoutedNoIpAddress(self):
72 inst = objects.Instance(name="eiphei1e.example.com", tags=[])
73 nic = objects.NIC(mac="93:28:76:54:32:10",
75 constants.NIC_MODE: constants.NIC_MODE_ROUTED,
76 constants.NIC_LINK: "",
79 self.assertRaises(errors.HypervisorError, hv_kvm._WriteNetScript,
83 if __name__ == "__main__":
84 testutils.GanetiTestProgram()