~ubuntu-branches/ubuntu/raring/virtinst/raring-proposed

« back to all changes in this revision

Viewing changes to tests/nodedev.py

  • Committer: Bazaar Package Importer
  • Author(s): Guido Günther
  • Date: 2009-03-22 20:13:27 UTC
  • mto: (1.4.1 sid)
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: james.westby@ubuntu.com-20090322201327-5ch3kqxe772e23zx
Tags: upstream-0.400.3
Import upstream version 0.400.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# This program is free software; you can redistribute it and/or modify
 
3
# it under the terms of the GNU General Public License as published by
 
4
# the Free  Software Foundation; either version 2 of the License, or
 
5
# (at your option)  any later version.
 
6
#
 
7
# This program is distributed in the hope that it will be useful,
 
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
# GNU General Public License for more details.
 
11
#
 
12
# You should have received a copy of the GNU General Public License
 
13
# along with this program; if not, write to the Free Software
 
14
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
15
# MA 02110-1301 USA.
 
16
 
 
17
import tests
 
18
import os.path
 
19
import unittest
 
20
import virtinst.NodeDeviceParser as nodeparse
 
21
from virtinst import VirtualHostDevice
 
22
import libvirt
 
23
 
 
24
conn = libvirt.open("test:///default")
 
25
 
 
26
class TestNodeDev(unittest.TestCase):
 
27
 
 
28
    def _nodeDevFromFile(self, filename):
 
29
        xml = file(os.path.join("tests/nodedev-xml/nodexml", filename)).read()
 
30
        return nodeparse.parse(xml)
 
31
 
 
32
    def _testCompare(self, filename, vals):
 
33
        dev = self._nodeDevFromFile(filename)
 
34
 
 
35
        for attr in vals.keys():
 
36
            self.assertEqual(vals[attr], getattr(dev, attr))
 
37
 
 
38
    def _testNode2DeviceCompare(self, nodefile, devfile, nodedev=None):
 
39
        devfile = os.path.join("tests/nodedev-xml/devxml", devfile)
 
40
        if not nodedev:
 
41
            nodedev = self._nodeDevFromFile(nodefile)
 
42
 
 
43
        dev = VirtualHostDevice.device_from_node(conn, nodedev=nodedev)
 
44
        tests.diff_compare(dev.get_xml_config(), devfile)
 
45
 
 
46
    def testSystemDevice(self):
 
47
        filename = "system.xml"
 
48
        vals = {"hw_vendor": "LENOVO", "hw_version": "ThinkPad T61",
 
49
                "hw_serial": "L3B2616",
 
50
                "hw_uuid": "97e80381-494f-11cb-8e0e-cbc168f7d753",
 
51
                "fw_vendor": "LENOVO", "fw_version": "7LET51WW (1.21 )",
 
52
                "fw_date": "08/22/2007",
 
53
                "device_type": nodeparse.CAPABILITY_TYPE_SYSTEM,
 
54
                "name": "computer", "parent": None}
 
55
        self._testCompare(filename, vals)
 
56
 
 
57
    def testNetDevice1(self):
 
58
        filename = "net1.xml"
 
59
        vals = {"name": "net_00_1c_25_10_b1_e4", "parent": "pci_8086_1049",
 
60
                "device_type": nodeparse.CAPABILITY_TYPE_NET,
 
61
                "interface": "eth0", "address": "00:1c:25:10:b1:e4",
 
62
                "capability_type": "80203"}
 
63
        self._testCompare(filename, vals)
 
64
 
 
65
    def testNetDevice2(self):
 
66
        filename = "net2.xml"
 
67
        vals = {"name": "net_00_1c_bf_04_29_a4", "parent": "pci_8086_4227",
 
68
                "device_type": nodeparse.CAPABILITY_TYPE_NET,
 
69
                "interface": "wlan0", "address": "00:1c:bf:04:29:a4",
 
70
                "capability_type": "80211"}
 
71
        self._testCompare(filename, vals)
 
72
 
 
73
    def testPCIDevice1(self):
 
74
        filename = "pci1.xml"
 
75
        vals = {"name": "pci_1180_592", "parent": "pci_8086_2448",
 
76
                "device_type": nodeparse.CAPABILITY_TYPE_PCI,
 
77
                "domain": "0", "bus": "21", "slot": "0", "function": "4",
 
78
                "product_id": "0x0592", "vendor_id": "0x1180",
 
79
                "product_name": "R5C592 Memory Stick Bus Host Adapter",
 
80
                "vendor_name": "Ricoh Co Ltd",}
 
81
        self._testCompare(filename, vals)
 
82
 
 
83
    def testPCIDevice2(self):
 
84
        filename = "pci2.xml"
 
85
        vals = {"name": "pci_8086_1049", "parent": "computer",
 
86
                "device_type": nodeparse.CAPABILITY_TYPE_PCI,
 
87
                "domain": "0", "bus": "0", "slot": "25", "function": "0",
 
88
                "product_id": "0x1049", "vendor_id": "0x8086",
 
89
                "product_name": "82566MM Gigabit Network Connection",
 
90
                "vendor_name": "Intel Corporation",}
 
91
        self._testCompare(filename, vals)
 
92
 
 
93
    def testUSBDevDevice1(self):
 
94
        filename = "usbdev1.xml"
 
95
        vals = {"name": "usb_device_781_5151_2004453082054CA1BEEE",
 
96
                "parent": "usb_device_1d6b_2_0000_00_1a_7",
 
97
                "device_type": nodeparse.CAPABILITY_TYPE_USBDEV,
 
98
                "bus": "1", "device": "4", "product_id": '0x5151',
 
99
                "vendor_id": '0x0781',
 
100
                "vendor_name": "SanDisk Corp.",
 
101
                "product_name": "Cruzer Micro 256/512MB Flash Drive" }
 
102
        self._testCompare(filename, vals)
 
103
 
 
104
    def testUSBDevDevice2(self):
 
105
        filename = "usbdev2.xml"
 
106
        vals = {"name": "usb_device_483_2016_noserial",
 
107
                "parent": "usb_device_1d6b_1_0000_00_1a_0",
 
108
                "device_type": nodeparse.CAPABILITY_TYPE_USBDEV,
 
109
                "bus": "3", "device": "3", "product_id": '0x2016',
 
110
                "vendor_id": '0x0483',
 
111
                "vendor_name": "SGS Thomson Microelectronics",
 
112
                "product_name": "Fingerprint Reader" }
 
113
        self._testCompare(filename, vals)
 
114
 
 
115
    def testStorageDevice1(self):
 
116
        filename = "storage1.xml"
 
117
        vals = {"name": "storage_serial_SATA_WDC_WD1600AAJS__WD_WCAP95119685",
 
118
                "parent": "pci_8086_27c0_scsi_host_scsi_device_lun0",
 
119
                "device_type": nodeparse.CAPABILITY_TYPE_STORAGE,
 
120
                "block": "/dev/sda", "bus": "scsi", "drive_type": "disk",
 
121
                "model": "WDC WD1600AAJS-2", "vendor": "ATA",
 
122
                "size": 160041885696, "removable": False,
 
123
                "hotpluggable": False, "media_available": False,
 
124
                "media_size": 0}
 
125
        self._testCompare(filename, vals)
 
126
 
 
127
    def testStorageDevice2(self):
 
128
        filename = "storage2.xml"
 
129
        vals = {"name": "storage_serial_SanDisk_Cruzer_Micro_2004453082054CA1BEEE_0_0",
 
130
                "parent": "usb_device_781_5151_2004453082054CA1BEEE_if0_scsi_host_0_scsi_device_lun0",
 
131
                "device_type": nodeparse.CAPABILITY_TYPE_STORAGE,
 
132
                "block": "/dev/sdb", "bus": "usb", "drive_type": "disk",
 
133
                "model": "Cruzer Micro", "vendor": "SanDisk", "size": 0,
 
134
                "removable": True, "hotpluggable": True,
 
135
                "media_available": True, "media_size": 12345678}
 
136
        self._testCompare(filename, vals)
 
137
 
 
138
    def testUSBBus(self):
 
139
        filename = "usbbus.xml"
 
140
        vals = {"name": "usb_device_781_5151_2004453082054CA1BEEE_if0",
 
141
                "parent": "usb_device_781_5151_2004453082054CA1BEEE",
 
142
                "device_type": nodeparse.CAPABILITY_TYPE_USBBUS,
 
143
                "number": "0", "classval": "8", "subclass": "6",
 
144
                "protocol": "80"}
 
145
        self._testCompare(filename, vals)
 
146
 
 
147
    def testSCSIBus(self):
 
148
        filename = "scsibus.xml"
 
149
        vals = {"name": "usb_device_781_5151_2004453082054CA1BEEE_if0_scsi_host_0",
 
150
                "parent": "usb_device_781_5151_2004453082054CA1BEEE_if0",
 
151
                "device_type": nodeparse.CAPABILITY_TYPE_SCSIBUS,
 
152
                "host": "5"}
 
153
        self._testCompare(filename, vals)
 
154
 
 
155
    def testSCSIDevice(self):
 
156
        filename = "scsidev.xml"
 
157
        vals = {"name": "usb_device_781_5151_2004453082054CA1BEEE_if0_scsi_host_0_scsi_device_lun0",
 
158
                "parent": "usb_device_781_5151_2004453082054CA1BEEE_if0_scsi_host_0",
 
159
                "host": "5", "bus": "0", "target": "0", "lun": "0",
 
160
                "type": "disk"}
 
161
        self._testCompare(filename, vals)
 
162
 
 
163
 
 
164
        # NodeDevice 2 Device XML tests
 
165
    def testNodeDev2USB1(self):
 
166
        nodefile = "usbdev1.xml"
 
167
        devfile = "usbdev1.xml"
 
168
        self._testNode2DeviceCompare(nodefile, devfile)
 
169
 
 
170
    def testNodeDev2USB2(self):
 
171
        nodefile = "usbdev1.xml"
 
172
        devfile = "usbdev2.xml"
 
173
        nodedev = self._nodeDevFromFile(nodefile)
 
174
 
 
175
        # Force xml building to use bus, addr
 
176
        nodedev.product_id = None
 
177
        nodedev.vendor_id = None
 
178
 
 
179
        self._testNode2DeviceCompare(nodefile, devfile, nodedev=nodedev)
 
180
 
 
181
    def testNodeDev2PCI(self):
 
182
        nodefile = "pci1.xml"
 
183
        devfile = "pcidev.xml"
 
184
        self._testNode2DeviceCompare(nodefile, devfile)
 
185
 
 
186
    def testNodeDevFail(self):
 
187
        nodefile = "usbbus.xml"
 
188
        devfile = ""
 
189
 
 
190
        # This should exist, since usbbus is not a valid device to
 
191
        # pass to a guest.
 
192
        self.assertRaises(ValueError,
 
193
                          self._testNode2DeviceCompare, nodefile, devfile)
 
194
 
 
195
if __name__ == "__main__":
 
196
    unittest.main()